sync.order.cs 610 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204
  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. namespace SiteCore.Handler
  47. {
  48. public partial class sync
  49. {
  50. public void get_erp_orderlist()
  51. {
  52. string poscode = CurrentUser.UserPost.Post.Code;
  53. DataStruct dStruct = GetPostStruct();
  54. //apiHelper.Api_SyncOrderByTime("598825");
  55. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  56. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  57. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  58. //banniuApiHelper.sendLogisticsInfo(null);
  59. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  60. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  61. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2484048723252587257");
  62. //int sid = commonHelper.autoDistributeToSupplier(entity);
  63. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  64. //tmcHelper.Api_TmcTradeMsg("{\"content\":{\"businessType\":\"GUARANTEE\",\"buyerMemo\":\"\",\"consolidateType\":\"\",\"createTime\":1744776673000,\"deliveryType\":\"OFFLINE\",\"discountFee\":15.0,\"flag\":\"YELLOW\",\"latestDeliveryTime\":1744949468000,\"lines\":[{\"mark2\":[],\"num\":1,\"outerId\":\"ALBGJ_1\",\"payment\":15.0,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i4/2233288693/O1CN01vImzW92E5Riiut2OS_!!2233288693.jpg\",\"platServiceFee\":0.0,\"price\":30.0,\"refOlId\":\"4303406414239764408\",\"refSkuId\":\"4818107244523\",\"refSpuId\":\"660415484506\",\"refundStatus\":\"REFUNDING\",\"sellPrice\":15.0,\"singleFee\":15.0,\"spuOuterId\":\"ALBGJ_1\",\"standards\":\"定制(尺寸图案logo二维码)\",\"status\":\"NOT_SHIPPED\",\"title\":\"珠宝开单卡定制玉石文玩售后服务卡片淘宝翡翠抖音直播间标签贴纸\",\"totalFee\":15.0,\"totalPrice\":30.0,\"totalSellPrice\":15.0}],\"logisticsOrderNo\":\"\",\"mark2\":[],\"modifyTime\":1744857847000,\"openBuyerId\":\"AAHZRHraABkUZRPgSx3O0f6_\",\"openBuyerNick\":\"路**\",\"openSellerNick\":\"米笛儿旗舰店\",\"orderSource\":\"SYNC\",\"orderTime\":1744776665000,\"payTime\":1744776668000,\"payment\":15.0,\"platServiceFee\":0.0,\"posCode\":\"midier\",\"posId\":598777,\"postFee\":0.0,\"props\":{\"payType\":\"ALI_PAY\",\"govSubsidyAmount\":0},\"receivedPayment\":0.0,\"receiverCity\":\"杭州市\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"萧山区\",\"receiverId\":\"b9e96393fff0e146e86ca91106043bfa$\",\"receiverState\":\"浙江省\",\"receiverTown\":\"城厢街道\",\"refOid\":\"4303406414239764408\",\"refType\":\"TMALL\",\"refundStatus\":\"PART_REFUNDED\",\"sellerMemo\":\"补差价:4303338699442764408-路飞二档\",\"serviceFee\":0.0,\"status\":\"NOT_SHIPPED\",\"totalFee\":15.0,\"totalPrice\":30.0,\"totalSellPrice\":15.0,\"type\":\"SALE\"}}");
  65. //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}}");
  66. List<string> lw = new List<string>();
  67. string tid = GetPostString("ctid");
  68. string date1 = GetPostString("date1");
  69. //12-1 修改
  70. string urgent = GetPostString("urgent");
  71. string back = GetPostString("back");
  72. string offlineSearch = GetPostString("offlineSearch");
  73. int paramsCount = 0;
  74. if (!string.IsNullOrWhiteSpace(urgent))
  75. {
  76. if (urgent.Equals("true"))
  77. {
  78. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  79. }
  80. }
  81. if (!string.IsNullOrWhiteSpace(back))
  82. {
  83. if (back.Equals("true"))
  84. {
  85. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  86. }
  87. }
  88. if (!string.IsNullOrWhiteSpace(offlineSearch))
  89. {
  90. if (offlineSearch.Equals("true"))
  91. {
  92. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  93. }
  94. }
  95. //end
  96. string date2 = GetPostString("date2");
  97. string buyernick = GetPostString("buyer_nick");
  98. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  99. {
  100. if (tid.Length <= 0 && buyernick.Length <= 0)
  101. {
  102. return;
  103. }
  104. }
  105. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  106. {
  107. if (tid.Length > 0)
  108. {
  109. string select_tid = getTidByCtid(tid);
  110. lw.Add(string.Format("tid='{0}'", select_tid));
  111. }
  112. if (buyernick.Length > 0)
  113. {
  114. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  115. }
  116. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  117. if (dw.Length > 0)
  118. {
  119. lw.Add(dw);
  120. }
  121. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  122. {
  123. string usershop = CurrentUser.User.pemShop;
  124. lw.Add(string.Format("ShopId in ({0})", usershop));
  125. }
  126. }
  127. else
  128. {
  129. if (ex_psize == 0)
  130. {
  131. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  132. }
  133. if (PKey != "admin")
  134. {
  135. string usershop = CurrentUser.User.pemShop;
  136. lw.Add(string.Format("ShopId in ({0})", usershop));
  137. paramsCount++;
  138. }
  139. }
  140. string uploaddate1 = GetPostString("uploaddate1");
  141. string uploaddate2 = GetPostString("uploaddate2");
  142. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  143. if (update.Length > 0) lw.Add(update);
  144. string deliverydate1 = GetPostString("deliverydate1");
  145. string deliverydate2 = GetPostString("deliverydate2");
  146. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  147. if (deliverydate.Length > 0)
  148. {
  149. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  150. };
  151. string shopname = GetPostString("shopname");
  152. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  153. string addwechat = GetPostString("addwechat");
  154. if (addwechat.Length > 0)
  155. {
  156. int addWt = Convert.ToInt32(addwechat);
  157. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  158. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  159. }
  160. string customer = GetPostString("customer");
  161. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  162. string design = GetPostString("design");
  163. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  164. string orderState = GetPostString("orderState");
  165. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  166. string address = GetPostString("address");
  167. 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));
  168. string sellermemo = GetPostString("seller_memo");
  169. if (sellermemo.Length > 0)
  170. {
  171. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  172. }
  173. string backReason = GetPostString("backReason");
  174. if (backReason.Length > 0)
  175. {
  176. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  177. }
  178. string apdate1 = GetPostString("apdate1");
  179. string apdate2 = GetPostString("apdate2");
  180. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  181. if (dwap.Length > 0) lw.Add(dwap);
  182. string price1 = GetPostString("price1");
  183. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  184. string price2 = GetPostString("price2");
  185. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  186. string isoldcustomer = GetPostString("isoldcus");
  187. string finishdate1 = GetPostString("finishdate1");
  188. string finishdate2 = GetPostString("finishdate2");
  189. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  190. bool isFinish = false;
  191. if (finishdate.Length > 0)
  192. {
  193. lw.Add(finishdate);
  194. isFinish = true;
  195. paramsCount++;
  196. }
  197. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  198. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  199. if (ex_psize > 0)
  200. {
  201. int UserID = CurrentUser.UserID;
  202. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  203. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  204. {
  205. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  206. }
  207. dStruct.Order = "pay_time desc";
  208. }
  209. string isNew = GetPostString("isNew");
  210. if (isNew == "true")
  211. {
  212. lw.Add(string.Format("IsNew = {0}", 1));
  213. }
  214. string overtime = GetPostString("overtime");
  215. if (overtime == "1")
  216. {
  217. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  218. }
  219. String usePost = CurrentUser.UserPost.Post.Code;
  220. if (usePost.Equals("Operation") == true)
  221. {
  222. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  223. }
  224. else
  225. {
  226. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  227. }
  228. //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";
  229. if (dStruct.PageSize == 100000)
  230. {
  231. dStruct.Order = "";
  232. }
  233. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  234. DataTable dt = null;
  235. string tablename = "view_orderlist";
  236. if (isFinish)
  237. {
  238. tablename = "view_orderlist_end";
  239. }
  240. dt = WebCache.GetData(tablename, dStruct);
  241. if (dt != null && dt.Rows.Count > 0)
  242. {
  243. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  244. foreach (DataRow dr in dt.Rows)
  245. {
  246. try
  247. {
  248. if (dr["refund_fees"] != null)
  249. {
  250. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  251. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  252. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  253. if (payment == refund_fees)
  254. {
  255. dr["refund_fees"] = Math.Round(refund_fees, 2);
  256. }
  257. else if (refund_fees == total_fee)
  258. {
  259. dr["refund_fees"] = payment;
  260. }
  261. else
  262. {
  263. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  264. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  265. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  266. }
  267. }
  268. // 对象操作
  269. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  270. ceErpTradeCell.ctid = dr["ctid"].ToString();
  271. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  272. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  273. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  274. if (dStruct.PageSize != 100000)
  275. {
  276. if (dr["DispatchSort"].ToString() == "2")
  277. {
  278. dr["gongchuang"] = 200;
  279. }
  280. else
  281. {
  282. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString());
  283. dr["gongchuang"] = response.code;
  284. }
  285. }
  286. }
  287. catch (NullReferenceException ex)
  288. {
  289. // 处理空引用异常
  290. dr["refund_fees"] = "0.00";
  291. }
  292. }
  293. }
  294. writeGridDataTableJson(dStruct.TotalCount, dt);
  295. }
  296. public void get_erp_orderlist_sumprice()
  297. {
  298. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  299. return;
  300. List<string> lw = new List<string>();
  301. string tid = GetPostString("ctid");
  302. string date1 = GetPostString("date1");
  303. string date2 = GetPostString("date2");
  304. if (tid.Length > 0 || date1.Length > 0)
  305. {
  306. lw.Add(string.Format("ctid like '%{0}%'", tid));
  307. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  308. if (dw.Length > 0) lw.Add(dw);
  309. }
  310. else
  311. {
  312. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  313. }
  314. string shopname = GetPostString("shopname");
  315. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  316. string buyernick = GetPostString("buyer_nick");
  317. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  318. string customer = GetPostString("customer");
  319. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  320. string design = GetPostString("design");
  321. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  322. string orderState = GetPostString("orderState");
  323. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  324. string address = GetPostString("address");
  325. 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));
  326. string sellermemo = GetPostString("seller_memo");
  327. if (sellermemo.Length > 0)
  328. {
  329. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  330. }
  331. string apdate1 = GetPostString("apdate1");
  332. string apdate2 = GetPostString("apdate2");
  333. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  334. if (dwap.Length > 0) lw.Add(dwap);
  335. string price1 = GetPostString("price1");
  336. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  337. string price2 = GetPostString("price2");
  338. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  339. string isoldcustomer = GetPostString("isoldcus");
  340. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  341. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  342. if (PKey != "admin")
  343. {
  344. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  345. lw.Add(string.Format("shopId in ({0})", usershop));
  346. }
  347. //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";
  348. string mainWhere = string.Join(" and ", lw.ToArray());
  349. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  350. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  351. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  352. decimal total = 0;
  353. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  354. {
  355. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  356. }
  357. var res = new
  358. {
  359. data = total
  360. };
  361. string ro_jsond = JsonConvert.SerializeObject(res);
  362. returnSuccess(ro_jsond);
  363. return;
  364. }
  365. public void get_erp_CustomerServiceGather()
  366. {
  367. string userWhere = "", orderWhere = "";
  368. List<string> lw = new List<string>();
  369. string customer = GetPostString("customer");
  370. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  371. string shopname = GetPostString("shopname");
  372. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  373. string date1 = GetPostString("date1");
  374. string date2 = GetPostString("date2");
  375. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  376. if (dw.Length > 0) lw.Add(dw);
  377. orderWhere = string.Join(" and ", lw.ToArray());
  378. 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 " +
  379. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  380. "left join " +
  381. "( " +
  382. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  383. ") as b on a.ID = b.CustomerUserId " +
  384. "left join " +
  385. "( " +
  386. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  387. ") as d on a.ID = d.CustomerUserId " +
  388. "left join " +
  389. "( " +
  390. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  391. ") as e on a.ID = e.CustomerUserId " +
  392. "left join " +
  393. "( " +
  394. " select CustomerUserId, RefundCount, RefundSum from " +
  395. " ( " +
  396. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  397. " from CE_ErpTradeRefund a " +
  398. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  399. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  400. " group by CustomerUserId " +
  401. " ) as a " +
  402. ") as f on a.ID = f.CustomerUserId " +
  403. "where a.PostCode = 'CustomerService'",
  404. userWhere, orderWhere);
  405. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  406. writeGridDataTableJson(dt.Rows.Count, dt);
  407. //writeGridDataTableJson(dt.Rows.Count, dt);
  408. }
  409. //设计汇总
  410. public void get_erp_DesignerGather()
  411. {
  412. string userWhere = "", orderWhere = "";
  413. List<string> lw = new List<string>();
  414. string Designer = GetPostString("designer");
  415. int org = GetPostInt("org");
  416. if (Designer.Length > 0)
  417. {
  418. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  419. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  420. }
  421. else if (org > 0)
  422. {
  423. userWhere = string.Format(" where OrgID ={0}", org);
  424. }
  425. string shopname = GetPostString("shopname");
  426. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  427. string state = GetPostString("state");
  428. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  429. string OrderArea = GetPostString("order_area");
  430. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  431. string date1 = GetPostString("date1");
  432. string date2 = GetPostString("date2");
  433. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  434. if (dw.Length > 0) lw.Add(dw);
  435. string UpDate1 = GetPostString("UpDate1");
  436. string UpDate2 = GetPostString("UpDate2");
  437. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  438. if (dw.Length > 0) lw.Add(dw);
  439. orderWhere = string.Join(" and ", lw.ToArray());
  440. 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 (" +
  441. "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 " +
  442. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  443. "left join " +
  444. "( " +
  445. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  446. ") as b on a.ID = b.DesignUserId " +
  447. "left join " +
  448. "( " +
  449. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  450. ") as d on a.ID = d.DesignUserId " +
  451. "left join " +
  452. "( " +
  453. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  454. ") as e on a.ID = e.DesignUserId " +
  455. "left join " +
  456. "( " +
  457. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  458. ") as g on a.ID = g.DesignUserId " +
  459. "left join " +
  460. "( " +
  461. " select CustomerUserId, RefundCount, RefundSum from " +
  462. " ( " +
  463. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  464. " from CE_ErpTradeRefund a " +
  465. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  466. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  467. " group by CustomerUserId " +
  468. " ) as a " +
  469. ") as f on a.ID = f.CustomerUserId " +
  470. "where a.PostCode = 'Designer') as z",
  471. userWhere, orderWhere);
  472. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  473. writeGridDataTableJson(dt.Rows.Count, dt);
  474. }
  475. //删除tradecell的订单
  476. public void del_erp_cellorder()
  477. {
  478. if (UrlPostParmsCheck("ctid"))
  479. {
  480. string eid = GetPostString("ctid");
  481. CeErpTradeCell.DelByCtid(eid);
  482. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  483. returnSuccessMsg("删除成功");
  484. }
  485. }
  486. public void clear_erp_refundstate()
  487. {
  488. if (UrlPostParmsCheck("ids"))
  489. {
  490. string eids = GetPostString("ids");
  491. string[] ctidList = eids.Split(',');
  492. foreach (string ctid in ctidList)
  493. {
  494. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  495. if (entity != null)
  496. {
  497. entity.IsRefund = 0;
  498. entity.Update();
  499. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  500. }
  501. else
  502. continue;
  503. }
  504. returnSuccessMsg("操作成功");
  505. return;
  506. }
  507. returnErrorMsg("缺少必要参数");
  508. }
  509. public void set_erp_urgency()
  510. {
  511. if (UrlPostParmsCheck("ctid"))
  512. {
  513. string eid = GetPostString("ctid");
  514. CeErpTradeCell entity = null;
  515. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  516. if (entity != null)
  517. {
  518. string utime = GetPostString("urgencytime");
  519. if (utime.Length > 0)
  520. {
  521. entity.UrgencyTime = Convert.ToDateTime(utime);
  522. }
  523. else
  524. {
  525. returnErrorMsg("请选择加急时间");
  526. return;
  527. }
  528. if (entity.OrderState <= 4)
  529. {
  530. //entity.seller_memo = entity.seller_memo + "-加急";
  531. string smemo = entity.seller_memo;
  532. int kindex = smemo.IndexOf(")");
  533. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  534. if (lastoneStr != "-")
  535. {
  536. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  537. }
  538. string prememo = smemo.Substring(0, kindex + 2);
  539. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  540. int lastkindex = lastmemo.IndexOf("(");
  541. DateTime urgtime = Convert.ToDateTime(utime);
  542. string newlastmemo = "";
  543. if (lastkindex == 0)
  544. {
  545. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  546. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  547. }
  548. else
  549. {
  550. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  551. }
  552. entity.seller_memo = prememo + newlastmemo;
  553. }
  554. entity.IsUrgency = true;
  555. entity.UpdateTime = DateTime.Now;
  556. entity.Update();
  557. ApiVo apiVo = new ApiVo();
  558. apiVo.orderNumber = entity.ctid;
  559. apiVo.actionName = "changeDesign";
  560. apiVo.orderRemarks = entity.seller_memo;
  561. apiVo.remarkSign = 3;
  562. designHelper.API_WorkCore(apiVo); //changeDesign
  563. CeErpSukuraData.createInfo(entity.ctid, 7);
  564. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  565. returnSuccessMsg("设置成功!");
  566. return;
  567. }
  568. returnErrorMsg("找不到记录");
  569. }
  570. }
  571. public void set_erp_reset()
  572. {
  573. if (UrlPostParmsCheck("ctid"))
  574. {
  575. string eid = GetPostString("ctid");
  576. CeErpTradeCell entity = null;
  577. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  578. if (entity != null)
  579. {
  580. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  581. {
  582. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  583. {
  584. returnErrorMsg("财务要求已下单已发货无法重置");
  585. return;
  586. }
  587. }
  588. entity.IsUrgency = false;
  589. entity.seller_memo = "";
  590. entity.OtherMemo = "";
  591. entity.OrderState = 0;
  592. entity.IsReturn = 0;
  593. //entity.IsRefund = 0;
  594. entity.MemoOpt = 0;
  595. entity.AfterSaleState = 0;
  596. entity.AfterSaleResponsible = "";
  597. entity.AfterSaleUserId = 0;
  598. entity.IsNeedBill = 0;
  599. entity.CustomerUserId = 0;
  600. entity.DesignUserId = 0;
  601. entity.SupplierId = 0;
  602. entity.PlaceUserId = 0;
  603. entity.ptid = "";
  604. entity.IsSample = 0;
  605. entity.IsXianHuo = 0;
  606. entity.isDianziOrder = 0;
  607. entity.DispatchSort = 0;
  608. entity.FinishPlaceTime = null;
  609. entity.Update();
  610. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  611. if (trade != null)
  612. {
  613. trade.seller_memo = "";
  614. trade.Update();
  615. }
  616. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  617. returnSuccessMsg("重置成功!");
  618. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  619. if (desginBill != null)
  620. {
  621. desginBill.isDel = 1;
  622. desginBill.Update();
  623. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  624. }
  625. ApiVo apiVo = new ApiVo();
  626. apiVo.orderNumber = entity.ctid;
  627. apiVo.actionName = "resetDesign";
  628. designHelper.API_WorkCore(apiVo);//resetDesign
  629. return;
  630. }
  631. returnErrorMsg("找不到记录");
  632. }
  633. }
  634. public void save_erp_sellermemo()
  635. {
  636. if (UrlPostParmsCheck("ctid"))
  637. {
  638. string ctid = GetPostString("ctid");
  639. CeErpTradeCell entity = null;
  640. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  641. if (entity != null)
  642. {
  643. string memo = GetPostString("seller_memo");
  644. memo = memo.Replace(" ", "");
  645. if (memo.Contains("补差"))
  646. {
  647. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  648. return;
  649. }
  650. if (entity.seller_memo != memo)
  651. {
  652. if (entity.IsSample == 2)
  653. {
  654. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  655. return;
  656. }
  657. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  658. {
  659. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  660. {
  661. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  662. return;
  663. }
  664. }
  665. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  666. }
  667. commonHelper.getCytPrice(entity);
  668. int memoopt = GetPostInt("MemoOpt");
  669. Boolean ismemoopt = false;
  670. if (memoopt > 0)
  671. {
  672. string stropt = "";
  673. if (memoopt == 1)
  674. {
  675. stropt = "“改稿”";
  676. ismemoopt = true;
  677. }
  678. else if (memoopt == 2)
  679. {
  680. stropt = "“定稿”";
  681. }
  682. else if (memoopt == 3)
  683. {
  684. stropt = "“查货”";
  685. CeErpSukuraData.createInfo(entity.ctid, 6);
  686. }
  687. entity.MemoOpt = Convert.ToInt32(memoopt);
  688. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  689. }
  690. if (entity.OrderState < 5)
  691. {
  692. memo = memo.Replace("(", "(");
  693. memo = memo.Replace(")", ")");
  694. }
  695. entity.seller_memo = memo;
  696. entity.UpdateTime = DateTime.Now;
  697. entity.Update();
  698. ApiVo apiVo = new ApiVo();
  699. apiVo.orderNumber = entity.ctid;
  700. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  701. apiVo.orderRemarks = memo;
  702. apiVo.remarkSign = memoopt;
  703. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  704. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  705. returnSuccessMsg("保存成功!");
  706. return;
  707. }
  708. returnErrorMsg("找不到记录");
  709. }
  710. }
  711. public void ins_erp_checkorder()
  712. {
  713. if (UrlPostParmsCheck("ctid"))
  714. {
  715. string ctid = GetPostString("ctid");
  716. CeErpTradeCell entity = null;
  717. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  718. if (entity != null)
  719. {
  720. if (entity.OrderState < 6)
  721. {
  722. returnErrorMsg("下单完成后才可查货");
  723. return;
  724. }
  725. /*if (entity.OrderState > 6)
  726. {
  727. returnErrorMsg("订单已发货");
  728. return;
  729. }*/
  730. if (entity.FinishPlaceTime != null)
  731. {
  732. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  733. {
  734. returnErrorMsg("下单时间不足,无法查货");
  735. return;
  736. }
  737. }
  738. entity.MemoOpt = 3;
  739. entity.CheckOrderTime = DateTime.Now;
  740. entity.UpdateTime = DateTime.Now;
  741. entity.Update();
  742. CeErpSukuraData.createInfo(entity.ctid, 6);
  743. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  744. returnSuccessMsg("操作成功!");
  745. return;
  746. }
  747. returnErrorMsg("找不到记录");
  748. }
  749. }
  750. public void save_erp_othermemo()
  751. {
  752. if (UrlPostParmsCheck("ctid"))
  753. {
  754. string ctid = GetPostString("ctid");
  755. CeErpTradeCell entity = null;
  756. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  757. if (entity != null)
  758. {
  759. entity.OtherMemo = GetPostString("otherMemo");
  760. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  761. {
  762. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  763. StringBuilder sql = new StringBuilder();
  764. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  765. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  766. if (dt != null && dt.Rows.Count > 0)
  767. {
  768. foreach (DataRow dr in dt.Rows)
  769. {
  770. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  771. {
  772. //品类一直
  773. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  774. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  775. if (ceErpSampleCustomer == null)
  776. {
  777. ceErpSampleCustomer = new CeErpSampleCustomer();
  778. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  779. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  780. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  781. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  782. ceErpSampleCustomer.shopId = entity.ShopId;
  783. }
  784. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  785. ceErpSampleCustomer.lastTid = entity.tid;
  786. if (ceErpSampleCustomer.ID > 0)
  787. {
  788. ceErpSampleCustomer.Update();
  789. }
  790. else
  791. {
  792. ceErpSampleCustomer.Create();
  793. }
  794. }
  795. }
  796. }
  797. }
  798. //if (entity.IsOldCustomer == 1)
  799. //{
  800. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  801. //{
  802. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  803. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  804. //}
  805. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  806. //{
  807. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  808. // {
  809. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  810. // {
  811. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  812. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  813. // }
  814. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  815. // {
  816. // entity.OrderState = 2;
  817. // entity.DesignUserId = 0;
  818. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  819. // }
  820. // else
  821. // {
  822. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  823. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  824. // }
  825. // }
  826. //}
  827. //}
  828. entity.Update();
  829. returnSuccessMsg("保存成功!");
  830. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  831. return;
  832. }
  833. returnErrorMsg("找不到记录");
  834. }
  835. }
  836. public void save_erp_customermemo()
  837. {
  838. if (UrlPostParmsCheck("ctid"))
  839. {
  840. string ctid = GetPostString("ctid");
  841. CeErpTradeCell entity = null;
  842. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  843. if (entity != null)
  844. {
  845. entity.CustomerMemo = GetPostString("CustomerMemo");
  846. entity.Update();
  847. ApiVo apiVo = new ApiVo();
  848. apiVo.orderNumber = entity.ctid;
  849. apiVo.actionName = "followRemarks";
  850. apiVo.orderRemarks = entity.CustomerMemo;
  851. designHelper.API_WorkCore(apiVo);//followRemarks
  852. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  853. returnSuccessMsg("保存成功!");
  854. return;
  855. }
  856. returnErrorMsg("找不到记录");
  857. }
  858. }
  859. public void upd_erp_addmemotag()
  860. {
  861. if (UrlPostParmsCheck("ctid"))
  862. {
  863. ;
  864. string eid = GetPostString("ctid");
  865. string sfTagstr = GetPostString("memotag");
  866. CeErpTradeCell entity = null;
  867. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  868. if (entity != null)
  869. {
  870. ApiVo apiVo = new ApiVo();
  871. if (entity.OrderState == 0)
  872. {
  873. returnErrorMsg("请先领单");
  874. return;
  875. }
  876. //撤销顺丰
  877. if (sfTagstr == "撤销顺丰")
  878. {
  879. entity.IsSF = 0;
  880. string reMsg = "";
  881. string oldmemo = entity.seller_memo;
  882. if (entity.OrderState < 5)
  883. {
  884. oldmemo = oldmemo.Replace("顺丰到付", "");
  885. oldmemo = oldmemo.Replace("顺丰寄付", "");
  886. entity.seller_memo = oldmemo;
  887. }
  888. else
  889. {
  890. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  891. {
  892. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  893. }
  894. }
  895. entity.Update();
  896. apiVo.orderNumber = entity.ctid;
  897. apiVo.actionName = "orderRemarks";
  898. apiVo.orderRemarks = entity.seller_memo;
  899. apiVo.isSf = entity.IsSF.ToString();
  900. designHelper.API_WorkCore(apiVo);//orderRemarks
  901. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  902. returnSuccessMsg("撤销成功!" + reMsg);
  903. return;
  904. }
  905. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  906. {
  907. //string oldmemo = entity.seller_memo;
  908. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  909. string sfStr = GetPostString("memotag");
  910. string smemo = entity.seller_memo;
  911. int kindex = smemo.IndexOf(")");
  912. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  913. if (lastoneStr != "-")
  914. {
  915. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  916. }
  917. string prememo = smemo.Substring(0, kindex + 2);
  918. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  919. int lastkindex = lastmemo.IndexOf("(");
  920. string newlastmemo = "";
  921. if (lastkindex == 0)
  922. {
  923. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  924. newlastmemo = "(" + sfStr + "." + useLastmemo;
  925. }
  926. else
  927. {
  928. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  929. }
  930. entity.seller_memo = prememo + newlastmemo;
  931. }
  932. string sfTagMSg = "";
  933. if (sfTagstr == "顺丰寄付")
  934. {
  935. entity.IsSF = 1;
  936. sfTagMSg = "顺丰寄付";
  937. }
  938. else if (sfTagstr == "顺丰到付")
  939. {
  940. entity.IsSF = 2;
  941. sfTagMSg = "顺丰到付";
  942. }
  943. entity.Update();
  944. apiVo = new ApiVo();
  945. apiVo.orderNumber = entity.ctid;
  946. apiVo.actionName = "orderRemarks";
  947. apiVo.orderRemarks = entity.seller_memo;
  948. apiVo.isSf = entity.IsSF.ToString();
  949. designHelper.API_WorkCore(apiVo);//orderRemarks
  950. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  951. returnSuccessMsg("标记成功!");
  952. return;
  953. }
  954. returnErrorMsg("找不到记录");
  955. }
  956. }
  957. public void upd_erp_ordertag()
  958. {
  959. if (UrlPostParmsCheck("ctid"))
  960. {
  961. string eid = GetPostString("ctid");
  962. CeErpTradeCell entity = null;
  963. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  964. if (entity != null)
  965. {
  966. int tag = GetPostInt("wechattag");
  967. //if(tag==4 && entity.IsSample == 2)
  968. //{
  969. // returnErrorMsg("补差价单不能标记微信单");
  970. // return;
  971. //}
  972. entity.wechatTag = tag;
  973. entity.Update();
  974. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  975. if (tag == 1)
  976. {
  977. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  978. if (cash == null)
  979. {
  980. CeErpTrade main = CeErpTrade.Get(entity.tid);
  981. cash = new CeErpReturnCash();
  982. cash.tid = entity.tid;
  983. cash.seller_nick = main.seller_nick;
  984. cash.payment = trade.payment;
  985. cash.buyer_nick = main.buyer_nick;
  986. cash.cashstate = 0;
  987. cash.rtype = "微信返现";
  988. cash.returnprice = 0;
  989. cash.created = DateTime.Now;
  990. cash.con = "订单标记微信单";
  991. cash.img = "";
  992. cash.applyuserid = CurrentUser.UserID;
  993. cash.Create();
  994. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  995. }
  996. else
  997. {
  998. cash.cashstate = 0;
  999. cash.Update();
  1000. }
  1001. CeErpSukuraData.createInfo(entity.ctid, 9);
  1002. }
  1003. else if (tag == 2)
  1004. {
  1005. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1006. if (cash == null)
  1007. {
  1008. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1009. cash = new CeErpReturnCash();
  1010. cash.tid = entity.tid;
  1011. cash.seller_nick = main.seller_nick;
  1012. cash.payment = trade.payment;
  1013. cash.buyer_nick = main.buyer_nick;
  1014. cash.cashstate = 0;
  1015. cash.rtype = "推购返现";
  1016. cash.returnprice = 5;
  1017. cash.created = DateTime.Now;
  1018. cash.con = "订单标记推购单";
  1019. cash.img = "";
  1020. cash.applyuserid = CurrentUser.UserID;
  1021. cash.Create();
  1022. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1023. }
  1024. else
  1025. {
  1026. cash.cashstate = 0;
  1027. cash.Update();
  1028. }
  1029. CeErpSukuraData.createInfo(entity.ctid, 9);
  1030. }
  1031. else if (tag == 3)
  1032. {
  1033. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1034. if (pers == null)
  1035. {
  1036. pers = new CeErpPersuade();
  1037. pers.ctid = entity.ctid;
  1038. pers.pstate = 0;
  1039. pers.created = DateTime.Now;
  1040. pers.applyuserid = CurrentUser.UserID;
  1041. pers.Create();
  1042. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1043. }
  1044. else
  1045. {
  1046. pers.pstate = 0;
  1047. pers.Update();
  1048. }
  1049. }
  1050. else if (tag == 4 || tag == 5)
  1051. {
  1052. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1053. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1054. if (pers == null)
  1055. {
  1056. pers = new CeErpStayGoods();
  1057. pers.t_id = entity.tid;
  1058. pers.status = "待审核";
  1059. pers.audit_type = 0;
  1060. if (tag == 4)
  1061. {
  1062. pers.stay_type = "微信推购";
  1063. }
  1064. else
  1065. {
  1066. pers.stay_type = "旺旺推购";
  1067. }
  1068. if (entity.IsXianHuo == 0)
  1069. {
  1070. pers.product_id = entity.ProductId;
  1071. }
  1072. pers.wangwang = main.buyer_nick;
  1073. pers.shop_name = main.seller_nick;
  1074. pers.creata_time = DateTime.Now;
  1075. pers.create_u_id = CurrentUser.UserID;
  1076. pers.create_u_name = CurrentUser.UserName;
  1077. pers.Create();
  1078. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1079. }
  1080. else
  1081. {
  1082. pers.audit_type = 0;
  1083. pers.Update();
  1084. }
  1085. CeErpSukuraData.createInfo(entity.ctid, 10);
  1086. }
  1087. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1088. returnSuccessMsg("标记成功!");
  1089. return;
  1090. }
  1091. returnErrorMsg("找不到记录");
  1092. }
  1093. }
  1094. public void upd_erp_ordertag_cancel()
  1095. {
  1096. if (UrlPostParmsCheck("ctid"))
  1097. {
  1098. string eid = GetPostString("ctid");
  1099. CeErpTradeCell entity = null;
  1100. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1101. if (entity != null)
  1102. {
  1103. entity.wechatTag = 0;
  1104. entity.Update();
  1105. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1106. if (pers != null)
  1107. {
  1108. pers.status = "取消推购";
  1109. pers.audit_type = 3;
  1110. pers.Update();
  1111. }
  1112. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1113. returnSuccessMsg("标记成功!");
  1114. return;
  1115. }
  1116. returnErrorMsg("找不到记录");
  1117. }
  1118. }
  1119. public void upd_erp_addweichattag()
  1120. {
  1121. if (UrlPostParmsCheck("ctid"))
  1122. {
  1123. ;
  1124. string eid = GetPostString("ctid");
  1125. CeErpTradeCell entity = null;
  1126. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1127. if (entity != null)
  1128. {
  1129. if (entity.IsAddWechat > 0)
  1130. {
  1131. returnErrorMsg("此单已经标记过了");
  1132. return;
  1133. }
  1134. 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);
  1135. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1136. if (dt.Rows.Count > 0)
  1137. {
  1138. entity.IsAddWechat = 2;
  1139. }
  1140. else
  1141. {
  1142. entity.IsAddWechat = 1;
  1143. }
  1144. entity.Update();
  1145. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1146. returnSuccessMsg("标记成功!");
  1147. return;
  1148. }
  1149. returnErrorMsg("找不到记录");
  1150. }
  1151. }
  1152. public void upd_erp_getmyorder()
  1153. {
  1154. if (UrlPostParmsCheck("ctid"))
  1155. {
  1156. ;
  1157. string eid = GetPostString("ctid");
  1158. CeErpTradeCell entity = null;
  1159. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1160. if (entity != null)
  1161. {
  1162. if (entity.ctid.IndexOf("C") != -1)
  1163. {
  1164. StringBuilder sql = new StringBuilder();
  1165. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1166. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1167. if (dt.Rows.Count > 0)
  1168. {
  1169. decimal total = 0;
  1170. foreach (DataRow dr in dt.Rows)
  1171. {
  1172. total += Convert.ToDecimal(dr["payment"]);
  1173. }
  1174. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1175. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1176. {
  1177. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1178. return;
  1179. }
  1180. }
  1181. }
  1182. if (entity.OrderState == -1)
  1183. {
  1184. returnErrorMsg("待审核订单无法领取!");
  1185. return;
  1186. }
  1187. entity.CustomerUserId = CurrentUser.UserID;
  1188. if (entity.OrderState < 2)
  1189. {
  1190. entity.OrderState = 2;
  1191. if (entity.ShopId != 0)
  1192. {
  1193. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1194. }
  1195. }
  1196. entity.UpdateTime = DateTime.Now;
  1197. entity.Update();
  1198. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1199. returnSuccessMsg("领单成功!");
  1200. return;
  1201. }
  1202. returnErrorMsg("找不到记录");
  1203. }
  1204. }
  1205. public void getmyorder_from_init()
  1206. {
  1207. if (UrlPostParmsCheck("ctid"))
  1208. {
  1209. string eid = GetPostString("ctid");
  1210. CeErpTradeCell entity = null;
  1211. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1212. if (entity != null)
  1213. {
  1214. string sellerMemo = GetPostString("sellerMemo");
  1215. if (sellerMemo.Length > 0)
  1216. {
  1217. entity.seller_memo = sellerMemo;
  1218. }
  1219. string oterhMemo = GetPostString("otherMemo");
  1220. if (oterhMemo.Length > 0)
  1221. {
  1222. entity.OtherMemo = oterhMemo;
  1223. }
  1224. int urg = GetPostInt("urgency");
  1225. entity.IsUrgency = (urg == 1 ? true : false);
  1226. int wechat = GetPostInt("wechat");
  1227. int command = GetPostInt("command");
  1228. if (wechat == 1)
  1229. {
  1230. entity.wechatTag = 1;
  1231. }
  1232. if (command == 1)
  1233. {
  1234. entity.wechatTag = 2;
  1235. }
  1236. string pPro = GetPostString("pprofession");
  1237. if (pPro.Length > 0)
  1238. {
  1239. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1240. string spro = GetPostString("profession");
  1241. if (spro.Length > 0)
  1242. {
  1243. entity.ProfessionId = Convert.ToInt32(spro);
  1244. }
  1245. }
  1246. string proId = GetPostString("productId");
  1247. if (proId.Length > 0)
  1248. {
  1249. entity.ProductId = Convert.ToInt32(proId);
  1250. }
  1251. entity.Material = GetPostString("material");
  1252. entity.Craft = GetPostString("craft");
  1253. entity.CustomerUserId = CurrentUser.UserID;
  1254. if (entity.OrderState < 2)
  1255. {
  1256. entity.OrderState = 2;
  1257. if (entity.ShopId != 0)
  1258. {
  1259. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1260. }
  1261. }
  1262. entity.Update();
  1263. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1264. returnSuccessMsg("领单成功!");
  1265. return;
  1266. }
  1267. returnErrorMsg("找不到记录");
  1268. }
  1269. }
  1270. public void upd_erp_setrelationorder()
  1271. {
  1272. if (UrlPostParmsCheck("ctid"))
  1273. {
  1274. ;
  1275. string eid = GetPostString("ctid");
  1276. string ftid = GetPostString("ftid");
  1277. CeErpTradeCell entity = null;
  1278. CeErpTradeCell fentity = null;
  1279. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1280. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1281. if (fentity == null)
  1282. {
  1283. returnErrorMsg("找不到关联的主订单");
  1284. return;
  1285. }
  1286. if (entity != null)
  1287. {
  1288. if (entity.OrderState >= 5)
  1289. {
  1290. returnErrorMsg("本单已经设计完成无法关联");
  1291. return;
  1292. }
  1293. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1294. {
  1295. returnErrorMsg("线下单续审核后才能关联!");
  1296. return;
  1297. }
  1298. entity.ptid = ftid;
  1299. entity.OrderState = fentity.OrderState;
  1300. //entity.status = fentity.status;
  1301. entity.CustomerUserId = fentity.CustomerUserId;
  1302. entity.DesignUserId = fentity.DesignUserId;
  1303. entity.seller_memo = "补差价单:" + ftid;
  1304. entity.IsSample = 2;
  1305. entity.Update();
  1306. ApiVo apiVo = new ApiVo();
  1307. apiVo.orderNumber = ftid;
  1308. apiVo.payment = entity.payment;
  1309. apiVo.actionName = "repairDesign";
  1310. designHelper.API_WorkCore(apiVo);//repairDesign
  1311. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1312. returnSuccessMsg("关联成功!");
  1313. return;
  1314. }
  1315. else
  1316. returnErrorMsg("找不到记录");
  1317. }
  1318. }
  1319. public void download_erp_neworder()
  1320. {
  1321. string seller = GetPostString("seller_nick");
  1322. string tid = GetPostString("tid");
  1323. if (seller.Length <= 0 || tid.Length <= 0)
  1324. {
  1325. returnErrorMsg("数据错误");
  1326. }
  1327. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1328. //{
  1329. // returnErrorMsg("找不到店铺Sessionkey");
  1330. //}
  1331. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1332. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1333. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1334. if (res.IndexOf("refOid") == -1)
  1335. {
  1336. returnErrorMsg("下载订单数据失败");
  1337. return;
  1338. }
  1339. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1340. returnSuccessMsg("下载完成");
  1341. //tmcHelper.createNewOrder(res);
  1342. //CeErpTrade entr = null;
  1343. //entr = CeErpTrade.Get(tid);
  1344. //if (entr != null)
  1345. //{
  1346. // returnSuccess("下载成功");
  1347. // //下载成功之后,Cell表生成对应的订单;
  1348. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1349. //}
  1350. //else
  1351. //{
  1352. // returnErrorMsg("下载失败或者创建订单失败");
  1353. //}
  1354. }
  1355. public void set_erp_atersale()
  1356. {
  1357. if (UrlPostParmsCheck("ctid"))
  1358. {
  1359. string eid = GetPostString("ctid");
  1360. string reason = GetPostString("AfterSaleReason");
  1361. CeErpTradeCell entity = null;
  1362. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1363. if (entity != null)
  1364. {
  1365. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1366. {
  1367. returnErrorMsg("此订单已经在售后");
  1368. return;
  1369. }
  1370. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1371. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1372. entity.AfterSaleTime = DateTime.Now;
  1373. entity.Update();
  1374. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1375. returnSuccessMsg("转售后成功!");
  1376. return;
  1377. }
  1378. returnErrorMsg("找不到记录");
  1379. }
  1380. }
  1381. public void set_erp_withdraw()
  1382. {
  1383. if (UrlPostParmsCheck("ctid"))
  1384. {
  1385. try
  1386. {
  1387. string eid = GetPostString("ctid");//商品id
  1388. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1389. CeWithdraw ceWithdrawSelect = null;
  1390. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1391. if (ceWithdrawSelect != null)
  1392. {
  1393. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1394. {
  1395. ceWithdrawSelect.status = -1;
  1396. ceWithdrawSelect.Update();
  1397. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1398. returnSuccessMsg("重新发起审核成功");
  1399. return;
  1400. }
  1401. else
  1402. {
  1403. returnSuccessMsg("请勿重复申请!");
  1404. return;
  1405. }
  1406. }
  1407. else
  1408. {
  1409. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1410. if (string.IsNullOrEmpty(CustomerUserId))
  1411. {
  1412. CustomerUserId = "-1";
  1413. }
  1414. int Userid = CurrentUser.UserID;//用户id
  1415. CeWithdraw ceWithdraw = new CeWithdraw();
  1416. ceWithdraw.tid = eid;
  1417. ceWithdraw.userid = Userid;
  1418. ceWithdraw.providerid = CustomerUserId;
  1419. ceWithdraw.status = 3;
  1420. ceWithdraw.creationtime = DateTime.Now;
  1421. ceWithdraw.Create();
  1422. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1423. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1424. return;
  1425. }
  1426. }
  1427. catch
  1428. {
  1429. returnErrorMsg("申请撤回订单失败");
  1430. return;
  1431. }
  1432. }
  1433. }
  1434. public void ins_erp_billinfo()
  1435. {
  1436. if (UrlPostParmsCheck("ctid"))
  1437. {
  1438. string eid = GetPostString("ctid");
  1439. CeErpTradeCell entity = null;
  1440. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1441. if (entity != null)
  1442. {
  1443. CeErpBill bill = CeErpBill.GetByTid(eid);
  1444. bool isHave = false;
  1445. if (bill != null)
  1446. {
  1447. isHave = true;
  1448. if (bill.state != 4)
  1449. {
  1450. returnErrorMsg("此单已经申请过发票了");
  1451. return;
  1452. }
  1453. }
  1454. if (entity.IsNeedBill == 0)
  1455. {
  1456. entity.IsNeedBill = 1;
  1457. }
  1458. entity.Update();
  1459. string errjson = "";
  1460. try
  1461. {
  1462. CeErpBill bill_entity = new CeErpBill();
  1463. bill_entity.tid = entity.tid;
  1464. bill_entity.title = GetPostString("title");
  1465. string taxstr = GetPostString("tax");
  1466. taxstr = taxstr.Replace(" ", "");
  1467. bill_entity.tax = taxstr;
  1468. bill_entity.bank = GetPostString("bank");
  1469. string bankacstr = GetPostString("bankac");
  1470. bankacstr = bankacstr.Replace(" ", "");
  1471. bill_entity.bankac = bankacstr;
  1472. bill_entity.address = GetPostString("address");
  1473. bill_entity.phone = GetPostString("phone");
  1474. bill_entity.price = GetPostString("price");
  1475. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1476. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1477. {
  1478. billCount += 1;
  1479. }
  1480. string prebill = "ltb";
  1481. for (int idx = 1; idx <= billCount; idx++)
  1482. {
  1483. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1484. string billoid = prebill + idx + dtstr;
  1485. bill_entity.billOrderId += billoid;
  1486. if (idx < billCount)
  1487. {
  1488. bill_entity.billOrderId += ",";
  1489. }
  1490. }
  1491. bill_entity.productId = GetPostInt("ProductName");
  1492. bill_entity.num = GetPostInt("num");
  1493. bill_entity.unit = GetPostString("unit");
  1494. bill_entity.type = GetPostString("type");
  1495. bill_entity.sendType = GetPostString("SendType");
  1496. bill_entity.email = GetPostString("email");
  1497. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1498. bill_entity.shopName = GetPostString("ShopName");
  1499. bill_entity.applymemo = GetPostString("applyMemo");
  1500. bill_entity.createTime = DateTime.Now;
  1501. bill_entity.state = 0;
  1502. bill_entity.userId = CurrentUser.UserID;
  1503. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1504. bill_entity.Create();
  1505. }
  1506. catch (Exception ex)
  1507. {
  1508. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1509. returnErrorMsg("创建发票出错!");
  1510. return;
  1511. }
  1512. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1513. returnSuccessMsg("发票申请成功!");
  1514. return;
  1515. }
  1516. returnErrorMsg("找不到记录");
  1517. }
  1518. }
  1519. public void ins_erp_neworder()
  1520. {
  1521. if (UrlPostParmsCheck("receiver_name"))
  1522. {
  1523. CeErpTrade entity = new CeErpTrade();
  1524. string plat_form = GetPostString("platform");
  1525. string preStr = "N_";
  1526. if (plat_form == "拼多多")
  1527. {
  1528. preStr = "P_";
  1529. }
  1530. else if (plat_form == "阿里巴巴")
  1531. {
  1532. preStr = "A_";
  1533. }
  1534. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1535. entity.seller_nick = GetPostString("seller_nick");
  1536. entity.buyer_nick = GetPostString("buyer_nick");
  1537. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1538. entity.total_fee = entity.payment;
  1539. entity.pay_time = DateTime.Now;
  1540. entity.status = "NOT_SHIPPED";
  1541. entity.receiver_name = GetPostString("receiver_name");
  1542. entity.receiver_mobile = GetPostString("receiver_mobile");
  1543. entity.receiver_state = GetPostString("receiver_state");
  1544. entity.receiver_city = GetPostString("receiver_city");
  1545. entity.receiver_district = GetPostString("receiver_district");
  1546. entity.receiver_address = GetPostString("receiver_address");
  1547. if (entity.receiver_state == "" || entity.receiver_city == "")
  1548. {
  1549. returnErrorMsg("收件地址不能为空");
  1550. return;
  1551. }
  1552. int shopId = 0;
  1553. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1554. if (nShop != null)
  1555. {
  1556. shopId = nShop.ID;
  1557. }
  1558. if (shopId != 34 && entity.payment == 0)
  1559. {
  1560. returnErrorMsg("公司自用的单金额才能为0");
  1561. return;
  1562. }
  1563. entity.Create();
  1564. CeErpTradeCell entitycell = new CeErpTradeCell();
  1565. entitycell.ctid = entity.tid;
  1566. entitycell.tid = entity.tid;
  1567. entitycell.ShopId = shopId;
  1568. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1569. entitycell.OrderState = 0;
  1570. entitycell.pay_time = entity.pay_time;
  1571. entitycell.IsOffLineOrder = 1;
  1572. entitycell.Create();
  1573. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1574. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1575. return;
  1576. }
  1577. }
  1578. public void ins_erp_neworder2()
  1579. {
  1580. if (UrlPostParmsCheck("receiver_name"))
  1581. {
  1582. //string plat_form = GetPostString("platform");
  1583. string preStr = "X_";
  1584. string memo = GetPostString("memo");
  1585. string productId = GetPostString("productId");
  1586. string primg = GetPostString("proofimg");
  1587. string sellerNick = GetPostString("seller_nick");
  1588. string addFrom = GetPostString("addfrom");
  1589. if (addFrom == "1")
  1590. {
  1591. preStr = "N_";
  1592. }
  1593. int shopId = 0;
  1594. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1595. if (nShop != null)
  1596. {
  1597. shopId = nShop.ID;
  1598. }
  1599. else
  1600. {
  1601. returnErrorMsg("找不到对应店铺");
  1602. return;
  1603. }
  1604. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1605. {
  1606. returnErrorMsg("必须上传付款凭证");
  1607. return;
  1608. }
  1609. CeErpTrade entity = new CeErpTrade();
  1610. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1611. entity.seller_nick = sellerNick;
  1612. entity.buyer_nick = GetPostString("buyer_nick");
  1613. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1614. entity.total_fee = entity.payment;
  1615. entity.pay_time = DateTime.Now;
  1616. entity.status = "NOT_SHIPPED";
  1617. entity.receiver_name = GetPostString("receiver_name");
  1618. entity.receiver_mobile = GetPostString("receiver_mobile");
  1619. entity.receiver_state = GetPostString("receiver_state");
  1620. entity.receiver_city = GetPostString("receiver_city");
  1621. entity.receiver_district = GetPostString("receiver_district");
  1622. entity.receiver_address = GetPostString("receiver_address");
  1623. entity.seller_memo = memo;
  1624. entity.orderFrom = 20;
  1625. entity.orderType = 15;
  1626. if (entity.receiver_state == "" || entity.receiver_city == "")
  1627. {
  1628. returnErrorMsg("收件地址不能为空");
  1629. return;
  1630. }
  1631. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1632. {
  1633. returnErrorMsg("公司自用的单金额才能为0");
  1634. return;
  1635. }
  1636. entity.Create();
  1637. string toWhere = GetPostString("towhere");
  1638. CeErpTradeCell entitycell = new CeErpTradeCell();
  1639. entitycell.ctid = entity.tid;
  1640. //唯一标识
  1641. entitycell.OrderSn = entity.tid;
  1642. string orderSn = dataHelper.getSaleOrderSn();
  1643. if (orderSn != "")
  1644. {
  1645. entitycell.OrderSn = orderSn;
  1646. }
  1647. entitycell.tid = entity.tid;
  1648. //if (preStr == "X_")
  1649. //{
  1650. entitycell.IsOffLineOrder = 1;
  1651. //}
  1652. entitycell.CustomerUserId = CurrentUser.UserID;
  1653. entitycell.PayProofImg = primg;
  1654. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1655. entitycell.ProductId = Convert.ToInt32(productId);
  1656. entitycell.ShopId = shopId;
  1657. entitycell.UpdateTime = DateTime.Now;
  1658. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1659. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1660. {
  1661. entitycell.IsXianHuo = 1;
  1662. }
  1663. entitycell.pay_time = entity.pay_time;
  1664. if (toWhere == "1")
  1665. {
  1666. entitycell.OrderState = 2;
  1667. }
  1668. else
  1669. {
  1670. entitycell.OrderState = 6;
  1671. entitycell.FinishPlaceTime = entitycell.pay_time;
  1672. }
  1673. if (shopId == 94)
  1674. {
  1675. entitycell.OrderState = 4;
  1676. entitycell.WaitDesignTime = entitycell.pay_time;
  1677. entitycell.StartDesignTime = entitycell.pay_time;
  1678. entitycell.DesignUserId = 218;
  1679. }
  1680. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1681. {
  1682. entitycell.OrderState = -1;//修改12-5
  1683. CeWithdraw ceWithdraw = new CeWithdraw();
  1684. ceWithdraw.tid = entity.tid;
  1685. ceWithdraw.providerid = "-1";
  1686. ceWithdraw.status = -1;
  1687. ceWithdraw.creationtime = DateTime.Now;
  1688. ceWithdraw.userid = 1337;
  1689. ceWithdraw.Create();
  1690. }
  1691. entitycell.Create();
  1692. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1693. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1694. {
  1695. addPlaceRegist(entitycell, CurrentUser.UserID);
  1696. }
  1697. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1698. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1699. return;
  1700. }
  1701. }
  1702. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1703. {
  1704. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1705. entity.PlactTime = tradecell.pay_time;
  1706. entity.AddUserId = userid;
  1707. entity.FileName = tradecell.seller_memo;
  1708. entity.Supplier = 24;
  1709. entity.CreateTime = DateTime.Now;
  1710. entity.Did = tradecell.ctid;
  1711. entity.tid = tradecell.tid;
  1712. entity.splitTag = tradecell.SplitTag;
  1713. entity.CurState = "未完成";
  1714. entity.Create();
  1715. }
  1716. public void get_erp_offlinelist()
  1717. {
  1718. DataStruct dStruct = GetPostStruct();
  1719. List<string> lw = new List<string>();
  1720. string tid = GetPostString("ctid");
  1721. string date1 = GetPostString("date1");
  1722. string date2 = GetPostString("date2");
  1723. if (tid.Length > 0 || date1.Length > 0)
  1724. {
  1725. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1726. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1727. if (dw.Length > 0) lw.Add(dw);
  1728. }
  1729. else
  1730. {
  1731. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1732. }
  1733. string shopname = GetPostString("shopname");
  1734. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1735. string buyernick = GetPostString("buyer_nick");
  1736. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1737. string customer = GetPostString("customer");
  1738. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1739. string design = GetPostString("design");
  1740. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1741. string orderState = GetPostString("orderState");
  1742. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1743. string address = GetPostString("address");
  1744. 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));
  1745. string sellermemo = GetPostString("seller_memo");
  1746. if (sellermemo.Length > 0)
  1747. {
  1748. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1749. }
  1750. string price1 = GetPostString("price1");
  1751. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1752. string price2 = GetPostString("price2");
  1753. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1754. //if (PKey != "admin")
  1755. //{
  1756. // string usershop = CurrentUser.User.pemShop;
  1757. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1758. //}
  1759. //if (ex_psize > 0)
  1760. //{
  1761. dStruct.Order = "pay_time desc";
  1762. //}
  1763. //else
  1764. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1765. lw.Add(string.Format("IsOffLineOrder=1"));
  1766. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1767. DataTable dt = null;
  1768. dt = WebCache.GetData("view_erptradecell", dStruct);
  1769. writeGridDataTableJson(dStruct.TotalCount, dt);
  1770. }
  1771. public void get_erp_returncashrecord()
  1772. {
  1773. DataStruct dStruct = GetPostStruct();
  1774. List<string> lw = new List<string>();
  1775. string tid = GetPostString("ctid");
  1776. if (tid.Length > 0)
  1777. {
  1778. lw.Add(string.Format("tid like '%{0}%'", tid));
  1779. dStruct.Order = "id desc";
  1780. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1781. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1782. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1783. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1784. return;
  1785. }
  1786. returnErrorMsg("id数据错误!");
  1787. }
  1788. public void ins_erp_returncashrecord()
  1789. {
  1790. if (UrlPostParmsCheck("tid"))
  1791. {
  1792. string tid = GetPostString("tid");
  1793. string retype = GetPostString("type");
  1794. StringBuilder sql = new StringBuilder();
  1795. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1796. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1797. if (dt.Rows.Count > 0)
  1798. {
  1799. returnErrorMsg("相同返现类型记录已存在");
  1800. return;
  1801. }
  1802. CeErpReturnCash entity = new CeErpReturnCash();
  1803. entity.tid = tid;
  1804. entity.seller_nick = GetPostString("seller_nick");
  1805. string pment = GetPostString("payment");
  1806. if (pment.Length > 0)
  1807. {
  1808. entity.payment = Convert.ToDouble(pment);
  1809. }
  1810. entity.buyer_nick = GetPostString("buyer_nick");
  1811. entity.cashstate = 0;
  1812. entity.rtype = retype;
  1813. string rPrice = GetPostString("returnprice");
  1814. if (rPrice.Length > 0)
  1815. {
  1816. entity.returnprice = Convert.ToDouble(rPrice);
  1817. }
  1818. entity.created = DateTime.Now;
  1819. entity.con = GetPostString("con");
  1820. entity.img = GetPostString("img");
  1821. entity.applyuserid = CurrentUser.UserID;
  1822. entity.Create();
  1823. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1824. returnSuccessMsg("操作成功!");
  1825. return;
  1826. }
  1827. }
  1828. public void set_erp_predelivery()
  1829. {
  1830. if (UrlPostParmsCheck("ctid"))
  1831. {
  1832. string eid = GetPostString("ctid");
  1833. CeErpTradeCell entity = null;
  1834. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1835. if (entity != null)
  1836. {
  1837. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1838. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1839. //{
  1840. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1841. // return;
  1842. //}
  1843. entity.IsPreDelivery = 1;
  1844. entity.Update();
  1845. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1846. returnSuccessMsg("预发货成功!");
  1847. return;
  1848. //string shop = GetPostString("seller_nick");
  1849. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1850. //string comName = GetPostString("comName");
  1851. //string comCode = GetPostString("comCode");
  1852. //string outSid = GetPostString("outSid");//运单号
  1853. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1854. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1855. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1856. //string apires = "";
  1857. //if (deliveryType == "虚拟发货")
  1858. //{
  1859. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1860. //}
  1861. //else
  1862. //{
  1863. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1864. //}
  1865. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1866. ////{
  1867. //if (apires.IndexOf("发货成功") != -1)
  1868. //{
  1869. // if (deliveryType != "虚拟发货")
  1870. // {
  1871. // //还要插入快递信息到 快递信息表
  1872. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1873. // exinfo.tid = eid;
  1874. // exinfo.out_sid = outSid;
  1875. // exinfo.company_code = comCode;
  1876. // exinfo.company_name = comName;
  1877. // exinfo.delivery_memo = deliveryMemo;
  1878. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1879. // exinfo.deliveryType = deliveryType;
  1880. // exinfo.Create();
  1881. // }
  1882. // returnSuccessMsg("发货成功!");
  1883. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1884. //}
  1885. //else
  1886. //{
  1887. // returnErrorMsg("淘宝发货失败!!");
  1888. //}
  1889. //return;
  1890. }
  1891. returnErrorMsg("找不到订单记录");
  1892. }
  1893. }
  1894. public void get_erp_unusuallist()
  1895. {
  1896. DataStruct dStruct = GetPostStruct();
  1897. List<string> lw = new List<string>();
  1898. string tid = GetPostString("ctid");
  1899. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  1900. string shopname = GetPostString("shopname");
  1901. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1902. string buyernick = GetPostString("buyer_nick");
  1903. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1904. string ResponsibleMan = GetPostString("responsible");
  1905. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  1906. string date1 = GetPostString("date1");
  1907. string date2 = GetPostString("date2");
  1908. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1909. if (dw.Length > 0) lw.Add(dw);
  1910. string price1 = GetPostString("price1");
  1911. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1912. string price2 = GetPostString("price2");
  1913. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1914. string orderState = GetPostString("orderState");
  1915. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  1916. string sellermemo = GetPostString("seller_memo");
  1917. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1918. lw.Add(string.Format("UnusualTag > 0"));
  1919. lw.Add(string.Format("IsRefund<={0}", 1));
  1920. dStruct.Order = "pay_time desc";
  1921. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1922. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  1923. writeGridDataTableJson(dStruct.TotalCount, dt);
  1924. }
  1925. public void set_erp_unusualtonomal()
  1926. {
  1927. if (UrlPostParmsCheck("ctid"))
  1928. {
  1929. string eid = GetPostString("ctid");
  1930. CeErpTradeCell entity = null;
  1931. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1932. if (entity != null)
  1933. {
  1934. entity.UnusualTag = -1;
  1935. entity.Update();
  1936. returnSuccessMsg("忽略成功!");
  1937. return;
  1938. }
  1939. returnErrorMsg("找不到记录");
  1940. }
  1941. }
  1942. public void ins_erp_unusualreason()
  1943. {
  1944. if (UrlPostParmsCheck("ctid"))
  1945. {
  1946. string eid = GetPostString("ctid");
  1947. CeErpTradeCell entity = null;
  1948. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1949. if (entity != null)
  1950. {
  1951. entity.MemoOpt = 4;
  1952. entity.UnusualCon = GetPostString("con");
  1953. entity.Update();
  1954. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1955. if (trade != null)
  1956. {
  1957. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  1958. }
  1959. //查货是否超时
  1960. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1961. if (ceErpTradeCellExtend == null)
  1962. {
  1963. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  1964. ceErpTradeCellExtend.ctid = entity.ctid;
  1965. }
  1966. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  1967. {
  1968. ceErpTradeCellExtend.CheckOut += 1;
  1969. }
  1970. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  1971. if (ceErpTradeCellExtend.ID > 0)
  1972. {
  1973. ceErpTradeCellExtend.Update();
  1974. }
  1975. else
  1976. {
  1977. ceErpTradeCellExtend.Create();
  1978. }
  1979. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  1980. returnSuccessMsg("操作成功!");
  1981. return;
  1982. }
  1983. returnErrorMsg("找不到记录");
  1984. }
  1985. }
  1986. public void upd_erp_sampleorder()
  1987. {
  1988. if (UrlPostParmsCheck("ctid"))
  1989. {
  1990. string eid = GetPostString("ctid");
  1991. string[] eArr = eid.Split(',');
  1992. if (eArr.Length > 1)
  1993. {
  1994. List<string> eLst = new List<string>();
  1995. for (int i = 0; i < eArr.Length; i++)
  1996. {
  1997. eLst.Add("'" + eArr[i] + "'");
  1998. }
  1999. eid = string.Join(",", eLst.ToArray());
  2000. }
  2001. else
  2002. {
  2003. eid = "'" + eid + "'";
  2004. }
  2005. StringBuilder sql = new StringBuilder();
  2006. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2007. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2008. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2009. if (dt.Rows.Count > 0)
  2010. {
  2011. string errmsg = "";
  2012. foreach (DataRow dr in dt.Rows)
  2013. {
  2014. StringBuilder sqlsb = new StringBuilder();
  2015. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2016. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2017. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2018. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2019. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2020. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2021. {
  2022. continue;
  2023. }
  2024. else
  2025. {
  2026. string emsg = commonHelper.KeepChinese(apires);
  2027. errmsg += emsg;
  2028. }
  2029. }
  2030. if (errmsg.Length > 0)
  2031. {
  2032. returnErrorMsg(errmsg);
  2033. return;
  2034. }
  2035. returnSuccessMsg("操作成功");
  2036. return;
  2037. }
  2038. returnErrorMsg("找不到记录");
  2039. }
  2040. }
  2041. public void upd_erp_transcustomer()
  2042. {
  2043. if (UrlPostParmsCheck("ctid"))
  2044. {
  2045. string eid = GetPostString("ctid");
  2046. int userid = GetPostInt("CustomerUserId");
  2047. CeErpTradeCell entity = null;
  2048. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2049. if (entity != null)
  2050. {
  2051. //string[] mlist = entity.seller_memo.Split('-');
  2052. //string sql = "select * from view_erpuser where id=" + userid;
  2053. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2054. //if (dt != null && dt.Rows.Count > 0)
  2055. //{
  2056. // string nmemo = "";
  2057. // for(int i = 0; i < mlist.Length - 1; i++)
  2058. // {
  2059. // nmemo += mlist[i];
  2060. // nmemo += "-";
  2061. // }
  2062. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2063. // entity.seller_memo = nmemo;
  2064. //}
  2065. entity.CustomerUserId = userid;
  2066. entity.Update();
  2067. returnSuccessMsg("操作成功!");
  2068. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2069. return;
  2070. }
  2071. returnErrorMsg("找不到记录");
  2072. }
  2073. }
  2074. public void upd_erp_transdesigner()
  2075. {
  2076. if (UrlPostParmsCheck("ctid"))
  2077. {
  2078. string eids = GetPostString("ctid");
  2079. string[] ctidList = eids.Split(',');
  2080. int userid = GetPostInt("DesignUserId");
  2081. foreach (string ctid in ctidList)
  2082. {
  2083. CeErpTradeCell entity = null;
  2084. CeErpDesignerBill entitys = null;
  2085. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2086. entitys = CeErpDesignerBill.GetByTid(ctid);
  2087. if (entity != null)
  2088. {
  2089. if (entity.OrderState > 4)
  2090. {
  2091. continue;
  2092. }
  2093. //存在退款不能流转
  2094. if (entity.IsRefund > 0)
  2095. {
  2096. continue;
  2097. }
  2098. entity.DesignUserId = userid;
  2099. entity.WaitDesignTime = DateTime.Now;
  2100. entity.Update();
  2101. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2102. }
  2103. }
  2104. returnSuccessMsg("操作成功!");
  2105. }
  2106. }
  2107. public void upd_erp_distributedesigner()
  2108. {
  2109. if (UrlPostParmsCheck("ctid"))
  2110. {
  2111. string eid = GetPostString("ctid");
  2112. int userid = GetPostInt("DesignUserId");
  2113. string[] idlist = eid.Split(',');
  2114. if (idlist.Length <= 0)
  2115. {
  2116. returnErrorMsg("订单不能为空");
  2117. return;
  2118. }
  2119. foreach (string ctid in idlist)
  2120. {
  2121. CeErpTradeCell entity = null;
  2122. CeErpDesignerBill entitys = null;
  2123. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2124. else continue;
  2125. if (entity != null)
  2126. {
  2127. if (userid == 2125 || userid == 3542)
  2128. { }
  2129. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2130. {
  2131. returnErrorMsg("金额错误的订单无法指派");
  2132. return;
  2133. }
  2134. if (entity.OrderState >= 5)
  2135. {
  2136. returnErrorMsg("已经设计完成无法指派");
  2137. return;
  2138. }
  2139. if (entity.OrderState == -1)
  2140. {
  2141. returnErrorMsg("审核中的订单无法指派");
  2142. return;
  2143. }
  2144. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2145. {
  2146. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2147. return;
  2148. }
  2149. //157赖橙帆 159林晨
  2150. 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)
  2151. {
  2152. returnErrorMsg("指派设计共创无法再次指派!");
  2153. return;
  2154. }
  2155. entity.OrderState = 3;
  2156. CeErpUserPost userEntity = CeErpUserPost.GetByUserID(userid);
  2157. if (entity.ctid.IndexOf("S_") == -1 && userEntity.OrgID == 10)
  2158. {
  2159. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2160. entity.SupplierId = suid;
  2161. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2162. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2163. }
  2164. if (userid == 2125 && entity.seller_memo != "")
  2165. {
  2166. apiDesign.API_GetPrintData_CreateOrder(entity);
  2167. }
  2168. if (userid == 3542 && entity.seller_memo != "")
  2169. {
  2170. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, CurrentUser.UserPost.Post.Code);
  2171. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2172. if (response.msg != "设计共创:成功")
  2173. {
  2174. returnErrorMsg(response.msg);
  2175. return;
  2176. }
  2177. entity.DispatchSort = 2;
  2178. }
  2179. else
  2180. {
  2181. if (entity.DispatchSort == 2)
  2182. {
  2183. ApiVo apiVo = new ApiVo();
  2184. apiVo.actionName = "closeDesign";
  2185. apiVo.orderNumber = entity.ctid;
  2186. designHelper.API_WorkCore(apiVo);//closeDesign
  2187. }
  2188. entity.DispatchSort = 0;
  2189. }
  2190. entity.DesignUserId = userid;
  2191. entity.WaitDesignTime = DateTime.Now;
  2192. entity.UpdateTime = DateTime.Now;
  2193. entity.Update();
  2194. string name = commonHelper.getUserNameById(userid);
  2195. commonHelper.UpdateRelationOrder(entity.ctid);
  2196. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2197. }
  2198. }
  2199. returnSuccessMsg("操作成功!");
  2200. return;
  2201. }
  2202. }
  2203. public string getTidByCtid(string ctid)
  2204. {
  2205. string tid = "";
  2206. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2207. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2208. if (dataTable != null && dataTable.Rows.Count > 0)
  2209. {
  2210. tid = dataTable.Rows[0]["tid"].ToString();
  2211. }
  2212. return tid;
  2213. }
  2214. public List<string> getTidByCtidLike(string ctid)
  2215. {
  2216. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2217. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2218. List<string> list = new List<string>();
  2219. if (dataTable != null && dataTable.Rows.Count > 0)
  2220. {
  2221. foreach (DataRow item in dataTable.Rows)
  2222. {
  2223. list.Add("'" + item["tid"].ToString() + "'");
  2224. }
  2225. }
  2226. return list;
  2227. }
  2228. public void get_erp_myorderlist()
  2229. {
  2230. DataStruct dStruct = GetPostStruct();
  2231. List<string> lw = new List<string>();
  2232. string tid = GetPostString("ctid");
  2233. if (tid.Length > 0)
  2234. {
  2235. string select_tid = getTidByCtid(tid);
  2236. lw.Add(string.Format("tid='{0}'", select_tid));
  2237. }
  2238. else
  2239. {
  2240. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2241. }
  2242. //12-1 修改
  2243. string urgent = GetPostString("urgent");
  2244. string back = GetPostString("back");
  2245. string offlineSearch = GetPostString("offlineSearch");
  2246. if (!string.IsNullOrWhiteSpace(urgent))
  2247. {
  2248. if (urgent.Equals("true"))
  2249. {
  2250. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2251. }
  2252. }
  2253. if (!string.IsNullOrWhiteSpace(back))
  2254. {
  2255. if (back.Equals("true"))
  2256. {
  2257. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2258. }
  2259. }
  2260. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2261. {
  2262. if (offlineSearch.Equals("true"))
  2263. {
  2264. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2265. }
  2266. }
  2267. //end
  2268. string shopname = GetPostString("shopname");
  2269. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2270. string buyernick = GetPostString("buyer_nick");
  2271. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2272. string design = GetPostString("design");
  2273. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2274. string orderState = GetPostString("orderState");
  2275. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2276. string sellermemo = GetPostString("seller_memo");
  2277. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2278. string date1 = GetPostString("date1");
  2279. string date2 = GetPostString("date2");
  2280. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2281. if (dw.Length > 0) lw.Add(dw);
  2282. string price1 = GetPostString("price1");
  2283. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2284. string price2 = GetPostString("price2");
  2285. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2286. string urgency = GetPostString("urgency");
  2287. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2288. string after = GetPostString("after");
  2289. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2290. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2291. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2292. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2293. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2294. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2295. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2296. if (dt != null && dt.Rows.Count > 0)
  2297. {
  2298. foreach (DataRow dr in dt.Rows)
  2299. {
  2300. try
  2301. {
  2302. // 对象操作
  2303. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2304. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2305. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2306. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2307. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2308. if (dStruct.PageSize != 100000)
  2309. {
  2310. if (dr["DispatchSort"].ToString() == "2")
  2311. {
  2312. dr["gongchuang"] = 200;
  2313. }
  2314. else
  2315. {
  2316. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString());
  2317. dr["gongchuang"] = response.code;
  2318. }
  2319. }
  2320. }
  2321. catch (NullReferenceException ex)
  2322. {
  2323. }
  2324. }
  2325. }
  2326. writeGridDataTableJson(dStruct.TotalCount, dt);
  2327. }
  2328. public void get_erp_myreturnorderlist()
  2329. {
  2330. DataStruct dStruct = GetPostStruct();
  2331. List<string> lw = new List<string>();
  2332. string tid = GetPostString("ctid");
  2333. if (tid.Length > 0)
  2334. {
  2335. string select_tid = getTidByCtid(tid);
  2336. lw.Add(string.Format("tid='{0}'", select_tid));
  2337. }
  2338. else
  2339. {
  2340. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2341. }
  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. if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2361. {
  2362. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2363. }
  2364. else
  2365. {
  2366. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2367. }
  2368. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2369. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2370. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2371. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2372. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2373. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2374. if (dt != null && dt.Rows.Count > 0)
  2375. {
  2376. foreach (DataRow dr in dt.Rows)
  2377. {
  2378. try
  2379. {
  2380. // 对象操作
  2381. if (dStruct.PageSize != 100000)
  2382. {
  2383. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString());
  2384. dr["gongchuang"] = response.code;
  2385. }
  2386. }
  2387. catch (NullReferenceException ex)
  2388. {
  2389. // 处理空引用异常
  2390. }
  2391. }
  2392. }
  2393. writeGridDataTableJson(dStruct.TotalCount, dt);
  2394. }
  2395. public void get_erp_myorderlist_pregather()
  2396. {
  2397. string date1 = GetPostString("date1");
  2398. string date2 = GetPostString("date2");
  2399. int userId = CurrentUser.UserID; //客服id
  2400. string orderWhere = "";
  2401. List<string> lw = new List<string>();
  2402. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2403. if (dw.Length > 0) lw.Add(dw);
  2404. lw.Add(string.Format("CustomerUserId={0}", userId));
  2405. lw.Add(string.Format("OrderState<9"));
  2406. orderWhere = string.Join(" and ", lw.ToArray());
  2407. string orderWhere2 = "";
  2408. List<string> lw2 = new List<string>();
  2409. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2410. if (dw2.Length > 0) lw2.Add(dw2);
  2411. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2412. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2413. string sql = string.Format("select *" +
  2414. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2415. "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 " +
  2416. "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 " +
  2417. "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");
  2418. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2419. //writeGridDataTableJson(dt.Rows.Count, dt);
  2420. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2421. }
  2422. public void upd_erp_publishorder()
  2423. {
  2424. if (UrlPostParmsCheck("ctid"))
  2425. {
  2426. string eid = GetPostString("ctid");
  2427. CeErpTradeCell entity = null;
  2428. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2429. if (entity != null)
  2430. {
  2431. entity.OrderState = 0; //发布后,变为待抢单
  2432. entity.Update();
  2433. commonHelper.UpdateRelationOrder(entity.ctid);
  2434. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2435. returnSuccessMsg("发布成功!");
  2436. return;
  2437. }
  2438. returnErrorMsg("找不到记录");
  2439. }
  2440. }
  2441. public void get_erp_my_tiporder()
  2442. {
  2443. StringBuilder sql = new StringBuilder();
  2444. int userId = 0;
  2445. if (CurrentUser != null) userId = CurrentUser.UserID;
  2446. string posCode = CurrentUser.UserPost.Post.Code;
  2447. string isTipedAfterSaleVerify = GetPostString("af");
  2448. DataTable dt = new DataTable();
  2449. if (posCode != "Supplier")
  2450. {
  2451. if (posCode == "CustomerService" || posCode == "Director")
  2452. {
  2453. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2454. }
  2455. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2456. {
  2457. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2458. }
  2459. else
  2460. {
  2461. string teamIds = CurrentUser.User.TeamIds;
  2462. if (teamIds == "")
  2463. {
  2464. teamIds = "0";
  2465. }
  2466. 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);
  2467. }
  2468. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2469. }
  2470. if (dt.Rows.Count <= 0)
  2471. {
  2472. string key = "aftersale_order_" + userId;
  2473. if (RedisHelper.HasKey(key))
  2474. {
  2475. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2476. dt.Columns.Add("ctid", typeof(string));
  2477. dt.Columns.Add("IsReadTag", typeof(int));
  2478. foreach (var i in list)
  2479. {
  2480. DataRow data = dt.NewRow();
  2481. data["ctid"] = i;
  2482. data["IsReadTag"] = 4;
  2483. dt.Rows.Add(data);
  2484. }
  2485. RedisHelper.StringDelete(key);
  2486. }
  2487. }
  2488. if (dt.Rows.Count <= 0)
  2489. {
  2490. sql = new StringBuilder();
  2491. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2492. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2493. }
  2494. if (posCode == "Supplier")
  2495. {
  2496. string ids = CurrentUser.User.pemVend;
  2497. if (ids != null && ids.Length > 0)
  2498. {
  2499. string[] ids_list = ids.Split(',');
  2500. foreach (var item in ids_list)
  2501. {
  2502. string key = "return_order_" + item;
  2503. if (RedisHelper.HasKey(key))
  2504. {
  2505. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2506. dt.Columns.Add("ctid", typeof(string));
  2507. dt.Columns.Add("IsReadTag", typeof(int));
  2508. foreach (var i in list)
  2509. {
  2510. DataRow data = dt.NewRow();
  2511. data["ctid"] = i;
  2512. data["IsReadTag"] = 1;
  2513. dt.Rows.Add(data);
  2514. }
  2515. RedisHelper.StringDelete(key);
  2516. }
  2517. }
  2518. }
  2519. if (dt.Rows.Count <= 0)
  2520. {
  2521. sql = new StringBuilder();
  2522. 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);
  2523. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2524. }
  2525. }
  2526. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2527. }
  2528. public void reset_erp_tiporder()
  2529. {
  2530. string ids = GetPostString("ids");
  2531. string[] ctidList = ids.Split(',');
  2532. foreach (string ctid in ctidList)
  2533. {
  2534. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2535. if (enty != null)
  2536. {
  2537. enty.IsReadTag = 0;
  2538. enty.Update();
  2539. }
  2540. }
  2541. returnSuccessMsg("成功!");
  2542. return;
  2543. }
  2544. public void get_erp_designlist()
  2545. {
  2546. DataStruct dStruct = GetPostStruct();
  2547. List<string> lw = new List<string>();
  2548. string tid = GetPostString("ctid");
  2549. if (tid.Length > 0)
  2550. {
  2551. string select_tid = getTidByCtid(tid);
  2552. lw.Add(string.Format("tid='{0}'", select_tid));
  2553. }
  2554. string shopname = GetPostString("shopname");
  2555. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2556. string buyernick = GetPostString("buyer_nick");
  2557. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2558. string customer = GetPostString("customer");
  2559. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2560. string design = GetPostString("design");
  2561. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2562. string orderState = GetPostString("orderState");
  2563. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2564. lw.Add(string.Format("OrderState<6"));
  2565. string address = GetPostString("address");
  2566. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2567. string sellermemo = GetPostString("seller_memo");
  2568. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2569. string date1 = GetPostString("date1");
  2570. string date2 = GetPostString("date2");
  2571. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2572. if (dw.Length > 0) lw.Add(dw);
  2573. string apdate1 = GetPostString("apdate1");
  2574. string apdate2 = GetPostString("apdate2");
  2575. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2576. if (dwap.Length > 0) lw.Add(dwap);
  2577. string price1 = GetPostString("price1");
  2578. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2579. string price2 = GetPostString("price2");
  2580. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2581. string designTime = GetPostString("designtime");
  2582. if (designTime.Length > 0)
  2583. {
  2584. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2585. }
  2586. string usershop = CurrentUser.User.pemShop;
  2587. if (usershop.Length > 0)
  2588. {
  2589. lw.Add(string.Format("shopId in ({0})", usershop));
  2590. }
  2591. int myOrgid = CurrentUser.UserPost.OrgID;
  2592. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2593. if (myOrgCode.IndexOf("Designer") != -1)
  2594. {
  2595. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2596. {
  2597. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2598. }
  2599. else
  2600. {
  2601. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2602. }
  2603. }
  2604. else
  2605. {
  2606. string orgId = GetPostString("designerhd");
  2607. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2608. }
  2609. if (tid.Length > 0 || buyernick.Length > 0)
  2610. {
  2611. lw.Add(string.Format("OrderState >= 3"));
  2612. }
  2613. else
  2614. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2615. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2616. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2617. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2618. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2619. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2620. if (dt != null && dt.Rows.Count > 0)
  2621. {
  2622. foreach (DataRow dr in dt.Rows)
  2623. {
  2624. try
  2625. {
  2626. // 对象操作
  2627. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2628. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2629. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2630. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2631. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2632. if (dStruct.PageSize != 100000)
  2633. {
  2634. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString());
  2635. dr["gongchuang"] = response.code;
  2636. }
  2637. }
  2638. catch (NullReferenceException ex)
  2639. {
  2640. }
  2641. }
  2642. }
  2643. writeGridDataTableJson(dStruct.TotalCount, dt);
  2644. }
  2645. public void get_erp_mydesignlist()
  2646. {
  2647. DataStruct dStruct = GetPostStruct();
  2648. List<string> lw = new List<string>();
  2649. string tid = GetPostString("ctid");
  2650. if (tid.Length > 0)
  2651. {
  2652. string select_tid = getTidByCtid(tid);
  2653. lw.Add(string.Format("tid='{0}'", select_tid));
  2654. }
  2655. string shopname = GetPostString("shopname");
  2656. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2657. string buyernick = GetPostString("buyer_nick");
  2658. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2659. string customer = GetPostString("customer");
  2660. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2661. string orderState = GetPostString("orderState");
  2662. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2663. //lw.Add(string.Format("OrderState<6"));
  2664. string date1 = GetPostString("date1");
  2665. string date2 = GetPostString("date2");
  2666. string dw = GetDateWhere("pay_time", date1, date2);
  2667. if (dw.Length > 0) lw.Add(dw);
  2668. string apdate1 = GetPostString("apdate1");
  2669. string apdate2 = GetPostString("apdate2");
  2670. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2671. if (dwap.Length > 0) lw.Add(dwap);
  2672. string price1 = GetPostString("price1");
  2673. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2674. string price2 = GetPostString("price2");
  2675. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2676. string olddownload = GetPostString("olddown");
  2677. if (olddownload == "1")
  2678. {
  2679. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2680. }
  2681. else if (olddownload == "2")
  2682. {
  2683. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2684. }
  2685. string sellermemo = GetPostString("seller_memo");
  2686. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2687. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2688. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2689. {
  2690. if (CurrentUser.User.TeamIds.Length > 0)
  2691. {
  2692. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2693. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2694. else
  2695. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2696. }
  2697. else
  2698. {
  2699. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2700. }
  2701. }
  2702. if (tid.Length <= 0)
  2703. {
  2704. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2705. }
  2706. lw.Add(string.Format("IsReturn!=3"));
  2707. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2708. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2709. string teamids = CurrentUser.User.TeamIds.ToString();
  2710. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2711. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2712. if (dt != null && dt.Rows.Count > 0)
  2713. {
  2714. foreach (DataRow dr in dt.Rows)
  2715. {
  2716. try
  2717. {
  2718. // 对象操作
  2719. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2720. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2721. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2722. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2723. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2724. if (dStruct.PageSize != 100000)
  2725. {
  2726. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString());
  2727. dr["gongchuang"] = response.code;
  2728. }
  2729. }
  2730. catch (NullReferenceException ex)
  2731. {
  2732. }
  2733. }
  2734. }
  2735. writeGridDataTableJson(dStruct.TotalCount, dt);
  2736. }
  2737. public void set_erp_startdesign()
  2738. {
  2739. if (UrlPostParmsCheck("ctid"))
  2740. {
  2741. string eid = GetPostString("ctid");
  2742. CeErpTradeCell entity = null;
  2743. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2744. if (entity != null)
  2745. {
  2746. if (entity.OrderState != 3)
  2747. {
  2748. returnErrorMsg("请刷新,订单已经设计了");
  2749. return;
  2750. }
  2751. entity.StartDesignTime = DateTime.Now;
  2752. entity.OrderState = 4;
  2753. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2754. {
  2755. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2756. entity.SupplierId = suid;
  2757. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2758. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2759. }
  2760. entity.UpdateTime = DateTime.Now;
  2761. //entity.MakeSupplier = suname;
  2762. entity.Update();
  2763. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2764. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2765. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2766. commonHelper.getCytPrice(entity);
  2767. returnSuccessMsg("操作成功!");
  2768. return;
  2769. }
  2770. returnErrorMsg("找不到记录");
  2771. }
  2772. }
  2773. public void ins_erp_designselfmemo()
  2774. {
  2775. if (UrlPostParmsCheck("ctid"))
  2776. {
  2777. string eid = GetPostString("ctid");
  2778. string con = GetPostString("con");
  2779. CeErpTradeCell entity = null;
  2780. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2781. if (entity != null)
  2782. {
  2783. entity.DesignSelfMemo = con;
  2784. entity.Update();
  2785. returnSuccessMsg("操作成功!");
  2786. return;
  2787. }
  2788. returnErrorMsg("找不到记录");
  2789. }
  2790. }
  2791. public void ins_erp_designprice()
  2792. {
  2793. if (UrlPostParmsCheck("ctid"))
  2794. {
  2795. string eid = GetPostString("ctid");
  2796. int uid = CurrentUser.UserID;
  2797. string userName = CurrentUser.UserName;
  2798. CeErpTradeCell entity = null;
  2799. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  2800. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2801. if (entitys == null)
  2802. {
  2803. entitys = new CeErpDesignerBill();
  2804. }
  2805. if (entity != null)
  2806. {
  2807. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  2808. //entity.Number = Convert.ToInt32(GetPostString("number"));
  2809. entity.StartDesignTime = DateTime.Now;
  2810. entity.OrderState = 4;
  2811. string suname = "";
  2812. if (entity.SupplierId == 0)
  2813. {
  2814. int sid = commonHelper.autoDistributeToSupplier(entity);
  2815. entity.SupplierId = sid;
  2816. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2817. }
  2818. entity.Update();
  2819. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  2820. if (ceErpUserPost != null)
  2821. {
  2822. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  2823. if (ceErpPost != null)
  2824. {
  2825. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  2826. {
  2827. entitys.tid = entity.ctid;
  2828. entitys.oid = entity.tid;
  2829. entitys.uid = uid;
  2830. entitys.userName = userName;
  2831. entitys.designerType = 1;
  2832. entitys.designerTypeText = "内部设计师";
  2833. entitys.price = Convert.ToDouble(GetPostString("price"));
  2834. entitys.designNum = GetPostInt("designNum");
  2835. entitys.modifyNum = GetPostInt("modifyNum");
  2836. entitys.designSize = GetPostString("designSize");
  2837. entitys.modifySize = GetPostString("modifySize");
  2838. if (CeErpDesignerBill.GetByTid("ctid") == null)
  2839. {
  2840. entitys.create_time = DateTime.Now;
  2841. entitys.create_u_id = uid;
  2842. entitys.create_u_name = userName;
  2843. entitys.Save();
  2844. }
  2845. else
  2846. {
  2847. entitys.update_time = DateTime.Now;
  2848. entitys.update_u_id = uid;
  2849. entitys.update_u_name = userName;
  2850. entitys.Update();
  2851. }
  2852. }
  2853. }
  2854. }
  2855. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2856. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2857. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  2858. if (suname != "")
  2859. {
  2860. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2861. }
  2862. commonHelper.getCytPrice(entity);
  2863. returnSuccessMsg("操作成功!");
  2864. return;
  2865. }
  2866. returnErrorMsg("找不到记录");
  2867. }
  2868. }
  2869. public void upload_erp_filecomplete()
  2870. {
  2871. if (UrlPostParmsCheck("ctid"))
  2872. {
  2873. string eid = GetPostString("ctid");
  2874. CeErpTradeCell entity = null;
  2875. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2876. if (entity != null)
  2877. {
  2878. entity.OrderState = 5; //设计完成
  2879. entity.Update();
  2880. returnSuccessMsg(eid + "上传成功,设计完成!");
  2881. return;
  2882. }
  2883. returnErrorMsg("找不到订单记录");
  2884. }
  2885. }
  2886. public void get_erp_designovertimelist()
  2887. {
  2888. DataStruct dStruct = GetPostStruct();
  2889. List<string> lw = new List<string>();
  2890. string tid = GetPostString("ctid");
  2891. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  2892. string shopname = GetPostString("shopname");
  2893. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2894. string buyernick = GetPostString("buyer_nick");
  2895. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2896. string ResponsibleMan = GetPostString("responsible");
  2897. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  2898. string date1 = GetPostString("date1");
  2899. string date2 = GetPostString("date2");
  2900. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2901. if (dw.Length > 0) lw.Add(dw);
  2902. string price1 = GetPostString("price1");
  2903. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2904. string price2 = GetPostString("price2");
  2905. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2906. string orderState = GetPostString("orderState");
  2907. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2908. string sellermemo = GetPostString("seller_memo");
  2909. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2910. lw.Add(string.Format("UnusualTag=3"));
  2911. lw.Add(string.Format("IsRefund<={0}", 1));
  2912. dStruct.Order = "WaitDesignTime desc";
  2913. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2914. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2915. writeGridDataTableJson(dStruct.TotalCount, dt);
  2916. }
  2917. //设计管理 获取抢单大厅列表
  2918. public void get_erp_grabinglist()
  2919. {
  2920. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  2921. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  2922. bool oldOrder = false;
  2923. if (org != null)
  2924. {
  2925. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  2926. }
  2927. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  2928. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  2929. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2930. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  2931. //先处理订单数据
  2932. if (dt.Rows.Count > 0)
  2933. {
  2934. Dictionary<string, int> design = null;
  2935. int count = 0;
  2936. foreach (DataRow row in dt.Rows)
  2937. {
  2938. if (map.ContainsKey(row["ShopId"].ToString()))
  2939. {
  2940. map.TryGetValue(row["ShopId"].ToString(), out design);
  2941. }
  2942. else
  2943. {
  2944. design = new Dictionary<string, int>();
  2945. }
  2946. if (design.ContainsKey(row["ProductId"].ToString()))
  2947. {
  2948. design.TryGetValue(row["ProductId"].ToString(), out count);
  2949. }
  2950. count++;
  2951. design[row["ProductId"].ToString()] = count;
  2952. map[row["ShopId"].ToString()] = design;
  2953. }
  2954. }
  2955. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  2956. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2957. //把店铺排序和技能排序分类
  2958. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  2959. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  2960. if (design_dt.Rows.Count > 0)
  2961. {
  2962. Dictionary<string, string> design = null;
  2963. List<string> shopIds = null;
  2964. foreach (DataRow row in design_dt.Rows)
  2965. {
  2966. if ("0".Equals(row["designId"].ToString()))
  2967. {
  2968. if (shop_orders.ContainsKey(row["orders"].ToString()))
  2969. {
  2970. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  2971. }
  2972. else
  2973. {
  2974. shopIds = new List<string>();
  2975. }
  2976. shopIds.Add(row["shopId"].ToString());
  2977. shop_orders[row["orders"].ToString()] = shopIds;
  2978. }
  2979. else
  2980. {
  2981. if (design_orders.ContainsKey(row["shopId"].ToString()))
  2982. {
  2983. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  2984. }
  2985. else
  2986. {
  2987. design = new Dictionary<string, string>();
  2988. }
  2989. design[row["orders"].ToString()] = row["designId"].ToString();
  2990. design_orders[row["shopId"].ToString()] = design;
  2991. }
  2992. }
  2993. //处理成key value后根据key排序
  2994. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  2995. foreach (List<string> val in shop_orders.Values)
  2996. {
  2997. if (val != null)
  2998. {
  2999. foreach (string key in val)
  3000. {
  3001. if (design_orders.ContainsKey(key.ToString()))
  3002. {
  3003. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3004. }
  3005. }
  3006. }
  3007. }
  3008. }
  3009. //校验哪个优先级有订单
  3010. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3011. foreach (string key in shop_orders.Keys)
  3012. {
  3013. List<string> ids = null;
  3014. shop_orders.TryGetValue(key, out ids);
  3015. //id为shopid
  3016. foreach (string id in ids)
  3017. {
  3018. Dictionary<string, int> list = null;
  3019. Dictionary<string, string> desing = null;
  3020. map.TryGetValue(id, out list);
  3021. design_orders.TryGetValue(id, out desing);
  3022. if (list != null && desing != null)
  3023. {
  3024. foreach (var item in desing)
  3025. {
  3026. int count = 0;
  3027. if (list.ContainsKey(item.Value))
  3028. {
  3029. list.TryGetValue(item.Value, out count);
  3030. if (count > 0)
  3031. {
  3032. designIds[id] = item.Value;
  3033. break;
  3034. }
  3035. }
  3036. }
  3037. }
  3038. }
  3039. if (designIds.Count > 0)
  3040. {
  3041. break;
  3042. }
  3043. }
  3044. DataTable table = new DataTable();
  3045. table.Columns.Add("tid", typeof(string));
  3046. table.Columns.Add("ctid", typeof(string));
  3047. table.Columns.Add("seller_nick", typeof(string));
  3048. table.Columns.Add("productName", typeof(string));
  3049. table.Columns.Add("pay_time", typeof(string));
  3050. table.Columns.Add("seller_memo", typeof(string));
  3051. if (designIds.Count > 0)
  3052. {
  3053. string shopId = "";
  3054. string productId = "";
  3055. foreach (var designInfo in designIds)
  3056. {
  3057. shopId = designInfo.Key;
  3058. productId = designInfo.Value;
  3059. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3060. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3061. if (dt.Rows.Count > 0)
  3062. {
  3063. foreach (DataRow row in dt.Rows)
  3064. {
  3065. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3066. {
  3067. DataRow data = table.NewRow();
  3068. data["ctid"] = row["ctid"].ToString();
  3069. data["tid"] = row["tid"].ToString();
  3070. data["seller_nick"] = ceErpShop.ShopName;
  3071. data["pay_time"] = row["pay_time"].ToString();
  3072. data["seller_memo"] = row["seller_memo"].ToString();
  3073. data["productName"] = ceErpProduct.PType;
  3074. table.Rows.Add(data);
  3075. }
  3076. }
  3077. }
  3078. }
  3079. }
  3080. writeGridDataTableJson(table.Rows.Count, table);
  3081. }
  3082. private object rushLockObject = new object();
  3083. public void set_erp_grabingorder()
  3084. {
  3085. if (UrlPostParmsCheck("ctid"))
  3086. {
  3087. int total = CurrentUser.User.Person.Total;
  3088. int userId = CurrentUser.User.ID;
  3089. int noFinish = CurrentUser.User.Person.NoFinish;
  3090. int finalization = CurrentUser.User.Person.Finalization;
  3091. string eids = GetPostString("ctid");
  3092. string key = "RushKey_" + userId;
  3093. int count = 0;
  3094. if (erpRedis.RedisHelper.KeyExists(key))
  3095. {
  3096. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3097. if (redisCount != null)
  3098. {
  3099. count = Convert.ToInt32(redisCount);
  3100. }
  3101. }
  3102. if (count >= total)
  3103. {
  3104. returnErrorMsg("半小时内已经抢" + total + "单");
  3105. return;
  3106. }
  3107. string[] ctidlist = eids.Split(',');
  3108. if (count + ctidlist.Length > total)
  3109. {
  3110. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3111. return;
  3112. }
  3113. int itag = 0;
  3114. lock (rushLockObject)
  3115. {
  3116. if (ctidlist.Length > 0)
  3117. {
  3118. string[] dtList = new string[ctidlist.Length];
  3119. for (int i = 0; i < ctidlist.Length; i++)
  3120. {
  3121. dtList[i] = "'" + ctidlist[i] + "'";
  3122. }
  3123. 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"));
  3124. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3125. if (dt_user.Rows.Count > 0)
  3126. {
  3127. int doing = 0;//未定稿
  3128. int finish = 0;//已完成
  3129. foreach (DataRow dr in dt_user.Rows)
  3130. {
  3131. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3132. {
  3133. doing++;
  3134. }
  3135. else
  3136. {
  3137. finish++;
  3138. }
  3139. }
  3140. if (doing >= noFinish)
  3141. {
  3142. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3143. return;
  3144. }
  3145. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3146. {
  3147. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3148. return;
  3149. }
  3150. }
  3151. //校验选择单子状态
  3152. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3153. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3154. if (dt.Rows.Count > 0)
  3155. {
  3156. List<string> list = new List<string>();
  3157. foreach (DataRow dr in dt.Rows)
  3158. {
  3159. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3160. {
  3161. list.Add(dr["ctid"].ToString());
  3162. }
  3163. }
  3164. if (list.Count > 0)
  3165. {
  3166. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3167. return;
  3168. }
  3169. }
  3170. foreach (string ctid in ctidlist)
  3171. {
  3172. CeErpTradeCell entity = null;
  3173. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3174. if (entity != null)
  3175. {
  3176. entity.OrderState = 3;
  3177. entity.DesignUserId = CurrentUser.UserID;
  3178. entity.WaitDesignTime = DateTime.Now;
  3179. entity.StartDesignTime = DateTime.Now;
  3180. entity.Update();
  3181. commonHelper.UpdateRelationOrder(entity.ctid);
  3182. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3183. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3184. itag++;
  3185. }
  3186. }
  3187. }
  3188. }
  3189. count += ctidlist.Length;
  3190. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3191. if (itag == 0)
  3192. returnErrorMsg("没有找到相关订单");
  3193. else
  3194. returnSuccessMsg("抢单成功!");
  3195. return;
  3196. }
  3197. }
  3198. public void get_erp_waitorderlist()
  3199. {
  3200. DataStruct dStruct = GetPostStruct();
  3201. List<string> lw = new List<string>();
  3202. string tid = GetPostString("ctid");
  3203. if (tid.Length > 0)
  3204. {
  3205. string select_tid = getTidByCtid(tid);
  3206. lw.Add(string.Format("tid='{0}'", select_tid));
  3207. }
  3208. string shopname = GetPostString("shopname");
  3209. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3210. string buyernick = GetPostString("buyer_nick");
  3211. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3212. string customer = GetPostString("customer");
  3213. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3214. string design = GetPostString("design");
  3215. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3216. string orderState = GetPostString("orderState");
  3217. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3218. string supplier = GetPostString("supplier");
  3219. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3220. string sellermemo = GetPostString("seller_memo");
  3221. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3222. string otherMemo = GetPostString("otherMemo");
  3223. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3224. string address = GetPostString("address");
  3225. 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));
  3226. string date1 = GetPostString("date1");
  3227. string date2 = GetPostString("date2");
  3228. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3229. if (dw.Length > 0) lw.Add(dw);
  3230. string price1 = GetPostString("price1");
  3231. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3232. string price2 = GetPostString("price2");
  3233. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3234. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3235. lw.Add(string.Format("IsSample != 2 "));
  3236. lw.Add(string.Format("OrderState = 5 "));
  3237. lw.Add(string.Format("IsRefund<={0}", 1));
  3238. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3239. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3240. string pagesize = GetPostString("pagesize");
  3241. if (pagesize != null)
  3242. {
  3243. dStruct.PageSize = 200;
  3244. }
  3245. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3246. if (dt != null)
  3247. {
  3248. foreach (DataRow dr in dt.Rows)
  3249. {
  3250. 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();
  3251. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3252. {
  3253. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3254. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3255. entity.SupplierId = suid;
  3256. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3257. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3258. entity.Update();
  3259. }
  3260. }
  3261. }
  3262. writeGridDataTableJson(dStruct.TotalCount, dt);
  3263. }
  3264. public void get_erp_supplierwaitorderlist()
  3265. {
  3266. DataStruct dStruct = GetPostStruct();
  3267. List<string> lw = new List<string>();
  3268. string tid = GetPostString("ctid");
  3269. if (tid.Length > 0)
  3270. {
  3271. string select_tid = getTidByCtid(tid);
  3272. lw.Add(string.Format("tid='{0}'", select_tid));
  3273. }
  3274. string shopname = GetPostString("shopname");
  3275. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3276. string sellermemo = GetPostString("seller_memo");
  3277. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3278. string date1 = GetPostString("date1");
  3279. string date2 = GetPostString("date2");
  3280. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3281. if (dw.Length > 0) lw.Add(dw);
  3282. lw.Add(string.Format("OrderState = 5 "));
  3283. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3284. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3285. {
  3286. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3287. }
  3288. string supplier = GetPostString("supplier");
  3289. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3290. {
  3291. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3292. }
  3293. lw.Add(string.Format("IsRefund<={0}", 1));
  3294. dStruct.Order = "FinishDesignTime desc";
  3295. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3296. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3297. if (dt != null)
  3298. {
  3299. foreach (DataRow dr in dt.Rows)
  3300. {
  3301. 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();
  3302. }
  3303. }
  3304. writeGridDataTableJson(dStruct.TotalCount, dt);
  3305. }
  3306. public void upd_erp_verifytosupplier()
  3307. {
  3308. if (UrlPostParmsCheck("ctid"))
  3309. {
  3310. string eids = GetPostString("ctid");
  3311. CeErpTradeCell entity = null;
  3312. string[] eidsList = eids.Split(',');
  3313. if (eidsList.Length <= 0)
  3314. {
  3315. returnErrorMsg("订单号不能空");
  3316. return;
  3317. }
  3318. List<string> tLst = new List<string>();
  3319. foreach (string ctidstr in eidsList)
  3320. {
  3321. tLst.Add("'" + ctidstr + "'");
  3322. CeErpDataSendOrderInfo.createObject(ctidstr);
  3323. }
  3324. string needtids = string.Join(",", tLst.ToArray());
  3325. StringBuilder sql = new StringBuilder();
  3326. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3327. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1} where SupplierId!=0 and ctid in ({0});", needtids, CurrentUser.UserID);
  3328. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3329. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3330. returnSuccessMsg("操作成功!");
  3331. return;
  3332. /**foreach (string ctidstr in eidsList)
  3333. {
  3334. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3335. if (entity != null)
  3336. {
  3337. if (entity.SupplierId == 0)
  3338. {
  3339. continue;
  3340. }
  3341. entity.IsVerifyToSupplier = true;
  3342. if (entity.IsReturn == 1) //1是供应商打回
  3343. {
  3344. entity.IsReturn = 0;
  3345. }
  3346. entity.FinishPlaceTime = DateTime.Now;
  3347. entity.PlaceUserId = CurrentUser.UserID;
  3348. entity.Update();
  3349. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3350. }
  3351. }
  3352. returnSuccessMsg("操作成功!");
  3353. return;**/
  3354. }
  3355. }
  3356. public void upd_erp_supplierback()
  3357. {
  3358. if (UrlPostParmsCheck("ctid"))
  3359. {
  3360. string eid = GetPostString("ctid");
  3361. string reason = GetPostString("returnreason");
  3362. CeErpTradeCell entity = null;
  3363. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3364. if (entity != null)
  3365. {
  3366. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3367. {
  3368. string key = "return_order_" + entity.SupplierId;
  3369. List<string> list = new List<string>();
  3370. if (RedisHelper.HasKey(key))
  3371. {
  3372. object data = RedisHelper.StringGet(key);
  3373. list = Convert.ToString(data).Split(',').ToList();
  3374. }
  3375. list.Add(eid);
  3376. RedisHelper.StringSet(key, string.Join(",", list));
  3377. }
  3378. entity.IsVerifyToSupplier = false;
  3379. entity.IsReturn = 1;
  3380. entity.ReturnTime = DateTime.Now;
  3381. entity.ReturnReason = reason;
  3382. if (entity.OrderState == 6)
  3383. {
  3384. entity.OrderState = 5;
  3385. }
  3386. entity.Update();
  3387. CeErpSukuraData.createInfo(entity.ctid, 5);
  3388. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  3389. returnSuccessMsg("操作成功!");
  3390. return;
  3391. }
  3392. returnErrorMsg("找不到订单记录");
  3393. }
  3394. }
  3395. public void upd_erp_toaftersaleorder()
  3396. {
  3397. if (UrlPostParmsCheck("ctid"))
  3398. {
  3399. string eid = GetPostString("ctid");
  3400. string reason = GetPostString("returnreason");
  3401. CeErpTradeCell entity = null;
  3402. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3403. if (entity != null)
  3404. {
  3405. if (entity.isAfterSaleOrder != 1)
  3406. {
  3407. returnErrorMsg("带S的售后单才能打回给售后");
  3408. return;
  3409. }
  3410. if (entity.OrderState >= 5)
  3411. {
  3412. returnErrorMsg("已经设计完成了不能打回给售后");
  3413. return;
  3414. }
  3415. entity.OrderState = 0;
  3416. entity.IsReturn = 3;
  3417. entity.ReturnTime = DateTime.Now;
  3418. entity.UpdateTime = DateTime.Now;
  3419. entity.ReturnReason = reason;
  3420. entity.Update();
  3421. CeErpSukuraData.createInfo(entity.ctid, 5);
  3422. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3423. returnSuccessMsg("操作成功!");
  3424. return;
  3425. }
  3426. returnErrorMsg("找不到订单记录");
  3427. }
  3428. }
  3429. public void upd_erp_aftersaletodesign()
  3430. {
  3431. if (UrlPostParmsCheck("ctid"))
  3432. {
  3433. string eid = GetPostString("ctid");
  3434. CeErpTradeCell entity = null;
  3435. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3436. if (entity != null)
  3437. {
  3438. entity.OrderState = 3;
  3439. entity.IsReturn = 0;
  3440. entity.UpdateTime = DateTime.Now;
  3441. entity.Update();
  3442. CeErpSukuraData.createInfo(entity.ctid, 5);
  3443. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3444. returnSuccessMsg("操作成功!");
  3445. return;
  3446. }
  3447. returnErrorMsg("找不到订单记录");
  3448. }
  3449. }
  3450. public void assign_erp_supplier()
  3451. {
  3452. if (UrlPostParmsCheck("ctid"))
  3453. {
  3454. string eids = GetPostString("ctid");
  3455. int sid = GetPostInt("SupplierName");
  3456. string fromTag = GetPostString("tag");
  3457. string[] eidList = eids.Split(',');
  3458. if (eidList.Length <= 0)
  3459. {
  3460. returnErrorMsg("指派不能为空");
  3461. return;
  3462. }
  3463. string errMsg = "";
  3464. string suname = commonHelper.getSupplierNameById(sid);
  3465. foreach (string ctid in eidList)
  3466. {
  3467. CeErpTradeCell entity = null;
  3468. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3469. if (entity != null)
  3470. {
  3471. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3472. {
  3473. errMsg += (ctid + "指派失败!!!");
  3474. continue;
  3475. }
  3476. entity.SupplierId = sid;
  3477. entity.Update();
  3478. commonHelper.UpdateRelationOrder(entity.ctid);
  3479. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3480. if (entity.OrderState >= 6)
  3481. {
  3482. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3483. //{
  3484. // string msl = entity.MakeSupplier;
  3485. // string[] mslist = msl.Split(',');
  3486. // 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);
  3487. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3488. //}
  3489. //else
  3490. //{
  3491. StringBuilder sql = new StringBuilder();
  3492. 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);
  3493. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3494. //}
  3495. }
  3496. }
  3497. else
  3498. {
  3499. continue;
  3500. }
  3501. }
  3502. if (errMsg.Length > 0)
  3503. {
  3504. returnErrorMsg(errMsg);
  3505. return;
  3506. }
  3507. returnSuccessMsg("操作成功!");
  3508. return;
  3509. }
  3510. }
  3511. public void assign_erp_makesupplier()
  3512. {
  3513. if (UrlPostParmsCheck("ctid"))
  3514. {
  3515. string eids = GetPostString("ctid");
  3516. string sname = GetPostString("SupplierName");
  3517. string[] eidList = eids.Split(',');
  3518. if (eidList.Length <= 0)
  3519. {
  3520. returnErrorMsg("指派不能为空");
  3521. return;
  3522. }
  3523. List<string> tLst = new List<string>();
  3524. foreach (string ctid in eidList)
  3525. {
  3526. CeErpTradeCell entity = null;
  3527. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3528. if (entity != null)
  3529. {
  3530. entity.MakeSupplier = sname;
  3531. entity.Update();
  3532. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3533. tLst.Add("'" + ctid + "'");
  3534. }
  3535. else
  3536. {
  3537. continue;
  3538. }
  3539. }
  3540. string ctids = string.Join(",", tLst.ToArray());
  3541. StringBuilder sql2 = new StringBuilder();
  3542. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3543. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3544. returnSuccessMsg("操作成功!");
  3545. return;
  3546. }
  3547. }
  3548. public void ins_erp_returnreason()
  3549. {
  3550. if (UrlPostParmsCheck("ctid"))
  3551. {
  3552. string eid = GetPostString("ctid");
  3553. CeErpTradeCell entity = null;
  3554. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3555. string userpost = CurrentUser.UserPost.Post.Code;
  3556. if (entity != null)
  3557. {
  3558. bool isPlace = false;
  3559. if (entity.OrderState > 6)
  3560. {
  3561. returnErrorMsg("已发货无法打回!");
  3562. return;
  3563. }
  3564. if (entity.OrderState == 6)
  3565. {
  3566. isPlace = true;
  3567. }
  3568. bool isNeedUpdateCell2 = false;
  3569. if (entity.OrderState >= 6)
  3570. {
  3571. isNeedUpdateCell2 = true;
  3572. }
  3573. int returnTag = 2;
  3574. if (userpost == "Supplier")
  3575. {
  3576. returnTag = 1;
  3577. }
  3578. int toType = GetPostInt("totype");
  3579. string fromType = "3";
  3580. if (entity.OrderState < 5)
  3581. {
  3582. fromType = "3";
  3583. }
  3584. else
  3585. {
  3586. fromType = "4";
  3587. }
  3588. if (entity.IsXianHuo == 0)
  3589. {
  3590. if (returnTag == 2)
  3591. {
  3592. if (toType == 1)
  3593. {
  3594. entity.OrderState = 0;
  3595. entity.ReturnUserType = 1;
  3596. string clearman = GetPostString("clearman");
  3597. if (!string.IsNullOrEmpty(clearman))
  3598. {
  3599. entity.DesignUserId = 0;
  3600. }
  3601. }
  3602. else
  3603. {
  3604. entity.OrderState = 3;
  3605. entity.ReturnUserType = 2;
  3606. }
  3607. entity.IsReadTag = 1;
  3608. }
  3609. else if (returnTag == 1)
  3610. {
  3611. entity.OrderState = 5;
  3612. }
  3613. entity.IsVerifyToSupplier = false;
  3614. }
  3615. if (entity.IsXianHuo == 1)
  3616. {
  3617. entity.OrderState = 5;
  3618. }
  3619. entity.UnusualTag = 0;
  3620. entity.UnusualTime = null;
  3621. entity.UnusualCon = "";
  3622. entity.IsReturn = returnTag;
  3623. entity.ReturnTime = DateTime.Now;
  3624. entity.UpdateTime = DateTime.Now;
  3625. entity.ReturnReason = GetPostString("returnreason");
  3626. entity.Update();
  3627. if (entity.OrderState == 3)
  3628. {
  3629. ApiVo apiVo = new ApiVo();
  3630. apiVo.orderNumber = entity.ctid;
  3631. apiVo.actionName = "rebutDesign";
  3632. apiVo.orderRemarks = entity.ReturnReason;
  3633. designHelper.API_WorkCore(apiVo);//rebutDesign
  3634. }
  3635. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3636. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3637. {
  3638. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3639. }
  3640. CeErpSukuraData.createInfo(entity.ctid, 5);
  3641. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3642. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3643. if (isPlace)
  3644. {
  3645. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3646. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3647. if (dth != null && dth.Rows.Count > 0)
  3648. {
  3649. dataSendOrderBean dataSendOrderBean = null;
  3650. foreach (DataRow item in dth.Rows)
  3651. {
  3652. try
  3653. {
  3654. dataSendOrderBean = new dataSendOrderBean();
  3655. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3656. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3657. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3658. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3659. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3660. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3661. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3662. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3663. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3664. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3665. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3666. dataSendOrderBean.Radio1723534706288 = "打回";
  3667. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3668. if (result != null)
  3669. {
  3670. if ("0".Equals(result.errcode))
  3671. {
  3672. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3673. }
  3674. else
  3675. {
  3676. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3677. }
  3678. }
  3679. }
  3680. catch (Exception ex)
  3681. {
  3682. }
  3683. }
  3684. }
  3685. }
  3686. if (isNeedUpdateCell2)
  3687. {
  3688. if (entity.MakeSupplier.IndexOf(",") != -1)
  3689. {
  3690. StringBuilder sql2 = new StringBuilder();
  3691. 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);
  3692. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3693. }
  3694. else
  3695. {
  3696. StringBuilder sql2 = new StringBuilder();
  3697. 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);
  3698. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3699. }
  3700. }
  3701. returnSuccessMsg("操作成功!");
  3702. return;
  3703. }
  3704. returnErrorMsg("找不到订单记录");
  3705. }
  3706. }
  3707. public void cyt_erp_returnreason()
  3708. {
  3709. if (UrlPostParmsCheck("ctid"))
  3710. {
  3711. string eid = GetPostString("ctid");
  3712. CeErpTradeCell entity = null;
  3713. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3714. string userpost = CurrentUser.UserPost.Post.Code;
  3715. if (entity != null)
  3716. {
  3717. if (entity.OrderState > 6)
  3718. {
  3719. returnErrorMsg("已发货无法打回!");
  3720. return;
  3721. }
  3722. JObject jsonObject = new JObject
  3723. {
  3724. { "Userid", "77886" },
  3725. { "Pwd", "lt666888" },
  3726. { "LTOrderId",eid }
  3727. };
  3728. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3729. JObject jsonObjects = JObject.Parse(response);
  3730. string msg = (string)jsonObjects["msg"];
  3731. if (msg != "取消成功")
  3732. {
  3733. returnErrorMsg(msg);
  3734. return;
  3735. }
  3736. bool isNeedUpdateCell2 = false;
  3737. if (entity.OrderState >= 6)
  3738. {
  3739. isNeedUpdateCell2 = true;
  3740. }
  3741. int returnTag = 2;
  3742. if (userpost == "Supplier")
  3743. {
  3744. returnTag = 1;
  3745. }
  3746. if (entity.IsXianHuo == 0)
  3747. {
  3748. if (returnTag == 2)
  3749. {
  3750. int toType = GetPostInt("totype");
  3751. if (toType == 1)
  3752. {
  3753. entity.OrderState = 0;
  3754. entity.ReturnUserType = 1;
  3755. }
  3756. else
  3757. {
  3758. entity.OrderState = 4;
  3759. entity.ReturnUserType = 2;
  3760. }
  3761. entity.IsReadTag = 1;
  3762. }
  3763. else if (returnTag == 1)
  3764. {
  3765. entity.OrderState = 5;
  3766. }
  3767. entity.IsVerifyToSupplier = false;
  3768. }
  3769. entity.UnusualTag = 0;
  3770. entity.UnusualTime = null;
  3771. entity.UnusualCon = "";
  3772. entity.IsReturn = returnTag;
  3773. entity.ReturnTime = DateTime.Now;
  3774. entity.ReturnReason = GetPostString("returnreason");
  3775. entity.Update();
  3776. if (entity.OrderState == 4)
  3777. {
  3778. ApiVo apiVo = new ApiVo();
  3779. apiVo.orderNumber = entity.ctid;
  3780. apiVo.actionName = "rebutDesign";
  3781. apiVo.orderRemarks = entity.ReturnReason;
  3782. designHelper.API_WorkCore(apiVo);//rebutDesign
  3783. }
  3784. CeErpSukuraData.createInfo(entity.ctid, 5);
  3785. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3786. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3787. if (isNeedUpdateCell2)
  3788. {
  3789. if (entity.MakeSupplier.IndexOf(",") != -1)
  3790. {
  3791. StringBuilder sql2 = new StringBuilder();
  3792. 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);
  3793. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3794. }
  3795. else
  3796. {
  3797. StringBuilder sql2 = new StringBuilder();
  3798. 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);
  3799. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3800. }
  3801. }
  3802. returnSuccessMsg("操作成功!");
  3803. return;
  3804. }
  3805. returnErrorMsg("找不到订单记录");
  3806. }
  3807. }
  3808. public void upd_erp_xianhuoreturntag()
  3809. {
  3810. if (UrlPostParmsCheck("ctid"))
  3811. {
  3812. string eids = GetPostString("ctid");
  3813. string[] ctids = eids.Split(',');
  3814. foreach (string ctid in ctids)
  3815. {
  3816. CeErpTradeCell entity = null;
  3817. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3818. if (entity != null)
  3819. {
  3820. entity.IsReturn = 0;
  3821. entity.Update();
  3822. CeErpSukuraData.createInfo(entity.ctid, 5);
  3823. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  3824. }
  3825. }
  3826. returnSuccessMsg("操作成功!");
  3827. return;
  3828. }
  3829. }
  3830. public void get_erp_waitdeliverylist()
  3831. {
  3832. DataStruct dStruct = GetPostStruct();
  3833. List<string> lw = new List<string>();
  3834. string tid = GetPostString("ctid");
  3835. if (tid.Length > 0)
  3836. {
  3837. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  3838. if (tid.Length > 5)
  3839. {
  3840. List<string> tids = getTidByCtidLike(tid);
  3841. if (tids.Count > 0 && tids.Count < 10)
  3842. {
  3843. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  3844. }
  3845. }
  3846. lw.Add(tid_sql);
  3847. }
  3848. string shopname = GetPostString("shopname");
  3849. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3850. string buyernick = GetPostString("buyer_nick");
  3851. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3852. //if (tid.Length == 0 && buyernick.Length == 0)
  3853. //{
  3854. // lw.Add(string.Format("IsRefund<={0}", 1));
  3855. //}
  3856. string customer = GetPostString("customer");
  3857. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3858. string design = GetPostString("design");
  3859. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3860. string orderState = GetPostString("orderState");
  3861. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3862. string address = GetPostString("address");
  3863. 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));
  3864. string sellermemo = GetPostString("seller_memo");
  3865. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3866. string supplier = GetPostString("supplier");
  3867. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3868. string OrderArea = GetPostString("order_area");
  3869. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  3870. string placedate1 = GetPostString("placedate1");
  3871. string placedate2 = GetPostString("placedate2");
  3872. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  3873. if (fdw.Length > 0) lw.Add(fdw);
  3874. string price1 = GetPostString("price1");
  3875. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3876. string price2 = GetPostString("price2");
  3877. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3878. string unusualCon = GetPostString("unusualcon");
  3879. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  3880. string otherMemo = GetPostString("otherMemo");
  3881. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3882. string posTag = CurrentUser.UserPost.Post.Code;
  3883. if (posTag == "Supplier")
  3884. {
  3885. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3886. }
  3887. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  3888. lw.Add(string.Format("type != 'PDD' "));
  3889. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  3890. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  3891. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3892. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3893. writeGridDataTableJson(dStruct.TotalCount, dt);
  3894. }
  3895. public void get_erp_changedeliverylist()
  3896. {
  3897. DataStruct dStruct = GetPostStruct();
  3898. List<string> lw = new List<string>();
  3899. string tid = GetPostString("ctid");
  3900. if (tid.Length > 0)
  3901. {
  3902. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  3903. if (tid.Length > 5)
  3904. {
  3905. List<string> tids = getTidByCtidLike(tid);
  3906. if (tids.Count > 0 && tids.Count < 10)
  3907. {
  3908. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  3909. }
  3910. }
  3911. lw.Add(tid_sql);
  3912. }
  3913. string shopname = GetPostString("shopname");
  3914. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3915. string buyernick = GetPostString("buyer_nick");
  3916. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3917. //if (tid.Length == 0 && buyernick.Length == 0)
  3918. //{
  3919. // lw.Add(string.Format("IsRefund<={0}", 1));
  3920. //}
  3921. string customer = GetPostString("customer");
  3922. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3923. string design = GetPostString("design");
  3924. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3925. string orderState = GetPostString("orderState");
  3926. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3927. string address = GetPostString("address");
  3928. 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));
  3929. string sellermemo = GetPostString("seller_memo");
  3930. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3931. string supplier = GetPostString("supplier");
  3932. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3933. string OrderArea = GetPostString("order_area");
  3934. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  3935. string placedate1 = GetPostString("placedate1");
  3936. string placedate2 = GetPostString("placedate2");
  3937. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  3938. if (fdw.Length > 0) lw.Add(fdw);
  3939. string price1 = GetPostString("price1");
  3940. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3941. string price2 = GetPostString("price2");
  3942. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3943. string unusualCon = GetPostString("unusualcon");
  3944. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  3945. string otherMemo = GetPostString("otherMemo");
  3946. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3947. string posTag = CurrentUser.UserPost.Post.Code;
  3948. if (posTag == "Supplier")
  3949. {
  3950. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3951. }
  3952. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  3953. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  3954. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  3955. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3956. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3957. /*if (tid.Length > 0)
  3958. {
  3959. List<string> tids = new List<string>();
  3960. if (dt != null && dt.Rows.Count > 0)
  3961. {
  3962. foreach (DataRow item in dt.Rows)
  3963. {
  3964. tids.Add("'" + item["tid"] + "'");
  3965. }
  3966. }
  3967. if (tids.Count > 0)
  3968. {
  3969. lw.RemoveAt(0);
  3970. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  3971. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3972. dt = WebCache.GetData("view_erptradecell", dStruct);
  3973. }
  3974. }*/
  3975. writeGridDataTableJson(dStruct.TotalCount, dt);
  3976. }
  3977. public void get_erp_pddderiving()
  3978. {
  3979. DataStruct dStruct = GetPostStruct();
  3980. List<string> lw = new List<string>();
  3981. string tid = GetPostString("ctid");
  3982. if (tid.Length > 0)
  3983. {
  3984. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  3985. if (tid.Length > 5)
  3986. {
  3987. List<string> tids = getTidByCtidLike(tid);
  3988. if (tids.Count > 0 && tids.Count < 10)
  3989. {
  3990. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  3991. }
  3992. }
  3993. lw.Add(tid_sql);
  3994. }
  3995. string shopname = GetPostString("shopname");
  3996. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3997. string buyernick = GetPostString("buyer_nick");
  3998. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3999. //if (tid.Length == 0 && buyernick.Length == 0)
  4000. //{
  4001. // lw.Add(string.Format("IsRefund<={0}", 1));
  4002. //}
  4003. string customer = GetPostString("customer");
  4004. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4005. string design = GetPostString("design");
  4006. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4007. string orderState = GetPostString("orderState");
  4008. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4009. string address = GetPostString("address");
  4010. 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));
  4011. string sellermemo = GetPostString("seller_memo");
  4012. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4013. string supplier = GetPostString("supplier");
  4014. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4015. string OrderArea = GetPostString("order_area");
  4016. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4017. string placedate1 = GetPostString("placedate1");
  4018. string placedate2 = GetPostString("placedate2");
  4019. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4020. if (fdw.Length > 0) lw.Add(fdw);
  4021. string price1 = GetPostString("price1");
  4022. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4023. string price2 = GetPostString("price2");
  4024. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4025. string unusualCon = GetPostString("unusualcon");
  4026. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4027. string posTag = CurrentUser.UserPost.Post.Code;
  4028. if (posTag == "Supplier")
  4029. {
  4030. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4031. }
  4032. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4033. lw.Add(string.Format("type = 'PDD' "));
  4034. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4035. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4036. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4037. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4038. /*if (tid.Length > 0)
  4039. {
  4040. List<string> tids = new List<string>();
  4041. if (dt != null && dt.Rows.Count > 0)
  4042. {
  4043. foreach (DataRow item in dt.Rows)
  4044. {
  4045. tids.Add("'" + item["tid"] + "'");
  4046. }
  4047. }
  4048. if (tids.Count > 0)
  4049. {
  4050. lw.RemoveAt(0);
  4051. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4052. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4053. dt = WebCache.GetData("view_erptradecell", dStruct);
  4054. }
  4055. }*/
  4056. writeGridDataTableJson(dStruct.TotalCount, dt);
  4057. }
  4058. public void get_erp_jdderiving()
  4059. {
  4060. DataStruct dStruct = GetPostStruct();
  4061. List<string> lw = new List<string>();
  4062. string tid = GetPostString("ctid");
  4063. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4064. string shopname = GetPostString("shopname");
  4065. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4066. string buyernick = GetPostString("buyer_nick");
  4067. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4068. //if (tid.Length == 0 && buyernick.Length == 0)
  4069. //{
  4070. // lw.Add(string.Format("IsRefund<={0}", 1));
  4071. //}
  4072. string customer = GetPostString("customer");
  4073. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4074. string design = GetPostString("design");
  4075. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4076. string orderState = GetPostString("orderState");
  4077. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4078. string address = GetPostString("address");
  4079. 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));
  4080. string sellermemo = GetPostString("seller_memo");
  4081. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4082. string supplier = GetPostString("supplier");
  4083. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4084. string OrderArea = GetPostString("order_area");
  4085. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4086. string placedate1 = GetPostString("placedate1");
  4087. string placedate2 = GetPostString("placedate2");
  4088. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4089. if (fdw.Length > 0) lw.Add(fdw);
  4090. string price1 = GetPostString("price1");
  4091. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4092. string price2 = GetPostString("price2");
  4093. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4094. string unusualCon = GetPostString("unusualcon");
  4095. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4096. string posTag = CurrentUser.UserPost.Post.Code;
  4097. if (posTag == "Supplier")
  4098. {
  4099. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4100. }
  4101. lw.Add(string.Format("OrderState = 6 "));
  4102. lw.Add(string.Format("type = 'JD' "));
  4103. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4104. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4105. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4106. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4107. writeGridDataTableJson(dStruct.TotalCount, dt);
  4108. }
  4109. public void get_erp_demoorderlist()
  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 select_tid = getTidByCtid(tid);
  4117. lw.Add(string.Format("tid='{0}'", select_tid));
  4118. }
  4119. string shopname = GetPostString("shopname");
  4120. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4121. string buyernick = GetPostString("buyer_nick");
  4122. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4123. string customer = GetPostString("customer");
  4124. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4125. string design = GetPostString("design");
  4126. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4127. string orderState = GetPostString("orderState");
  4128. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4129. string address = GetPostString("address");
  4130. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4131. string sellermemo = GetPostString("seller_memo");
  4132. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4133. string supplier = GetPostString("supplier");
  4134. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4135. string OrderArea = GetPostString("order_area");
  4136. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4137. string date1 = GetPostString("date1");
  4138. string date2 = GetPostString("date2");
  4139. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4140. if (dw.Length > 0) lw.Add(dw);
  4141. string price1 = GetPostString("price1");
  4142. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4143. string price2 = GetPostString("price2");
  4144. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4145. string posTag = CurrentUser.UserPost.Post.Code;
  4146. if (posTag == "Supplier")
  4147. {
  4148. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4149. }
  4150. //lw.Add(string.Format("OrderState = 6 "));
  4151. lw.Add(string.Format("IsSample={0}", 3));
  4152. lw.Add(string.Format("IsRefund<={0}", 1));
  4153. dStruct.Order = "pay_time desc";
  4154. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4155. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4156. writeGridDataTableJson(dStruct.TotalCount, dt);
  4157. }
  4158. public void save_erp_checkmemo()
  4159. {
  4160. if (UrlPostParmsCheck("ctid"))
  4161. {
  4162. string ctid = GetPostString("ctid");
  4163. CeErpTradeCell entity = null;
  4164. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4165. if (entity != null)
  4166. {
  4167. entity.CheckMemo = GetPostString("CheckMemo");
  4168. entity.Update();
  4169. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4170. if (trade != null)
  4171. {
  4172. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4173. }
  4174. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4175. returnSuccessMsg("保存成功!");
  4176. return;
  4177. }
  4178. returnErrorMsg("找不到记录");
  4179. }
  4180. }
  4181. public void get_erp_returnlist()
  4182. {
  4183. DataStruct dStruct = GetPostStruct();
  4184. List<string> lw = new List<string>();
  4185. string tid = GetPostString("ctid");
  4186. if (tid.Length > 0)
  4187. {
  4188. string select_tid = getTidByCtid(tid);
  4189. lw.Add(string.Format("tid='{0}'", select_tid));
  4190. }
  4191. string shopname = GetPostString("shopname");
  4192. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4193. string buyernick = GetPostString("buyer_nick");
  4194. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4195. string customer = GetPostString("customer");
  4196. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4197. string design = GetPostString("design");
  4198. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4199. string orderState = GetPostString("orderState");
  4200. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4201. string address = GetPostString("address");
  4202. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4203. string sellermemo = GetPostString("seller_memo");
  4204. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4205. string supplier = GetPostString("supplier");
  4206. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4207. string date1 = GetPostString("date1");
  4208. string date2 = GetPostString("date2");
  4209. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4210. if (dw.Length > 0) lw.Add(dw);
  4211. string bdate1 = GetPostString("backdate1");
  4212. string bdate2 = GetPostString("backdate2");
  4213. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4214. if (dw_back.Length > 0) lw.Add(dw_back);
  4215. string price1 = GetPostString("price1");
  4216. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4217. string price2 = GetPostString("price2");
  4218. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4219. lw.Add(string.Format("IsReturn>0"));
  4220. lw.Add(string.Format("IsXianHuo=0"));
  4221. lw.Add(string.Format("IsReturn!=3"));
  4222. string backtype = GetPostString("backtype");
  4223. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4224. dStruct.Order = "FinishDesignTime desc";
  4225. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4226. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4227. writeGridDataTableJson(dStruct.TotalCount, dt);
  4228. }
  4229. public void get_erp_today_sumreturn()
  4230. {
  4231. DataStruct dStruct = GetPostStruct();
  4232. List<string> lw = new List<string>();
  4233. string bdate1 = GetPostString("returnTimeS");
  4234. string bdate2 = GetPostString("returnTimeE");
  4235. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4236. if (dw_back.Length > 0) lw.Add(dw_back);
  4237. lw.Add(string.Format("IsReturn=0"));
  4238. lw.Add(string.Format("IsXianHuo=0"));
  4239. string mainWhere = string.Join(" and ", lw.ToArray());
  4240. string sql = "";
  4241. if (dw_back.Length > 0)
  4242. {
  4243. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4244. }
  4245. else
  4246. {
  4247. 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 + "'";
  4248. }
  4249. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4250. decimal total = 0, today_finish = 0;
  4251. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4252. {
  4253. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4254. }
  4255. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4256. {
  4257. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4258. }
  4259. var res = new
  4260. {
  4261. data = total,
  4262. data1 = today_finish,
  4263. };
  4264. string ro_jsond = JsonConvert.SerializeObject(res);
  4265. returnSuccess(ro_jsond);
  4266. return;
  4267. }
  4268. public void get_erp_allreturnlist()
  4269. {
  4270. DataStruct dStruct = GetPostStruct();
  4271. List<string> lw = new List<string>();
  4272. string tid = GetPostString("ctid");
  4273. if (tid.Length > 0)
  4274. {
  4275. string select_tid = getTidByCtid(tid);
  4276. lw.Add(string.Format("tid='{0}'", select_tid));
  4277. }
  4278. string shopname = GetPostString("shopname");
  4279. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4280. string buyernick = GetPostString("buyer_nick");
  4281. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4282. string customer = GetPostString("customer");
  4283. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4284. string design = GetPostString("design");
  4285. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4286. string orderState = GetPostString("orderState");
  4287. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4288. string address = GetPostString("address");
  4289. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4290. string sellermemo = GetPostString("seller_memo");
  4291. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4292. string supplier = GetPostString("supplier");
  4293. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4294. string date1 = GetPostString("date1");
  4295. string date2 = GetPostString("date2");
  4296. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4297. if (dw.Length > 0) lw.Add(dw);
  4298. string bdate1 = GetPostString("backdate1");
  4299. string bdate2 = GetPostString("backdate2");
  4300. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4301. if (dw_back.Length > 0) lw.Add(dw_back);
  4302. string price1 = GetPostString("price1");
  4303. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4304. string price2 = GetPostString("price2");
  4305. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4306. string backreason = GetPostString("backreason");
  4307. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4308. lw.Add(string.Format("IsXianHuo=0"));
  4309. lw.Add(string.Format("ReturnTime != ''"));
  4310. string backtype = GetPostString("backtype");
  4311. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4312. dStruct.Order = "FinishDesignTime desc";
  4313. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4314. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4315. writeGridDataTableJson(dStruct.TotalCount, dt);
  4316. }
  4317. public void get_erp_aftersalereturnlist()
  4318. {
  4319. DataStruct dStruct = GetPostStruct();
  4320. List<string> lw = new List<string>();
  4321. string tid = GetPostString("ctid");
  4322. if (tid.Length > 0)
  4323. {
  4324. string select_tid = getTidByCtid(tid);
  4325. lw.Add(string.Format("tid='{0}'", select_tid));
  4326. }
  4327. string shopname = GetPostString("shopname");
  4328. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4329. string buyernick = GetPostString("buyer_nick");
  4330. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4331. string customer = GetPostString("customer");
  4332. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4333. string design = GetPostString("design");
  4334. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4335. string orderState = GetPostString("orderState");
  4336. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4337. string address = GetPostString("address");
  4338. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4339. string sellermemo = GetPostString("seller_memo");
  4340. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4341. string supplier = GetPostString("supplier");
  4342. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4343. string date1 = GetPostString("date1");
  4344. string date2 = GetPostString("date2");
  4345. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4346. if (dw.Length > 0) lw.Add(dw);
  4347. string bdate1 = GetPostString("backdate1");
  4348. string bdate2 = GetPostString("backdate2");
  4349. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4350. if (dw_back.Length > 0) lw.Add(dw_back);
  4351. string price1 = GetPostString("price1");
  4352. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4353. string price2 = GetPostString("price2");
  4354. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4355. lw.Add(string.Format("IsReturn=3"));
  4356. string backtype = GetPostString("backtype");
  4357. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4358. string backreason = GetPostString("backreason");
  4359. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4360. dStruct.Order = "ReturnTime desc";
  4361. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4362. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4363. writeGridDataTableJson(dStruct.TotalCount, dt);
  4364. }
  4365. public void get_erp_xianhuoreturnlist()
  4366. {
  4367. DataStruct dStruct = GetPostStruct();
  4368. List<string> lw = new List<string>();
  4369. string tid = GetPostString("ctid");
  4370. if (tid.Length > 0)
  4371. {
  4372. string select_tid = getTidByCtid(tid);
  4373. lw.Add(string.Format("tid='{0}'", select_tid));
  4374. }
  4375. string shopname = GetPostString("shopname");
  4376. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4377. string buyernick = GetPostString("buyer_nick");
  4378. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4379. string customer = GetPostString("customer");
  4380. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4381. string design = GetPostString("design");
  4382. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4383. string orderState = GetPostString("orderState");
  4384. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4385. string address = GetPostString("address");
  4386. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4387. string sellermemo = GetPostString("seller_memo");
  4388. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4389. string supplier = GetPostString("supplier");
  4390. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4391. string OrderArea = GetPostString("order_area");
  4392. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4393. string date1 = GetPostString("date1");
  4394. string date2 = GetPostString("date2");
  4395. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4396. if (dw.Length > 0) lw.Add(dw);
  4397. string price1 = GetPostString("price1");
  4398. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4399. string price2 = GetPostString("price2");
  4400. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4401. string posTag = CurrentUser.UserPost.Post.Code;
  4402. if (posTag == "Supplier")
  4403. {
  4404. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4405. }
  4406. lw.Add(string.Format("OrderState=6 "));
  4407. lw.Add(string.Format("IsXianHuo=1 "));
  4408. lw.Add(string.Format("IsReturn>0 "));
  4409. lw.Add(string.Format("IsReturn!=3"));
  4410. lw.Add(string.Format("IsRefund<={0}", 1));
  4411. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4412. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4413. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4414. writeGridDataTableJson(dStruct.TotalCount, dt);
  4415. }
  4416. public void set_erp_orderdelivery()
  4417. {
  4418. if (UrlPostParmsCheck("ctid"))
  4419. {
  4420. string eid = GetPostString("ctid");
  4421. CeErpTradeCell entity = null;
  4422. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4423. if (entity != null)
  4424. {
  4425. if (entity.OrderState >= 7)
  4426. {
  4427. returnErrorMsg("此单已发货,无需重复发货");
  4428. return;
  4429. }
  4430. if (entity.OrderState != 6)
  4431. {
  4432. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4433. return;
  4434. }
  4435. string shop = GetPostString("seller_nick");
  4436. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4437. string comName = GetPostString("comName");
  4438. string comCode = GetPostString("comCode");
  4439. string outSid = GetPostString("outSid");
  4440. string deliveryType = GetPostString("deliveryType");
  4441. string deliveryMemo = GetPostString("deliveryMemo");
  4442. outSid = outSid.Trim();
  4443. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4444. if (mainEn == null)
  4445. {
  4446. returnErrorMsg("找不到原始订单记录");
  4447. return;
  4448. }
  4449. bool isInitOrderDeliv = false;
  4450. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4451. {
  4452. isInitOrderDeliv = true;
  4453. }
  4454. string apires = "";
  4455. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4456. 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)
  4457. {
  4458. apires = "发货成功true";
  4459. }
  4460. else
  4461. {
  4462. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4463. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4464. }
  4465. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4466. {
  4467. entity.OrderState = 7;//发货后订单已发货
  4468. entity.OutSid = outSid;
  4469. entity.MemoOpt = 0;
  4470. entity.UpdateTime = DateTime.Now;
  4471. entity.FinishDeliveryTime = DateTime.Now;
  4472. entity.Update();
  4473. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4474. commonHelper.UpdateRelationOrder(entity.ctid);
  4475. //还要插入快递信息到 快递信息表
  4476. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4477. exinfo.tid = eid;
  4478. exinfo.out_sid = outSid;
  4479. exinfo.company_code = comCode;
  4480. exinfo.company_name = comName;
  4481. exinfo.delivery_memo = deliveryMemo;
  4482. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4483. exinfo.deliveryType = deliveryType;
  4484. exinfo.Create();
  4485. returnSuccessMsg("发货操作成功!");
  4486. commonHelper.UpdateRelationOrder(entity.ctid);
  4487. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4488. CeErpSukuraData.createInfo(entity.ctid, 4);
  4489. if (entity.SupplierId == 64)
  4490. {
  4491. commonHelper.sendCytExpress(exinfo);
  4492. }
  4493. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4494. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4495. }
  4496. else
  4497. {
  4498. string errmsg = commonHelper.KeepChinese(apires);
  4499. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4500. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4501. }
  4502. return;
  4503. }
  4504. returnErrorMsg("找不到订单记录");
  4505. }
  4506. }
  4507. public void set_erp_multidelivery()
  4508. {
  4509. string eids = GetPostString("tids");
  4510. string[] eidList = eids.Split(',');
  4511. if (eidList.Length <= 0)
  4512. {
  4513. returnErrorMsg("发货不能为空");
  4514. return;
  4515. }
  4516. foreach (string ctid in eidList)
  4517. {
  4518. if (ctid.Length <= 0) continue;
  4519. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4520. if (expInfo != null)
  4521. {
  4522. StringBuilder sql = new StringBuilder();
  4523. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4524. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4525. if (dt.Rows.Count > 0)
  4526. {
  4527. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4528. {
  4529. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4530. expInfo.state = "异常";
  4531. expInfo.isMultiDelivery = 1;
  4532. expInfo.Update();
  4533. continue;
  4534. }
  4535. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4536. {
  4537. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4538. expInfo.state = "异常";
  4539. expInfo.Update();
  4540. continue;
  4541. }
  4542. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4543. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4544. bool isInitOrderDeliv = false;
  4545. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4546. {
  4547. isInitOrderDeliv = true;
  4548. expInfo.isMultiDelivery = 1;
  4549. }
  4550. if (ctid.IndexOf("N") != -1)
  4551. {
  4552. StringBuilder sqlbucha = new StringBuilder();
  4553. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4554. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4555. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4556. commonHelper.UpdateRelationOrder(ctid);
  4557. expInfo.delivery_memo = "发货成功";
  4558. expInfo.state = "发货成功";
  4559. expInfo.isMultiDelivery = 1;
  4560. expInfo.Update();
  4561. }
  4562. else
  4563. {
  4564. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4565. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4566. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4567. {
  4568. expInfo.delivery_memo = "发货成功";
  4569. expInfo.state = "发货成功";
  4570. expInfo.isMultiDelivery = 1;
  4571. expInfo.Update();
  4572. commonHelper.UpdateRelationOrder(ctid);
  4573. CeErpSukuraData.createInfo(ctid, 4);
  4574. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4575. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4576. }
  4577. else
  4578. {
  4579. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4580. expInfo.state = "异常";
  4581. expInfo.Update();
  4582. }
  4583. }
  4584. }
  4585. }
  4586. }
  4587. returnSuccessMsg("操作完成");
  4588. }
  4589. public void reset_erp_memoopt()
  4590. {
  4591. if (UrlPostParmsCheck("ctid"))
  4592. {
  4593. string eid = GetPostString("ctid");
  4594. CeErpTradeCell entity = null;
  4595. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4596. if (entity != null)
  4597. {
  4598. string stropt = "";
  4599. if (entity.MemoOpt == 1)
  4600. {
  4601. stropt = "“改稿”";
  4602. }
  4603. else if (entity.MemoOpt == 2)
  4604. {
  4605. stropt = "“定稿”";
  4606. }
  4607. else if (entity.MemoOpt == 3)
  4608. {
  4609. stropt = "“完成查货”";
  4610. CeErpSukuraData.createInfo(entity.ctid, 6);
  4611. }
  4612. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4613. entity.UpdateTime = DateTime.Now;
  4614. entity.MemoOpt = 0;
  4615. entity.Update();
  4616. returnSuccessMsg("操作成功!");
  4617. return;
  4618. }
  4619. returnErrorMsg("找不到记录");
  4620. }
  4621. }
  4622. public void get_erp_deliveryunusual()
  4623. {
  4624. DataStruct dStruct = GetPostStruct();
  4625. List<string> lw = new List<string>();
  4626. string tid = GetPostString("ctid");
  4627. if (tid.Length > 0)
  4628. {
  4629. string select_tid = getTidByCtid(tid);
  4630. lw.Add(string.Format("tid='{0}'", select_tid));
  4631. }
  4632. string shopname = GetPostString("shopname");
  4633. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4634. string buyernick = GetPostString("buyer_nick");
  4635. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4636. string customer = GetPostString("customer");
  4637. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4638. string design = GetPostString("design");
  4639. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4640. string sellermemo = GetPostString("seller_memo");
  4641. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4642. string supplier = GetPostString("supplier");
  4643. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4644. string date1 = GetPostString("date1");
  4645. string date2 = GetPostString("date2");
  4646. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4647. if (dw.Length > 0) lw.Add(dw);
  4648. string placedate1 = GetPostString("placedate1");
  4649. string placedate2 = GetPostString("placedate2");
  4650. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4651. if (dw_place.Length > 0) lw.Add(dw_place);
  4652. string price1 = GetPostString("price1");
  4653. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4654. string price2 = GetPostString("price2");
  4655. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4656. string unusualCon = GetPostString("unusualcon");
  4657. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4658. string posTag = CurrentUser.UserPost.Post.Code;
  4659. if (posTag == "Supplier")
  4660. {
  4661. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4662. }
  4663. lw.Add(string.Format("OrderState = 6"));
  4664. lw.Add(string.Format("UnusualTag = 5"));
  4665. lw.Add(string.Format("IsRefund<={0}", 1));
  4666. dStruct.Order = "FinishPlaceTime desc";
  4667. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4668. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4669. writeGridDataTableJson(dStruct.TotalCount, dt);
  4670. }
  4671. public void get_erp_deliveryedlist()
  4672. {
  4673. DataStruct dStruct = GetPostStruct();
  4674. List<string> lw = new List<string>();
  4675. string tid = GetPostString("ctid");
  4676. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4677. string shopname = GetPostString("shopname");
  4678. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4679. string buyernick = GetPostString("buyer_nick");
  4680. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4681. string customer = GetPostString("customer");
  4682. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4683. string design = GetPostString("design");
  4684. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4685. string sellermemo = GetPostString("seller_memo");
  4686. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4687. string logistics = GetPostString("logistics");
  4688. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4689. string date1 = GetPostString("date1");
  4690. string date2 = GetPostString("date2");
  4691. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4692. //if (dw.Length > 0) lw.Add(dw);
  4693. string placedate1 = GetPostString("placedate1");
  4694. string placedate2 = GetPostString("placedate2");
  4695. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4696. if (fdw.Length > 0) lw.Add(fdw);
  4697. string devdate1 = GetPostString("deliverydate1");
  4698. string devdate2 = GetPostString("deliverydate2");
  4699. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4700. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4701. string price1 = GetPostString("price1");
  4702. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4703. string price2 = GetPostString("price2");
  4704. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4705. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4706. {
  4707. if (tid.Length > 0)
  4708. {
  4709. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4710. if (tid.Length > 5)
  4711. {
  4712. List<string> tids = getTidByCtidLike(tid);
  4713. if (tids.Count > 0 && tids.Count < 10)
  4714. {
  4715. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4716. }
  4717. }
  4718. lw.Add(tid_sql);
  4719. }
  4720. if (buyernick.Length > 0)
  4721. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4722. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4723. if (dw.Length > 0) lw.Add(dw);
  4724. }
  4725. else
  4726. {
  4727. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4728. }
  4729. string posTag = CurrentUser.UserPost.Post.Code;
  4730. if (posTag == "Supplier")
  4731. {
  4732. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4733. }
  4734. else
  4735. {
  4736. string supplier = GetPostString("supplier");
  4737. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4738. }
  4739. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4740. lw.Add(string.Format("type != 'PDD' "));
  4741. lw.Add(string.Format("IsRefund!={0}", 2));
  4742. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4743. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4744. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4745. /*if (tid.Length > 0)
  4746. {
  4747. List<string> tids = new List<string>();
  4748. if (dt != null && dt.Rows.Count > 0)
  4749. {
  4750. foreach (DataRow item in dt.Rows)
  4751. {
  4752. tids.Add("'" + item["tid"] + "'");
  4753. }
  4754. }
  4755. if (tids.Count > 0)
  4756. {
  4757. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4758. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4759. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4760. dt = WebCache.GetData("view_erptradecell", dStruct);
  4761. }
  4762. }*/
  4763. if (dt != null)
  4764. {
  4765. foreach (DataRow dr in dt.Rows)
  4766. {
  4767. 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();
  4768. }
  4769. }
  4770. writeGridDataTableJson(dStruct.TotalCount, dt);
  4771. }
  4772. public void get_erp_pdddeliveryed()
  4773. {
  4774. DataStruct dStruct = GetPostStruct();
  4775. List<string> lw = new List<string>();
  4776. string tid = GetPostString("ctid");
  4777. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4778. string shopname = GetPostString("shopname");
  4779. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4780. string buyernick = GetPostString("buyer_nick");
  4781. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4782. string customer = GetPostString("customer");
  4783. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4784. string design = GetPostString("design");
  4785. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4786. string sellermemo = GetPostString("seller_memo");
  4787. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4788. string logistics = GetPostString("logistics");
  4789. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4790. string date1 = GetPostString("date1");
  4791. string date2 = GetPostString("date2");
  4792. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4793. //if (dw.Length > 0) lw.Add(dw);
  4794. string placedate1 = GetPostString("placedate1");
  4795. string placedate2 = GetPostString("placedate2");
  4796. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4797. if (fdw.Length > 0) lw.Add(fdw);
  4798. string devdate1 = GetPostString("deliverydate1");
  4799. string devdate2 = GetPostString("deliverydate2");
  4800. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4801. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4802. string price1 = GetPostString("price1");
  4803. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4804. string price2 = GetPostString("price2");
  4805. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4806. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4807. {
  4808. if (tid.Length > 0)
  4809. {
  4810. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4811. if (tid.Length > 5)
  4812. {
  4813. List<string> tids = getTidByCtidLike(tid);
  4814. if (tids.Count > 0 && tids.Count < 10)
  4815. {
  4816. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4817. }
  4818. }
  4819. lw.Add(tid_sql);
  4820. }
  4821. if (buyernick.Length > 0)
  4822. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4823. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4824. if (dw.Length > 0) lw.Add(dw);
  4825. }
  4826. else
  4827. {
  4828. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4829. }
  4830. string posTag = CurrentUser.UserPost.Post.Code;
  4831. if (posTag == "Supplier")
  4832. {
  4833. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4834. }
  4835. else
  4836. {
  4837. string supplier = GetPostString("supplier");
  4838. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4839. }
  4840. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4841. lw.Add(string.Format("type = 'PDD' "));
  4842. lw.Add(string.Format("IsRefund!={0}", 2));
  4843. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4844. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4845. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4846. /* if (tid.Length > 0)
  4847. {
  4848. List<string> tids = new List<string>();
  4849. if (dt != null && dt.Rows.Count > 0)
  4850. {
  4851. foreach (DataRow item in dt.Rows)
  4852. {
  4853. tids.Add("'" + item["tid"] + "'");
  4854. }
  4855. }
  4856. if (tids.Count > 0)
  4857. {
  4858. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4859. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4860. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4861. dt = WebCache.GetData("view_erptradecell", dStruct);
  4862. }
  4863. }*/
  4864. foreach (DataRow dr in dt.Rows)
  4865. {
  4866. 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();
  4867. }
  4868. writeGridDataTableJson(dStruct.TotalCount, dt);
  4869. }
  4870. public void get_erp_jddeliveryed()
  4871. {
  4872. DataStruct dStruct = GetPostStruct();
  4873. List<string> lw = new List<string>();
  4874. string tid = GetPostString("ctid");
  4875. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4876. string shopname = GetPostString("shopname");
  4877. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4878. string buyernick = GetPostString("buyer_nick");
  4879. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4880. string customer = GetPostString("customer");
  4881. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4882. string design = GetPostString("design");
  4883. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4884. string sellermemo = GetPostString("seller_memo");
  4885. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4886. string date1 = GetPostString("date1");
  4887. string date2 = GetPostString("date2");
  4888. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4889. //if (dw.Length > 0) lw.Add(dw);
  4890. string placedate1 = GetPostString("placedate1");
  4891. string placedate2 = GetPostString("placedate2");
  4892. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4893. if (fdw.Length > 0) lw.Add(fdw);
  4894. string devdate1 = GetPostString("deliverydate1");
  4895. string devdate2 = GetPostString("deliverydate2");
  4896. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4897. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4898. string price1 = GetPostString("price1");
  4899. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4900. string price2 = GetPostString("price2");
  4901. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4902. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4903. {
  4904. if (tid.Length > 0)
  4905. lw.Add(string.Format("ctid like '%{0}%'", tid));
  4906. if (buyernick.Length > 0)
  4907. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4908. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4909. if (dw.Length > 0) lw.Add(dw);
  4910. }
  4911. else
  4912. {
  4913. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4914. }
  4915. string posTag = CurrentUser.UserPost.Post.Code;
  4916. if (posTag == "Supplier")
  4917. {
  4918. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4919. }
  4920. else
  4921. {
  4922. string supplier = GetPostString("supplier");
  4923. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4924. }
  4925. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4926. lw.Add(string.Format("type = 'JD' "));
  4927. lw.Add(string.Format("IsRefund!={0}", 2));
  4928. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4929. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4930. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4931. foreach (DataRow dr in dt.Rows)
  4932. {
  4933. 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();
  4934. }
  4935. writeGridDataTableJson(dStruct.TotalCount, dt);
  4936. }
  4937. public void get_erp_allplacelist()
  4938. {
  4939. DataStruct dStruct = GetPostStruct();
  4940. List<string> lw = new List<string>();
  4941. string tid = GetPostString("ctid");
  4942. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  4943. string shopname = GetPostString("shopname");
  4944. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4945. string buyernick = GetPostString("buyer_nick");
  4946. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4947. string customer = GetPostString("customer");
  4948. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4949. string design = GetPostString("design");
  4950. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4951. string sellermemo = GetPostString("seller_memo");
  4952. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4953. string supplier = GetPostString("supplier");
  4954. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  4955. string date1 = GetPostString("date1");
  4956. string date2 = GetPostString("date2");
  4957. string pldate1 = GetPostString("placedate1");
  4958. string pldate2 = GetPostString("placedate2");
  4959. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4960. //if (dw.Length > 0) lw.Add(dw);
  4961. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  4962. {
  4963. if (tid.Length > 0)
  4964. {
  4965. string select_tid = getTidByCtid(tid);
  4966. lw.Add(string.Format("tid='{0}'", select_tid));
  4967. }
  4968. if (buyernick.Length > 0)
  4969. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4970. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4971. if (dw.Length > 0) lw.Add(dw);
  4972. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  4973. if (dw_place.Length > 0) lw.Add(dw_place);
  4974. }
  4975. else
  4976. {
  4977. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  4978. {
  4979. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4980. }
  4981. }
  4982. string price1 = GetPostString("price1");
  4983. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4984. string price2 = GetPostString("price2");
  4985. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4986. string posTag = CurrentUser.UserPost.Post.Code;
  4987. if (posTag == "Supplier")
  4988. {
  4989. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4990. }
  4991. lw.Add(string.Format("OrderState >= 6"));
  4992. lw.Add(string.Format("IsSample != 2 "));
  4993. //lw.Add(string.Format("isDianziOrder = 0 "));
  4994. lw.Add(string.Format("SupplierId > 0 "));
  4995. //lw.Add(string.Format("IsRefund<={0}", 1));
  4996. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4997. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4998. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  4999. foreach (DataRow dr in dt.Rows)
  5000. {
  5001. 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();
  5002. }
  5003. writeGridDataTableJson(dStruct.TotalCount, dt);
  5004. }
  5005. public void get_erp_financeallplacelist()
  5006. {
  5007. DataStruct dStruct = GetPostStruct();
  5008. List<string> lw = new List<string>();
  5009. string tid = GetPostString("ctid");
  5010. string shopname = GetPostString("shopname");
  5011. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5012. string buyernick = GetPostString("buyer_nick");
  5013. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5014. string customer = GetPostString("customer");
  5015. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5016. string design = GetPostString("design");
  5017. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5018. string sellermemo = GetPostString("seller_memo");
  5019. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5020. string supplier = GetPostString("supplier");
  5021. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5022. string date1 = GetPostString("date1");
  5023. string date2 = GetPostString("date2");
  5024. string pldate1 = GetPostString("placedate1");
  5025. string pldate2 = GetPostString("placedate2");
  5026. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5027. {
  5028. if (tid.Length > 0)
  5029. {
  5030. string select_tid = getTidByCtid(tid);
  5031. lw.Add(string.Format("tid='{0}'", select_tid));
  5032. }
  5033. if (buyernick.Length > 0)
  5034. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5035. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5036. if (dw.Length > 0) lw.Add(dw);
  5037. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5038. if (dw_place.Length > 0) lw.Add(dw_place);
  5039. }
  5040. else
  5041. {
  5042. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5043. {
  5044. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5045. }
  5046. }
  5047. string price1 = GetPostString("price1");
  5048. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5049. string price2 = GetPostString("price2");
  5050. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5051. string posTag = CurrentUser.UserPost.Post.Code;
  5052. if (posTag == "Supplier")
  5053. {
  5054. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5055. }
  5056. //lw.Add(string.Format("OrderState >= 6"));
  5057. lw.Add(string.Format("IsSample != 2 "));
  5058. lw.Add(string.Format("isDianziOrder = 0 "));
  5059. //lw.Add(string.Format("IsRefund<={0}", 1));
  5060. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5061. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5062. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5063. foreach (DataRow dr in dt.Rows)
  5064. {
  5065. 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();
  5066. }
  5067. writeGridDataTableJson(dStruct.TotalCount, dt);
  5068. }
  5069. public void get_erp_expresslist()
  5070. {
  5071. int listtype = GetInt("ltype");
  5072. DataStruct dStruct = GetPostStruct();
  5073. List<string> lw = new List<string>();
  5074. string tid = GetPostString("tid");
  5075. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5076. string outsid = GetPostString("out_sid");
  5077. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5078. string importer = GetPostString("ImportUserName");
  5079. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5080. string file = GetPostString("import_file");
  5081. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5082. string printman = GetPostString("printman");
  5083. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5084. string date1 = GetPostString("date1");
  5085. string date2 = GetPostString("date2");
  5086. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5087. if (dw.Length > 0) lw.Add(dw);
  5088. string fdate1 = GetPostString("finishdate1");
  5089. string fdate2 = GetPostString("finishdate2");
  5090. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5091. if (fdw.Length > 0) lw.Add(fdw);
  5092. string supplierId = GetPostString("supplierId");
  5093. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5094. if (listtype == 1)
  5095. {
  5096. lw.Add(string.Format("importUserId !=0"));
  5097. }
  5098. string posTag = CurrentUser.UserPost.Post.Code;
  5099. if (posTag == "Supplier")
  5100. {
  5101. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5102. }
  5103. if (dStruct.PageSize != 100000)
  5104. {
  5105. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5106. }
  5107. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5108. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5109. writeGridDataTableJson(dStruct.TotalCount, dt);
  5110. }
  5111. public void set_erp_buchaorderdelivery()
  5112. {
  5113. if (UrlPostParmsCheck("ctid"))
  5114. {
  5115. string eid = GetPostString("ctid");
  5116. CeErpTradeCell entity = null;
  5117. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5118. if (entity != null)
  5119. {
  5120. if (entity.IsSample != 2)
  5121. {
  5122. returnErrorMsg("补差价单才能标记为已发货");
  5123. return;
  5124. }
  5125. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5126. entity.OrderState = 7;
  5127. entity.Update();
  5128. returnSuccessMsg("操作成功!");
  5129. return;
  5130. }
  5131. returnErrorMsg("找不到记录");
  5132. }
  5133. }
  5134. public void get_stdtemplates()
  5135. {
  5136. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5137. //string res = taobaoHelper.test();
  5138. string res = apiHelper.API_PrintTemplate();
  5139. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5140. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5141. {
  5142. int sidx = res.IndexOf("error_code");
  5143. int eidx = res.IndexOf("success");
  5144. string msg = res.Substring(sidx, eidx - sidx);
  5145. returnErrorMsg(msg);
  5146. return;
  5147. }
  5148. if (res.Length <= 0)
  5149. {
  5150. returnErrorMsg("模板数据为空!");
  5151. return;
  5152. }
  5153. ReturnSuccess(res);
  5154. }
  5155. public void cancel_print_order()
  5156. {
  5157. if (UrlPostParmsCheck("ctid"))
  5158. {
  5159. string ctid = GetPostString("ctid");
  5160. CeErpTradeCell entity = null;
  5161. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5162. if (entity != null)
  5163. {
  5164. string res = "";
  5165. string code = entity.LastBillWaybillCode;
  5166. if (code == "")
  5167. {
  5168. code = entity.OutSid;
  5169. }
  5170. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5171. XLog.SaveLog(0, "取消面单" + res);
  5172. }
  5173. }
  5174. }
  5175. public void set_erp_printwaybill()
  5176. {
  5177. if (UrlPostParmsCheck("ctid"))
  5178. {
  5179. string ctid = GetPostString("ctid");
  5180. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5181. string cpName = GetPostString("cpname");
  5182. string isTogether = GetPostString("together");
  5183. //var res_obj = new
  5184. //{
  5185. // restype = 1,
  5186. // 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\"}"
  5187. //};
  5188. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5189. //ReturnSuccess(ro_json);
  5190. //return;
  5191. bool isUseLastWayBillCode = false;
  5192. CeErpTradeCell entity = null;
  5193. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5194. if (entity != null)
  5195. {
  5196. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5197. {
  5198. isUseLastWayBillCode = true;
  5199. }
  5200. if (entity.OrderState == 7 && "2".Equals(isTogether))
  5201. {
  5202. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5203. return;
  5204. }
  5205. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5206. {
  5207. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5208. return;
  5209. }
  5210. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5211. {
  5212. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5213. return;
  5214. }
  5215. }
  5216. string res = "";
  5217. Api_waybill_code_response_Obj fullObj = null;
  5218. string pData_str = "";
  5219. string curUseWayBillCode = "";
  5220. if (isUseLastWayBillCode == false)
  5221. {
  5222. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5223. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5224. if (res.IndexOf("failure") != -1)
  5225. {
  5226. //int idx = res.IndexOf("sub_message");
  5227. //int idx2 = res.IndexOf("flag");
  5228. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5229. string errMsgNeed = commonHelper.KeepChinese(res);
  5230. var res_objd = new
  5231. {
  5232. restype = 0,
  5233. data = "获取面单失败" + errMsgNeed
  5234. };
  5235. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5236. returnSuccess(ro_jsond);
  5237. if (res.IndexOf("停发") != -1)
  5238. {
  5239. entity.UnusualCon = "物流停发";
  5240. entity.Update();
  5241. }
  5242. //returnErrorMsg("获取面单失败,"+emsg);
  5243. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5244. return;
  5245. }
  5246. else if (res.IndexOf("errorMsg") != -1)
  5247. {
  5248. //int idx = res.IndexOf("errorMsg");
  5249. //int idx2 = res.IndexOf("}]}");
  5250. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5251. string errMsgNeed = commonHelper.KeepChinese(res);
  5252. var res_objf = new
  5253. {
  5254. restype = 0,
  5255. data = "获取面单失败2" + errMsgNeed
  5256. };
  5257. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5258. if (res.IndexOf("停发") != -1)
  5259. {
  5260. entity.UnusualCon = "物流停发";
  5261. entity.Update();
  5262. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5263. if (trade != null)
  5264. {
  5265. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5266. }
  5267. }
  5268. returnSuccess(ro_jsonf);
  5269. //returnErrorMsg("获取面单失败," + emsg);
  5270. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5271. return;
  5272. }
  5273. try
  5274. {
  5275. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5276. //res = res.Replace(" ", "");
  5277. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5278. }
  5279. catch (Exception ex)
  5280. {
  5281. XLog.SaveLog(0, "生成fullObj" + res);
  5282. var res_objf = new
  5283. {
  5284. restype = 0,
  5285. data = "生成fullObj发生错误" + ex.Message
  5286. };
  5287. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5288. returnSuccess(ro_jsonf);
  5289. return;
  5290. }
  5291. if (fullObj.response.data.content.Count > 0)
  5292. {
  5293. ContentItem codeObj = fullObj.response.data.content[0];
  5294. if (cpCode.IndexOf("SFFQ-") != -1)
  5295. {
  5296. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5297. }
  5298. else
  5299. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5300. curUseWayBillCode = codeObj.waybillCode;
  5301. }
  5302. else
  5303. {
  5304. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5305. var res_objf = new
  5306. {
  5307. restype = 0,
  5308. data = "生成fullObj找不到快递单号waybillCode"
  5309. };
  5310. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5311. returnSuccess(ro_jsonf);
  5312. return;
  5313. }
  5314. }
  5315. else
  5316. {
  5317. //使用上次打印的快递单号
  5318. if (cpCode == "SFFQ-LY")
  5319. {
  5320. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5321. }
  5322. else
  5323. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5324. curUseWayBillCode = entity.LastBillWaybillCode;
  5325. }
  5326. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5327. {
  5328. var res_obje = new
  5329. {
  5330. restype = 0,
  5331. data = "获取加密打印数据失败"
  5332. };
  5333. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5334. returnSuccess(ro_jsone);
  5335. entity.LastBillCpCode = cpCode;
  5336. entity.LastBillWaybillCode = curUseWayBillCode;
  5337. entity.Update();
  5338. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5339. //returnErrorMsg("获取加密打印数据失败");
  5340. return;
  5341. }
  5342. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5343. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5344. string btnType = "";
  5345. string errorMsg = "";
  5346. if (entity != null)
  5347. {
  5348. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5349. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5350. //cpcode是 YTO-CAINIAO
  5351. //string comCode = cpCode.Split('-')[0].ToString();
  5352. string apires = "";
  5353. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5354. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5355. {
  5356. if (ctid.IndexOf("N") != -1)
  5357. {
  5358. apires = "发货成功";
  5359. }
  5360. else
  5361. {
  5362. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5363. }
  5364. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5365. //打单后发货
  5366. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5367. {
  5368. try
  5369. {
  5370. btnType = "待发货";
  5371. entity.OutSid = curUseWayBillCode;
  5372. entity.OrderState = 7;
  5373. entity.IsUrgency = false;
  5374. entity.LastBillCpCode = "";
  5375. entity.LastBillWaybillCode = "";
  5376. entity.FinishDeliveryTime = DateTime.Now;
  5377. entity.IsReturn = 0;
  5378. entity.MemoOpt = 0;
  5379. entity.UpdateTime = DateTime.Now;
  5380. entity.Update();
  5381. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5382. //还要插入快递信息到 快递信息表
  5383. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5384. exinfo.tid = entity.ctid;
  5385. exinfo.out_sid = curUseWayBillCode;
  5386. exinfo.company_code = cpCode;
  5387. exinfo.company_name = cpName;
  5388. exinfo.supplierUserName = supplierName;
  5389. exinfo.deliveryType = "发货成功";
  5390. exinfo.print_time = DateTime.Now;
  5391. exinfo.printUser = CurrentUser.UserName;
  5392. exinfo.postData = pData_str;
  5393. exinfo.Create();
  5394. commonHelper.UpdateRelationOrder(entity.ctid);
  5395. CeErpSukuraData.createInfo(ctid, 4);
  5396. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5397. if (entity.SupplierId == 64)
  5398. {
  5399. commonHelper.sendCytExpress(exinfo);
  5400. }
  5401. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5402. if (!string.IsNullOrEmpty(isTogether))
  5403. {
  5404. if (Convert.ToInt32(isTogether) > 0)
  5405. {
  5406. StringBuilder sqlsb = new StringBuilder();
  5407. 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);
  5408. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5409. }
  5410. }
  5411. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5412. }
  5413. catch (Exception ex)
  5414. {
  5415. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5416. }
  5417. }
  5418. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5419. {
  5420. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5421. if (entity.OrderState == 6)
  5422. {
  5423. entity.OrderState = 7;
  5424. }
  5425. entity.UpdateTime = DateTime.Now;
  5426. entity.FinishDeliveryTime = DateTime.Now;
  5427. btnType = "已发货";
  5428. entity.Update();
  5429. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5430. exinfo.tid = entity.ctid;
  5431. exinfo.out_sid = curUseWayBillCode;
  5432. exinfo.company_code = cpCode;
  5433. exinfo.company_name = cpName;
  5434. exinfo.supplierUserName = supplierName;
  5435. exinfo.deliveryType = "发货成功";
  5436. exinfo.print_time = DateTime.Now;
  5437. exinfo.printUser = CurrentUser.UserName;
  5438. exinfo.postData = pData_str;
  5439. exinfo.Create();
  5440. commonHelper.UpdateRelationOrder(entity.ctid);
  5441. CeErpSukuraData.createInfo(entity.ctid, 4);
  5442. if (entity.SupplierId == 64)
  5443. {
  5444. commonHelper.sendCytExpress(exinfo);
  5445. }
  5446. if (!string.IsNullOrEmpty(isTogether))
  5447. {
  5448. if (Convert.ToInt32(isTogether) > 0)
  5449. {
  5450. StringBuilder sqlsb = new StringBuilder();
  5451. 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);
  5452. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5453. }
  5454. }
  5455. //不处理
  5456. }
  5457. else
  5458. {
  5459. entity.UpdateTime = DateTime.Now;
  5460. entity.LastBillCpCode = cpCode;
  5461. entity.LastBillWaybillCode = curUseWayBillCode;
  5462. entity.Update();
  5463. string errmsg = commonHelper.KeepChinese(apires);
  5464. var res_objz = new
  5465. {
  5466. restype = 0,
  5467. data = "打单后发货失败"
  5468. };
  5469. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5470. returnSuccess(ro_jsonz);
  5471. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5472. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5473. return;
  5474. }
  5475. }
  5476. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5477. {
  5478. StringBuilder allSql = new StringBuilder();
  5479. allSql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,tid from view_ErpTradeCell where SupplierId={0} and orderstate=6", entity.SupplierId);
  5480. if (string.IsNullOrEmpty(mainEn.receiverId))
  5481. {
  5482. allSql.AppendFormat(" and (tid='{0}');", entity.tid);
  5483. }
  5484. else
  5485. {
  5486. //查询同车间同状态下的收货地址相同的单子
  5487. allSql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}') );", entity.tid, mainEn.receiverId, entity.IsSF);
  5488. }
  5489. DataTable dt = DbHelper.DbConn.ExecuteDataset(allSql.ToString()).Tables[0];
  5490. List<string> list = new List<string>();
  5491. List<string> send_list = new List<string>();
  5492. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5493. CeErpTrade ceErpTrade = new CeErpTrade();
  5494. foreach (DataRow row in dt.Rows)
  5495. {
  5496. list.Add("'" + row["ctid"] + "'");
  5497. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5498. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5499. if (ctid.IndexOf("N") != -1)
  5500. {
  5501. apires = "发货成功";
  5502. }
  5503. else
  5504. {
  5505. if (!send_list.Contains(ceErpTrade.tid))
  5506. {
  5507. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5508. }
  5509. else
  5510. {
  5511. apires = "发货成功";
  5512. }
  5513. }
  5514. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5515. {
  5516. send_list.Add(ceErpTrade.tid);
  5517. try
  5518. {
  5519. btnType = "待发货";
  5520. ceErpTradeCell.OutSid = curUseWayBillCode;
  5521. ceErpTradeCell.OrderState = 7;
  5522. ceErpTradeCell.IsUrgency = false;
  5523. ceErpTradeCell.LastBillCpCode = "";
  5524. ceErpTradeCell.LastBillWaybillCode = "";
  5525. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5526. ceErpTradeCell.IsReturn = 0;
  5527. ceErpTradeCell.MemoOpt = 0;
  5528. ceErpTradeCell.UpdateTime = DateTime.Now;
  5529. ceErpTradeCell.Update();
  5530. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5531. //还要插入快递信息到 快递信息表
  5532. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5533. exinfo.tid = ceErpTradeCell.ctid;
  5534. exinfo.out_sid = curUseWayBillCode;
  5535. exinfo.company_code = cpCode;
  5536. exinfo.company_name = cpName;
  5537. exinfo.supplierUserName = supplierName;
  5538. exinfo.deliveryType = "发货成功";
  5539. exinfo.print_time = DateTime.Now;
  5540. exinfo.printUser = CurrentUser.UserName;
  5541. exinfo.postData = pData_str;
  5542. exinfo.Create();
  5543. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5544. CeErpSukuraData.createInfo(ctid, 4);
  5545. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5546. if (ceErpTradeCell.SupplierId == 64)
  5547. {
  5548. commonHelper.sendCytExpress(exinfo);
  5549. }
  5550. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5551. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5552. }
  5553. catch (Exception ex)
  5554. {
  5555. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5556. }
  5557. }
  5558. else
  5559. {
  5560. ceErpTradeCell.UpdateTime = DateTime.Now;
  5561. ceErpTradeCell.LastBillCpCode = cpCode;
  5562. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5563. ceErpTradeCell.Update();
  5564. string errmsg = commonHelper.KeepChinese(apires);
  5565. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5566. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5567. }
  5568. }
  5569. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5570. }
  5571. }
  5572. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5573. var res_obj = new
  5574. {
  5575. restype = 1,
  5576. data = pData_str,
  5577. errorMsg
  5578. };
  5579. string ro_json = JsonConvert.SerializeObject(res_obj);
  5580. ReturnSuccess(ro_json);
  5581. return;
  5582. }
  5583. }
  5584. private string GetUTF8String(byte[] vs)
  5585. {
  5586. throw new NotImplementedException();
  5587. }
  5588. public void set_erp_printwaybill_cn()
  5589. {
  5590. if (UrlPostParmsCheck("ctid"))
  5591. {
  5592. string ctid = GetPostString("ctid");
  5593. string cpCode = GetPostString("cpcode");
  5594. string cpName = GetPostString("cpname");
  5595. string tempUrl = GetPostString("tempurl");
  5596. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5597. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5598. //string res = taobaoHelper.test();
  5599. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5600. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5601. {
  5602. int sidx = res.IndexOf("errorMsg");
  5603. int eidx = res.IndexOf("}");
  5604. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5605. var res_objzxx = new
  5606. {
  5607. restype = 0,
  5608. data = msg
  5609. };
  5610. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5611. returnSuccess(ro_jsonzxx);
  5612. //returnErrorMsg(msg);
  5613. return;
  5614. }
  5615. int idx = res.IndexOf("waybillCode");
  5616. int idx2 = res.IndexOf("printData");
  5617. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5618. string eid = GetPostString("ctid");
  5619. CeErpTradeCell entity = null;
  5620. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5621. if (entity != null)
  5622. {
  5623. string osid = entity.OutSid;
  5624. entity.OutSid = osid + "," + outsid;
  5625. entity.FinishDeliveryTime = DateTime.Now;
  5626. entity.OrderState = 7;
  5627. entity.UpdateTime = DateTime.Now;
  5628. entity.IsReturn = 0;
  5629. entity.Update();
  5630. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5631. exinfo.tid = entity.ctid;
  5632. exinfo.out_sid = outsid;
  5633. exinfo.company_code = cpCode;
  5634. exinfo.company_name = cpName;
  5635. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5636. exinfo.deliveryType = "发货成功";
  5637. exinfo.print_time = DateTime.Now;
  5638. exinfo.printUser = CurrentUser.UserName;
  5639. exinfo.Create();
  5640. if (entity.SupplierId == 64)
  5641. {
  5642. commonHelper.sendCytExpress(exinfo);
  5643. }
  5644. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5645. }
  5646. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5647. var res_objz = new
  5648. {
  5649. restype = 1,
  5650. data = res
  5651. };
  5652. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5653. returnSuccess(ro_jsonz);
  5654. //ReturnSuccess(res);
  5655. }
  5656. }
  5657. ////打单,打印面单 获取面单号
  5658. //public void set_erp_printwaybill()
  5659. //{
  5660. // if (UrlPostParmsCheck("ctid"))
  5661. // {
  5662. // string ctid = GetPostString("ctid");
  5663. // string cpCode = GetPostString("cpcode");
  5664. // string tempUrl = GetPostString("tempurl");
  5665. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5666. // //string res = taobaoHelper.test();
  5667. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5668. // if (res.IndexOf("error_response") != -1)
  5669. // {
  5670. // int sidx = res.IndexOf("sub_msg");
  5671. // int eidx = res.IndexOf("request_id");
  5672. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5673. // returnErrorMsg(msg);
  5674. // return;
  5675. // }
  5676. // int idx = res.IndexOf("waybill_code");
  5677. // int idx2 = res.IndexOf("}]}");
  5678. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5679. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5680. // ReturnSuccess(res);
  5681. // }
  5682. //}
  5683. public void cancel_erp_aftersale()
  5684. {
  5685. if (UrlPostParmsCheck("ctid"))
  5686. {
  5687. string eid = GetPostString("ctid");
  5688. CeErpTradeCell entity = null;
  5689. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5690. if (entity != null)
  5691. {
  5692. //有过处理的售后,取消也不能删除 售 字,保留
  5693. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5694. {
  5695. entity.AfterSaleState = 4;
  5696. }
  5697. else
  5698. entity.AfterSaleState = 0;
  5699. entity.UpdateTime = DateTime.Now;
  5700. entity.Update();
  5701. returnSuccessMsg("操作成功!");
  5702. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5703. return;
  5704. }
  5705. returnErrorMsg("找不到订单记录");
  5706. }
  5707. }
  5708. public void get_erp_aftersalelist()
  5709. {
  5710. DataStruct dStruct = GetPostStruct();
  5711. List<string> lw = new List<string>();
  5712. int st = GetInt("st");
  5713. string tid = GetPostString("ctid");
  5714. if (st == 3)
  5715. {
  5716. if (tid.Length > 0)
  5717. {
  5718. string select_tid = getTidByCtid(tid);
  5719. lw.Add(string.Format("tid='{0}'", select_tid));
  5720. }
  5721. }
  5722. else
  5723. {
  5724. if (tid.Length > 0)
  5725. {
  5726. string select_tid = getTidByCtid(tid);
  5727. lw.Add(string.Format("tid='{0}'", select_tid));
  5728. }
  5729. }
  5730. string shopname = GetPostString("shopname");
  5731. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5732. string buyernick = GetPostString("buyer_nick");
  5733. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5734. string sellermemo = GetPostString("seller_memo");
  5735. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5736. string orderState = GetPostString("orderState");
  5737. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5738. string afterState = GetPostString("afterstate");
  5739. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5740. string date1 = GetPostString("date1");
  5741. string date2 = GetPostString("date2");
  5742. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5743. if (dw.Length > 0) lw.Add(dw);
  5744. string price1 = GetPostString("price1");
  5745. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5746. string price2 = GetPostString("price2");
  5747. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5748. //lw.Add(string.Format("IsRefund!={0}", 1));
  5749. string reason = GetPostString("reason");
  5750. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5751. string method = GetPostString("method");
  5752. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5753. string handler = GetPostString("handler");
  5754. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5755. string handledate1 = GetPostString("handledate1");
  5756. string handledate2 = GetPostString("handledate2");
  5757. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5758. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5759. string finish1 = GetPostString("finishdate1");
  5760. string finish2 = GetPostString("finishdate2");
  5761. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  5762. if (dwfinish.Length > 0) lw.Add(dwfinish);
  5763. string afterdate1 = GetPostString("afterdate1");
  5764. string afterdate2 = GetPostString("afterdate2");
  5765. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5766. if (afterDate.Length > 0) lw.Add(afterDate);
  5767. string supplier = GetPostString("supplier");
  5768. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5769. string responsible = GetPostString("responsibleman");
  5770. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5771. string customer = GetPostString("customer");
  5772. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5773. string design = GetPostString("design");
  5774. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5775. string afterMemoType = GetPostString("aftermemotype");
  5776. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  5777. string posCode = CurrentUser.UserPost.Post.Code;
  5778. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  5779. //{
  5780. // string vstate = GetPostString("vstate");
  5781. // if (vstate.Length > 0)
  5782. // {
  5783. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  5784. // }
  5785. // if (posCode == "Supplier")
  5786. // {
  5787. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  5788. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  5789. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  5790. // }
  5791. // else
  5792. // {
  5793. // lw.Add(string.Format("AfterSaleState = {0}", st));
  5794. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  5795. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  5796. // {
  5797. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  5798. // }
  5799. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  5800. // {
  5801. // int orgid = CurrentUser.UserPost.OrgID;
  5802. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  5803. // }
  5804. // else if (CurrentUser.UserPost.Post.Code == "Director")
  5805. // {
  5806. // string shopid = CurrentUser.User.pemShop;
  5807. // lw.Add(string.Format("shopId in ({0})", shopid));
  5808. // }
  5809. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  5810. // //{
  5811. // // int org_id = CurrentUser.UserPost.OrgID;
  5812. // // lw.Add(string.Format("OrgID={0}", org_id));
  5813. // //}
  5814. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  5815. // }
  5816. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5817. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  5818. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5819. //}
  5820. if (st == 5)
  5821. {
  5822. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  5823. {
  5824. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  5825. {
  5826. string shopid = CurrentUser.User.pemShop;
  5827. lw.Add(string.Format("shopId in ({0})", shopid));
  5828. }
  5829. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  5830. {
  5831. int mrOrgid = CurrentUser.UserPost.OrgID;
  5832. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  5833. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  5834. }
  5835. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  5836. //{
  5837. // int mrOrgid = CurrentUser.UserPost.OrgID;
  5838. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  5839. //}
  5840. else
  5841. {
  5842. string userIdStr = "";
  5843. if (posCode == "CustomerService")
  5844. {
  5845. userIdStr = CurrentUser.UserID + "_k";
  5846. }
  5847. else if (posCode == "Designer" || posCode == "wxDesigner")
  5848. {
  5849. userIdStr = CurrentUser.UserID + "_s";
  5850. }
  5851. else if (posCode == "Place")
  5852. {
  5853. userIdStr = CurrentUser.UserID + "_x";
  5854. }
  5855. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  5856. }
  5857. }
  5858. string placedate1 = GetPostString("placedate1");
  5859. string placedate2 = GetPostString("placedate2");
  5860. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5861. if (dwplace.Length > 0) lw.Add(dwplace);
  5862. string supState = GetPostString("supState");
  5863. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  5864. string searchType = GetPostString("searchType");
  5865. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  5866. {
  5867. lw.Add(string.Format("BackNum>1"));
  5868. }
  5869. lw.Add(string.Format("AfterSaleState>0"));
  5870. if (ex_psize > 0)
  5871. {
  5872. if (CurrentUser.UserPost.Post.Code == "Finance")
  5873. dStruct.Order = "pay_time desc";
  5874. else
  5875. dStruct.Order = "HandleTime desc";
  5876. }
  5877. else
  5878. dStruct.Order = "HandleTime desc";
  5879. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5880. DataTable dt = WebCache.GetData("view_test", dStruct);
  5881. writeGridDataTableJson(dStruct.TotalCount, dt);
  5882. }
  5883. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  5884. //{
  5885. // lw.Add(string.Format("AfterSaleState=4"));
  5886. // string code = CurrentUser.UserPost.Post.Code;
  5887. // if (code == "CustomerService")
  5888. // {
  5889. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  5890. // }
  5891. // else if (code == "Designer" || code == "DesignerMr")
  5892. // {
  5893. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  5894. // }
  5895. // else if (code == "Place" || code == "PlaceMr")
  5896. // {
  5897. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  5898. // }
  5899. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  5900. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5901. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5902. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5903. //}
  5904. //else //处理中的售后,待处理和处理中合并
  5905. //{
  5906. // if (afterState.Length <= 0)
  5907. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  5908. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  5909. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5910. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5911. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5912. //}
  5913. }
  5914. public void get_erp_disagreeftersalelist()
  5915. {
  5916. DataStruct dStruct = GetPostStruct();
  5917. List<string> lw = new List<string>();
  5918. int st = 2;
  5919. string tid = GetPostString("ctid");
  5920. if (tid.Length > 0)
  5921. {
  5922. string select_tid = getTidByCtid(tid);
  5923. lw.Add(string.Format("tid='{0}'", select_tid));
  5924. }
  5925. string shopname = GetPostString("shopname");
  5926. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5927. string buyernick = GetPostString("buyer_nick");
  5928. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  5929. string sellermemo = GetPostString("seller_memo");
  5930. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5931. string orderState = GetPostString("orderState");
  5932. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  5933. string afterState = GetPostString("afterstate");
  5934. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5935. string date1 = GetPostString("date1");
  5936. string date2 = GetPostString("date2");
  5937. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5938. if (dw.Length > 0) lw.Add(dw);
  5939. string price1 = GetPostString("price1");
  5940. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5941. string price2 = GetPostString("price2");
  5942. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5943. //lw.Add(string.Format("IsRefund!={0}", 1));
  5944. string reason = GetPostString("reason");
  5945. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5946. string method = GetPostString("method");
  5947. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5948. string handler = GetPostString("handler");
  5949. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5950. string handledate1 = GetPostString("handledate1");
  5951. string handledate2 = GetPostString("handledate2");
  5952. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5953. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5954. string afterdate1 = GetPostString("afterdate1");
  5955. string afterdate2 = GetPostString("afterdate2");
  5956. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5957. if (afterDate.Length > 0) lw.Add(afterDate);
  5958. string backdate1 = GetPostString("backdate1");
  5959. string backdate2 = GetPostString("backdate2");
  5960. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  5961. if (backDate.Length > 0) lw.Add(backDate);
  5962. string supplier = GetPostString("supplier");
  5963. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5964. string responsible = GetPostString("responsibleman");
  5965. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5966. string customer = GetPostString("customer");
  5967. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5968. string design = GetPostString("design");
  5969. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5970. string afterSaleMemo = GetPostString("afterSaleMemo");
  5971. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  5972. string afterMemoType = GetPostString("aftermemotype");
  5973. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  5974. string aftersakereason = GetPostString("aftersakereason");
  5975. if (aftersakereason.Length > 0)
  5976. {
  5977. if (aftersakereason == "1")
  5978. {
  5979. lw.Add(string.Format("AfterSaleResSupId > 0"));
  5980. }
  5981. if (aftersakereason == "2")
  5982. {
  5983. lw.Add(string.Format("AfterSaleResSupId = 0"));
  5984. }
  5985. }
  5986. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  5987. string poscode = CurrentUser.UserPost.Post.Code;
  5988. if (poscode != "SysAdmin")
  5989. {
  5990. string shopid = CurrentUser.User.pemShop;
  5991. lw.Add(string.Format("shopId in ({0})", shopid));
  5992. }
  5993. string searchType = GetPostString("searchType");
  5994. if (searchType == "wait")
  5995. {
  5996. lw.Add(string.Format("HandleTime is null"));
  5997. }
  5998. if (searchType == "handling")
  5999. {
  6000. lw.Add(string.Format("HandleTime is not null "));
  6001. }
  6002. if (searchType == "back" || searchType == "puBack")
  6003. {
  6004. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6005. }
  6006. if (searchType == "reBack")
  6007. {
  6008. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6009. }
  6010. if (searchType == "moreBack")
  6011. {
  6012. lw.Add(string.Format("backNum > 1"));
  6013. }
  6014. lw.Add(string.Format("(AfterSaleState=5)"));
  6015. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6016. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6017. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6018. writeGridDataTableJson(dStruct.TotalCount, dt);
  6019. }
  6020. public void get_erp_handlingaftersalelist()
  6021. {
  6022. DataStruct dStruct = GetPostStruct();
  6023. List<string> lw = new List<string>();
  6024. int st = 2;
  6025. string tid = GetPostString("ctid");
  6026. if (tid.Length > 0)
  6027. {
  6028. string select_tid = getTidByCtid(tid);
  6029. lw.Add(string.Format("tid='{0}'", select_tid));
  6030. }
  6031. string shopname = GetPostString("shopname");
  6032. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6033. string buyernick = GetPostString("buyer_nick");
  6034. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6035. string sellermemo = GetPostString("seller_memo");
  6036. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6037. string orderState = GetPostString("orderState");
  6038. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6039. string afterState = GetPostString("afterstate");
  6040. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6041. string date1 = GetPostString("date1");
  6042. string date2 = GetPostString("date2");
  6043. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6044. if (dw.Length > 0) lw.Add(dw);
  6045. string price1 = GetPostString("price1");
  6046. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6047. string price2 = GetPostString("price2");
  6048. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6049. //lw.Add(string.Format("IsRefund!={0}", 1));
  6050. string reason = GetPostString("reason");
  6051. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6052. string method = GetPostString("method");
  6053. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6054. string handler = GetPostString("handler");
  6055. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6056. string handledate1 = GetPostString("handledate1");
  6057. string handledate2 = GetPostString("handledate2");
  6058. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6059. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6060. string afterdate1 = GetPostString("afterdate1");
  6061. string afterdate2 = GetPostString("afterdate2");
  6062. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6063. if (afterDate.Length > 0) lw.Add(afterDate);
  6064. string supplier = GetPostString("supplier");
  6065. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6066. string responsible = GetPostString("responsibleman");
  6067. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6068. string customer = GetPostString("customer");
  6069. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6070. string design = GetPostString("design");
  6071. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6072. string afterSaleMemo = GetPostString("afterSaleMemo");
  6073. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6074. string afterMemoType = GetPostString("aftermemotype");
  6075. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6076. string afterresult = GetPostString("afterresult");
  6077. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6078. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6079. string poscode = CurrentUser.UserPost.Post.Code;
  6080. if (poscode != "SysAdmin")
  6081. {
  6082. string shopid = CurrentUser.User.pemShop;
  6083. lw.Add(string.Format("shopId in ({0})", shopid));
  6084. }
  6085. string searchType = GetPostString("searchType");
  6086. if (searchType == "wait")
  6087. {
  6088. lw.Add(string.Format("HandleTime is null"));
  6089. }
  6090. if (searchType == "documentary")
  6091. {
  6092. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6093. }
  6094. if (searchType == "handling")
  6095. {
  6096. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6097. }
  6098. if (searchType == "back" || searchType == "puBack")
  6099. {
  6100. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6101. }
  6102. if (searchType == "reBack")
  6103. {
  6104. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6105. }
  6106. if (afterState.Length <= 0)
  6107. {
  6108. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6109. }
  6110. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6111. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6112. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6113. writeGridDataTableJson(dStruct.TotalCount, dt);
  6114. }
  6115. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6116. //public void get_erp_back_handlingaftersalelist()
  6117. //{
  6118. // DataStruct dStruct = GetPostStruct();
  6119. // List<string> lw = new List<string>();
  6120. // string tid = GetPostString("ctid");
  6121. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6122. // string shopname = GetPostString("shopname");
  6123. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6124. // string buyernick = GetPostString("buyer_nick");
  6125. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6126. // string sellermemo = GetPostString("seller_memo");
  6127. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6128. // string orderState = GetPostString("orderState");
  6129. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6130. // string afterState = GetPostString("afterstate");
  6131. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6132. // string date1 = GetPostString("date1");
  6133. // string date2 = GetPostString("date2");
  6134. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6135. // if (dw.Length > 0) lw.Add(dw);
  6136. // string price1 = GetPostString("price1");
  6137. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6138. // string price2 = GetPostString("price2");
  6139. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6140. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6141. // string reason = GetPostString("reason");
  6142. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6143. // string method = GetPostString("method");
  6144. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6145. // string handler = GetPostString("handler");
  6146. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6147. // string handledate1 = GetPostString("handledate1");
  6148. // string handledate2 = GetPostString("handledate2");
  6149. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6150. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6151. // string afterdate1 = GetPostString("afterdate1");
  6152. // string afterdate2 = GetPostString("afterdate2");
  6153. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6154. // if (afterDate.Length > 0) lw.Add(afterDate);
  6155. // string supplier = GetPostString("supplier");
  6156. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6157. // string responsible = GetPostString("responsibleman");
  6158. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6159. // string customer = GetPostString("customer");
  6160. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6161. // string design = GetPostString("design");
  6162. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6163. // string afterMemoType = GetPostString("aftermemotype");
  6164. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6165. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6166. // if (afterState.Length <= 0)
  6167. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6168. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6169. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6170. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6171. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6172. //}
  6173. public void get_erp_aftersaleverifylist()
  6174. {
  6175. DataStruct dStruct = GetPostStruct();
  6176. List<string> lw = new List<string>();
  6177. string tid = GetPostString("ctid");
  6178. if (tid.Length > 0)
  6179. {
  6180. string select_tid = getTidByCtid(tid);
  6181. lw.Add(string.Format("tid='{0}'", select_tid));
  6182. }
  6183. string shopname = GetPostString("shopname");
  6184. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6185. string buyernick = GetPostString("buyer_nick");
  6186. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6187. string sellermemo = GetPostString("seller_memo");
  6188. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6189. string orderState = GetPostString("orderState");
  6190. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6191. //lw.Add(string.Format("IsRefund!={0}", 1));
  6192. string reason = GetPostString("reason");
  6193. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6194. string method = GetPostString("method");
  6195. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6196. string handler = GetPostString("handler");
  6197. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6198. string handledate1 = GetPostString("handledate1");
  6199. string handledate2 = GetPostString("handledate2");
  6200. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6201. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6202. string finish1 = GetPostString("finishdate1");
  6203. string finish2 = GetPostString("finishdate2");
  6204. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6205. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6206. string supplier = GetPostString("supplier");
  6207. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6208. string responsible = GetPostString("responsibleman");
  6209. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6210. string posCode = CurrentUser.UserPost.Post.Code;
  6211. string vstate = GetPostString("vstate");
  6212. if (vstate.Length > 0)
  6213. {
  6214. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6215. }
  6216. if (posCode == "Supplier")
  6217. {
  6218. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6219. lw.Add(string.Format("VerifyState = 0"));
  6220. lw.Add("type = 1");
  6221. lw.Add(string.Format("AfterSaleState={0}", 3));
  6222. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6223. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6224. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6225. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6226. writeGridDataTableJson(dStruct.TotalCount, dt);
  6227. }
  6228. else if (posCode == "logistics")
  6229. {
  6230. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6231. lw.Add(string.Format("VerifyState = 0"));
  6232. lw.Add("type = 2");
  6233. lw.Add(string.Format("AfterSaleState={0}", 3));
  6234. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6235. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6236. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6237. writeGridDataTableJson(dStruct.TotalCount, dt);
  6238. }
  6239. else
  6240. {
  6241. lw.Add(string.Format("(AfterSaleState = 3)"));
  6242. string reasonState = GetPostString("reasonState");
  6243. lw.Add("type = 0");
  6244. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  6245. || posCode == "Summarize" || posCode == "Finance")
  6246. {
  6247. if (reasonState == "2")
  6248. {
  6249. lw.Add("VerifyState = 3");
  6250. }
  6251. else if (reasonState == "1")
  6252. {
  6253. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6254. }
  6255. else
  6256. {
  6257. lw.Add("VerifyState in (0,3)");
  6258. }
  6259. //不加条件,可以看全部
  6260. }
  6261. 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")
  6262. {
  6263. int orgid = CurrentUser.UserPost.OrgID;
  6264. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6265. if (string.IsNullOrEmpty(manageOrgId))
  6266. {
  6267. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6268. }
  6269. else
  6270. {
  6271. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6272. }
  6273. if (reasonState == "1")
  6274. {
  6275. lw.Add("VerifyState = 3");
  6276. }
  6277. else if (reasonState == "2")
  6278. {
  6279. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6280. }
  6281. else
  6282. {
  6283. }
  6284. }
  6285. else
  6286. {
  6287. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6288. }
  6289. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6290. //{
  6291. // int org_id = CurrentUser.UserPost.OrgID;
  6292. // lw.Add(string.Format("OrgID={0}", org_id));
  6293. //}
  6294. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6295. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6296. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6297. writeGridDataTableJson(dStruct.TotalCount, dt);
  6298. }
  6299. }
  6300. public void get_erp_finishaftersalelist()
  6301. {
  6302. DataStruct dStruct = GetPostStruct();
  6303. List<string> lw = new List<string>();
  6304. int st = 4;
  6305. string tid = GetPostString("ctid");
  6306. if (tid.Length > 0)
  6307. {
  6308. string select_tid = getTidByCtid(tid);
  6309. lw.Add(string.Format("tid='{0}'", select_tid));
  6310. }
  6311. string shopname = GetPostString("shopname");
  6312. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6313. //lw.Add(string.Format("IsRefund!={0}", 1));
  6314. string reason = GetPostString("reason");
  6315. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6316. string method = GetPostString("method");
  6317. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6318. string buyernick = GetPostString("buyer_nick");
  6319. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6320. string handler = GetPostString("handler");
  6321. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6322. string handledate1 = GetPostString("handledate1");
  6323. string handledate2 = GetPostString("handledate2");
  6324. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6325. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6326. string finish1 = GetPostString("finishdate1");
  6327. string finish2 = GetPostString("finishdate2");
  6328. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6329. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6330. string supplier = GetPostString("supplier");
  6331. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6332. string responsible = GetPostString("responsibleman");
  6333. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6334. string vstate = GetPostString("vstate");
  6335. if (vstate.Length > 0)
  6336. {
  6337. if ("3".Equals(vstate))
  6338. {
  6339. lw.Add(string.Format("IsTem=1"));
  6340. }
  6341. else
  6342. {
  6343. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6344. }
  6345. }
  6346. lw.Add(string.Format("AfterSaleState=4"));
  6347. string code = CurrentUser.UserPost.Post.Code;
  6348. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6349. {
  6350. //不加条件,可以看全部
  6351. }
  6352. else if (code == "Supplier")
  6353. {
  6354. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6355. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6356. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6357. }
  6358. else if (code == "logistics")
  6359. {
  6360. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6361. lw.Add("type = 2");
  6362. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6363. }
  6364. 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")
  6365. {
  6366. int orgid = CurrentUser.UserPost.OrgID;
  6367. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6368. if (string.IsNullOrEmpty(manageOrgIds))
  6369. {
  6370. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6371. }
  6372. else
  6373. {
  6374. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6375. }
  6376. }
  6377. else
  6378. {
  6379. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6380. }
  6381. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6382. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6383. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6384. writeGridDataTableJson(dStruct.TotalCount, dt);
  6385. }
  6386. public void handle_erp_aftersale()
  6387. {
  6388. if (UrlPostParmsCheck("ctid"))
  6389. {
  6390. string eid = GetPostString("ctid");
  6391. string responStr = GetPostString("AfterSaleResponsible");
  6392. if (responStr.Length <= 0)
  6393. {
  6394. returnErrorMsg("售后责任人不能为空");
  6395. return;
  6396. }
  6397. bool isDesign = false;
  6398. double designFree = 0.00;
  6399. int responsibleId = 0;
  6400. CeErpTradeCell entity = null;
  6401. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6402. if (entity != null)
  6403. {
  6404. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6405. string afterMethod = GetPostString("AfterSaleMethod");
  6406. if (isNeedNewOrder == 1)
  6407. {
  6408. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6409. bool ishav = true;
  6410. if (newentity == null)
  6411. {
  6412. newentity = entity.Clone() as CeErpTradeCell;
  6413. ishav = false;
  6414. newentity.ctid = "S_" + entity.ctid;
  6415. newentity.OrderState = 0;
  6416. //唯一标识
  6417. newentity.OrderSn = newentity.ctid;
  6418. string orderSn = dataHelper.getSaleOrderSn();
  6419. if (orderSn != "")
  6420. {
  6421. newentity.OrderSn = orderSn;
  6422. }
  6423. }
  6424. newentity.UpdateTime = DateTime.Now;
  6425. newentity.AfterSaleState = 0;
  6426. newentity.AfterSaleMethod = afterMethod;
  6427. if (!ishav)
  6428. {
  6429. string memo_str = newentity.seller_memo;
  6430. memo_str = memo_str.Replace("(", "(");
  6431. memo_str = memo_str.Replace(")", ")");
  6432. int sIndex = memo_str.IndexOf("(");
  6433. int eIndex = memo_str.IndexOf(")");
  6434. if (sIndex == -1 || eIndex == -1)
  6435. {
  6436. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6437. return;
  6438. }
  6439. string first = memo_str.Substring(0, sIndex + 1);
  6440. string memoCtid = newentity.OrderSn;
  6441. //if (memoCtid.IndexOf("C") != -1)
  6442. //{
  6443. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6444. //if (CIdx.IndexOf("+") != -1)
  6445. //{
  6446. //CIdx = "C" + CIdx.Split('+')[1];
  6447. //}
  6448. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6449. //}
  6450. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6451. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6452. string newMemo = first + memoCtid + last;
  6453. newentity.seller_memo = newMemo;
  6454. newentity.FinishPlaceTime = null;
  6455. newentity.UnusualTag = 0;
  6456. newentity.UnusualCon = "";
  6457. newentity.UnusualTime = null;
  6458. newentity.AfterSaleMemo = "";
  6459. newentity.AfterSaleMethod = afterMethod;
  6460. newentity.AfterSalePreTime = null;
  6461. newentity.AfterSaleReason = "";
  6462. newentity.AfterSaleResponsible = "";
  6463. newentity.AfterSaleState = 0;
  6464. newentity.AfterSaleTime = null;
  6465. newentity.AfterSaleUserId = 0;
  6466. newentity.AfterSaleSupplierState = 0;
  6467. newentity.LastBillWaybillCode = "";
  6468. newentity.LastBillCpCode = "";
  6469. newentity.FinishAfterSaleTime = null;
  6470. newentity.HandleTime = null;
  6471. newentity.IsSF = 0;
  6472. newentity.IsOldCustomer = 0;
  6473. newentity.UrgencyTime = null;
  6474. newentity.ResponsibleUserId = "";
  6475. newentity.IsVerifyToSupplier = false;
  6476. newentity.payment = 0;
  6477. newentity.CheckMemo = "";
  6478. newentity.OutSid = "";
  6479. newentity.CheckOrderTime = null;
  6480. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6481. }
  6482. newentity.isAfterSaleOrder = 1;
  6483. newentity.IsRefund = 0;
  6484. string receiveMobile = GetPostString("receiver_mobile");
  6485. if (receiveMobile.Length > 0)
  6486. {
  6487. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6488. if (trade != null)
  6489. {
  6490. trade.receiver_name = GetPostString("receiver_name");
  6491. trade.receiver_mobile = receiveMobile;
  6492. trade.receiver_state = GetPostString("receiver_state");
  6493. trade.receiver_city = GetPostString("receiver_city");
  6494. trade.receiver_district = GetPostString("receiver_district");
  6495. trade.receiver_address = GetPostString("receiver_address");
  6496. newentity.IsOffLineOrder = 1;
  6497. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6498. }
  6499. }
  6500. string st = GetPostString("ToState");
  6501. if (st.Length > 0)
  6502. {
  6503. if (newentity.OrderState <= 3)
  6504. {
  6505. newentity.WaitDesignTime = DateTime.Now;
  6506. newentity.StartDesignTime = null;
  6507. newentity.FinishDesignTime = null;
  6508. newentity.OrderState = 3;
  6509. if (st == "下单员")
  6510. {
  6511. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6512. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6513. {
  6514. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6515. }
  6516. }
  6517. else
  6518. {
  6519. newentity.WaitDesignTime = DateTime.Now;
  6520. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6521. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6522. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6523. {
  6524. DataRow user = dt1.Rows[0];
  6525. //找主管
  6526. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6527. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6528. if (dt != null && dt.Rows.Count > 0)
  6529. {
  6530. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6531. newentity.DesignUserId = designMr;
  6532. string key = "aftersale_order_" + designMr;
  6533. if (RedisHelper.HasKey(key))
  6534. {
  6535. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6536. list.Add(newentity.ctid);
  6537. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6538. }
  6539. }
  6540. //账号正常
  6541. if (user["State"].ToString() == "0")
  6542. {
  6543. newentity.DesignUserId = entity.DesignUserId;
  6544. string key = "aftersale_order_" + entity.DesignUserId;
  6545. if (RedisHelper.HasKey(key))
  6546. {
  6547. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6548. list.Add(newentity.ctid);
  6549. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6550. }
  6551. }
  6552. }
  6553. }
  6554. }
  6555. if (entity.IsXianHuo == 1)
  6556. {
  6557. newentity.OrderState = 6;
  6558. entity.FinishPlaceTime = DateTime.Now;
  6559. }
  6560. }
  6561. if (ishav)
  6562. {
  6563. newentity.Update();
  6564. }
  6565. else
  6566. {
  6567. newentity.Create();
  6568. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6569. newCellExtend.ctid = newentity.ctid;
  6570. newCellExtend.orderFrom = 20;
  6571. newCellExtend.orderType = 30;
  6572. if (st == "下单员")
  6573. {
  6574. }
  6575. else
  6576. {
  6577. newCellExtend.ReprintTime = DateTime.Now;
  6578. }
  6579. newCellExtend.Create();
  6580. }
  6581. if (st != "下单员")
  6582. {
  6583. designHelper.API_GetPrintData_CreateOrder(newentity);
  6584. }
  6585. }
  6586. //处理售后扩展
  6587. string resIdStr = GetPostString("ResponsibleUserId");
  6588. string refundFees = GetPostString("refundFrees");
  6589. int IsComplain = GetPostInt("isComplain");
  6590. int IsBad = GetPostInt("isBad");
  6591. string IsOriginal = GetPostString("isOriginal");
  6592. double diffResultPrice = GetPostDouble("diffResultPrice");
  6593. string textResult = GetPostString("textResult");
  6594. string supplierResponsible = GetPostString("supplierResponsible");
  6595. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6596. if (ceErpTradeAfterSaleExtend == null)
  6597. {
  6598. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6599. ceErpTradeAfterSaleExtend.tid = eid;
  6600. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6601. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6602. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6603. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6604. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6605. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6606. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6607. ceErpTradeAfterSaleExtend.Create();
  6608. }
  6609. else
  6610. {
  6611. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6612. {
  6613. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6614. }
  6615. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6616. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6617. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6618. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6619. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6620. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6621. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6622. ceErpTradeAfterSaleExtend.Update();
  6623. }
  6624. int gysid = GetPostInt("ResponsibleSupId");
  6625. if (entity.AfterSaleUserId == 0)
  6626. {
  6627. entity.AfterSaleUserId = CurrentUser.UserID;
  6628. }
  6629. entity.ResponsibleUserId = resIdStr;
  6630. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6631. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6632. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6633. {
  6634. CeErpTradeResponsible.DelByTid(eid, -1);
  6635. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6636. int backNum = 0;
  6637. if (number != null)
  6638. {
  6639. backNum = number.BackNum;
  6640. }
  6641. char[] separator = { ',' };
  6642. string[] sArray = resIdStr.Split(separator);
  6643. string[] refundFreeList = { };
  6644. if (refundFees.Length > 0)
  6645. {
  6646. refundFreeList = refundFees.Split(separator);
  6647. }
  6648. int index = -1;
  6649. foreach (string i in sArray)
  6650. {
  6651. index++;
  6652. if (i.Length <= 0) continue;
  6653. char[] separator2 = { '_' };
  6654. string idstr = i.Split(separator2)[0];
  6655. string idtype = i.Split(separator2)[1];
  6656. double refudFree = 0;
  6657. if (refundFreeList.Length > 0)
  6658. {
  6659. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6660. }
  6661. if (idtype == "s")
  6662. {
  6663. isDesign = true;
  6664. designFree = refudFree;
  6665. }
  6666. int userId = Convert.ToInt32(idstr);
  6667. int type = 0;
  6668. if (idtype == "g")
  6669. {
  6670. type = 1;
  6671. }
  6672. if (idtype == "w")
  6673. {
  6674. type = 2;
  6675. }
  6676. if (idtype == "t")
  6677. {
  6678. type = 3;
  6679. }
  6680. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6681. if (ceErpTradeResponsible == null)
  6682. {
  6683. ceErpTradeResponsible = new CeErpTradeResponsible();
  6684. ceErpTradeResponsible.tid = eid;
  6685. ceErpTradeResponsible.UserId = userId;
  6686. ceErpTradeResponsible.createdTime = DateTime.Now;
  6687. ceErpTradeResponsible.type = type;
  6688. if (type == 1)
  6689. {
  6690. ceErpTradeResponsible.IsSup = 1;
  6691. }
  6692. if (type == 2)
  6693. {
  6694. ceErpTradeResponsible.IsFlow = 1;
  6695. }
  6696. }
  6697. ceErpTradeResponsible.RefundFee = refudFree;
  6698. ceErpTradeResponsible.VerifyState = 0;
  6699. if (userId == 2125 || idtype == "w")
  6700. {
  6701. ceErpTradeResponsible.VerifyState = 1;
  6702. }
  6703. if (idtype == "w" && userId == 101)
  6704. {
  6705. ceErpTradeResponsible.VerifyState = 0;
  6706. }
  6707. if (ceErpTradeResponsible.ID > 0)
  6708. {
  6709. ceErpTradeResponsible.Update();
  6710. }
  6711. else
  6712. {
  6713. ceErpTradeResponsible.Create();
  6714. }
  6715. if (isDesign)
  6716. {
  6717. responsibleId = ceErpTradeResponsible.ID;
  6718. }
  6719. }
  6720. CeErpTradeResponsible.NumByTid(backNum, eid);
  6721. }
  6722. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6723. if (ceErpTradeCellExtend != null)
  6724. {
  6725. ceErpTradeCellExtend.returnVisit = 0;
  6726. ceErpTradeCellExtend.Update();
  6727. }
  6728. if (entity.HandleTime != null)
  6729. {
  6730. if (entity.AfterSaleState == 1)
  6731. {
  6732. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6733. }
  6734. else
  6735. {
  6736. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  6737. }
  6738. }
  6739. else
  6740. {
  6741. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  6742. entity.HandleTime = DateTime.Now;
  6743. }
  6744. bool isCompale = false;
  6745. if (entity.AfterSaleState == 5)
  6746. {
  6747. isCompale = true;
  6748. entity.AfterSaleState = 3;
  6749. }
  6750. entity.AfterSaleSupplierState = 0;
  6751. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  6752. {
  6753. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  6754. }
  6755. string sImgs = GetPostString("img");
  6756. entity.AfterSaleSupplierImg = sImgs;
  6757. entity.supRefundType = GetPostString("supRefundType");
  6758. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  6759. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  6760. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  6761. entity.AfterSaleMemoType = GetPostString("MemoType");
  6762. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  6763. {
  6764. //entity.AfterSaleSupplierState = 2;
  6765. }
  6766. string df = GetPostString("DeductFee");
  6767. if (df == "")
  6768. {
  6769. df = "0";
  6770. }
  6771. string rf = GetPostString("RefundFee");
  6772. if (rf == "")
  6773. {
  6774. rf = "0";
  6775. }
  6776. string pm = GetPostString("AfterSalePayment");
  6777. if (pm == "")
  6778. {
  6779. pm = "0";
  6780. }
  6781. entity.AfterSalePayment = Convert.ToDouble(pm);
  6782. entity.DeductFee = Convert.ToDouble(df);
  6783. entity.RefundFee = Convert.ToDouble(rf);
  6784. entity.UpdateTime = DateTime.Now;
  6785. entity.Update();
  6786. string toState = GetPostString("ToState");
  6787. string original = GetPostString("isOriginal");
  6788. ApiVo apiVo = new ApiVo();
  6789. apiVo.orderNumber = entity.ctid;
  6790. apiVo.actionName = "afterDesign";
  6791. apiVo.orderRemarks = entity.AfterSaleMethod;
  6792. apiVo.reasonRemarks = entity.AfterSaleReason;
  6793. apiVo.isDesign = isDesign;
  6794. apiVo.designFree = designFree;
  6795. apiVo.responsibleId = responsibleId;
  6796. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  6797. if (toState == "设计师")
  6798. {
  6799. apiVo.isOriginal = Convert.ToBoolean(original);
  6800. }
  6801. designHelper.API_WorkCore(apiVo);//afterDesign
  6802. CeErpMethod methodSql = new CeErpMethod();
  6803. methodSql.con = entity.AfterSaleMethod;
  6804. methodSql.addTime = DateTime.Now;
  6805. methodSql.Create();
  6806. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  6807. CeErpMethod.ExecuteNonQuery(delsql);
  6808. if (isCompale)
  6809. {
  6810. aftersale_data_change(entity.ctid);
  6811. }
  6812. returnSuccessMsg("操作成功!");
  6813. return;
  6814. }
  6815. returnErrorMsg("找不到订单记录");
  6816. }
  6817. }
  6818. public void ins_erp_toresponsible()
  6819. {
  6820. if (UrlPostParmsCheck("ctid"))
  6821. {
  6822. string eid = GetPostString("ctid");
  6823. CeErpTradeCell entity = null;
  6824. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6825. if (entity != null)
  6826. {
  6827. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  6828. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  6829. {
  6830. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  6831. return;
  6832. }
  6833. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  6834. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  6835. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  6836. if (entity.AfterSalePreTime == null)
  6837. {
  6838. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  6839. {
  6840. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  6841. }
  6842. }
  6843. entity.AfterSalePreTime = DateTime.Now;
  6844. //预完成给售后主管审核客户问题直接完成
  6845. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  6846. {
  6847. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  6848. {
  6849. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  6850. }
  6851. }
  6852. ceErpTradeAfterSaleExtend.Update();
  6853. entity.AfterSaleState = 2;
  6854. entity.UpdateTime = DateTime.Now;
  6855. entity.Update();
  6856. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  6857. aftersale_data_change(entity.ctid);
  6858. returnSuccessMsg("操作成功!");
  6859. return;
  6860. }
  6861. returnErrorMsg("找不到订单记录");
  6862. }
  6863. }
  6864. public void cancel_erp_aftersaleanddelnew()
  6865. {
  6866. if (UrlPostParmsCheck("ctid"))
  6867. {
  6868. string eid = GetPostString("ctid");
  6869. CeErpTradeCell entity = null;
  6870. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6871. if (entity != null)
  6872. {
  6873. entity.AfterSaleState = 0;
  6874. entity.AfterSaleReason = "";
  6875. entity.AfterSaleMethod = "";
  6876. entity.AfterSaleMemo = "";
  6877. entity.AfterSaleResponsible = "";
  6878. entity.ResponsibleUserId = "";
  6879. entity.DeductFee = 0;
  6880. entity.RefundFee = 0;
  6881. entity.IsArbitrate = 0;
  6882. CeErpTradeResponsible.DelByTid(eid, -1);
  6883. entity.Update();
  6884. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  6885. if (after != null)
  6886. {
  6887. if (after.OrderState < 5)
  6888. CeErpTradeCell.DelByCtid("S_" + eid);
  6889. }
  6890. returnSuccessMsg("操作成功!");
  6891. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  6892. return;
  6893. }
  6894. returnErrorMsg("找不到订单记录");
  6895. }
  6896. }
  6897. public void get_erp_aftersale_pregather()
  6898. {
  6899. List<string> lw = new List<string>();
  6900. int st = GetInt("st");
  6901. string tid = GetPostString("ctid");
  6902. if (tid.Length > 0)
  6903. {
  6904. string select_tid = getTidByCtid(tid);
  6905. lw.Add(string.Format("tid='{0}'", select_tid));
  6906. }
  6907. string shopname = GetPostString("shopname");
  6908. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6909. string buyernick = GetPostString("buyer_nick");
  6910. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6911. string sellermemo = GetPostString("seller_memo");
  6912. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6913. string orderState = GetPostString("orderState");
  6914. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6915. string reason = GetPostString("reason");
  6916. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6917. string method = GetPostString("method");
  6918. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6919. string handler = GetPostString("handler");
  6920. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6921. string handledate1 = GetPostString("handledate1");
  6922. string handledate2 = GetPostString("handledate2");
  6923. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6924. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6925. string supplier = GetPostString("supplier");
  6926. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6927. string responsible = GetPostString("responsibleman");
  6928. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6929. string customer = GetPostString("customer");
  6930. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6931. string design = GetPostString("design");
  6932. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6933. string afterMemoType = GetPostString("aftermemotype");
  6934. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6935. string afterSaleMemo = GetPostString("afterSaleMemo");
  6936. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6937. string afterresult = GetPostString("afterresult");
  6938. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  6939. string poscode = CurrentUser.UserPost.Post.Code;
  6940. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  6941. {
  6942. string shopid = CurrentUser.User.pemShop;
  6943. lw.Add(string.Format("shopId in ({0})", shopid));
  6944. }
  6945. var mainwhere = string.Join(" and ", lw.ToArray());
  6946. string ro_json = "";
  6947. string type = GetPostString("gather_type");
  6948. int number = 0;
  6949. if (poscode == "AfterSale")
  6950. {
  6951. //处理中
  6952. if (type == "Handling")
  6953. {
  6954. 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) : ""));
  6955. DataTable dt = null;
  6956. try
  6957. {
  6958. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6959. number = Convert.ToInt32(dt.Rows[0]["number"]);
  6960. }
  6961. catch (Exception e)
  6962. {
  6963. dt = new DataTable();
  6964. }
  6965. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  6966. return;
  6967. }
  6968. if (type == "Wait")
  6969. {
  6970. //待处理
  6971. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  6972. DataTable dt1 = null;
  6973. try
  6974. {
  6975. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6976. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  6977. }
  6978. catch (Exception e)
  6979. {
  6980. dt1 = new DataTable();
  6981. }
  6982. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  6983. return;
  6984. }
  6985. if (type == "back")
  6986. {
  6987. //打回
  6988. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  6989. DataTable dt2 = null;
  6990. try
  6991. {
  6992. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  6993. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  6994. }
  6995. catch (Exception e)
  6996. {
  6997. dt2 = new DataTable();
  6998. }
  6999. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7000. return;
  7001. }
  7002. if (type == "preCompletion")
  7003. {
  7004. //预完成
  7005. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7006. DataTable dt3 = null;
  7007. try
  7008. {
  7009. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7010. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7011. }
  7012. catch (Exception e)
  7013. {
  7014. dt3 = new DataTable();
  7015. }
  7016. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7017. return;
  7018. }
  7019. if (type == "documentary")
  7020. {
  7021. //跟单中
  7022. 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) : ""));
  7023. DataTable dt4 = null;
  7024. try
  7025. {
  7026. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7027. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7028. }
  7029. catch (Exception e)
  7030. {
  7031. dt4 = new DataTable();
  7032. }
  7033. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7034. return;
  7035. }
  7036. if (type == "reBack")
  7037. {
  7038. //被打回
  7039. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7040. DataTable dt1 = null;
  7041. try
  7042. {
  7043. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7044. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7045. }
  7046. catch (Exception e)
  7047. {
  7048. dt1 = new DataTable();
  7049. }
  7050. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7051. return;
  7052. }
  7053. }
  7054. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7055. {
  7056. if (type == "puBack")
  7057. {
  7058. //退回
  7059. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7060. DataTable dt = null;
  7061. try
  7062. {
  7063. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7064. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7065. }
  7066. catch (Exception e)
  7067. {
  7068. dt = new DataTable();
  7069. }
  7070. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7071. return;
  7072. }
  7073. if (type == "reBack")
  7074. {
  7075. //打回
  7076. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7077. DataTable dt1 = null;
  7078. try
  7079. {
  7080. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7081. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7082. }
  7083. catch (Exception e)
  7084. {
  7085. dt1 = new DataTable();
  7086. }
  7087. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7088. return;
  7089. }
  7090. if (type == "examEd")
  7091. {
  7092. //已审核
  7093. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7094. DataTable dt2 = null;
  7095. try
  7096. {
  7097. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7098. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7099. }
  7100. catch (Exception e)
  7101. {
  7102. dt2 = new DataTable();
  7103. }
  7104. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7105. return;
  7106. }
  7107. if (type == "waitExam")
  7108. {
  7109. //待审核
  7110. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7111. DataTable dt3 = null;
  7112. try
  7113. {
  7114. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7115. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7116. }
  7117. catch (Exception e)
  7118. {
  7119. dt3 = new DataTable();
  7120. }
  7121. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7122. return;
  7123. }
  7124. if (type == "Handling")
  7125. {
  7126. //处理中
  7127. 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) : ""));
  7128. DataTable dt4 = null;
  7129. try
  7130. {
  7131. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7132. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7133. }
  7134. catch (Exception e)
  7135. {
  7136. dt4 = new DataTable();
  7137. }
  7138. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7139. return;
  7140. }
  7141. if (type == "Wait")
  7142. {
  7143. //待处理
  7144. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7145. DataTable dt5 = null;
  7146. try
  7147. {
  7148. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7149. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7150. }
  7151. catch (Exception e)
  7152. {
  7153. dt5 = new DataTable();
  7154. }
  7155. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7156. return;
  7157. }
  7158. if (type == "documentary")
  7159. {
  7160. //跟单中
  7161. 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) : ""));
  7162. DataTable dt6 = null;
  7163. try
  7164. {
  7165. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7166. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7167. }
  7168. catch (Exception e)
  7169. {
  7170. dt6 = new DataTable();
  7171. }
  7172. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7173. return;
  7174. }
  7175. }
  7176. returnSuccess(ro_json);
  7177. }
  7178. public void end_erp_aftersale()
  7179. {
  7180. if (UrlPostParmsCheck("ctid"))
  7181. {
  7182. string eid = GetPostString("ctid");
  7183. CeErpTradeCell entity = null;
  7184. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7185. if (entity != null)
  7186. {
  7187. string stype = GetPostString("stype");
  7188. string typeStr = stype;
  7189. entity.AfterSaleState = 4;
  7190. entity.FinishAfterSaleTime = DateTime.Now;
  7191. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7192. entity.Update();
  7193. ApiVo apiVo = new ApiVo();
  7194. apiVo.orderNumber = entity.ctid;
  7195. apiVo.actionName = "afterOver";
  7196. designHelper.API_WorkCore(apiVo); //afterOver
  7197. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7198. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7199. CeErpSukuraData.createInfo(entity.ctid, 8);
  7200. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7201. returnSuccessMsg("操作成功!");
  7202. return;
  7203. }
  7204. returnErrorMsg("找不到订单记录");
  7205. }
  7206. }
  7207. public void ins_erp_finishaftersale()
  7208. {
  7209. if (UrlPostParmsCheck("id"))
  7210. {
  7211. string eid = GetPostString("id");
  7212. CeErpTradeResponsible entity = null;
  7213. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7214. if (entity != null)
  7215. {
  7216. entity.VerifyState = 1;
  7217. entity.VerifyTime = DateTime.Now;
  7218. entity.Update();
  7219. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7220. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7221. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7222. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7223. if (dt.Rows.Count <= 0)
  7224. {
  7225. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7226. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7227. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7228. CeErpSukuraData.createInfo(entity.tid, 8);
  7229. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7230. {
  7231. CeErpDesignerBill.Del(entity.tid);
  7232. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7233. }
  7234. }
  7235. returnSuccessMsg("操作成功!");
  7236. return;
  7237. }
  7238. returnErrorMsg("找不到订单记录");
  7239. }
  7240. }
  7241. public void upd_erp_arbitrateaftersale()
  7242. {
  7243. if (UrlPostParmsCheck("id"))
  7244. {
  7245. string eid = GetPostString("id");
  7246. CeErpTradeResponsible entity = null;
  7247. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7248. if (entity != null)
  7249. {
  7250. entity.IsArbitrate = 1;
  7251. entity.ArbitradeMemo = GetPostString("reason");
  7252. entity.VerifyState = 2;
  7253. entity.Update();
  7254. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7255. if (tradecell != null)
  7256. {
  7257. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7258. tradecell.IsArbitrate = 1;
  7259. tradecell.Update();
  7260. }
  7261. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7262. returnSuccessMsg("操作成功!");
  7263. return;
  7264. }
  7265. returnErrorMsg("找不到订单记录");
  7266. }
  7267. }
  7268. public void upd_erp_backaftersale()
  7269. {
  7270. if (UrlPostParmsCheck("tid"))
  7271. {
  7272. string eid = GetPostString("tid");
  7273. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7274. int backNum = 0;
  7275. if (number != null)
  7276. {
  7277. backNum = number.BackNum;
  7278. }
  7279. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7280. CeErpTradeCell entity = null;
  7281. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7282. if (entity != null)
  7283. {
  7284. entity.AfterSaleBackReason = GetPostString("backreason");
  7285. entity.AfterSaleState = 1;
  7286. entity.AfterSaleSupplierState = 0;
  7287. entity.UpdateTime = DateTime.Now;
  7288. entity.Update();
  7289. returnSuccessMsg("操作成功!");
  7290. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7291. return;
  7292. }
  7293. returnErrorMsg("找不到订单记录");
  7294. }
  7295. }
  7296. public void get_erp_supplieraftersalelist()
  7297. {
  7298. DataStruct dStruct = GetPostStruct();
  7299. List<string> lw = new List<string>();
  7300. string tid = GetPostString("ctid");
  7301. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7302. string shopname = GetPostString("shopname");
  7303. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7304. string buyernick = GetPostString("buyer_nick");
  7305. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7306. string sellermemo = GetPostString("seller_memo");
  7307. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7308. string orderState = GetPostString("orderState");
  7309. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7310. string afterState = GetPostString("afterstate");
  7311. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7312. string date1 = GetPostString("date1");
  7313. string date2 = GetPostString("date2");
  7314. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7315. if (dw.Length > 0) lw.Add(dw);
  7316. string price1 = GetPostString("price1");
  7317. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7318. string price2 = GetPostString("price2");
  7319. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7320. string reason = GetPostString("reason");
  7321. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7322. string method = GetPostString("method");
  7323. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7324. string handledate1 = GetPostString("handledate1");
  7325. string handledate2 = GetPostString("handledate2");
  7326. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7327. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7328. string handler = GetPostString("handler");
  7329. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7330. string afterdate1 = GetPostString("afterdate1");
  7331. string afterdate2 = GetPostString("afterdate2");
  7332. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7333. if (afterDate.Length > 0) lw.Add(afterDate);
  7334. string customer = GetPostString("customer");
  7335. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7336. string design = GetPostString("design");
  7337. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7338. string afterMemoType = GetPostString("aftermemotype");
  7339. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7340. string vstate = GetPostString("vstate");
  7341. if (vstate.Length > 0)
  7342. {
  7343. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7344. }
  7345. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7346. string supplier = GetPostString("supplier");
  7347. int supid = commonHelper.getSupplierIDByName(supplier);
  7348. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7349. string posCode = CurrentUser.UserPost.Post.Code;
  7350. if (posCode == "Supplier")
  7351. {
  7352. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7353. }
  7354. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7355. {
  7356. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7357. }
  7358. else
  7359. {
  7360. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7361. }
  7362. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7363. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7364. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7365. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7366. writeGridDataTableJson(dStruct.TotalCount, dt);
  7367. }
  7368. public void upd_erp_supverifyaftersale()
  7369. {
  7370. if (UrlPostParmsCheck("id"))
  7371. {
  7372. string id = GetPostString("id");
  7373. int st = GetPostInt("afterstate");
  7374. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7375. CeErpTradeCell entity = null;
  7376. if (ceErpTradeResponsible != null)
  7377. {
  7378. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7379. }
  7380. string afmemo = GetPostString("supmemo");
  7381. string image = GetPostString("image");
  7382. if (entity != null)
  7383. {
  7384. entity.AfterSaleSupplierState = st;
  7385. entity.AfterSaleSupplierMemo = afmemo;
  7386. if (st == 1)
  7387. {
  7388. ceErpTradeResponsible.VerifyState = 1;
  7389. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7390. ceErpTradeResponsible.Update();
  7391. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7392. if (isAll)
  7393. {
  7394. entity.AfterSaleState = 4;
  7395. entity.FinishAfterSaleTime = DateTime.Now;
  7396. }
  7397. }
  7398. else
  7399. {
  7400. CeErpTradeResponsible.dateByTid(entity.ctid);
  7401. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7402. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7403. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7404. if (num <= 1)
  7405. {
  7406. entity.AfterSaleState = 1;
  7407. }
  7408. else
  7409. {
  7410. entity.AfterSaleState = 5;
  7411. }
  7412. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7413. if (ceErpTradeAfterSaleExtend != null)
  7414. {
  7415. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7416. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7417. ceErpTradeAfterSaleExtend.Update();
  7418. }
  7419. else
  7420. {
  7421. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7422. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7423. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7424. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7425. ceErpTradeAfterSaleExtend.Create();
  7426. }
  7427. }
  7428. if (entity.AfterSaleState == 4)
  7429. {
  7430. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7431. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7432. {
  7433. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7434. }
  7435. ApiVo apiVo = new ApiVo();
  7436. apiVo.orderNumber = entity.ctid;
  7437. apiVo.actionName = "afterOver";
  7438. designHelper.API_WorkCore(apiVo); //afterOver
  7439. }
  7440. entity.UpdateTime = DateTime.Now;
  7441. entity.Update();
  7442. returnSuccessMsg("操作成功!");
  7443. CeErpSukuraData.createInfo(entity.ctid, 8);
  7444. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7445. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7446. return;
  7447. }
  7448. returnErrorMsg("找不到订单记录");
  7449. }
  7450. }
  7451. public void upd_erp_masteraftersale()
  7452. {
  7453. if (UrlPostParmsCheck("id"))
  7454. {
  7455. string id = GetPostString("id");
  7456. int st = GetPostInt("afterstate");
  7457. string afmemo = GetPostString("supmemo");
  7458. string image = GetPostString("image");
  7459. string textResult = GetPostString("textResult");
  7460. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7461. if (ceErpTradeResponsible != null)
  7462. {
  7463. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7464. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7465. ceErpTradeResponsible.Update();
  7466. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7467. if (entity != null)
  7468. {
  7469. entity.AfterSaleSupplierState = st;
  7470. entity.AfterSaleSupplierMemo = afmemo;
  7471. if (st == 1)
  7472. {
  7473. }
  7474. else
  7475. {
  7476. CeErpTradeResponsible.dateByTid(entity.ctid);
  7477. //退回到售后
  7478. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7479. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7480. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7481. if (num <= 1)
  7482. {
  7483. entity.AfterSaleState = 1;
  7484. }
  7485. else
  7486. {
  7487. entity.AfterSaleState = 5;
  7488. }
  7489. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7490. if (ceErpTradeAfterSaleExtend != null)
  7491. {
  7492. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7493. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7494. ceErpTradeAfterSaleExtend.Update();
  7495. }
  7496. else
  7497. {
  7498. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7499. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7500. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7501. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7502. ceErpTradeAfterSaleExtend.Create();
  7503. }
  7504. }
  7505. entity.UpdateTime = DateTime.Now;
  7506. entity.Update();
  7507. returnSuccessMsg("操作成功!");
  7508. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7509. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7510. return;
  7511. }
  7512. }
  7513. returnErrorMsg("找不到订单记录");
  7514. }
  7515. }
  7516. public void upd_erp_personaftersale()
  7517. {
  7518. if (UrlPostParmsCheck("id"))
  7519. {
  7520. string id = GetPostString("id");
  7521. int st = GetPostInt("afterstate");
  7522. string afmemo = GetPostString("supmemo");
  7523. string image = GetPostString("image");
  7524. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7525. if (ceErpTradeResponsible != null)
  7526. {
  7527. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7528. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7529. ceErpTradeResponsible.Update();
  7530. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7531. if (entity != null)
  7532. {
  7533. entity.AfterSaleSupplierMemo = afmemo;
  7534. entity.AfterSaleSupplierState = st;
  7535. if (st == 1)
  7536. {
  7537. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7538. if (isAll)
  7539. {
  7540. entity.AfterSaleState = 4;
  7541. entity.FinishAfterSaleTime = DateTime.Now;
  7542. }
  7543. }
  7544. else
  7545. {
  7546. CeErpTradeResponsible.dateByTid(entity.ctid);
  7547. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7548. if (ceErpTradeAfterSaleExtend != null)
  7549. {
  7550. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7551. ceErpTradeAfterSaleExtend.Update();
  7552. }
  7553. else
  7554. {
  7555. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7556. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7557. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7558. ceErpTradeAfterSaleExtend.Create();
  7559. }
  7560. //退回到主管
  7561. //entity.AfterSaleState = 2;
  7562. }
  7563. if (entity.AfterSaleState == 4)
  7564. {
  7565. ApiVo apiVo = new ApiVo();
  7566. apiVo.orderNumber = entity.ctid;
  7567. apiVo.actionName = "afterOver";
  7568. designHelper.API_WorkCore(apiVo); //afterOver
  7569. }
  7570. entity.UpdateTime = DateTime.Now;
  7571. entity.Update();
  7572. returnSuccessMsg("操作成功!");
  7573. CeErpSukuraData.createInfo(entity.ctid, 8);
  7574. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7575. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7576. return;
  7577. }
  7578. }
  7579. returnErrorMsg("找不到订单记录");
  7580. }
  7581. }
  7582. public void set_erp_supplierrefundtag()
  7583. {
  7584. if (UrlPostParmsCheck("ctid"))
  7585. {
  7586. string eid = GetPostString("ctid");
  7587. CeErpTradeCell entity = null;
  7588. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7589. if (entity != null)
  7590. {
  7591. entity.IsSupplierRefund = GetPostInt("tag");
  7592. entity.Update();
  7593. returnSuccessMsg("操作成功!");
  7594. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7595. return;
  7596. }
  7597. returnErrorMsg("找不到订单记录");
  7598. }
  7599. }
  7600. public void get_erp_refundlist()
  7601. {
  7602. DataStruct dStruct = GetPostStruct();
  7603. List<string> lw = new List<string>();
  7604. string tid = GetPostString("tid");
  7605. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7606. //string rid = GetPostString("refund_id");
  7607. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7608. string shopname = GetPostString("shopname");
  7609. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7610. string buyernick = GetPostString("buyer_nick");
  7611. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7612. string customer = GetPostString("customer");
  7613. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7614. string design = GetPostString("design");
  7615. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7616. string sellermemo = GetPostString("seller_memo");
  7617. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7618. //string date1 = GetPostString("date1");
  7619. //string date2 = GetPostString("date2");
  7620. //string dateType = GetPostString("dateType");
  7621. //if (dateType.Length > 0)
  7622. //{
  7623. // if (dateType == "1001") dateType = "0";
  7624. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7625. // if (searchDT.Count == 2)
  7626. // {
  7627. // date1 = searchDT[0].ToString();
  7628. // date2 = searchDT[1].ToString();
  7629. // }
  7630. //}
  7631. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7632. //if (dw.Length > 0) lw.Add(dw);
  7633. string redate1 = GetPostString("refunddate1");
  7634. string redate2 = GetPostString("refunddate2");
  7635. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7636. if (dwdate.Length > 0) lw.Add(dwdate);
  7637. string price1 = GetPostString("price1");
  7638. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7639. string price2 = GetPostString("price2");
  7640. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7641. string ispartrefund = GetPostString("ispartrefund");
  7642. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7643. string refundState = GetPostString("refundvstate");
  7644. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7645. int st = GetInt("st");
  7646. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7647. {
  7648. string responsible = GetPostString("responsibleman");
  7649. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7650. lw.Add(string.Format("RefundState>={0}", st));
  7651. string code = CurrentUser.UserPost.Post.Code;
  7652. if (code == "CustomerService")
  7653. {
  7654. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7655. }
  7656. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7657. {
  7658. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7659. }
  7660. else if (code == "Place" || code == "PlaceMr")
  7661. {
  7662. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7663. }
  7664. dStruct.Order = "RefundState asc,created desc";
  7665. }
  7666. else if (st == 10)
  7667. {
  7668. string responsible = GetPostString("responsibleman");
  7669. if (responsible == "空白")
  7670. {
  7671. lw.Add(string.Format("ResponsibleUserName = ''"));
  7672. }
  7673. else if (responsible.Length > 0)
  7674. {
  7675. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7676. }
  7677. lw.Add(string.Format("RefundState>=0"));
  7678. dStruct.Order = "created desc";
  7679. }
  7680. else
  7681. {
  7682. string responsible = GetPostString("responsibleman");
  7683. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7684. lw.Add(string.Format("RefundState={0}", st));
  7685. dStruct.Order = "created desc";
  7686. }
  7687. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7688. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7689. dt.Columns.Add("refund_fees");
  7690. foreach (DataRow dr in dt.Rows)
  7691. {
  7692. String status = dr["status"].ToString();
  7693. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7694. {
  7695. dr["refund_fees"] = dr["refund_fee"];
  7696. }
  7697. else
  7698. {
  7699. dr["refund_fees"] = "0.0";
  7700. }
  7701. }
  7702. writeGridDataTableJson(dStruct.TotalCount, dt);
  7703. }
  7704. public void get_erp_refunddesignlist()
  7705. {
  7706. DataStruct dStruct = GetPostStruct();
  7707. List<string> lw = new List<string>();
  7708. string tid = GetPostString("tid");
  7709. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7710. string shopname = GetPostString("shopname");
  7711. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7712. string buyernick = GetPostString("buyer_nick");
  7713. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7714. string customer = GetPostString("customer");
  7715. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7716. string design = GetPostString("design");
  7717. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7718. string sellermemo = GetPostString("seller_memo");
  7719. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7720. string redate1 = GetPostString("refunddate1");
  7721. string redate2 = GetPostString("refunddate2");
  7722. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7723. if (dwdate.Length > 0) lw.Add(dwdate);
  7724. string price1 = GetPostString("price1");
  7725. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7726. string price2 = GetPostString("price2");
  7727. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7728. string ispartrefund = GetPostString("ispartrefund");
  7729. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7730. string designerorg = GetPostString("designerorg");
  7731. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  7732. string refundState = GetPostString("refundState");
  7733. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  7734. int myOrgid = CurrentUser.UserPost.OrgID;
  7735. string myOrgCode = CurrentUser.UserPost.Post.Code;
  7736. if ("Designer".Equals(myOrgCode))//设计师能看到的
  7737. {
  7738. if (CurrentUser.User.TeamIds.Length > 0)
  7739. {
  7740. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  7741. }
  7742. else
  7743. {
  7744. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  7745. }
  7746. }
  7747. else if ("SysAdmin".Equals(myOrgCode))
  7748. {
  7749. }
  7750. else
  7751. {
  7752. if (CurrentUser.User.ManageOrgIds.Length > 0)
  7753. {
  7754. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  7755. }
  7756. else
  7757. {
  7758. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  7759. }
  7760. }
  7761. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  7762. dStruct.Order = "created desc";
  7763. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7764. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  7765. dt.Columns.Add("refund_fees");
  7766. foreach (DataRow dr in dt.Rows)
  7767. {
  7768. String status = dr["status"].ToString();
  7769. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7770. {
  7771. dr["refund_fees"] = dr["refund_fee"];
  7772. }
  7773. else
  7774. {
  7775. dr["refund_fees"] = "0.0";
  7776. }
  7777. }
  7778. writeGridDataTableJson(dStruct.TotalCount, dt);
  7779. }
  7780. public void handle_erp_refundtag()
  7781. {
  7782. if (UrlPostParmsCheck("refund_id"))
  7783. {
  7784. string eid = GetPostString("refund_id");
  7785. string respMan = GetPostString("ResponsibleName");
  7786. if (respMan.Length <= 0)
  7787. {
  7788. returnErrorMsg("责任人不能为空");
  7789. return;
  7790. }
  7791. CeErpTradeRefund entity = null;
  7792. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7793. if (entity != null)
  7794. {
  7795. entity.ResponsibleUserName = respMan;
  7796. string userid = GetPostString("ResponsibleUserId");
  7797. if (userid.Length > 0)
  7798. {
  7799. entity.ResponsibleUserId = userid;
  7800. }
  7801. entity.Memo = GetPostString("Memo");
  7802. if (respMan.IndexOf("客服") != -1 ||
  7803. respMan.IndexOf("设计师") != -1 ||
  7804. respMan.IndexOf("下单员") != -1)
  7805. {
  7806. entity.RefundState = 2;
  7807. }
  7808. else
  7809. {
  7810. entity.RefundState = 3;
  7811. }
  7812. entity.modified = DateTime.Now;
  7813. entity.Update();
  7814. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  7815. returnSuccessMsg("操作成功!");
  7816. return;
  7817. }
  7818. returnErrorMsg("找不到订单记录");
  7819. }
  7820. }
  7821. public void handle_erp_designrefundtag()
  7822. {
  7823. if (UrlPostParmsCheck("refund_id"))
  7824. {
  7825. string eid = GetPostString("refund_id");
  7826. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  7827. if (ceErpTradeCellExtend == null)
  7828. {
  7829. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  7830. ceErpTradeCellExtend.ctid = eid;
  7831. }
  7832. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  7833. if (ceErpTradeCellExtend.ID > 0)
  7834. {
  7835. ceErpTradeCellExtend.Update();
  7836. }
  7837. else
  7838. {
  7839. ceErpTradeCellExtend.Create();
  7840. }
  7841. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  7842. returnSuccessMsg("操作成功!");
  7843. return;
  7844. }
  7845. returnErrorMsg("找不到订单记录");
  7846. }
  7847. public void upd_erp_refundverify()
  7848. {
  7849. if (UrlPostParmsCheck("refund_id"))
  7850. {
  7851. string eid = GetPostString("refund_id");
  7852. CeErpTradeRefund entity = null;
  7853. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7854. if (entity != null)
  7855. {
  7856. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  7857. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  7858. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  7859. {
  7860. entity.RefundState = 2;
  7861. }
  7862. else
  7863. {
  7864. entity.RefundState = 3;
  7865. }
  7866. entity.Update();
  7867. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  7868. returnSuccessMsg("操作成功!");
  7869. return;
  7870. }
  7871. returnErrorMsg("找不到订单记录");
  7872. }
  7873. }
  7874. public void upd_erp_refundapprove()
  7875. {
  7876. if (UrlPostParmsCheck("refund_id"))
  7877. {
  7878. string eid = GetPostString("refund_id");
  7879. CeErpTradeRefund entity = null;
  7880. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7881. if (entity != null)
  7882. {
  7883. int apr = GetPostInt("approve");
  7884. if (apr == 0)
  7885. {
  7886. entity.RefundState = 1;
  7887. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  7888. }
  7889. else if (apr == 1)
  7890. {
  7891. entity.RefundState = 3;
  7892. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  7893. }
  7894. entity.modified = DateTime.Now;
  7895. entity.Update();
  7896. returnSuccessMsg("操作成功!");
  7897. return;
  7898. }
  7899. returnErrorMsg("找不到订单记录");
  7900. }
  7901. }
  7902. public void get_erp_billlist()
  7903. {
  7904. DataStruct dStruct = GetPostStruct();
  7905. List<string> lw = new List<string>();
  7906. string title = GetPostString("title");
  7907. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  7908. string tid = GetPostString("tid");
  7909. string tids = GetPostString("tids");
  7910. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7911. if (tids.Length > 0)
  7912. {
  7913. tids = "'" + tids + "'";
  7914. tids = tids.Replace(",", "','");
  7915. lw.Add(string.Format("tid in ({0})", tids));
  7916. }
  7917. string shopname = GetPostString("shopname");
  7918. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7919. string buyernick = GetPostString("buyer_nick");
  7920. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7921. string customer = GetPostString("customer");
  7922. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7923. string date1 = GetPostString("date1");
  7924. string date2 = GetPostString("date2");
  7925. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7926. if (dw.Length > 0) lw.Add(dw);
  7927. string price1 = GetPostString("price1");
  7928. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7929. string price2 = GetPostString("price2");
  7930. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7931. string returndate1 = GetPostString("returndate1");
  7932. string returndate2 = GetPostString("returndate2");
  7933. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  7934. if (dw1.Length > 0) lw.Add(dw1);
  7935. string billtype = GetPostString("billtype");
  7936. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  7937. string billstate = GetPostString("billstate");
  7938. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  7939. string usershop = CurrentUser.User.pemShop;
  7940. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  7941. dStruct.Order = "createTime desc";
  7942. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7943. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  7944. //foreach (DataRow dr in dt.Rows)
  7945. //{
  7946. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  7947. //}
  7948. writeGridDataTableJson(dStruct.TotalCount, dt);
  7949. }
  7950. public void modify_erp_billinfo()
  7951. {
  7952. if (UrlPostParmsCheck("ID"))
  7953. {
  7954. string eid = GetPostString("ID");
  7955. CeErpBill bill_entity = null;
  7956. if (eid != "") bill_entity = CeErpBill.Get(eid);
  7957. if (bill_entity != null)
  7958. {
  7959. bill_entity.tid = GetPostString("tid");
  7960. bill_entity.title = GetPostString("title");
  7961. bill_entity.tax = GetPostString("tax");
  7962. bill_entity.bank = GetPostString("bank");
  7963. bill_entity.bankac = GetPostString("bankac");
  7964. bill_entity.address = GetPostString("address");
  7965. bill_entity.phone = GetPostString("phone");
  7966. bill_entity.price = GetPostString("price");
  7967. bill_entity.productId = GetPostInt("ProductName");
  7968. bill_entity.num = GetPostInt("num");
  7969. bill_entity.unit = GetPostString("unit");
  7970. bill_entity.type = GetPostString("type");
  7971. bill_entity.sendType = GetPostString("SendType");
  7972. bill_entity.email = GetPostString("email");
  7973. bill_entity.buyer_nick = GetPostString("buyer_nick");
  7974. bill_entity.shopName = GetPostString("ShopName");
  7975. bill_entity.applymemo = GetPostString("applymemo");
  7976. bill_entity.modifyTime = DateTime.Now;
  7977. bill_entity.createTime = DateTime.Now;
  7978. bill_entity.state = 0;
  7979. bill_entity.Update();
  7980. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  7981. returnSuccessMsg("发票修改成功!");
  7982. return;
  7983. }
  7984. returnErrorMsg("找不到对应记录");
  7985. }
  7986. }
  7987. public void set_erp_invoicing()
  7988. {
  7989. if (UrlPostParmsCheck("id"))
  7990. {
  7991. try
  7992. {
  7993. string eid = GetPostString("id");
  7994. CeErpBill bill_entity = null;
  7995. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  7996. if (bill_entity != null)
  7997. {
  7998. int ComId = GetPostInt("ComId");
  7999. //string memo = GetPostString("Memo");
  8000. int allInfo = GetPostInt("allinfo");
  8001. string clert = CurrentUser.User.Name;
  8002. //string detailValue = GetPostString("detailvalue");
  8003. string billId = bill_entity.billOrderId;
  8004. string[] billIdList = billId.Split(',');
  8005. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8006. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8007. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8008. {
  8009. billCount += 1;
  8010. }
  8011. if (billId.Length <= 0 || billIdList.Length != billCount)
  8012. {
  8013. bill_entity.billOrderId = "";
  8014. string prebill = "ltb";
  8015. for (int idx = 1; idx <= billCount; idx++)
  8016. {
  8017. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8018. string billoid = prebill + idx + dtstr;
  8019. bill_entity.billOrderId += billoid;
  8020. if (idx < billCount)
  8021. {
  8022. bill_entity.billOrderId += ",";
  8023. }
  8024. }
  8025. }
  8026. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8027. if (bill_entity.state == 5)
  8028. {
  8029. string errMsg = bill_entity.failerror;
  8030. string[] errlist = errMsg.Split('|');
  8031. string[] errTags = new string[errlist.Length];
  8032. for (int itag = 0; itag < errlist.Length; itag++)
  8033. {
  8034. if (errlist[itag].Length <= 0) continue;
  8035. errTags[itag] = errlist[itag].Split('&')[0];
  8036. }
  8037. for (int iii = 0; iii < errTags.Length; iii++)
  8038. {
  8039. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8040. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8041. if (billOrderList.Length >= erroBillOrderTag)
  8042. {
  8043. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8044. if (needModifyBillId.Length <= 19)
  8045. {
  8046. needModifyBillId = needModifyBillId + "1";
  8047. }
  8048. else
  8049. {
  8050. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8051. last = last + 1;
  8052. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8053. }
  8054. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8055. }
  8056. }
  8057. }
  8058. bool isHaveBillSucces = false;
  8059. string totalRes = "";
  8060. bill_entity.failerror = "";
  8061. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8062. {
  8063. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8064. totalRes += res;
  8065. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8066. {
  8067. isHaveBillSucces = true;
  8068. bill_entity.comId = ComId;
  8069. bill_entity.state = 1;
  8070. bill_entity.executeTime = DateTime.Now;
  8071. bill_entity.executeUser = clert;
  8072. }
  8073. else
  8074. {
  8075. bill_entity.state = 5;
  8076. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8077. }
  8078. }
  8079. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8080. bill_entity.Update();
  8081. if (isHaveBillSucces)
  8082. {
  8083. StringBuilder sql = new StringBuilder();
  8084. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8085. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8086. }
  8087. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8088. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8089. {
  8090. returnErrorMsg("开票失败");
  8091. }
  8092. else
  8093. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8094. return;
  8095. }
  8096. returnErrorMsg("找不到对应记录");
  8097. }
  8098. catch (Exception ex)
  8099. {
  8100. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8101. returnErrorMsg("操作失败");
  8102. }
  8103. }
  8104. }
  8105. public void get_erp_invoicing_back()
  8106. {
  8107. if (UrlPostParmsCheck("id"))
  8108. {
  8109. try
  8110. {
  8111. string id = GetPostString("id");
  8112. CeErpBill entiy = CeErpBill.Get(id);
  8113. if (entiy != null)
  8114. {
  8115. if (entiy.state == 0)
  8116. {
  8117. returnErrorMsg("发票还未开具");
  8118. return;
  8119. }
  8120. string[] billOrderList = entiy.billOrderId.Split(',');
  8121. int iTag = 0;
  8122. entiy.fplsh = "";
  8123. entiy.fpdm = "";
  8124. entiy.fphm = "";
  8125. foreach (string billOrderId in billOrderList)
  8126. {
  8127. iTag++;
  8128. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8129. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8130. {
  8131. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8132. try
  8133. {
  8134. Invoicing_get_response_Obj iObj = null;
  8135. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8136. if (iObj != null)
  8137. {
  8138. entiy.state = 2;
  8139. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8140. entiy.fpdm += iObj.list[0].c_fpdm;
  8141. entiy.fphm += iObj.list[0].c_fphm;
  8142. if (iTag < billOrderList.Length)
  8143. {
  8144. entiy.fplsh += ",";
  8145. entiy.fpdm += ",";
  8146. entiy.fphm += ",";
  8147. }
  8148. entiy.Update();
  8149. }
  8150. StringBuilder sql = new StringBuilder();
  8151. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8152. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8153. returnSuccessMsg("开票成功");
  8154. }
  8155. catch (Exception ex)
  8156. {
  8157. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8158. }
  8159. return;
  8160. }
  8161. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8162. {
  8163. var res_obj = new
  8164. {
  8165. data = "开票中"
  8166. };
  8167. string ro_json = JsonConvert.SerializeObject(res_obj);
  8168. returnSuccess(ro_json);
  8169. return;
  8170. }
  8171. else
  8172. {
  8173. int eidx = res.IndexOf("c_resultmsg");
  8174. int lidx = res.IndexOf("c_status");
  8175. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8176. entiy.state = 5;
  8177. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8178. entiy.Update();
  8179. returnErrorMsg("开票失败");
  8180. return;
  8181. }
  8182. }
  8183. }
  8184. }
  8185. catch (Exception ex)
  8186. {
  8187. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8188. }
  8189. return;
  8190. }
  8191. }
  8192. public void get_erp_invoicing()
  8193. {
  8194. if (UrlPostParmsCheck("id"))
  8195. {
  8196. try
  8197. {
  8198. string id = GetPostString("id");
  8199. CeErpBill entiy = CeErpBill.Get(id);
  8200. if (entiy != null)
  8201. {
  8202. if (entiy.state == 0)
  8203. {
  8204. returnErrorMsg("发票还未开具");
  8205. return;
  8206. }
  8207. if (entiy.sendType == "纸质发票")
  8208. {
  8209. if (entiy.img.Length <= 0)
  8210. {
  8211. returnErrorMsg("查无纸质发票");
  8212. return;
  8213. }
  8214. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8215. returnSuccess(returnres);
  8216. return;
  8217. }
  8218. string[] billOrderList = entiy.billOrderId.Split(',');
  8219. int iTag = 0;
  8220. string fpUrl = "";
  8221. entiy.fplsh = "";
  8222. entiy.fpdm = "";
  8223. entiy.fphm = "";
  8224. foreach (string billOrderId in billOrderList)
  8225. {
  8226. iTag++;
  8227. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8228. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8229. {
  8230. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8231. Invoicing_get_response_Obj iObj = null;
  8232. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8233. if (iObj != null)
  8234. {
  8235. //entiy.state = 2;
  8236. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8237. entiy.fpdm += iObj.list[0].c_fpdm;
  8238. entiy.fphm += iObj.list[0].c_fphm;
  8239. if (iTag < billOrderList.Length)
  8240. {
  8241. entiy.fplsh += ",";
  8242. entiy.fpdm += ",";
  8243. entiy.fphm += ",";
  8244. }
  8245. entiy.Update();
  8246. fpUrl += iObj.list[0].c_url + ",";
  8247. }
  8248. //returnSuccess(res);
  8249. StringBuilder sql = new StringBuilder();
  8250. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8251. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8252. }
  8253. else
  8254. {
  8255. int eidx = res.IndexOf("c_resultmsg");
  8256. //int lidx = res.IndexOf("c_status");
  8257. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8258. //开票失败
  8259. entiy.state = 5;
  8260. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8261. entiy.Update();
  8262. returnErrorMsg("开票失败");
  8263. return;
  8264. }
  8265. }
  8266. var returnObj = new
  8267. {
  8268. data = fpUrl
  8269. };
  8270. string ro_json = JsonConvert.SerializeObject(returnObj);
  8271. returnSuccess(ro_json);
  8272. }
  8273. }
  8274. catch (Exception ex)
  8275. {
  8276. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8277. }
  8278. return;
  8279. }
  8280. }
  8281. public void save_erp_billimg()
  8282. {
  8283. if (UrlPostParmsCheck("id"))
  8284. {
  8285. string eid = GetPostString("id");
  8286. CeErpBill bill_entity = null;
  8287. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8288. if (bill_entity != null)
  8289. {
  8290. bill_entity.img = GetPostString("img");
  8291. bill_entity.executeTime = DateTime.Now;
  8292. bill_entity.state = 2;
  8293. bill_entity.Update();
  8294. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8295. returnSuccessMsg("保存成功");
  8296. }
  8297. return;
  8298. }
  8299. }
  8300. public void upd_erp_billreturnback()
  8301. {
  8302. if (UrlPostParmsCheck("id"))
  8303. {
  8304. int eid = GetPostInt("id");
  8305. CeErpBill bill_entity = null;
  8306. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8307. if (bill_entity != null)
  8308. {
  8309. bill_entity.state = 3;
  8310. bill_entity.returnReason = GetPostString("reason");
  8311. bill_entity.Update();
  8312. returnSuccessMsg("驳回成功!");
  8313. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8314. }
  8315. return;
  8316. }
  8317. }
  8318. public void cancel_erp_bill()
  8319. {
  8320. if (UrlPostParmsCheck("id"))
  8321. {
  8322. int eid = GetPostInt("id");
  8323. int detailValue = GetPostInt("detailvalue");
  8324. CeErpBill bill_entity = null;
  8325. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8326. string cres = "";
  8327. string gres = "";
  8328. if (bill_entity != null)
  8329. {
  8330. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8331. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8332. {
  8333. int iTag = 0;
  8334. bill_entity.fplsh = "";
  8335. bill_entity.fpdm = "";
  8336. bill_entity.fphm = "";
  8337. foreach (string billOrderId in billOrderList)
  8338. {
  8339. iTag++;
  8340. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8341. if (gres.IndexOf("success") != -1)
  8342. {
  8343. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8344. Invoicing_get_response_Obj iObj = null;
  8345. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8346. if (iObj != null)
  8347. {
  8348. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8349. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8350. bill_entity.fphm += iObj.list[0].c_fphm;
  8351. if (iTag < billOrderList.Length)
  8352. {
  8353. bill_entity.fplsh += ",";
  8354. bill_entity.fpdm += ",";
  8355. bill_entity.fphm += ",";
  8356. }
  8357. bill_entity.Update();
  8358. }
  8359. }
  8360. else
  8361. {
  8362. returnErrorMsg(gres);
  8363. return;
  8364. }
  8365. }
  8366. }
  8367. if (bill_entity.sendType == "纸质发票")
  8368. {
  8369. //作废
  8370. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8371. //if (DateTime.Now.Month == extime.Month)
  8372. //{
  8373. //cres = taobaoHelper.cancel_invoicing(eid);
  8374. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8375. //{
  8376. bill_entity.state = 4;//已作废
  8377. bill_entity.Update();
  8378. returnSuccessMsg("发票已作废");
  8379. return;
  8380. //}
  8381. //else
  8382. //{
  8383. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8384. // bill_entity.Update();
  8385. // returnErrorMsg(cres);
  8386. // return;
  8387. //}
  8388. //}
  8389. //else
  8390. //{
  8391. // returnErrorMsg("纸质发票只能作废本月的发票");
  8392. // return;
  8393. //}
  8394. }
  8395. //红冲
  8396. int redTag = 0;
  8397. string[] fpdmList = bill_entity.fpdm.Split(',');
  8398. string[] fphmList = bill_entity.fphm.Split(',');
  8399. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8400. {
  8401. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8402. return;
  8403. }
  8404. foreach (string billOrderId in billOrderList)
  8405. {
  8406. redTag++;
  8407. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8408. cres += onecres;
  8409. cres += ",";
  8410. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8411. {
  8412. bill_entity.state = 4;//已作废
  8413. //bill_entity.Update();
  8414. //returnSuccessMsg("发票已红冲");
  8415. }
  8416. else if (onecres.IndexOf("重复冲红") != -1)
  8417. {
  8418. bill_entity.state = 4;//已作废
  8419. //bill_entity.Update();
  8420. //returnSuccessMsg("发票已红冲");
  8421. }
  8422. else
  8423. {
  8424. string errmsg = commonHelper.KeepChinese(onecres);
  8425. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8426. }
  8427. }
  8428. bill_entity.Update();
  8429. if (cres.IndexOf("失败") != -1)
  8430. returnErrorMsg("红冲失败");
  8431. else
  8432. returnSuccessMsg("发票已红冲");
  8433. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8434. return;
  8435. }
  8436. return;
  8437. }
  8438. }
  8439. public void del_erp_billorder()
  8440. {
  8441. if (UrlPostParmsCheck("id"))
  8442. {
  8443. string eid = GetPostString("id");
  8444. CeErpBill.Del(eid);
  8445. CeErpBill bill = CeErpBill.Get(eid);
  8446. if (bill != null)
  8447. {
  8448. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8449. }
  8450. returnSuccessMsg("删除成功");
  8451. }
  8452. }
  8453. public void finish_erp_bill()
  8454. {
  8455. if (UrlPostParmsCheck("ids"))
  8456. {
  8457. string eids = GetPostString("ids");
  8458. string[] list = eids.Split(',');
  8459. foreach (string eid in list)
  8460. {
  8461. CeErpBill bill = CeErpBill.Get(eid);
  8462. if (bill != null)
  8463. {
  8464. bill.state = 2;
  8465. bill.Update();
  8466. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8467. }
  8468. }
  8469. returnSuccessMsg("操作成功");
  8470. }
  8471. }
  8472. public void get_erp_returncash()
  8473. {
  8474. DataStruct dStruct = GetPostStruct();
  8475. List<string> lw = new List<string>();
  8476. string tid = GetPostString("tid");
  8477. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8478. string shopname = GetPostString("shopname");
  8479. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8480. string buyernick = GetPostString("buyer_nick");
  8481. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8482. string customer = GetPostString("customer");
  8483. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8484. string returndate1 = GetPostString("returndate1");
  8485. string returndate2 = GetPostString("returndate2");
  8486. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8487. if (dw.Length > 0) lw.Add(dw);
  8488. string finishDate1 = GetPostString("finishdate1");
  8489. string finishDate2 = GetPostString("finishdate2");
  8490. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8491. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8492. string returntype = GetPostString("returntype");
  8493. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8494. string returnvstate = GetPostString("returnvstate");
  8495. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8496. dStruct.Order = "created desc";
  8497. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8498. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8499. writeGridDataTableJson(dStruct.TotalCount, dt);
  8500. }
  8501. public void get_erp_staygoods()
  8502. {
  8503. DataStruct dStruct = GetPostStruct();
  8504. List<string> lw = new List<string>();
  8505. string tid = GetPostString("tid");
  8506. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8507. string shopname = GetPostString("shopname");
  8508. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8509. string wangwang = GetPostString("wangwang");
  8510. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8511. string customer = GetPostString("customer");
  8512. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8513. string returndate1 = GetPostString("returndate1");
  8514. string returndate2 = GetPostString("returndate2");
  8515. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8516. if (dw.Length > 0) lw.Add(dw);
  8517. string finishDate1 = GetPostString("finishdate1");
  8518. string finishDate2 = GetPostString("finishdate2");
  8519. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8520. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8521. string returnvstate = GetPostString("returnvstate");
  8522. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8523. string persuadetype = GetPostString("persuadetype");
  8524. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8525. string customerOrg = GetPostString("customerOrg");
  8526. if (customerOrg.Length > 0)
  8527. {
  8528. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8529. }
  8530. dStruct.Order = "creata_time desc";
  8531. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8532. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8533. writeGridDataTableJson(dStruct.TotalCount, dt);
  8534. }
  8535. public void upd_erp_staygoods()
  8536. {
  8537. if (UrlPostParmsCheck("id"))
  8538. {
  8539. int eid = GetPostInt("id");
  8540. CeErpStayGoods entity = null;
  8541. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8542. if (entity != null)
  8543. {
  8544. entity.audit_type = 1;
  8545. entity.audit_time = DateTime.Now;
  8546. entity.audit_u_id = CurrentUser.UserID;
  8547. entity.audit_u_name = CurrentUser.UserName;
  8548. entity.Update();
  8549. returnSuccessMsg("审核成功!");
  8550. return;
  8551. }
  8552. returnErrorMsg("找不到订单记录");
  8553. }
  8554. }
  8555. public void upd_erp_stayGoodsback()
  8556. {
  8557. if (UrlPostParmsCheck("id"))
  8558. {
  8559. int eid = GetPostInt("id");
  8560. CeErpStayGoods entity = null;
  8561. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8562. if (entity != null)
  8563. {
  8564. entity.audit_text = GetPostString("reason");
  8565. entity.audit_type = 2;
  8566. entity.audit_time = DateTime.Now;
  8567. entity.audit_u_id = CurrentUser.UserID;
  8568. entity.audit_u_name = CurrentUser.UserName;
  8569. entity.Update();
  8570. returnSuccessMsg("退回成功!");
  8571. return;
  8572. }
  8573. returnErrorMsg("找不到订单记录");
  8574. }
  8575. }
  8576. public void upd_erp_returncashverify()
  8577. {
  8578. if (UrlPostParmsCheck("ID"))
  8579. {
  8580. int eid = GetPostInt("ID");
  8581. CeErpReturnCash entity = null;
  8582. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8583. if (entity != null)
  8584. {
  8585. entity.cashstate = 1;
  8586. entity.verifytime = DateTime.Now;
  8587. entity.verifyuserid = CurrentUser.UserID;
  8588. entity.Update();
  8589. returnSuccessMsg("审核成功!");
  8590. return;
  8591. }
  8592. returnErrorMsg("找不到订单记录");
  8593. }
  8594. }
  8595. public void upd_all_erp_returncashverify()
  8596. {
  8597. if (UrlPostParmsCheck("ID"))
  8598. {
  8599. String[] list = GetPostString("ID").Split(',');
  8600. CeErpReturnCash entity = null;
  8601. for (int i = 0; i < list.Length; i++)
  8602. {
  8603. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8604. if (entity != null)
  8605. {
  8606. if (entity.cashstate == 1)
  8607. {
  8608. returnErrorMsg("已审核过的订单不需要在审核!");
  8609. return;
  8610. }
  8611. entity.cashstate = 1;
  8612. entity.verifytime = DateTime.Now;
  8613. entity.verifyuserid = CurrentUser.UserID;
  8614. entity.Update();
  8615. }
  8616. }
  8617. returnSuccessMsg("审核成功!");
  8618. return;
  8619. }
  8620. }
  8621. public void upd_erp_returncashback()
  8622. {
  8623. if (UrlPostParmsCheck("ID"))
  8624. {
  8625. int eid = GetPostInt("ID");
  8626. CeErpReturnCash entity = null;
  8627. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8628. if (entity != null)
  8629. {
  8630. entity.backreason = GetPostString("reason");
  8631. entity.cashstate = 2;
  8632. entity.verifytime = DateTime.Now;
  8633. entity.verifyuserid = CurrentUser.UserID;
  8634. entity.Update();
  8635. returnSuccessMsg("退回成功!");
  8636. return;
  8637. }
  8638. returnErrorMsg("找不到订单记录");
  8639. }
  8640. }
  8641. public void upd_erp_returnprice()
  8642. {
  8643. if (UrlPostParmsCheck("ID"))
  8644. {
  8645. int eid = GetPostInt("ID");
  8646. CeErpReturnCash entity = null;
  8647. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8648. if (entity != null)
  8649. {
  8650. if (entity.cashstate == 1)
  8651. {
  8652. returnErrorMsg("审核通过了不能改");
  8653. return;
  8654. }
  8655. entity.returnprice = GetPostDouble("returnprice");
  8656. entity.Update();
  8657. returnSuccessMsg("修改成功!");
  8658. return;
  8659. }
  8660. returnErrorMsg("找不到订单记录");
  8661. }
  8662. }
  8663. public void del_erp_returncash()
  8664. {
  8665. if (UrlPostParmsCheck("ID"))
  8666. {
  8667. int eid = GetPostInt("ID");
  8668. CeErpReturnCash.Del(eid);
  8669. returnSuccessMsg("操作成功");
  8670. return;
  8671. }
  8672. }
  8673. public void test_for_do_sql()
  8674. {
  8675. string sql = GetPostString("sqlstr");
  8676. if (sql.Length > 0)
  8677. {
  8678. try
  8679. {
  8680. DbHelper.DbConn.ExecuteNonQuery(sql);
  8681. var res_obj = new
  8682. {
  8683. data = "成功",
  8684. };
  8685. string ro_json = JsonConvert.SerializeObject(res_obj);
  8686. returnSuccess(ro_json);
  8687. }
  8688. catch (Exception ex)
  8689. {
  8690. var res_obj = new
  8691. {
  8692. data = ex.Message,
  8693. };
  8694. string ro_json = JsonConvert.SerializeObject(res_obj);
  8695. returnSuccess(ro_json);
  8696. }
  8697. }
  8698. }
  8699. public void get_user_info()
  8700. {
  8701. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8702. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8703. }
  8704. public void get_total_data()
  8705. {
  8706. int userId = CurrentUser.UserID;
  8707. string sql = "";
  8708. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8709. {
  8710. 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);
  8711. }
  8712. else
  8713. {
  8714. 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 " +
  8715. "(select ID from CE_ErpUser where ID = {0}) d " +
  8716. "left join " +
  8717. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8718. ") a on d.ID = a.id left join " +
  8719. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8720. ") b on a.id = b.id1 left join" +
  8721. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8722. ") c on a.id = c.id2;", userId);
  8723. }
  8724. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8725. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8726. }
  8727. public void get_date_area_total_data2()
  8728. {
  8729. int userId = CurrentUser.UserID;
  8730. string date_type = GetPostString("timetype");
  8731. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8732. string sql = "";
  8733. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8734. {
  8735. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  8736. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  8737. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8738. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8739. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8740. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  8741. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8742. ") a on e.ID = a.id left join " +
  8743. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  8744. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8745. ") b on a.id = b.id1 " +
  8746. "left join " +
  8747. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8748. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8749. ") c on a.id = c.id2 " +
  8750. "left join " +
  8751. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8752. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8753. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8754. }
  8755. else
  8756. {
  8757. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  8758. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8759. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8760. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8761. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  8762. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  8763. ") a on e.ID = a.id left join " +
  8764. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8765. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  8766. ") c on a.id = c.id2 " +
  8767. "left join " +
  8768. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8769. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8770. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8771. }
  8772. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8773. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8774. }
  8775. public void get_date_area_total_data()
  8776. {
  8777. int userId = CurrentUser.UserID;
  8778. string date_type = GetPostString("timetype");
  8779. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8780. string date1 = searchDT[0].ToString();
  8781. string date2 = searchDT[1].ToString();
  8782. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8783. {
  8784. SqlParameter[] sqlParameter ={
  8785. new SqlParameter("@userId", SqlDbType.Int,4),
  8786. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8787. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8788. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8789. };
  8790. sqlParameter[0].Value = userId;
  8791. sqlParameter[1].Value = date1;
  8792. sqlParameter[2].Value = date2;
  8793. sqlParameter[3].Direction = ParameterDirection.Output;
  8794. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  8795. string res = sqlParameter[3].Value.ToString();
  8796. var res_obj = new
  8797. {
  8798. data = res
  8799. };
  8800. string ro_json = JsonConvert.SerializeObject(res_obj);
  8801. returnSuccess(ro_json);
  8802. }
  8803. else
  8804. {
  8805. SqlParameter[] sqlParameter ={
  8806. new SqlParameter("@userId", SqlDbType.Int,4),
  8807. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8808. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8809. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8810. };
  8811. sqlParameter[0].Value = userId;
  8812. sqlParameter[1].Value = date1;
  8813. sqlParameter[2].Value = date2;
  8814. sqlParameter[3].Direction = ParameterDirection.Output;
  8815. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  8816. string res = sqlParameter[3].Value.ToString();
  8817. var res_obj = new
  8818. {
  8819. data = res
  8820. };
  8821. string ro_json = JsonConvert.SerializeObject(res_obj);
  8822. returnSuccess(ro_json);
  8823. }
  8824. //writeGridDataViewJson(dt.Rows.Count, dv);
  8825. }
  8826. public void get_order_list()
  8827. {
  8828. string strFields = GetPostString("paraFields");
  8829. string strOrder = GetPostString("paraOrder");
  8830. string strWhere = GetPostString("paraWhere");
  8831. string strPageSize = GetPostString("paraPageSize");
  8832. DataStruct dStruct = GetPostStruct();
  8833. dStruct.PageSize = int.Parse(strPageSize);
  8834. dStruct.Fileds = strFields;
  8835. dStruct.Order = strOrder;
  8836. dStruct.MainWhere = strWhere;
  8837. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  8838. writeGridDataTableJson(dStruct.TotalCount, dt);
  8839. }
  8840. ////获取待开始订单列表
  8841. //public void get_wait_design_order_list()
  8842. //{
  8843. // string date_type = GetPostString("date_type");
  8844. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8845. // DataStruct dStruct = GetPostStruct();
  8846. // dStruct.PageSize = 1000;
  8847. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  8848. // List<string> lw = new List<string>();
  8849. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  8850. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  8851. // dStruct.Order = "WaitDesignTime asc";
  8852. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8853. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  8854. // writeGridDataTableJson(dStruct.TotalCount, dt);
  8855. //}
  8856. //获取完成单量排名
  8857. public void get_finish_order_count_ranking()
  8858. {
  8859. /* string date_type = GetPostString("date_type");
  8860. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8861. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  8862. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8863. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  8864. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  8865. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8866. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  8867. writeGridDataTableJson(0, new DataTable());
  8868. }
  8869. public void get_finish_order_amount_ranking()
  8870. {
  8871. /*string date_type = GetPostString("date_type");
  8872. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8873. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  8874. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8875. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  8876. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  8877. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8878. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  8879. writeGridDataTableJson(0, new DataTable());
  8880. }
  8881. public void get_finish_refund_count_ranking()
  8882. {
  8883. string date_type = GetPostString("date_type");
  8884. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8885. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  8886. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8887. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  8888. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  8889. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8890. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8891. writeGridDataTableJson(dt.Rows.Count, dt);
  8892. }
  8893. public void get_finish_refund_amount_ranking()
  8894. {
  8895. string date_type = GetPostString("date_type");
  8896. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8897. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  8898. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8899. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  8900. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  8901. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8902. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8903. writeGridDataTableJson(dt.Rows.Count, dt);
  8904. }
  8905. public void set_erp_finishorder_director()
  8906. {
  8907. if (UrlPostParmsCheck("ctid"))
  8908. {
  8909. string eid = GetPostString("ctid");
  8910. CeErpTradeCell entity = null;
  8911. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  8912. if (entity != null)
  8913. {
  8914. entity.OrderState = 8;
  8915. entity.Update();
  8916. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  8917. returnSuccessMsg("操作成功!");
  8918. return;
  8919. }
  8920. returnErrorMsg("找不到记录");
  8921. }
  8922. }
  8923. public void get_erp_placeregistlist()
  8924. {
  8925. DataStruct dStruct = GetPostStruct();
  8926. List<string> lw = new List<string>();
  8927. string outsid = GetPostString("outsid");
  8928. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  8929. string memo = GetPostString("memo");
  8930. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  8931. string filename = GetPostString("filename");
  8932. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  8933. string islate = GetPostString("islate");
  8934. if (islate.Length > 0)
  8935. {
  8936. if (islate == "1")
  8937. lw.Add(string.Format("OutLate>0"));
  8938. else
  8939. lw.Add(string.Format("OutLate=0"));
  8940. }
  8941. string placedate1 = GetPostString("placedate1");
  8942. string placedate2 = GetPostString("placedate2");
  8943. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  8944. if (dw.Length > 0) lw.Add(dw);
  8945. string deliveryDate1 = GetPostString("deliverydate1");
  8946. string deliveryDate2 = GetPostString("deliverydate2");
  8947. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  8948. if (dw_deli.Length > 0) lw.Add(dw_deli);
  8949. dStruct.Order = "ID desc";
  8950. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8951. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  8952. writeGridDataTableJson(dStruct.TotalCount, dt);
  8953. }
  8954. public void ins_erp_placeregist()
  8955. {
  8956. if (UrlPostParmsCheck("id"))
  8957. {
  8958. string eid = GetPostString("id");
  8959. CeErpPlaceRegister entity = null;
  8960. if (eid == "0")//新增
  8961. {
  8962. entity = new CeErpPlaceRegister();
  8963. string xdTime = GetPostString("placeTime");
  8964. if (xdTime.Length > 0)
  8965. {
  8966. entity.PlactTime = Convert.ToDateTime(xdTime);
  8967. }
  8968. string fhTime = GetPostString("deliveryTime");
  8969. if (fhTime.Length > 0)
  8970. {
  8971. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  8972. }
  8973. string preTime = GetPostString("preOutTime");
  8974. if (preTime.Length > 0)
  8975. {
  8976. entity.PreOutTime = Convert.ToDateTime(preTime);
  8977. }
  8978. entity.DeliveryCount = GetPostInt("deliveryCount");
  8979. entity.ReceiveCount = GetPostInt("receiveCount");
  8980. entity.OutSid = GetPostString("outSid");
  8981. entity.FileName = GetPostString("fileName");
  8982. entity.Memo = GetPostString("memo");
  8983. entity.AddUserId = CurrentUser.UserID;
  8984. entity.CreateTime = DateTime.Now;
  8985. entity.Img = GetPostString("img");
  8986. entity.Supplier = GetPostInt("supplier");
  8987. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  8988. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  8989. {
  8990. DateTime dt1 = (DateTime)entity.DeliveryTime;
  8991. DateTime dt2 = (DateTime)entity.PreOutTime;
  8992. TimeSpan span = dt1.Subtract(dt2);
  8993. if (span.Days > 0)
  8994. {
  8995. entity.OutLate = span.Days;
  8996. }
  8997. }
  8998. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  8999. entity.Create();
  9000. returnSuccessMsg("添加成功!");
  9001. return;
  9002. }
  9003. else //修改
  9004. {
  9005. entity = CeErpPlaceRegister.Get(eid);
  9006. if (entity != null)
  9007. {
  9008. string xdTime = GetPostString("placeTime");
  9009. if (xdTime.Length > 0)
  9010. {
  9011. entity.PlactTime = Convert.ToDateTime(xdTime);
  9012. }
  9013. string fhTime = GetPostString("deliveryTime");
  9014. if (fhTime.Length > 0)
  9015. {
  9016. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9017. }
  9018. string preTime = GetPostString("preOutTime");
  9019. if (preTime.Length > 0)
  9020. {
  9021. entity.PreOutTime = Convert.ToDateTime(preTime);
  9022. }
  9023. entity.DeliveryCount = GetPostInt("deliveryCount");
  9024. entity.ReceiveCount = GetPostInt("receiveCount");
  9025. if (entity.DeliveryCount == entity.ReceiveCount)
  9026. {
  9027. entity.CurState = "已完成";
  9028. }
  9029. else
  9030. {
  9031. entity.CurState = "未完成";
  9032. }
  9033. entity.OutSid = GetPostString("outSid");
  9034. entity.FileName = GetPostString("fileName");
  9035. entity.Memo = GetPostString("memo");
  9036. entity.Img = GetPostString("img");
  9037. entity.Supplier = GetPostInt("supplier");
  9038. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9039. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9040. {
  9041. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9042. DateTime dt2 = (DateTime)entity.PreOutTime;
  9043. TimeSpan span = dt1.Subtract(dt2);
  9044. if (span.Days > 0)
  9045. {
  9046. entity.OutLate = span.Days;
  9047. }
  9048. }
  9049. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9050. entity.Update();
  9051. returnSuccessMsg("修改成功");
  9052. return;
  9053. }
  9054. returnErrorMsg("找不到对应的记录");
  9055. return;
  9056. }
  9057. }
  9058. returnErrorMsg("缺少必要参数");
  9059. }
  9060. public void del_erp_placeregist()
  9061. {
  9062. string eid = GetPostString("id");
  9063. CeErpPlaceRegister.Del(eid);
  9064. returnSuccessMsg("删除成功!");
  9065. return;
  9066. }
  9067. public void ins_erp_placeregistbyorder()
  9068. {
  9069. string ctid = GetPostString("ctid");
  9070. if (ctid.Length > 0)
  9071. {
  9072. StringBuilder sql = new StringBuilder();
  9073. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9074. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9075. if (dt.Rows.Count > 0)
  9076. {
  9077. foreach (DataRow dr in dt.Rows)
  9078. {
  9079. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9080. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9081. entity.AddUserId = CurrentUser.UserID;
  9082. entity.tid = dr["tid"].ToString();
  9083. entity.Did = Convert.ToString(dr["ctid"]);
  9084. entity.splitTag = dr["SplitTag"].ToString();
  9085. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9086. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9087. if (pre_ctid.Length > 0)
  9088. {
  9089. sellmemo = sellmemo.Replace(pre_ctid, "");
  9090. }
  9091. sellmemo = sellmemo.Replace("[", "");
  9092. sellmemo = sellmemo.Replace("]", "");
  9093. entity.FileName = sellmemo;
  9094. string count = dr["ProductCount"].ToString();
  9095. int usecount = commonHelper.getIntCountFromString(count);
  9096. entity.DeliveryCount = usecount;
  9097. entity.CurState = "未完成";
  9098. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9099. {
  9100. entity.Supplier = 24;//dl手提袋定制
  9101. }
  9102. else
  9103. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9104. entity.CreateTime = DateTime.Now;
  9105. entity.Create();
  9106. }
  9107. returnSuccessMsg("操作成功");
  9108. return;
  9109. }
  9110. returnErrorMsg("没有找到对应订单");
  9111. return;
  9112. }
  9113. returnErrorMsg("缺少订单编号");
  9114. return;
  9115. }
  9116. public void get_erp_persuadelist()
  9117. {
  9118. DataStruct dStruct = GetPostStruct();
  9119. List<string> lw = new List<string>();
  9120. string ctid = GetPostString("ctid");
  9121. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9122. string shopname = GetPostString("shopname");
  9123. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9124. string buyernick = GetPostString("buyer_nick");
  9125. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9126. string customer = GetPostString("customer");
  9127. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9128. string returndate1 = GetPostString("returndate1");
  9129. string returndate2 = GetPostString("returndate2");
  9130. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9131. if (dw.Length > 0) lw.Add(dw);
  9132. string finishDate1 = GetPostString("finishdate1");
  9133. string finishDate2 = GetPostString("finishdate2");
  9134. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9135. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9136. string persuadetype = GetPostString("persuadetype");
  9137. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9138. string returnvstate = GetPostString("returnvstate");
  9139. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9140. dStruct.Order = "created desc";
  9141. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9142. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9143. writeGridDataTableJson(dStruct.TotalCount, dt);
  9144. }
  9145. public void upd_erp_returnpersuadeback()
  9146. {
  9147. if (UrlPostParmsCheck("ID"))
  9148. {
  9149. int eid = GetPostInt("ID");
  9150. CeErpPersuade entity = null;
  9151. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9152. if (entity != null)
  9153. {
  9154. entity.backreason = GetPostString("reason");
  9155. entity.pstate = 2;
  9156. entity.verifytime = DateTime.Now;
  9157. entity.verifyuserid = CurrentUser.UserID;
  9158. entity.Update();
  9159. returnSuccessMsg("退回成功!");
  9160. return;
  9161. }
  9162. returnErrorMsg("找不到订单记录");
  9163. }
  9164. }
  9165. public void upd_erp_returnpersuadeverify()
  9166. {
  9167. if (UrlPostParmsCheck("ID"))
  9168. {
  9169. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9170. {
  9171. returnErrorMsg("暂无权限审核");
  9172. return;
  9173. }
  9174. int eid = GetPostInt("ID");
  9175. CeErpPersuade entity = null;
  9176. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9177. if (entity != null)
  9178. {
  9179. entity.pstate = 1;
  9180. entity.verifytime = DateTime.Now;
  9181. entity.verifyuserid = CurrentUser.UserID;
  9182. entity.Update();
  9183. returnSuccessMsg("审核成功!");
  9184. return;
  9185. }
  9186. returnErrorMsg("找不到订单记录");
  9187. }
  9188. }
  9189. public void del_erp_persuade()
  9190. {
  9191. if (UrlPostParmsCheck("ID"))
  9192. {
  9193. int eid = GetPostInt("ID");
  9194. CeErpPersuade.Del(eid);
  9195. returnSuccessMsg("操作成功");
  9196. return;
  9197. }
  9198. }
  9199. public void get_erp_oldcustoupload()
  9200. {
  9201. DataStruct dStruct = GetPostStruct();
  9202. List<string> lw = new List<string>();
  9203. string buyernick = GetPostString("buyer_nick");
  9204. if (buyernick.Length > 0)
  9205. {
  9206. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9207. }
  9208. else
  9209. return;
  9210. dStruct.Order = "pay_time desc";
  9211. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9212. DataTable dt = null;
  9213. dt = WebCache.GetData("view_erptradecell", dStruct);
  9214. writeGridDataTableJson(dStruct.TotalCount, dt);
  9215. }
  9216. public void get_erp_checkorderlist()
  9217. {
  9218. DataStruct dStruct = GetPostStruct();
  9219. List<string> lw = new List<string>();
  9220. string tid = GetPostString("ctid");
  9221. if (tid.Length > 0)
  9222. {
  9223. string select_tid = getTidByCtid(tid);
  9224. lw.Add(string.Format("tid='{0}'", select_tid));
  9225. }
  9226. string shopname = GetPostString("shopname");
  9227. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9228. string buyernick = GetPostString("buyer_nick");
  9229. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9230. string customer = GetPostString("customer");
  9231. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9232. string design = GetPostString("design");
  9233. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9234. string orderState = GetPostString("orderState");
  9235. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9236. string address = GetPostString("address");
  9237. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9238. string sellermemo = GetPostString("seller_memo");
  9239. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9240. string supplier = GetPostString("supplier");
  9241. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9242. {
  9243. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9244. }
  9245. else
  9246. {
  9247. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9248. }
  9249. string date1 = GetPostString("date1");
  9250. string date2 = GetPostString("date2");
  9251. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9252. if (dw.Length > 0) lw.Add(dw);
  9253. string placedate1 = GetPostString("placedate1");
  9254. string placedate2 = GetPostString("placedate2");
  9255. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9256. if (fdw.Length > 0) lw.Add(fdw);
  9257. string price1 = GetPostString("price1");
  9258. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9259. string price2 = GetPostString("price2");
  9260. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9261. string checkst = GetPostString("checkstate");
  9262. if (checkst.Length > 0 && "10".Equals(checkst))
  9263. {
  9264. lw.Add(string.Format("CheckOut>0"));
  9265. }
  9266. else
  9267. {
  9268. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9269. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9270. }
  9271. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9272. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9273. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9274. writeGridDataTableJson(dStruct.TotalCount, dt);
  9275. }
  9276. public void ins_erp_startCheck()
  9277. {
  9278. if (UrlPostParmsCheck("ctid"))
  9279. {
  9280. string eid = GetPostString("ctid");
  9281. CeErpTradeCell entity = null;
  9282. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9283. if (entity != null)
  9284. {
  9285. entity.MemoOpt = 4;
  9286. entity.UpdateTime = DateTime.Now;
  9287. entity.Update();
  9288. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9289. CeErpSukuraData.createInfo(entity.ctid, 6);
  9290. returnSuccessMsg("操作成功!");
  9291. return;
  9292. }
  9293. returnErrorMsg("找不到记录");
  9294. }
  9295. }
  9296. public void upd_erp_sendXlw()
  9297. {
  9298. if (UrlPostParmsCheck("ctid"))
  9299. {
  9300. string eid = GetPostString("ctid");
  9301. CeErpTradeCell entity = null;
  9302. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9303. if (entity != null)
  9304. {
  9305. if (entity.IsSendGift == 1)
  9306. {
  9307. returnErrorMsg("请勿重复标记");
  9308. return;
  9309. }
  9310. entity.IsSendGift = 1;
  9311. entity.Update();
  9312. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9313. returnSuccessMsg("操作成功!");
  9314. return;
  9315. }
  9316. returnErrorMsg("找不到记录");
  9317. }
  9318. }
  9319. public void cancel_sendXlw()
  9320. {
  9321. if (UrlPostParmsCheck("ctid"))
  9322. {
  9323. string eid = GetPostString("ctid");
  9324. CeErpTradeCell entity = null;
  9325. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9326. if (entity != null)
  9327. {
  9328. if (entity.IsSendGift == 0)
  9329. {
  9330. returnErrorMsg("未标记小礼物");
  9331. return;
  9332. }
  9333. entity.IsSendGift = 0;
  9334. entity.Update();
  9335. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9336. returnSuccessMsg("操作成功!");
  9337. return;
  9338. }
  9339. returnErrorMsg("找不到记录");
  9340. }
  9341. }
  9342. public void get_erp_designbill()
  9343. {
  9344. DataStruct dStruct = GetPostStruct();
  9345. List<string> lw = new List<string>();
  9346. int isMy = GetInt("my");
  9347. if (isMy == 1)
  9348. {
  9349. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9350. }
  9351. string tid = GetPostString("tid");
  9352. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9353. string userName = GetPostString("design");
  9354. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9355. string price1 = GetPostString("price1");
  9356. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9357. string price2 = GetPostString("price2");
  9358. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9359. string rePrice1 = GetPostString("rePrice1");
  9360. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9361. string rePrice2 = GetPostString("rePrice2");
  9362. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9363. string designerType = GetPostString("designerType");
  9364. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9365. string orderState = GetPostString("orderState");
  9366. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9367. string endTime1 = GetPostString("endTime1");
  9368. string endTime2 = GetPostString("endTime2");
  9369. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9370. if (dw.Length > 0) lw.Add(dw);
  9371. string isDk = GetPostString("isDk");
  9372. if (isDk == "1")
  9373. {
  9374. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9375. }
  9376. else if (isDk == "0")
  9377. {
  9378. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9379. }
  9380. dStruct.Order = "oid, create_time desc";
  9381. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9382. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9383. writeGridDataTableJson(dStruct.TotalCount, dt);
  9384. }
  9385. public void upd_erp_designerbill()
  9386. {
  9387. if (UrlPostParmsCheck("ID"))
  9388. {
  9389. string eid = GetPostString("ID");
  9390. CeErpDesignerBill entity = null;
  9391. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9392. if (entity != null)
  9393. {
  9394. if (GetPostDouble("designerpirce") > 0)
  9395. {
  9396. entity.realPrice = GetPostDouble("designerpirce");
  9397. entity.update_time = DateTime.Now;
  9398. entity.update_u_id = CurrentUser.UserID;
  9399. entity.update_u_name = CurrentUser.UserName;
  9400. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9401. entity.Update();
  9402. returnSuccessMsg("操作成功!");
  9403. return;
  9404. }
  9405. else
  9406. {
  9407. entity.price = GetPostDouble("price");
  9408. entity.update_time = DateTime.Now;
  9409. entity.update_u_id = CurrentUser.UserID;
  9410. entity.update_u_name = CurrentUser.UserName;
  9411. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9412. entity.Update();
  9413. returnSuccessMsg("操作成功!");
  9414. return;
  9415. }
  9416. }
  9417. returnErrorMsg("找不到记录");
  9418. }
  9419. }
  9420. public void audit_erp_designerbill()
  9421. {
  9422. if (UrlPostParmsCheck("ID"))
  9423. {
  9424. string eid = GetPostString("ID");
  9425. CeErpDesignerBill entity = null;
  9426. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9427. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9428. if (entity != null)
  9429. {
  9430. entity.realPrice = GetPostDouble("designerpirce");
  9431. entity.update_time = DateTime.Now;
  9432. entity.update_u_id = CurrentUser.UserID;
  9433. entity.update_u_name = CurrentUser.UserName;
  9434. entity.isAudit = 1;
  9435. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9436. entity.Update();
  9437. if (orderEntity != null)
  9438. {
  9439. orderEntity.IsReadTag = 3;
  9440. orderEntity.Update();
  9441. }
  9442. returnSuccessMsg("操作成功!");
  9443. return;
  9444. }
  9445. returnErrorMsg("找不到记录");
  9446. }
  9447. }
  9448. public void all_audit_erp_designerbill()
  9449. {
  9450. if (UrlPostParmsCheck("idList"))
  9451. {
  9452. string[] list = GetPostString("idList").Split(',');
  9453. CeErpDesignerBill entity = null;
  9454. for (int i = 0; i < list.Length; i++)
  9455. {
  9456. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9457. if (entity == null) return;
  9458. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9459. if (orderEntity == null) return;
  9460. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9461. entity.update_time = DateTime.Now;
  9462. entity.update_u_id = CurrentUser.UserID;
  9463. entity.update_u_name = CurrentUser.UserName;
  9464. entity.isAudit = 1;
  9465. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9466. entity.Update();
  9467. orderEntity.IsReadTag = 3;
  9468. orderEntity.Update();
  9469. }
  9470. returnSuccessMsg("操作成功!");
  9471. return;
  9472. }
  9473. }
  9474. public void get_erp_sameorders()
  9475. {
  9476. if (UrlPostParmsCheck("ctid"))
  9477. {
  9478. string eid = GetPostString("ctid");
  9479. CeErpTradeCell entity = null;
  9480. entity = CeErpTradeCell.GetByCtid(eid);
  9481. if (entity != null)
  9482. {
  9483. StringBuilder sql = new StringBuilder();
  9484. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9485. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9486. var res = new
  9487. {
  9488. data = dt.Rows.Count
  9489. };
  9490. string ro_jsond = JsonConvert.SerializeObject(res);
  9491. returnSuccess(ro_jsond);
  9492. return;
  9493. }
  9494. returnErrorMsg("未找到订单");
  9495. return;
  9496. }
  9497. returnErrorMsg("缺少必要的参数");
  9498. }
  9499. public void get_erp_islasthavesameorder()
  9500. {
  9501. if (UrlPostParmsCheck("ctid"))
  9502. {
  9503. string eid = GetPostString("ctid");
  9504. string[] ctidList = eid.Split(',');
  9505. StringBuilder sql = new StringBuilder();
  9506. string tisCtid = "";
  9507. foreach (string ctid in ctidList)
  9508. {
  9509. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9510. if (entity != null)
  9511. {
  9512. sql = new StringBuilder();
  9513. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9514. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9515. if (dth.Rows.Count > 0)
  9516. {
  9517. tisCtid += entity.ctid;
  9518. tisCtid += ",";
  9519. }
  9520. }
  9521. }
  9522. if (tisCtid.Length > 0)
  9523. {
  9524. var res = new
  9525. {
  9526. data = tisCtid
  9527. };
  9528. string ro_jsond = JsonConvert.SerializeObject(res);
  9529. returnSuccess(ro_jsond);
  9530. }
  9531. else
  9532. {
  9533. var res = new
  9534. {
  9535. data = ""
  9536. };
  9537. string ro_jsond = JsonConvert.SerializeObject(res);
  9538. returnSuccess(ro_jsond);
  9539. }
  9540. return;
  9541. }
  9542. returnErrorMsg("缺少必要的参数");
  9543. }
  9544. public void file_client_down_url()
  9545. {
  9546. if (!UrlPostParmsCheck("userId"))
  9547. {
  9548. returnErrorMsg("缺少必要的参数");
  9549. }
  9550. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9551. }
  9552. public void checkout_form_data()
  9553. {
  9554. if (!UrlPostParmsCheck("tid"))
  9555. {
  9556. returnErrorMsg("缺少必要的参数");
  9557. }
  9558. string tid = GetPostString("tid");
  9559. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9560. if (ceErpOrderFormData != null)
  9561. {
  9562. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9563. returnSuccess(ro_jsond);
  9564. return;
  9565. }
  9566. returnErrorMsg("尚未有文件!");
  9567. }
  9568. public void back_supplier_audit()
  9569. {
  9570. int userId = CurrentUser.UserID;
  9571. StringBuilder sql = new StringBuilder();
  9572. 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);
  9573. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9574. if (dt.Rows.Count > 0)
  9575. {
  9576. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9577. }
  9578. else
  9579. {
  9580. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9581. }
  9582. }
  9583. public void back_supplier_query()
  9584. {
  9585. string eid = GetPostString("ctid");
  9586. if (eid != "")
  9587. {
  9588. StringBuilder sql = new StringBuilder();
  9589. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9590. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9591. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9592. }
  9593. else
  9594. {
  9595. returnErrorMsg("找不到订单记录");
  9596. return;
  9597. }
  9598. }
  9599. public void verified_to_order()
  9600. {
  9601. int userId = CurrentUser.UserID;
  9602. StringBuilder sql = new StringBuilder();
  9603. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9604. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9605. if (dt.Rows.Count > 0)
  9606. {
  9607. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9608. }
  9609. else
  9610. {
  9611. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9612. }
  9613. }
  9614. public void upd_supplier_audit()
  9615. {
  9616. if (UrlPostParmsCheck("ctid"))
  9617. {
  9618. string eid = GetPostString("ctid");
  9619. string reason = GetPostString("returnreason");
  9620. CeErpTradeCell entity = null;
  9621. CeWithdraw withdraw = null;
  9622. withdraw = CeWithdraw.GetByTid(eid);
  9623. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9624. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9625. {
  9626. if (withdraw != null)
  9627. {
  9628. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9629. {
  9630. returnSuccessMsg("您没有权限操作!");
  9631. return;
  9632. }
  9633. else
  9634. {
  9635. if (reason.Equals("1"))
  9636. {
  9637. if (entity.OrderState == -1)
  9638. {
  9639. if (entity.FinishPlaceTime == null)
  9640. {
  9641. entity.OrderState = 2;
  9642. }
  9643. else
  9644. {
  9645. entity.OrderState = 6;
  9646. }
  9647. }
  9648. entity.Update();
  9649. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9650. if (withdraw != null)
  9651. {
  9652. withdraw.status = int.Parse(reason);
  9653. withdraw.Update();
  9654. }
  9655. returnSuccessMsg("操作成功!");
  9656. return;
  9657. }
  9658. else
  9659. {
  9660. withdraw.status = int.Parse(reason);
  9661. withdraw.acknowledgingtime = DateTime.Now;
  9662. withdraw.Update();
  9663. returnSuccessMsg("查看详细请点击线下订单查询");
  9664. return;
  9665. }
  9666. }
  9667. }
  9668. // 第一个字符是 'N'
  9669. }
  9670. if (eid[0] != 'N')
  9671. {
  9672. }
  9673. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9674. {
  9675. entity.IsVerifyToSupplier = false;
  9676. entity.IsReturn = 1;
  9677. entity.ReturnTime = DateTime.Now;
  9678. entity.ReturnReason = reason;
  9679. if (entity.OrderState == 6)
  9680. {
  9681. entity.OrderState = 5;
  9682. }
  9683. entity.Update();
  9684. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9685. if (withdraw != null)
  9686. {
  9687. withdraw.status = int.Parse(reason);
  9688. withdraw.Update();
  9689. }
  9690. returnSuccessMsg("操作成功!");
  9691. return;
  9692. }
  9693. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9694. {
  9695. ;
  9696. if (withdraw != null)
  9697. {
  9698. withdraw.status = int.Parse(reason);
  9699. withdraw.acknowledgingtime = DateTime.Now;
  9700. withdraw.Update();
  9701. returnSuccessMsg("供应商取消撤回!");
  9702. return;
  9703. }
  9704. }
  9705. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9706. {
  9707. if (entity.OrderState == -1)
  9708. {
  9709. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9710. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id))
  9711. {
  9712. returnErrorMsg("订单spu没有确认无法通过审核!");
  9713. return;
  9714. }
  9715. if (entity.FinishPlaceTime == null)
  9716. {
  9717. entity.OrderState = 2;
  9718. }
  9719. else
  9720. {
  9721. entity.OrderState = 3;
  9722. }
  9723. commonHelper.getCytPrice(entity);
  9724. }
  9725. entity.Update();
  9726. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9727. if (withdraw != null)
  9728. {
  9729. withdraw.status = int.Parse(reason);
  9730. withdraw.Update();
  9731. }
  9732. returnSuccessMsg("操作成功!");
  9733. return;
  9734. }
  9735. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  9736. {
  9737. if (withdraw == null)
  9738. {
  9739. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  9740. return;
  9741. }
  9742. }
  9743. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  9744. {
  9745. if (withdraw != null)
  9746. {
  9747. withdraw.status = int.Parse(reason);
  9748. withdraw.acknowledgingtime = DateTime.Now;
  9749. withdraw.Update();
  9750. returnSuccessMsg("查看详细请点击线下订单查询");
  9751. return;
  9752. }
  9753. }
  9754. return;
  9755. }
  9756. }
  9757. //校验报价
  9758. public void refund_order_tip()
  9759. {
  9760. int userid = CurrentUser.UserID;
  9761. int sectionId = CurrentUser.UserPost.OrgID;
  9762. StringBuilder sql = new StringBuilder();
  9763. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  9764. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9765. List<string> ids = new List<string>();
  9766. if (dth.Rows.Count > 0)
  9767. {
  9768. foreach (DataRow dr in dth.Rows)
  9769. {
  9770. ids.Add(dr["ID"].ToString());
  9771. }
  9772. try
  9773. {
  9774. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  9775. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  9776. }
  9777. catch (Exception ex)
  9778. {
  9779. }
  9780. }
  9781. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9782. }
  9783. public void refund_order_Design()
  9784. {
  9785. int userid = CurrentUser.UserID;
  9786. int sectionId = CurrentUser.UserPost.OrgID;
  9787. StringBuilder sql = new StringBuilder();
  9788. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  9789. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9790. List<string> ids = new List<string>();
  9791. if (dth.Rows.Count > 0)
  9792. {
  9793. foreach (DataRow dr in dth.Rows)
  9794. {
  9795. ids.Add(dr["ID"].ToString());
  9796. }
  9797. try
  9798. {
  9799. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  9800. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9801. }
  9802. catch (Exception ex)
  9803. {
  9804. }
  9805. }
  9806. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9807. }
  9808. public void change_order_info()
  9809. {
  9810. int userid = CurrentUser.UserID;
  9811. StringBuilder sql = new StringBuilder();
  9812. 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);
  9813. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9814. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  9815. }
  9816. public void change_win_mome()
  9817. {
  9818. if (UrlPostParmsCheck("id,ctid"))
  9819. {
  9820. string id = GetPostString("id");
  9821. string ctid = GetPostString("ctid");
  9822. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  9823. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  9824. if (ce == null || ceErpMessageTip == null)
  9825. {
  9826. returnSuccessMsg("未找到对应的订单!");
  9827. return;
  9828. }
  9829. if (ce.OrderState >= 5)
  9830. {
  9831. returnSuccessMsg("已上传文件无法修改!");
  9832. return;
  9833. }
  9834. int type = GetPostInt("type");
  9835. string content = GetPostString("content");
  9836. if (type == 0)
  9837. {
  9838. content = content.Replace("(", "(");
  9839. content = content.Replace(")", ")");
  9840. string check = MidStrEx(content, "(", ")").Trim();
  9841. if (string.IsNullOrEmpty(check))
  9842. {
  9843. returnSuccessMsg("文件名格式不正确");
  9844. return;
  9845. }
  9846. }
  9847. ce.seller_memo = content;
  9848. ce.Update();
  9849. ceErpMessageTip.isVisit = true;
  9850. ceErpMessageTip.Update();
  9851. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  9852. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  9853. ApiVo apiVo = new ApiVo();
  9854. apiVo.orderNumber = ce.ctid;
  9855. apiVo.actionName = "demandDesign";
  9856. apiVo.orderRemarks = content;
  9857. apiVo.demandExamine = type + 1;
  9858. designHelper.API_WorkCore(apiVo);//demandDesign
  9859. returnSuccessMsg("修改成功!");
  9860. }
  9861. }
  9862. public static string MidStrEx(string sourse, string startstr, string endstr)
  9863. {
  9864. string result = string.Empty;
  9865. int startindex, endindex;
  9866. try
  9867. {
  9868. startindex = sourse.IndexOf(startstr);
  9869. if (startindex == -1)
  9870. return result;
  9871. string tmpstr = sourse.Substring(startindex + startstr.Length);
  9872. endindex = tmpstr.IndexOf(endstr);
  9873. if (endindex == -1)
  9874. return result;
  9875. result = tmpstr.Remove(endindex);
  9876. }
  9877. catch (Exception ex)
  9878. {
  9879. Console.WriteLine("MidStrEx Err:" + ex.Message);
  9880. }
  9881. return result;
  9882. }
  9883. public void refund_order_list()
  9884. {
  9885. int userid = CurrentUser.UserID;
  9886. int sectionId = CurrentUser.UserPost.OrgID;
  9887. StringBuilder sql = new StringBuilder();
  9888. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  9889. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9890. DataStruct dStruct = GetPostStruct();
  9891. DataTable dt = null;
  9892. List<string> ids = new List<string>();
  9893. List<string> tids = new List<string>();
  9894. if (dth.Rows.Count > 0)
  9895. {
  9896. foreach (DataRow dr in dth.Rows)
  9897. {
  9898. tids.Add("'" + dr["tid"].ToString() + "'");
  9899. ids.Add(dr["id"].ToString());
  9900. }
  9901. try
  9902. {
  9903. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  9904. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9905. List<string> lw = new List<string>();
  9906. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  9907. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9908. dt = WebCache.GetData("view_orderlist", dStruct);
  9909. }
  9910. catch (Exception ex)
  9911. {
  9912. }
  9913. }
  9914. writeGridDataTableJson(dStruct.TotalCount, dt);
  9915. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  9916. }
  9917. //新增
  9918. public void order_batch_downloads()
  9919. {
  9920. string ceid = GetPostString("tid");
  9921. String[] tid = ceid.Split(',');
  9922. order_batch_caiyingtong(tid);
  9923. /* (string success, string errors) = UploadFiles(tid);
  9924. returnSuccessMsg(success + errors);*/
  9925. return;
  9926. }
  9927. //报价接口
  9928. public void Get_To_Quote()
  9929. {
  9930. string ceid = GetPostString("ctid");
  9931. if (ceid != null)
  9932. {
  9933. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  9934. if (entity != null)
  9935. {
  9936. if (entity.seller_memo.IndexOf("种子纸") > -1)
  9937. {
  9938. return;
  9939. }
  9940. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  9941. double price = 0;
  9942. if (cp == null)
  9943. {
  9944. JObject jsonObject12 = new JObject
  9945. {
  9946. { "UserId", "77886" },
  9947. { "Pwd", "lt666888" },
  9948. { "Filename", entity.seller_memo }
  9949. };
  9950. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  9951. JObject jsonObjects1 = JObject.Parse(response1);
  9952. string ms1g = (string)jsonObjects1["msg"];
  9953. if (ms1g == "报价成功")
  9954. {
  9955. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  9956. string data = (string)jsonObject1["price"];
  9957. 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 + "');";
  9958. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9959. returnSuccessMsg("获取报价成功:" + data);
  9960. price = Convert.ToDouble(data);
  9961. }
  9962. else
  9963. {
  9964. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  9965. return;
  9966. }
  9967. }
  9968. String[] beizhu = entity.seller_memo.Split('-');
  9969. String chanp = "";
  9970. if (beizhu.Length > 0)
  9971. {
  9972. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  9973. }
  9974. else
  9975. {
  9976. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  9977. }
  9978. JObject jsonObject = new JObject
  9979. {
  9980. { "UserId", "77886" },
  9981. { "Pwd", "lt666888" },
  9982. { "Filename", chanp }
  9983. };
  9984. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  9985. JObject jsonObjects = JObject.Parse(response);
  9986. string msg = (string)jsonObjects["msg"];
  9987. if (msg == "报价成功")
  9988. {
  9989. JObject jsonObject1 = (JObject)jsonObjects["data"];
  9990. string data = (string)jsonObject1["price"];
  9991. 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 + "');";
  9992. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9993. returnSuccessMsg("获取报价成功:" + data);
  9994. price = Convert.ToDouble(data);
  9995. }
  9996. else
  9997. {
  9998. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  9999. return;
  10000. }
  10001. if (price > 0)
  10002. {
  10003. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10004. if (ceErpTradeCellExtend == null)
  10005. {
  10006. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10007. ceErpTradeCellExtend.ctid = entity.ctid;
  10008. ceErpTradeCellExtend.payment_cyt = price;
  10009. ceErpTradeCellExtend.Create();
  10010. }
  10011. else
  10012. {
  10013. ceErpTradeCellExtend.payment_cyt = price;
  10014. ceErpTradeCellExtend.Update();
  10015. }
  10016. }
  10017. return;
  10018. }
  10019. }
  10020. else
  10021. {
  10022. returnErrorMsg("请至少选择一条数据");
  10023. return;
  10024. }
  10025. }
  10026. //新增
  10027. public void order_To_Supplier()
  10028. {
  10029. string ceid = GetPostString("tid");
  10030. String[] tid = ceid.Split(',');
  10031. if (tid.Length > 0)
  10032. {
  10033. try
  10034. {
  10035. for (int i = 0; i < tid.Length; i++)
  10036. {
  10037. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10038. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10039. entity.SupplierId = suid;
  10040. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10041. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10042. entity.Update();
  10043. }
  10044. }
  10045. catch (Exception ex)
  10046. {
  10047. returnErrorMsg("自动匹配供应商失败");
  10048. return;
  10049. }
  10050. }
  10051. else
  10052. {
  10053. returnErrorMsg("请至少选择一条数据");
  10054. return;
  10055. }
  10056. returnSuccessMsg("自动匹配供应商成功");
  10057. return;
  10058. }
  10059. public (string, string) UploadFiles(string[] urls)
  10060. {
  10061. string success = "";
  10062. string errors = "";
  10063. int userid = CurrentUser.UserID;
  10064. foreach (string url in urls)
  10065. {
  10066. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10067. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10068. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10069. {
  10070. JObject jsonObject = new JObject
  10071. {
  10072. { "Userid", "77886" },
  10073. { "pwd", "cyt86435015" },
  10074. { "content", base64FileContent },
  10075. { "ext", Path.GetExtension(fileName) }
  10076. };
  10077. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10078. JObject jsonObjects = JObject.Parse(response);
  10079. string msg = (string)jsonObjects["msg"];
  10080. if (msg.Equals("上传成功"))
  10081. {
  10082. success += url + " 上传成功";
  10083. }
  10084. else
  10085. {
  10086. errors += url + " 上传失败";
  10087. }
  10088. }
  10089. else
  10090. {
  10091. errors += url + " 格式出现问题";
  10092. }
  10093. }
  10094. if (urls.Length == 0)
  10095. {
  10096. return (success, errors);
  10097. }
  10098. return (success, errors);
  10099. }
  10100. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10101. {
  10102. return true; //总是接受
  10103. }
  10104. public static string HttpPost(string url, string param = null)
  10105. {
  10106. HttpWebRequest request;
  10107. //如果是发送HTTPS请求
  10108. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10109. {
  10110. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10111. request = WebRequest.Create(url) as HttpWebRequest;
  10112. request.ProtocolVersion = HttpVersion.Version10;
  10113. }
  10114. else
  10115. {
  10116. request = WebRequest.Create(url) as HttpWebRequest;
  10117. }
  10118. request.Method = "POST";
  10119. request.ContentType = "application/json";
  10120. request.Accept = "*/*";
  10121. request.Timeout = 120000;
  10122. request.AllowAutoRedirect = false;
  10123. StreamWriter requestStream = null;
  10124. WebResponse response = null;
  10125. string responseStr = null;
  10126. try
  10127. {
  10128. requestStream = new StreamWriter(request.GetRequestStream());
  10129. requestStream.Write(param);
  10130. requestStream.Close();
  10131. response = request.GetResponse();
  10132. if (response != null)
  10133. {
  10134. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10135. responseStr = reader.ReadToEnd();
  10136. reader.Close();
  10137. }
  10138. }
  10139. catch (Exception ex)
  10140. {
  10141. return ex.Message;
  10142. }
  10143. finally
  10144. {
  10145. request = null;
  10146. requestStream = null;
  10147. response = null;
  10148. }
  10149. return responseStr;
  10150. }
  10151. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10152. {
  10153. string base64FileContent;
  10154. string fileName;
  10155. using (WebClient webClient = new WebClient())
  10156. {
  10157. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10158. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10159. {
  10160. using (Stream stream = response.GetResponseStream())
  10161. {
  10162. using (MemoryStream memoryStream = new MemoryStream())
  10163. {
  10164. stream.CopyTo(memoryStream);
  10165. byte[] fileBytes = memoryStream.ToArray();
  10166. base64FileContent = Convert.ToBase64String(fileBytes);
  10167. fileName = response.Headers["Content-Disposition"];
  10168. if (!string.IsNullOrEmpty(fileName))
  10169. {
  10170. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10171. if (index >= 0)
  10172. {
  10173. fileName = fileName.Substring(index + 9).Trim('\"');
  10174. }
  10175. }
  10176. else
  10177. {
  10178. fileName = Path.GetFileName(downloadUrl);
  10179. }
  10180. }
  10181. }
  10182. }
  10183. }
  10184. return (fileName, base64FileContent);
  10185. }
  10186. //新增
  10187. public void order_batch_caiyingtong(string[] downloadUrls)
  10188. {
  10189. try
  10190. {
  10191. //遍历文件
  10192. DataStruct dStruct = GetPostStruct();
  10193. DataTable dt = null;
  10194. int userid = CurrentUser.UserID;
  10195. List<string> ids = new List<string>();//失败组
  10196. List<string> tids = new List<string>();
  10197. using (WebClient webClient = new WebClient())
  10198. {
  10199. foreach (var url in downloadUrls)
  10200. {
  10201. try
  10202. {
  10203. tids.Add("'" + url + "'");
  10204. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10205. if (entity != null)
  10206. {
  10207. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10208. if (cp == null)
  10209. {
  10210. JObject jsonObject = new JObject
  10211. {
  10212. { "Userid", "77886" },
  10213. { "pwd", "lt666888" },
  10214. { "Filename",entity.seller_memo }
  10215. };
  10216. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10217. JObject jsonObjects = JObject.Parse(response);
  10218. string msg = (string)jsonObjects["msg"];
  10219. if (msg == "报价成功")
  10220. {
  10221. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10222. DownloadAndConvertToBase64(url1);
  10223. }
  10224. else
  10225. {
  10226. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10227. }
  10228. }
  10229. else
  10230. {
  10231. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10232. JObject jsonObject = new JObject
  10233. {
  10234. { "Userid", "77886" },
  10235. { "pwd", "lt666888" },
  10236. { "Filename",chanp }
  10237. };
  10238. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10239. JObject jsonObjects = JObject.Parse(response);
  10240. string msg = (string)jsonObjects["msg"];
  10241. if (msg == "报价成功")
  10242. {
  10243. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10244. DownloadAndConvertToBase64(url1);
  10245. }
  10246. else
  10247. {
  10248. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10249. }
  10250. }
  10251. }
  10252. // 上传文件到FTP
  10253. }
  10254. catch (Exception ex)
  10255. {
  10256. Console.WriteLine($"An error occurred: {ex.Message}");
  10257. }
  10258. }
  10259. List<string> lw = new List<string>();
  10260. lw.Add(string.Format("( OrderState < 6 )"));
  10261. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10262. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10263. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10264. if (dt.Rows.Count > 0)
  10265. {
  10266. foreach (DataRow dr in dt.Rows)
  10267. {
  10268. ids.Add(dr["ctid"].ToString());
  10269. }
  10270. }
  10271. String ErrorMsgs = "";
  10272. foreach (String id in ids)
  10273. {
  10274. ErrorMsgs += id + ",";
  10275. }
  10276. if (ErrorMsgs.Length > 1)
  10277. {
  10278. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10279. }
  10280. if (ErrorMsgs.Length < 1)
  10281. {
  10282. ErrorMsgs = "上传成功";
  10283. returnSuccessMsg(ErrorMsgs);
  10284. }
  10285. else
  10286. {
  10287. returnErrorMsg("以下订单" + ErrorMsgs);
  10288. }
  10289. }
  10290. // 删除文件夹及其内容
  10291. /* Directory.Delete(localDirectory, true);*/
  10292. }
  10293. catch { }
  10294. }
  10295. public void get_center_data()
  10296. {
  10297. int userId = CurrentUser.UserID;
  10298. string postCode = CurrentUser.UserPost.Post.Code;
  10299. List<string> lw = new List<string>();
  10300. List<string> ww = new List<string>();
  10301. DateTime currentTime = DateTime.Now;
  10302. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10303. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10304. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10305. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10306. string sql = " SELECT ";
  10307. string startTime = "2023-10-01 11:22:31";
  10308. //设计
  10309. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10310. {
  10311. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10312. 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));
  10313. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10314. 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));
  10315. }
  10316. //客服
  10317. else if (postCode == "CustomerService" || postCode == "Director")
  10318. {
  10319. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10320. 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));
  10321. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10322. 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));
  10323. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10324. 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));
  10325. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10326. 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));
  10327. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10328. 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));
  10329. }
  10330. //售后
  10331. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10332. {
  10333. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10334. 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));
  10335. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10336. 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));
  10337. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10338. 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));
  10339. }
  10340. //下单部
  10341. else if (postCode == "Place" || postCode == "PlaceMr")
  10342. {
  10343. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10344. 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));
  10345. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10346. 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));
  10347. }
  10348. //车间
  10349. else if (postCode == "Supplier")
  10350. {
  10351. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10352. 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));
  10353. }
  10354. DataTable dt = new DataTable();
  10355. if (lw.Count > 0)
  10356. {
  10357. sql += string.Join(" , ", lw);
  10358. sql += " FROM ";
  10359. sql += string.Join(" , ", ww);
  10360. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10361. }
  10362. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10363. }
  10364. public void get_center_data_list()
  10365. {
  10366. int userId = CurrentUser.UserID;
  10367. string postCode = CurrentUser.UserPost.Post.Code;
  10368. string shopIds = CurrentUser.User.pemShop;
  10369. DataStruct dStruct = GetPostStruct();
  10370. List<string> lw = new List<string>();
  10371. DateTime currentTime = DateTime.Now;
  10372. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10373. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10374. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10375. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10376. string startTime = "2023-10-01 11:22:31";
  10377. int order_type = GetPostInt("order_type");
  10378. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10379. {
  10380. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10381. if (order_type == 0)
  10382. {
  10383. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10384. }
  10385. else if (order_type == 3)
  10386. {
  10387. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10388. }
  10389. else
  10390. {
  10391. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10392. }
  10393. }
  10394. //客服
  10395. if (postCode == "CustomerService" || postCode == "Director")
  10396. {
  10397. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10398. if (order_type == 0)
  10399. {
  10400. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10401. }
  10402. else if (order_type == 1)
  10403. {
  10404. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10405. }
  10406. else if (order_type == 2)
  10407. {
  10408. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10409. }
  10410. else if (order_type == 3)
  10411. {
  10412. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10413. }
  10414. else if (order_type == 4)
  10415. {
  10416. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10417. }
  10418. else
  10419. {
  10420. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10421. }
  10422. }
  10423. //售后
  10424. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10425. {
  10426. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10427. if (shopIds != "")
  10428. {
  10429. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10430. }
  10431. if (order_type == 2)
  10432. {
  10433. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10434. }
  10435. else if (order_type == 4)
  10436. {
  10437. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10438. }
  10439. else if (order_type == 5)
  10440. {
  10441. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10442. }
  10443. else
  10444. {
  10445. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10446. }
  10447. }
  10448. //下单部
  10449. if (postCode == "Place" || postCode == "PlaceMr")
  10450. {
  10451. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10452. if (shopIds != "")
  10453. {
  10454. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10455. }
  10456. else if (order_type == 1)
  10457. {
  10458. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10459. }
  10460. else if (order_type == 2)
  10461. {
  10462. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10463. }
  10464. else
  10465. {
  10466. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10467. }
  10468. }
  10469. //车间
  10470. if (postCode == "Supplier")
  10471. {
  10472. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10473. if (order_type == 5)
  10474. {
  10475. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10476. }
  10477. else
  10478. {
  10479. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10480. }
  10481. }
  10482. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10483. dStruct.Fileds = "tid,ctid";
  10484. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10485. writeGridDataTableJson(dStruct.TotalCount, dt);
  10486. }
  10487. public void aftersale_audit_master()
  10488. {
  10489. if (UrlPostParmsCheck("ctid"))
  10490. {
  10491. string ctid = GetPostString("ctid");
  10492. if (ctid.Length > 0)
  10493. {
  10494. bool result = aftersale_data_change(ctid);
  10495. if (result)
  10496. {
  10497. returnSuccessMsg("修改成功!");
  10498. return;
  10499. }
  10500. }
  10501. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10502. }
  10503. }
  10504. public void aftersale_batch_audit_master()
  10505. {
  10506. if (UrlPostParmsCheck("ctids"))
  10507. {
  10508. string ctids = GetPostString("ctids");
  10509. if (ctids.Length > 0)
  10510. {
  10511. List<string> list = new List<string>();
  10512. string[] ctid_list = ctids.Split(',');
  10513. foreach (var item in ctid_list)
  10514. {
  10515. bool result = aftersale_data_change(item);
  10516. if (!result)
  10517. {
  10518. list.Add(item);
  10519. }
  10520. }
  10521. if (list.Count > 0)
  10522. {
  10523. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10524. return;
  10525. }
  10526. returnSuccessMsg("修改成功!");
  10527. return;
  10528. }
  10529. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10530. }
  10531. }
  10532. public bool aftersale_data_change(string ctid)
  10533. {
  10534. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10535. if (ceErpTradeCell != null)
  10536. {
  10537. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10538. ceErpTradeCell.AfterSaleSupplierState = 0;
  10539. StringBuilder sql = new StringBuilder();
  10540. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10541. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10542. CeErpTradeResponsible.DelByTid(ctid, 0);
  10543. 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 == "不理赔")
  10544. {
  10545. CeErpTradeResponsible.DelByTid(ctid, 1);
  10546. ceErpTradeCell.AfterSaleSupplierState = 1;
  10547. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10548. ceErpTradeCell.AfterSaleState = 4;
  10549. }
  10550. else
  10551. {
  10552. ceErpTradeCell.AfterSaleState = 3;
  10553. }
  10554. bool needCyt = false;
  10555. if (dt != null)
  10556. {
  10557. if (dt.Rows.Count == 1)
  10558. {
  10559. bool isEnd = false;
  10560. foreach (DataRow dr in dt.Rows)
  10561. {
  10562. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10563. {
  10564. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10565. isEnd = true;
  10566. }
  10567. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10568. {
  10569. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10570. isEnd = true;
  10571. }
  10572. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10573. {
  10574. needCyt = true;
  10575. }
  10576. }
  10577. if (isEnd)
  10578. {
  10579. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10580. ceErpTradeCell.AfterSaleState = 4;
  10581. ceErpTradeCell.AfterSaleSupplierState = 1;
  10582. }
  10583. }
  10584. else
  10585. {
  10586. bool isAll = true;
  10587. foreach (DataRow dr in dt.Rows)
  10588. {
  10589. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10590. {
  10591. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10592. continue;
  10593. }
  10594. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10595. {
  10596. string path = "";
  10597. int OrgID = 0;
  10598. if (!Convert.IsDBNull(dr["OrgPath"]))
  10599. {
  10600. path = dr["OrgPath"].ToString();
  10601. }
  10602. if (!Convert.IsDBNull(dr["OrgID"]))
  10603. {
  10604. OrgID = Convert.ToInt32(dr["OrgID"]);
  10605. }
  10606. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10607. {
  10608. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10609. continue;
  10610. }
  10611. }
  10612. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10613. {
  10614. needCyt = true;
  10615. }
  10616. isAll = false;
  10617. }
  10618. if (isAll)
  10619. {
  10620. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10621. ceErpTradeCell.AfterSaleState = 4;
  10622. ceErpTradeCell.AfterSaleSupplierState = 1;
  10623. }
  10624. }
  10625. }
  10626. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10627. {
  10628. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10629. }
  10630. if (ceErpTradeCell.AfterSaleState == 4)
  10631. {
  10632. ApiVo apiVo = new ApiVo();
  10633. apiVo.orderNumber = ceErpTradeCell.ctid;
  10634. apiVo.actionName = "afterOver";
  10635. designHelper.API_WorkCore(apiVo); //afterOver
  10636. }
  10637. ceErpTradeCell.Update();
  10638. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10639. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10640. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10641. return true;
  10642. }
  10643. return false;
  10644. }
  10645. public void get_erp_wechatorder()
  10646. {
  10647. DataStruct dStruct = GetPostStruct();
  10648. List<string> lw = new List<string>();
  10649. string tid = GetPostString("tid");
  10650. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10651. string shopname = GetPostString("shopname");
  10652. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10653. string buyernick = GetPostString("buyer_nick");
  10654. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10655. string customer = GetPostString("customer");
  10656. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10657. string returndate1 = GetPostString("returndate1");
  10658. string returndate2 = GetPostString("returndate2");
  10659. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10660. if (dw.Length > 0) lw.Add(dw);
  10661. string finishDate1 = GetPostString("finishdate1");
  10662. string finishDate2 = GetPostString("finishdate2");
  10663. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10664. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10665. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10666. dStruct.Order = "created desc";
  10667. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10668. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10669. writeGridDataTableJson(dStruct.TotalCount, dt);
  10670. }
  10671. public void get_erp_wechatlist_sumprice()
  10672. {
  10673. DataStruct dStruct = GetPostStruct();
  10674. List<string> lw = new List<string>();
  10675. string tid = GetPostString("tid");
  10676. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10677. string shopname = GetPostString("shopname");
  10678. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10679. string buyernick = GetPostString("buyer_nick");
  10680. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10681. string customer = GetPostString("customer");
  10682. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10683. string returndate1 = GetPostString("returndate1");
  10684. string returndate2 = GetPostString("returndate2");
  10685. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10686. if (dw.Length > 0) lw.Add(dw);
  10687. string finishDate1 = GetPostString("finishdate1");
  10688. string finishDate2 = GetPostString("finishdate2");
  10689. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10690. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10691. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10692. string mainWhere = string.Join(" and ", lw.ToArray());
  10693. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10694. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10695. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10696. decimal total = 0;
  10697. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10698. {
  10699. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10700. }
  10701. var res = new
  10702. {
  10703. data = total
  10704. };
  10705. string ro_jsond = JsonConvert.SerializeObject(res);
  10706. returnSuccess(ro_jsond);
  10707. return;
  10708. }
  10709. public void get_erp_qr_waitdeliverylist()
  10710. {
  10711. DataStruct dStruct = GetPostStruct();
  10712. List<string> lw = new List<string>();
  10713. string tid = GetPostString("ctid");
  10714. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10715. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10716. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  10717. var res_objz = new
  10718. {
  10719. restype = 1,
  10720. data = dt
  10721. };
  10722. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  10723. returnSuccess(ro_jsonz);
  10724. }
  10725. public void get_erp_yield_list()
  10726. {
  10727. DataStruct dStruct = GetPostStruct();
  10728. List<string> lw = new List<string>();
  10729. string tid = GetPostString("ctid");
  10730. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  10731. string shopname = GetPostString("shopname");
  10732. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  10733. string buyernick = GetPostString("buyer_nick");
  10734. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  10735. //if (tid.Length == 0 && buyernick.Length == 0)
  10736. //{
  10737. // lw.Add(string.Format("IsRefund<={0}", 1));
  10738. //}
  10739. string customer = GetPostString("customer");
  10740. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  10741. string design = GetPostString("design");
  10742. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  10743. string orderState = GetPostString("orderState");
  10744. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  10745. string address = GetPostString("address");
  10746. 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));
  10747. string sellermemo = GetPostString("seller_memo");
  10748. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  10749. string supplier = GetPostString("supplier");
  10750. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  10751. string OrderArea = GetPostString("order_area");
  10752. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  10753. string placedate1 = GetPostString("placedate1");
  10754. string placedate2 = GetPostString("placedate2");
  10755. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  10756. if (fdw.Length > 0) lw.Add(fdw);
  10757. string price1 = GetPostString("price1");
  10758. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  10759. string price2 = GetPostString("price2");
  10760. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  10761. string unusualCon = GetPostString("unusualcon");
  10762. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  10763. string posTag = CurrentUser.UserPost.Post.Code;
  10764. if (posTag == "Supplier")
  10765. {
  10766. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  10767. }
  10768. lw.Add(string.Format("OrderState = 6 "));
  10769. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  10770. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  10771. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10772. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  10773. writeGridDataTableJson(dStruct.TotalCount, dt);
  10774. }
  10775. public void change_erp_sup_state()
  10776. {
  10777. if (UrlPostParmsCheck("ctid"))
  10778. {
  10779. string ctid = GetPostString("ctid");
  10780. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10781. if (ceErpTradeCell != null)
  10782. {
  10783. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10784. if (ceErpTradeCellExtend == null)
  10785. {
  10786. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10787. ceErpTradeCellExtend.ctid = ctid;
  10788. ceErpTradeCellExtend.SupState = 1;
  10789. ceErpTradeCellExtend.Create();
  10790. }
  10791. else
  10792. {
  10793. ceErpTradeCellExtend.SupState = 1;
  10794. ceErpTradeCellExtend.Update();
  10795. }
  10796. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  10797. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  10798. return;
  10799. }
  10800. returnErrorMsg("找不到订单");
  10801. }
  10802. }
  10803. public void supplier_all_downs()
  10804. {
  10805. if (UrlPostParmsCheck("tids"))
  10806. {
  10807. string tids = GetPostString("tids");
  10808. if (tids != null && tids.Length > 0)
  10809. {
  10810. StringBuilder sql = new StringBuilder();
  10811. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  10812. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10813. sql = new StringBuilder();
  10814. 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, "下载设计文件");
  10815. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10816. string[] list = tids.Split(',');
  10817. foreach (string ctid in list)
  10818. {
  10819. CeErpSukuraData.createInfo(ctid, 3);
  10820. }
  10821. designHelper.api_approveDesign(tids); //approveDesign
  10822. returnSuccessMsg("下载成功!");
  10823. return;
  10824. }
  10825. returnErrorMsg("下载订单更新失败");
  10826. }
  10827. }
  10828. public void uploaderFileSuccess()
  10829. {
  10830. if (UrlPostParmsCheck("fileName"))
  10831. {
  10832. string fileName = GetPostString("fileName");
  10833. ApiVo apiVo = new ApiVo();
  10834. apiVo.orderNumber = fileName;
  10835. apiVo.actionName = "finishDesign";
  10836. designHelper.API_WorkCore(apiVo);//finishDesign
  10837. returnSuccessMsg("");
  10838. }
  10839. }
  10840. public void get_sample2_order()
  10841. {
  10842. if (UrlPostParmsCheck("ctid"))
  10843. {
  10844. string ctid = GetPostString("ctid");
  10845. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10846. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  10847. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  10848. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  10849. double total = 0.0;
  10850. double order_price = 0.0;
  10851. if (dt_bu.Rows.Count > 0)
  10852. {
  10853. foreach (DataRow dr in dt_bu.Rows)
  10854. {
  10855. total += Convert.ToDouble(dr["payment"]);
  10856. }
  10857. }
  10858. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  10859. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  10860. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  10861. string tid = ctid.Replace("S_", "");
  10862. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  10863. double paymant = 0.0;
  10864. if (entity != null)
  10865. {
  10866. paymant = entity.payment;
  10867. }
  10868. string return_reason = "";
  10869. if (dt_after != null && dt_after.Rows.Count > 0)
  10870. {
  10871. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  10872. }
  10873. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  10874. }
  10875. }
  10876. public void get_erp_design_status()
  10877. {
  10878. string designName = GetPostString("designName");
  10879. DataStruct dStruct = GetPostStruct();
  10880. if (designName.Length > 0)
  10881. {
  10882. 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";
  10883. sql_user += " and Name like '%" + designName + "%'";
  10884. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  10885. List<string> ids_list = new List<string>();
  10886. if (user_table.Rows.Count > 0)
  10887. {
  10888. foreach (DataRow item in user_table.Rows)
  10889. {
  10890. ids_list.Add(item["id"].ToString());
  10891. string ids_s = item["TeamIds"].ToString();
  10892. if (ids_s.Length > 0)
  10893. {
  10894. ids_list.AddRange(ids_s.Split(','));
  10895. }
  10896. }
  10897. }
  10898. HashSet<string> set = new HashSet<string>(ids_list);
  10899. ids_list = set.ToList();
  10900. if (ids_list.Count > 0)
  10901. {
  10902. 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));
  10903. dStruct.MainWhere = sql;
  10904. DataTable dt = null;
  10905. dt = WebCache.GetData("view_ErpUser", dStruct);
  10906. writeGridDataTableJson(dStruct.TotalCount, dt);
  10907. }
  10908. }
  10909. }
  10910. public void change_erp_order_price()
  10911. {
  10912. string ctid = GetPostString("ctid");
  10913. double price = GetPostDouble("price");
  10914. if (ctid.Length > 0)
  10915. {
  10916. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10917. if (ceErpTradeCellExtend == null)
  10918. {
  10919. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10920. ceErpTradeCellExtend.ctid = ctid;
  10921. ceErpTradeCellExtend.payment_cyt = price;
  10922. ceErpTradeCellExtend.Create();
  10923. }
  10924. else
  10925. {
  10926. ceErpTradeCellExtend.payment_cyt = price;
  10927. ceErpTradeCellExtend.Update();
  10928. }
  10929. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  10930. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  10931. {
  10932. ceErpDataSendOrderInfo.isSync = false;
  10933. ceErpDataSendOrderInfo.Update();
  10934. }
  10935. if (ceErpDataSendOrderInfo == null)
  10936. {
  10937. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  10938. ceErpDataSendOrderInfo.isSync = false;
  10939. ceErpDataSendOrderInfo.ctid = ctid;
  10940. ceErpDataSendOrderInfo.Create();
  10941. }
  10942. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  10943. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  10944. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10945. if (dth != null && dth.Rows.Count > 0)
  10946. {
  10947. dataSendOrderBean dataSendOrderBean = null;
  10948. foreach (DataRow item in dth.Rows)
  10949. {
  10950. try
  10951. {
  10952. dataSendOrderBean = new dataSendOrderBean();
  10953. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  10954. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  10955. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  10956. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  10957. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  10958. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  10959. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  10960. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  10961. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  10962. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  10963. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  10964. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  10965. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  10966. if (result != null)
  10967. {
  10968. if ("0".Equals(result.errcode))
  10969. {
  10970. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  10971. }
  10972. else
  10973. {
  10974. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  10975. }
  10976. }
  10977. }
  10978. catch (Exception ex)
  10979. {
  10980. }
  10981. }
  10982. }
  10983. returnSuccessMsg("修改成功!");
  10984. return;
  10985. }
  10986. returnErrorMsg("找不到订单");
  10987. }
  10988. public void find_he_together()
  10989. {
  10990. string ctid = GetPostString("ctid");
  10991. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10992. List<string> list = new List<string>();
  10993. if (ceErpTradeCell != null)
  10994. {
  10995. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  10996. {
  10997. 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);
  10998. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10999. if (table != null && table.Rows.Count > 0)
  11000. {
  11001. foreach (TableRow row in table.Rows)
  11002. {
  11003. }
  11004. }
  11005. }
  11006. }
  11007. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11008. }
  11009. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11010. {
  11011. //chy----19
  11012. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11013. //GD-CYT-----64
  11014. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11015. //ZHX----3
  11016. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11017. //JK----97
  11018. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11019. //ZT----70
  11020. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11021. //LHCY-----98
  11022. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11023. //XD-----90
  11024. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11025. //CYCY-----14
  11026. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11027. };
  11028. //其他改名
  11029. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11030. {
  11031. {15,"滴塑" }, {119,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11032. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11033. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11034. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11035. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11036. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11037. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11038. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11039. };
  11040. //不统计
  11041. List<int> no_suppliers = new List<int>()
  11042. {
  11043. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11044. };
  11045. //配件单
  11046. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11047. {
  11048. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11049. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11050. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11051. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11052. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11053. {"旗杆",new List<string>(){ "班旗" } },
  11054. {"牙签",new List<string>(){ "不干胶" } }
  11055. };
  11056. public void get_place_order_data()
  11057. {
  11058. string date1 = GetPostString("date1");
  11059. string date2 = GetPostString("date2");
  11060. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11061. DateTime start = DateTime.Parse(starttime);
  11062. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11063. DateTime end = DateTime.Parse(endtime);
  11064. if (date1 != null && date1.Length > 0)
  11065. {
  11066. DateTime dateTime = DateTime.Parse(date1);
  11067. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11068. start = DateTime.Parse(starttime);
  11069. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11070. end = DateTime.Parse(endtime);
  11071. }
  11072. if (date2 != null && date2.Length > 0)
  11073. {
  11074. DateTime dateTime = DateTime.Parse(date2);
  11075. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11076. end = DateTime.Parse(endtime);
  11077. }
  11078. 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);
  11079. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11080. //不干胶-----1,卡片-----29
  11081. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11082. foreach (DataRow row in data.Rows)
  11083. {
  11084. int productId = Convert.ToInt32(row["ProductId"]);
  11085. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11086. if (no_suppliers.Contains(supplierId))
  11087. {
  11088. continue;
  11089. }
  11090. string seller_memo = row["seller_memo"].ToString();
  11091. bool ispj = false;//是否配件单
  11092. bool isfirst = true;//第一个配
  11093. maps.Keys.ForEach(key =>
  11094. {
  11095. //备注包含配件
  11096. if (seller_memo.Contains(key) && isfirst)
  11097. {
  11098. List<string> list = maps[key];
  11099. ispj = true;
  11100. isfirst = false;
  11101. for (int i = 0; i < list.Count; i++)
  11102. {
  11103. if (seller_memo.Contains(list[i]))
  11104. {
  11105. ispj = false;
  11106. break;
  11107. }
  11108. }
  11109. }
  11110. });
  11111. if (ispj)
  11112. {
  11113. continue;
  11114. }
  11115. seller_memo = seller_memo.Replace("UV", "uv");
  11116. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11117. //吊牌归到卡片
  11118. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11119. seller_memo = seller_memo.Replace("卡套", "卡片");
  11120. seller_memo = seller_memo.Replace("封套", "卡片");
  11121. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11122. seller_memo = seller_memo.Replace("腰封", "卡片");
  11123. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11124. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11125. seller_memo = seller_memo.Replace("横幅", "条幅");
  11126. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11127. string map_key = "";
  11128. string type = "";
  11129. if (supplierMap.ContainsKey(supplierId))
  11130. {
  11131. foreach (var kvp in supplierMap[supplierId])
  11132. {
  11133. if (seller_memo.Contains(kvp.Key))
  11134. {
  11135. map_key = kvp.Value;
  11136. type = kvp.Value;
  11137. break;
  11138. }
  11139. }
  11140. }
  11141. if (map_key == "")
  11142. {
  11143. type = "其他";
  11144. map_key = "其他";
  11145. }
  11146. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11147. {
  11148. map_key = suppliers[supplierId];
  11149. }
  11150. if (supplierId == 70)
  11151. {
  11152. supplierId = 70;
  11153. }
  11154. map_key += "_" + row["SupplierName"].ToString();
  11155. Dictionary<string, int> map = null;
  11156. if (other_map.ContainsKey(map_key))
  11157. {
  11158. other_map.TryGetValue(map_key, out map);
  11159. }
  11160. else
  11161. {
  11162. map = new Dictionary<string, int>();
  11163. map.Add("dayDev", 0);//当天出货
  11164. map.Add("dayTotal", 0);//下单总数
  11165. map.Add("payTotal", 0);//500以上
  11166. map.Add("today", 0);//当天出货数量
  11167. map.Add("unusua", 0);//异常数
  11168. other_map.Add(map_key, map);
  11169. other_map.TryGetValue(map_key, out map);
  11170. }
  11171. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11172. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11173. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11174. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11175. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11176. {
  11177. map["dayTotal"]++;
  11178. if (supplierId == 97)
  11179. {
  11180. supplierId = 97;
  11181. }
  11182. }
  11183. if (Convert.ToDecimal(row["payment"]) >= 500)
  11184. {
  11185. map["payTotal"]++;
  11186. }
  11187. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11188. {
  11189. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11190. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11191. {
  11192. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11193. {
  11194. map["today"]++;
  11195. }
  11196. }
  11197. else
  11198. {
  11199. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11200. {
  11201. map["today"]++;
  11202. }
  11203. else
  11204. {
  11205. if (supplierId == 119)
  11206. {
  11207. Debug.WriteLine(row["seller_memo"].ToString());
  11208. }
  11209. }
  11210. }
  11211. }
  11212. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11213. {
  11214. map["unusua"]++;
  11215. }
  11216. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11217. //GD-CYT-----64
  11218. DateTime two = palceTimeStart.AddHours(14);
  11219. DateTime three = palceTimeStart.AddHours(15);
  11220. DateTime four = palceTimeStart.AddHours(16);
  11221. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11222. {
  11223. //下午四点前 500-1000
  11224. string count = row["ProductCount"].ToString();
  11225. if (count != null && count.Length > 0)
  11226. {
  11227. int productCount = commonHelper.getPlaceProductCount(count);
  11228. if (productCount >= 500 && productCount <= 1000)
  11229. {
  11230. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11231. {
  11232. map["dayDev"]++;
  11233. }
  11234. }
  11235. }
  11236. }
  11237. //UV
  11238. else if ("uv".Equals(type))
  11239. {
  11240. //ZT----70
  11241. //ZHX----3
  11242. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11243. {
  11244. map["dayDev"]++;
  11245. }
  11246. //JK----97
  11247. //HZX----105
  11248. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11249. {
  11250. map["dayDev"]++;
  11251. if (supplierId == 97)
  11252. {
  11253. supplierId = 97;
  11254. }
  11255. }
  11256. }
  11257. //帆布---52|条幅---27
  11258. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11259. {
  11260. //LHCY-----98
  11261. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11262. {
  11263. map["dayDev"]++;
  11264. }
  11265. }
  11266. //条幅
  11267. else if ("条幅".Equals(type))
  11268. {
  11269. //XD-----90
  11270. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11271. {
  11272. map["dayDev"]++;
  11273. }
  11274. }
  11275. //桌布
  11276. else if ("桌布".Equals(type))
  11277. {
  11278. //XD-----90
  11279. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11280. {
  11281. map["dayDev"]++;
  11282. }
  11283. }
  11284. //DL---10
  11285. //AYTW---119
  11286. //FS-CYT-DY ----80
  11287. //JK----97
  11288. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11289. {
  11290. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11291. {
  11292. map["dayDev"]++;
  11293. }
  11294. }
  11295. }
  11296. DataTable dt = new DataTable();
  11297. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11298. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11299. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11300. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11301. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11302. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11303. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11304. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11305. other_map.Keys.ForEach(key =>
  11306. {
  11307. DataRow dr = dt.NewRow();
  11308. Dictionary<string, int> map = other_map[key];
  11309. string[] key_list = key.Split('_');
  11310. dr[0] = key_list[0];
  11311. dr[1] = key_list[1];
  11312. if (key_list.Length > 2)
  11313. {
  11314. dr[1] += "(" + key_list[2] + ")";
  11315. }
  11316. dr[2] = map["dayTotal"];
  11317. dr[3] = map["payTotal"];
  11318. dr[4] = map["today"];
  11319. dr[5] = map["unusua"];
  11320. dr[6] = map["dayDev"];
  11321. double rate = 0.00;
  11322. if (map["dayDev"] > 0)
  11323. {
  11324. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11325. }
  11326. dr[7] = rate.ToString();
  11327. dt.Rows.Add(dr);
  11328. });
  11329. DataView dv = new DataView(dt);
  11330. dv.Sort = "SupplierName";
  11331. //dv.Sort = "AllOrder desc";
  11332. DataTable dtNew = dv.ToTable();
  11333. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11334. }
  11335. public void check_order_desing_info()
  11336. {
  11337. string ctid = GetPostString("ctid");
  11338. if (!string.IsNullOrEmpty(ctid))
  11339. {
  11340. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11341. if (ceErpTradeCell != null)
  11342. {
  11343. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11344. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11345. return;
  11346. }
  11347. returnErrorMsg("找不到订单");
  11348. return;
  11349. }
  11350. returnErrorMsg("找不到订单");
  11351. }
  11352. public void get_timeout_detail()
  11353. {
  11354. string poscode = CurrentUser.UserPost.Post.Code;
  11355. DataStruct dStruct = GetPostStruct();
  11356. List<string> lw = new List<string>();
  11357. string id = GetPostString("id");
  11358. string pay_date1 = GetPostString("pay_date1");
  11359. string pay_date2 = GetPostString("pay_date2");
  11360. int type = GetPostInt("type");
  11361. if (type == 0)
  11362. {
  11363. if (pay_date1.Length > 0)
  11364. {
  11365. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11366. }
  11367. if (pay_date2.Length > 0)
  11368. {
  11369. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11370. }
  11371. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11372. }
  11373. if (type == 1)
  11374. {
  11375. if (pay_date1.Length > 0)
  11376. {
  11377. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11378. }
  11379. if (pay_date2.Length > 0)
  11380. {
  11381. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11382. }
  11383. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11384. }
  11385. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11386. DataTable dt = null;
  11387. dt = WebCache.GetData("view_orderlist", dStruct);
  11388. writeGridDataTableJson(dStruct.TotalCount, dt);
  11389. }
  11390. public void saveUrgentChargePrice()
  11391. {
  11392. string ctid = GetPostString("ctid");
  11393. if (!string.IsNullOrEmpty(ctid))
  11394. {
  11395. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11396. if (ceErpTradeCell != null)
  11397. {
  11398. double price = GetPostDouble("price");
  11399. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11400. if (ceErpTradeCellExtend == null)
  11401. {
  11402. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11403. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11404. }
  11405. ceErpTradeCellExtend.urgentCharge = price;
  11406. if (ceErpTradeCellExtend.ID > 0)
  11407. {
  11408. ceErpTradeCellExtend.Update();
  11409. }
  11410. else
  11411. {
  11412. ceErpTradeCellExtend.Save();
  11413. }
  11414. returnSuccessMsg("修改成功!");
  11415. return;
  11416. }
  11417. returnErrorMsg("找不到订单");
  11418. return;
  11419. }
  11420. returnErrorMsg("找不到订单");
  11421. }
  11422. public void finish_erp_order()
  11423. {
  11424. string ctid = GetPostString("ctid");
  11425. if (!string.IsNullOrEmpty(ctid))
  11426. {
  11427. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11428. {
  11429. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11430. if (ceErpTradeCell != null)
  11431. {
  11432. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11433. ceErpTradeCell.Update();
  11434. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11435. returnSuccessMsg("修改成功!");
  11436. return;
  11437. }
  11438. }
  11439. }
  11440. returnErrorMsg("找不到订单");
  11441. }
  11442. public void get_trade_order_list()
  11443. {
  11444. string tid = GetPostString("tid");
  11445. if (!string.IsNullOrEmpty(tid))
  11446. {
  11447. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11448. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11449. writeGridDataTableJson(data.Rows.Count, data);
  11450. return;
  11451. }
  11452. returnErrorMsg("找不到订单");
  11453. }
  11454. public void save_cell_spu()
  11455. {
  11456. string ctid = GetPostString("ctid");
  11457. string spu_id = GetPostString("spu_id");
  11458. if (!string.IsNullOrEmpty(ctid))
  11459. {
  11460. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11461. if (ceErpTradeCellExtend == null)
  11462. {
  11463. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11464. ceErpTradeCellExtend.ctid = ctid;
  11465. }
  11466. ceErpTradeCellExtend.spu_id = spu_id;
  11467. if (ceErpTradeCellExtend.ID == 0)
  11468. {
  11469. ceErpTradeCellExtend.Create();
  11470. }
  11471. else
  11472. {
  11473. ceErpTradeCellExtend.Update();
  11474. }
  11475. returnSuccessMsg("修改成功!");
  11476. return;
  11477. }
  11478. returnErrorMsg("找不到订单");
  11479. }
  11480. public void change_express_info()
  11481. {
  11482. string ctid = GetPostString("ctid");
  11483. string transNo = GetPostString("transNo");
  11484. string transCom = GetPostString("transCom");
  11485. if (!string.IsNullOrEmpty(ctid))
  11486. {
  11487. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11488. if (ceErpTradeCellExtend == null)
  11489. {
  11490. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11491. ceErpTradeCellExtend.ctid = ctid;
  11492. }
  11493. ceErpTradeCellExtend.modExpressNo = transNo;
  11494. ceErpTradeCellExtend.modExpressCom = transCom;
  11495. ceErpTradeCellExtend.readMod = 2;
  11496. if (ceErpTradeCellExtend.ID == 0)
  11497. {
  11498. ceErpTradeCellExtend.Create();
  11499. }
  11500. else
  11501. {
  11502. ceErpTradeCellExtend.Update();
  11503. }
  11504. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11505. returnSuccessMsg("修改成功!");
  11506. return;
  11507. }
  11508. returnErrorMsg("找不到订单");
  11509. }
  11510. public void get_change_express_list()
  11511. {
  11512. DataStruct dStruct = GetPostStruct();
  11513. List<string> lw = new List<string>();
  11514. int st = 2;
  11515. string tid = GetPostString("ctid");
  11516. if (tid.Length > 0)
  11517. {
  11518. string select_tid = getTidByCtid(tid);
  11519. lw.Add(string.Format("tid='{0}'", select_tid));
  11520. }
  11521. string shopname = GetPostString("shopname");
  11522. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11523. string buyernick = GetPostString("buyer_nick");
  11524. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11525. string sellermemo = GetPostString("seller_memo");
  11526. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11527. string supplier = GetPostString("supplier");
  11528. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11529. string customer = GetPostString("customer");
  11530. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11531. string design = GetPostString("design");
  11532. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11533. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11534. string poscode = CurrentUser.UserPost.Post.Code;
  11535. if (poscode != "SysAdmin")
  11536. {
  11537. string shopid = CurrentUser.User.pemShop;
  11538. lw.Add(string.Format("shopId in ({0})", shopid));
  11539. }
  11540. lw.Add("readMod = 2");
  11541. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11542. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11543. writeGridDataTableJson(dStruct.TotalCount, dt);
  11544. }
  11545. public void deal_express_complete()
  11546. {
  11547. string ctid = GetPostString("ctid");
  11548. if (!string.IsNullOrEmpty(ctid))
  11549. {
  11550. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11551. if (ceErpTradeCellExtend == null)
  11552. {
  11553. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11554. ceErpTradeCellExtend.ctid = ctid;
  11555. }
  11556. ceErpTradeCellExtend.readMod = 1;
  11557. if (ceErpTradeCellExtend.ID == 0)
  11558. {
  11559. ceErpTradeCellExtend.Create();
  11560. }
  11561. else
  11562. {
  11563. ceErpTradeCellExtend.Update();
  11564. }
  11565. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11566. returnSuccessMsg("修改成功!");
  11567. return;
  11568. }
  11569. returnErrorMsg("找不到订单");
  11570. }
  11571. public void aftersale_return_visit()
  11572. {
  11573. string ctid = GetPostString("ctid");
  11574. if (!string.IsNullOrEmpty(ctid))
  11575. {
  11576. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11577. if (ceErpTradeCellExtend == null)
  11578. {
  11579. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11580. ceErpTradeCellExtend.ctid = ctid;
  11581. }
  11582. ceErpTradeCellExtend.returnVisit = 1;
  11583. if (ceErpTradeCellExtend.ID == 0)
  11584. {
  11585. ceErpTradeCellExtend.Create();
  11586. }
  11587. else
  11588. {
  11589. ceErpTradeCellExtend.Update();
  11590. }
  11591. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11592. if (ceErpTradeAfterSaleExtend != null)
  11593. {
  11594. ceErpTradeAfterSaleExtend.TextResult = "";
  11595. ceErpTradeAfterSaleExtend.Update();
  11596. }
  11597. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11598. returnSuccessMsg("修改成功!");
  11599. return;
  11600. }
  11601. returnErrorMsg("找不到订单");
  11602. }
  11603. public void orderPlaceInfo()
  11604. {
  11605. string ctids = GetPostString("ctids");
  11606. string[] list = ctids.Split(',');
  11607. foreach (string ctid in list)
  11608. {
  11609. CeErpSukuraData.createInfo(ctid, 3);
  11610. }
  11611. StringBuilder sql = new StringBuilder();
  11612. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11613. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11614. designHelper.api_approveDesign(ctids); //approveDesign
  11615. returnSuccessMsg("");
  11616. }
  11617. public void get_issue_list()
  11618. {
  11619. DataStruct dStruct = GetPostStruct();
  11620. List<string> lw = new List<string>();
  11621. int st = 2;
  11622. string tid = GetPostString("ctid");
  11623. if (tid.Length > 0)
  11624. {
  11625. string select_tid = getTidByCtid(tid);
  11626. lw.Add(string.Format("tid='{0}'", select_tid));
  11627. }
  11628. string shopname = GetPostString("shopname");
  11629. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11630. string buyernick = GetPostString("buyer_nick");
  11631. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11632. string sellermemo = GetPostString("seller_memo");
  11633. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11634. string supplier = GetPostString("supplier");
  11635. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11636. string customer = GetPostString("customer");
  11637. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11638. string design = GetPostString("design");
  11639. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11640. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11641. string poscode = CurrentUser.UserPost.Post.Code;
  11642. if (poscode != "SysAdmin")
  11643. {
  11644. string shopid = CurrentUser.User.pemShop;
  11645. lw.Add(string.Format("shopId in ({0})", shopid));
  11646. }
  11647. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode))
  11648. {
  11649. lw.Add("IssueState = 1");
  11650. }
  11651. lw.Add("IssueState > 0");
  11652. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11653. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11654. writeGridDataTableJson(dStruct.TotalCount, dt);
  11655. }
  11656. public void saveIssueContent()
  11657. {
  11658. string ctid = GetPostString("ctid");
  11659. if (!string.IsNullOrEmpty(ctid))
  11660. {
  11661. string content = GetPostString("content");
  11662. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11663. if (ceErpTradeAfterSaleExtend == null)
  11664. {
  11665. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11666. ceErpTradeAfterSaleExtend.tid = ctid;
  11667. }
  11668. ceErpTradeAfterSaleExtend.IssueContent = content;
  11669. ceErpTradeAfterSaleExtend.IssueState = 1;
  11670. if (ceErpTradeAfterSaleExtend.ID > 0)
  11671. {
  11672. ceErpTradeAfterSaleExtend.Update();
  11673. }
  11674. else
  11675. {
  11676. ceErpTradeAfterSaleExtend.Create();
  11677. }
  11678. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11679. returnSuccessMsg("添加成功!");
  11680. return;
  11681. }
  11682. returnErrorMsg("找不到订单");
  11683. }
  11684. public void dealIssueContent()
  11685. {
  11686. string ctid = GetPostString("ctid");
  11687. if (!string.IsNullOrEmpty(ctid))
  11688. {
  11689. string content = GetPostString("content");
  11690. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11691. if (ceErpTradeAfterSaleExtend != null)
  11692. {
  11693. ceErpTradeAfterSaleExtend.IssueState = 2;
  11694. ceErpTradeAfterSaleExtend.Update();
  11695. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  11696. returnSuccessMsg("修改完成!");
  11697. return;
  11698. }
  11699. }
  11700. returnErrorMsg("找不到订单");
  11701. }
  11702. public void set_tid_attachments()
  11703. {
  11704. string tid = GetPostString("tid");
  11705. string atta = GetPostString("atta");
  11706. if (!string.IsNullOrEmpty(tid))
  11707. {
  11708. if (string.IsNullOrEmpty(atta))
  11709. {
  11710. returnErrorMsg("文件地址为空");
  11711. return;
  11712. }
  11713. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11714. if (ceErpTradeCell != null)
  11715. {
  11716. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11717. if (ceErpTrade == null)
  11718. {
  11719. returnErrorMsg("找不到订单");
  11720. return;
  11721. }
  11722. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  11723. bool isSend = false;
  11724. if (dt != null && dt.Rows.Count > 0)
  11725. {
  11726. foreach (DataRow row in dt.Rows)
  11727. {
  11728. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  11729. {
  11730. isSend = true;
  11731. }
  11732. }
  11733. if (isSend)
  11734. {
  11735. returnErrorMsg("已发货无法修改");
  11736. return;
  11737. }
  11738. ceErpTrade.Attachments = atta;
  11739. ceErpTrade.Update();
  11740. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址", 6);
  11741. returnSuccessMsg("上传成功!");
  11742. return;
  11743. }
  11744. }
  11745. }
  11746. returnErrorMsg("找不到订单");
  11747. }
  11748. public void get_tid_attachments()
  11749. {
  11750. string tid = GetPostString("tid");
  11751. if (!string.IsNullOrEmpty(tid))
  11752. {
  11753. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11754. if (ceErpTradeCell != null)
  11755. {
  11756. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11757. if (ceErpTrade == null)
  11758. {
  11759. returnErrorMsg("找不到订单");
  11760. return;
  11761. }
  11762. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  11763. return;
  11764. }
  11765. }
  11766. returnErrorMsg("找不到订单");
  11767. }
  11768. public void check_erp_sameorders()
  11769. {
  11770. if (UrlPostParmsCheck("ctid"))
  11771. {
  11772. string eid = GetPostString("ctid");
  11773. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  11774. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  11775. if (entity != null && ceErpTrade != null)
  11776. {
  11777. if (entity.OrderState > 6)
  11778. {
  11779. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11780. return;
  11781. }
  11782. StringBuilder sql = new StringBuilder();
  11783. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo from view_ErpTradeCell where SupplierId={0} and orderstate=6", entity.SupplierId);
  11784. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  11785. {
  11786. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  11787. }
  11788. else
  11789. {
  11790. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  11791. }
  11792. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11793. List<string> ids = new List<string>();
  11794. if (dt != null && dt.Rows.Count > 1)
  11795. {
  11796. bool needhe = true;
  11797. foreach (DataRow dr in dt.Rows)
  11798. {
  11799. ids.Add("'" + dr["ctid"] + "'");
  11800. /* //备注有合包
  11801. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  11802. {
  11803. needhe = true;
  11804. }
  11805. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  11806. {
  11807. needhe = true;
  11808. }
  11809. //顺丰快递
  11810. if (Convert.ToInt32(dr["IsSF"]) > 0)
  11811. {
  11812. needhe = true;
  11813. }*/
  11814. }
  11815. if (!needhe)
  11816. {
  11817. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11818. return;
  11819. }
  11820. sql = new StringBuilder();
  11821. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  11822. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  11823. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  11824. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11825. foreach (DataRow dr in dt.Rows)
  11826. {
  11827. dr["dstate"] = 0;
  11828. dr["dnumber"] = 0;
  11829. foreach (DataRow row in dt1.Rows)
  11830. {
  11831. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  11832. {
  11833. dr["dstate"] = 2;
  11834. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  11835. }
  11836. }
  11837. if (eid.Equals(dr["ctid"].ToString()))
  11838. {
  11839. dr["dstate"] = 1;
  11840. }
  11841. }
  11842. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  11843. return;
  11844. }
  11845. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11846. return;
  11847. }
  11848. returnErrorMsg("未找到订单");
  11849. return;
  11850. }
  11851. returnErrorMsg("缺少必要的参数");
  11852. }
  11853. public void get_mark_number()
  11854. {
  11855. string eid = GetPostString("ctid");
  11856. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  11857. if (entity != null)
  11858. {
  11859. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  11860. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  11861. int current = 1;
  11862. if (ceErpDeliverMark == null)
  11863. {
  11864. StringBuilder sql = new StringBuilder();
  11865. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo from view_ErpTradeCell where SupplierId={0} and orderstate=6", entity.SupplierId);
  11866. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  11867. {
  11868. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  11869. }
  11870. else
  11871. {
  11872. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  11873. }
  11874. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11875. List<string> ids = new List<string>();
  11876. if (dt != null && dt.Rows.Count > 1)
  11877. {
  11878. foreach (DataRow dr in dt.Rows)
  11879. {
  11880. ids.Add("'" + dr["ctid"] + "'");
  11881. }
  11882. //查询已有的编号
  11883. sql = new StringBuilder();
  11884. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  11885. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11886. if (dt1 == null || dt1.Rows.Count == 0)
  11887. {
  11888. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  11889. List<int> list_number = new List<int>();
  11890. foreach (DataRow row in numbers.Rows)
  11891. {
  11892. list_number.Add(Convert.ToInt32(row["markNumber"]));
  11893. }
  11894. //查询空余编号
  11895. for (int i = 0; i < list_number.Count + 2; i++)
  11896. {
  11897. if (!list_number.Contains(current))
  11898. {
  11899. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  11900. //防止查询过程中有新数据生成
  11901. if (ceErpDeliverMark1 == null)
  11902. {
  11903. break;
  11904. }
  11905. }
  11906. current++;
  11907. }
  11908. }
  11909. else
  11910. {
  11911. foreach (DataRow row in dt1.Rows)
  11912. {
  11913. current = Convert.ToInt32(row["markNumber"]);
  11914. }
  11915. }
  11916. ceErpDeliverMark = new CeErpDeliverMark();
  11917. ceErpDeliverMark.ctid = eid;
  11918. ceErpDeliverMark.createtime = DateTime.Now;
  11919. if (ceErpTrade != null)
  11920. {
  11921. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  11922. }
  11923. ceErpDeliverMark.markNumber = current;
  11924. ceErpDeliverMark.Create();
  11925. }
  11926. }
  11927. else
  11928. {
  11929. current = ceErpDeliverMark.markNumber;
  11930. }
  11931. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  11932. return;
  11933. }
  11934. }
  11935. }
  11936. }