sync.order.cs 657 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047
  1. using BizCom;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using NHibernate.Linq;
  5. using NHibernate.Mapping;
  6. using NPOI.OpenXmlFormats.Dml.Diagram;
  7. using NPOI.OpenXmlFormats.Shared;
  8. using NPOI.SS.Formula.Eval;
  9. using NPOI.SS.Formula.Functions;
  10. using NPOI.SS.Formula.Udf;
  11. using SiteCore.Redis;
  12. using SiteCore.taobao;
  13. using SiteCore.taoObj;
  14. using SQLData;
  15. using System;
  16. using System.Collections;
  17. using System.Collections.Generic;
  18. using System.ComponentModel.Design;
  19. using System.Data;
  20. using System.Data.SqlClient;
  21. using System.Data.SqlTypes;
  22. using System.Diagnostics;
  23. using System.Drawing;
  24. using System.Drawing.Drawing2D;
  25. using System.IO;
  26. using System.Linq;
  27. using System.Net;
  28. using System.Net.Security;
  29. using System.Reflection.Emit;
  30. using System.Security.Cryptography;
  31. using System.Security.Cryptography.X509Certificates;
  32. using System.Security.Policy;
  33. using System.Text;
  34. using System.Text.RegularExpressions;
  35. using System.Threading;
  36. using System.Web.UI;
  37. using System.Web;
  38. using System.Web.UI.WebControls;
  39. using Utils;
  40. using Utils.Serialization;
  41. using static NHibernate.Linq.Visitors.LeftJoinDetector;
  42. using static SiteCore.taoObj.Api_trade_info;
  43. using static SiteCore.taoObj.Api_waybill_code_response_Obj;
  44. using static SiteCore.taoObj.work_core_vo;
  45. using static System.Net.Mime.MediaTypeNames;
  46. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  47. using NPOI.Util;
  48. using static NPOI.HSSF.Util.HSSFColor;
  49. using BizCom.Enum;
  50. using NPOI.POIFS.Properties;
  51. using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;
  52. using static SiteCore.taoObj.Api_tmc_refund_info_Obj;
  53. namespace SiteCore.Handler
  54. {
  55. public partial class sync
  56. {
  57. public void get_erp_orderlist()
  58. {
  59. string poscode = CurrentUser.UserPost.Post.Code;
  60. DataStruct dStruct = GetPostStruct();
  61. //string a = SecurityHelper.DecryptSymmetric("YDaPXIhsKgw=");
  62. //jiemiUtils.ossFileDecrypt("C:\\Users\\231010\\Downloads\\领淘文件名命名规范.xls");
  63. //apiHelper.Api_SyncOrderByTime("598825");
  64. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  65. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  66. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  67. //banniuApiHelper.sendLogisticsInfo(null);
  68. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  69. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  70. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2811249339088067154");
  71. //int sid = commonHelper.autoDistributeToSupplier(entity);
  72. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  73. //tmcHelper.Api_TmcTradeMsg("{\"content\":{\"businessType\":\"GUARANTEE\",\"buyerMemo\":\"\",\"consolidateType\":\"\",\"createTime\":1756945416000,\"deliveryType\":\"OFFLINE\",\"discountFee\":20.0,\"flag\":\"NONE\",\"latestDeliveryTime\":1757118213000,\"lines\":[{\"latestDeliveryTime\":1757118213000,\"mark2\":[\"DELIVERED\"],\"num\":1,\"outerId\":\"JSBHUVZYT\",\"payment\":10.0,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i2/490100363/O1CN01pEaojF1EYIjYhp76h_!!490100363.jpg\",\"platServiceFee\":0.0,\"price\":30.0,\"refOlId\":\"4718408366815008220\",\"refSkuId\":\"5139754537453\",\"refSpuId\":\"641811002682\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":10.0,\"singleFee\":10.0,\"spuOuterId\":\"JSBHUVZYT\",\"standards\":\"【撕膜留字 | 易撕无残留】\",\"status\":\"SHIPPED\",\"title\":\"水晶标贴UV转印贴logo定制透明标识贴纸设计金属商标烫金标签定做\",\"totalFee\":10.0,\"totalPrice\":30.0,\"totalSellPrice\":10.0}],\"logisticsOrderNo\":\"YT7568465598389\",\"mark2\":[],\"modifyTime\":1756946987000,\"openBuyerId\":\"AAEVRHraABkUZRPgSx3gFRIR\",\"openBuyerNick\":\"a**\",\"openSellerNick\":\"琳19890725\",\"orderSource\":\"SYNC\",\"orderTime\":1756945412000,\"payTime\":1756945413000,\"payment\":10.0,\"platServiceFee\":0.0,\"posCode\":\"guliang\",\"posId\":598696,\"postFee\":0.0,\"props\":{\"payType\":\"ALI_PAY\",\"govSubsidyAmount\":0,\"logisticList\":[{\"logisticNo\":\"YT7568465598389\",\"logisticName\":\"圆通速递\"}]},\"receivedPayment\":0.0,\"receiverCity\":\"苏州市\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"吴江区\",\"receiverId\":\"871dbaa880a955e031c5061436d7a5c1$\",\"receiverState\":\"江苏省\",\"receiverTown\":\"江陵街道\",\"refOid\":\"4718408366815008220\",\"refType\":\"TMALL\",\"refundStatus\":\"NO_REFUND\",\"sellerMemo\":\"寄样-不干胶-uv转印贴小尺寸字母银色黑色-aa_小f-龙井-5,寄样-不干胶-金属标字母银色黑色-aa_小f-龙井-5\",\"serviceFee\":0.0,\"shippingTime\":1756946983000,\"status\":\"SHIPPED\",\"sysTags\":[],\"totalFee\":10.0,\"totalPrice\":30.0,\"totalSellPrice\":10.0,\"type\":\"SALE\"}}");
  74. //refundTmcHelper.Api_TmcRefundMsg("{\"content\":{\"afterStatus\":\"SUCCESS\",\"createTime\":1735287446000,\"desc\":\"\",\"interceptInvestor\":\"NONE\",\"interceptStatus\":\"NONE\",\"interceptType\":\"NONE\",\"lines\":[{\"num\":2,\"outerId\":\"\",\"price\":50.0,\"refAid\":\"313001208133750610\",\"refAlId\":\"313001208133750610\",\"refBoughtSkuId\":\"\",\"refOid\":\"4181722704291751006\",\"refOlId\":\"4181722704291751006\",\"refSkuId\":\"0\",\"refSpuId\":\"865893808768\",\"refundFee\":98.86,\"refundStatus\":\"SUCCESS\",\"title\":\"新年会抽奖券定制2025蛇年公司活动正副可撕代金券打印纪念票根奖品兑换尾牙晚宴邀请卡号码牌创意入场券设计\",\"totalFee\":98.86,\"type\":1}],\"logisticsCompany\":\"\",\"logisticsOrderNo\":\"\",\"mark2\":[],\"openBuyerNick\":\"0**\",\"openSellerNick\":\"万慕办公旗舰店\",\"posCode\":\"wanmu\",\"posId\":598798,\"reason\":\"订单信息拍错(规格/尺码/颜色等)\",\"receiverCity\":\"\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"\",\"receiverId\":\"\",\"receiverState\":\"\",\"receiverTown\":\"\",\"receiverZip\":\"\",\"refAid\":\"313001208133750610\",\"refOid\":\"4181722704291751006\",\"refPlatform\":\"TB\",\"refType\":\"TMALL\",\"refundCreateTime\":1735287358000,\"refundFee\":\"98.86\",\"refundPhase\":\"ON_SALE\",\"refundTime\":1735289443000,\"refundUpdateTime\":1735289443000,\"refundVersion\":1735287358100,\"senderAddress\":\"\",\"senderCity\":\"\",\"senderCountry\":\"中国\",\"senderDistrict\":\"\",\"senderMobile\":\"\",\"senderName\":\"\",\"senderPhone\":\"\",\"senderState\":\"\",\"senderTown\":\"\",\"senderZip\":\"\",\"status\":\"SUCCESS\",\"statusCode\":\"SUCCESS\",\"statusName\":\"退款成功\",\"totalFee\":\"98.86\",\"type\":\"REFUND\",\"updateTime\":1735289479000}}");
  75. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  76. //string res = apiHelper.API_GetWaybill("YTO-PDD-CYT", "250703-469248284251412");
  77. //preSalesHelper.dealMessageInfo("{\"bizOrder\":{\"id\":235819,\"parentId\":null,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderNo\":\"4624034580248409502\",\"shopId\":4,\"shopCode\":\"aolifu\",\"customerId\":345874,\"customerServiceId\":3184,\"thirdOrderId\":\"4624034580248409502\",\"orderPlatform\":\"TMALL\",\"openBuyerId\":\"AAEORHraABkUZRHgSx6ksuhU\",\"openBuyerNick\":\"tb278604202340\",\"openSellerNick\":\"奥丽芙旗舰店\",\"productUrl\":null,\"totalPrice\":130.0,\"totalSellPrice\":125.0,\"payAmount\":125.0,\"unrefundedAmount\":125.0,\"discountAmount\":5.0,\"csDiscountAmount\":-35.0,\"num\":13,\"province\":\"山西省\",\"city\":\"吕梁市\",\"area\":\"孝义市\",\"receiverTown\":\"孝义市\",\"address\":null,\"thirdReceiverId\":\"4679677a0c7af72f1e8d0e672d57c575$\",\"receiverName\":null,\"receiverMobile\":null,\"weChatId\":null,\"phone\":null,\"designContent\":\"\",\"designPics\":\"[]\",\"weChatQrPics\":\"[]\",\"addressFileUrl\":\"\",\"thirdFlag\":\"NONE\",\"remark\":null,\"sellerRemark\":\"\",\"buyerRemark\":\"\",\"timeoutRemark\":null,\"discountRemark\":null,\"status\":\"NOT_SHIPPED\",\"refundStatus\":0,\"internalStatus\":2,\"auditStatus\":null,\"auditUserId\":null,\"auditor\":null,\"customTag\":null,\"isRepurchase\":false,\"isOffline\":false,\"paymentFile\":null,\"orderTime\":\"2025-07-10 14:46:13\",\"modifyTime\":\"2025-07-10 14:46:37\",\"payTime\":\"2025-07-10 14:46:37\",\"confirmTime\":\"2025-07-10 14:51:23\",\"auditTime\":null,\"shippingTime\":null,\"finishTime\":null,\"erpCustomerServiceId\":3319,\"openBuyerID\":\"AAEORHraABkUZRHgSx6ksuhU\",\"orderFrom\":\"10\",\"receiverId\":\"4679677a0c7af72f1e8d0e672d57c575$\",\"bizOrderItems\":[{\"id\":310334,\"orderId\":235819,\"thirdOrderItemId\":\"4624034580248409502\",\"thirdSpuId\":\"740203900330\",\"thirdSkuId\":\"0\",\"title\":\"pvc贴纸定制防水不干胶圆形贴标自粘商标logo广告二维码标签印刷\",\"specification\":\"\",\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/2433960672/O1CN01D0ZzzR1GppCHSoBjD_!!4611686018427382496-0-item_pic.jpg\",\"price\":10.0,\"sellPrice\":9.62,\"amount\":9.62,\"totalPrice\":130.0,\"totalSellPrice\":125.0,\"totalAmount\":125.0,\"num\":13,\"refundStatus\":\"NO_REFUND\"}],\"bizOrderSplits\":[{\"id\":151557,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderId\":235819,\"bizOrderNo\":\"4624034580248409502\",\"spuId\":\"740203900330\",\"customerId\":345874,\"designerId\":null,\"uniqueNo\":\"250710145121328848\",\"splitNo\":\"C1_4624034580248409502\",\"splitInfoNo\":\"C2+1\",\"splitAmount\":52.64,\"quoteRecordId\":520208,\"quoteAmount\":40.0,\"parentSplitNo\":null,\"compensateAmount\":0,\"internalStatus\":2,\"designStatus\":null,\"errorStatus\":0,\"errorReason\":null,\"backTime\":null,\"syncErpFlag\":0,\"syncErpMsg\":null,\"designTimeoutType\":null,\"isToDesignSys\":false,\"isSpot\":false,\"isRepurchase\":false,\"isGift\":0,\"isUrgent\":false,\"isCombinedShipping\":false,\"designEstimateTime\":null,\"designFinishTime\":null,\"shippingTime\":null,\"finalDraftTime\":null,\"sampleMark\":0,\"sfMark\":0,\"wechatMark\":0,\"sendGiftMark\":0,\"addWechatMark\":0,\"otherMark\":null,\"systemRemark\":\"(250710145121328848)-[C2+1]-80x20mm-200张-铜版纸不干胶覆亮膜模切\",\"otherRemark\":\"-老客户改稿 之前下单号:13935850820ma\",\"followOrderRemark\":null,\"timeoutRemark\":null,\"workshopNote\":\"\",\"isPreShipping\":0,\"workOrderFiles\":null,\"checkOrderTime\":null,\"refundStatus\":0,\"refundAmount\":0.0,\"afterSaleStatus\":0,\"afterSaleReason\":null,\"afterSalePayAmount\":null,\"afterSalePics\":null,\"afterSaleBackPics\":null,\"afterSaleBackReason\":null,\"afterSaleMethod\":null,\"afterSaleRemark\":null,\"afterSaleTime\":null,\"afterSaleFinishTime\":null,\"erpCustomerServiceId\":3319,\"OrderSn\":\"250710145121328848\",\"orderFrom\":\"10\",\"ptid\":\"4624034580248409502\",\"offerAmount\":40.0,\"paymentFile\":null,\"cate1Id\":\"770260a9d3ee11efba6a00163e010e55\",\"cate1\":\"不干胶\",\"cate2Id\":\"77026444d3ee11efba6a00163e010e55\",\"cate2\":\"平张不干胶\",\"cate3Id\":\"7702655dd3ee11efba6a00163e010e55\",\"productCategory\":\"铜版纸不干胶\",\"sceneId\":0,\"scene\":\"合版印刷\",\"materialId\":15,\"material\":\"铜版纸不干胶\",\"craft\":\"[{\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 11, \\\"productCraftName\\\": \\\"覆亮膜\\\"}, {\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 163, \\\"productCraftName\\\": \\\"模切\\\"}]\",\"numbers\":1,\"opSceneId\":\"\",\"opScene\":\"\",\"length\":80.00,\"width\":20.00,\"height\":0,\"recSize\":\"\",\"sizeUnit\":\"mm\",\"size\":\"80x20mm\",\"numberUnit\":\"张\",\"quantity\":200,\"productQuantity\":\"200张\",\"discountAmount\":40.00,\"numberType\":\"\",\"isDianziOrder\":0},{\"id\":151558,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderId\":235819,\"bizOrderNo\":\"4624034580248409502\",\"spuId\":\"740203900330\",\"customerId\":345874,\"designerId\":null,\"uniqueNo\":\"250710145121328853\",\"splitNo\":\"C2_4624034580248409502\",\"splitInfoNo\":\"C2+2\",\"splitAmount\":72.36,\"quoteRecordId\":520209,\"quoteAmount\":55.0,\"parentSplitNo\":null,\"compensateAmount\":0,\"internalStatus\":2,\"designStatus\":null,\"errorStatus\":0,\"errorReason\":null,\"backTime\":null,\"syncErpFlag\":0,\"syncErpMsg\":null,\"designTimeoutType\":null,\"isToDesignSys\":false,\"isSpot\":false,\"isRepurchase\":false,\"isGift\":0,\"isUrgent\":false,\"isCombinedShipping\":false,\"designEstimateTime\":null,\"designFinishTime\":null,\"shippingTime\":null,\"finalDraftTime\":null,\"sampleMark\":0,\"sfMark\":0,\"wechatMark\":0,\"sendGiftMark\":0,\"addWechatMark\":0,\"otherMark\":null,\"systemRemark\":\"(250710145121328853)-[C2+2]-90x50mm-200张-铜版纸不干胶覆亮膜模切\",\"otherRemark\":\"-老客户改稿 之前下单号:13935850820ma\",\"followOrderRemark\":null,\"timeoutRemark\":null,\"workshopNote\":\"\",\"isPreShipping\":0,\"workOrderFiles\":null,\"checkOrderTime\":null,\"refundStatus\":0,\"refundAmount\":0.0,\"afterSaleStatus\":0,\"afterSaleReason\":null,\"afterSalePayAmount\":null,\"afterSalePics\":null,\"afterSaleBackPics\":null,\"afterSaleBackReason\":null,\"afterSaleMethod\":null,\"afterSaleRemark\":null,\"afterSaleTime\":null,\"afterSaleFinishTime\":null,\"erpCustomerServiceId\":3319,\"OrderSn\":\"250710145121328853\",\"orderFrom\":\"10\",\"ptid\":\"4624034580248409502\",\"offerAmount\":55.0,\"paymentFile\":null,\"cate1Id\":\"770260a9d3ee11efba6a00163e010e55\",\"cate1\":\"不干胶\",\"cate2Id\":\"77026444d3ee11efba6a00163e010e55\",\"cate2\":\"平张不干胶\",\"cate3Id\":\"7702655dd3ee11efba6a00163e010e55\",\"productCategory\":\"铜版纸不干胶\",\"sceneId\":0,\"scene\":\"合版印刷\",\"materialId\":15,\"material\":\"铜版纸不干胶\",\"craft\":\"[{\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 11, \\\"productCraftName\\\": \\\"覆亮膜\\\"}, {\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 163, \\\"productCraftName\\\": \\\"模切\\\"}]\",\"numbers\":1,\"opSceneId\":\"\",\"opScene\":\"\",\"length\":90.00,\"width\":50.00,\"height\":0,\"recSize\":\"\",\"sizeUnit\":\"mm\",\"size\":\"90x50mm\",\"numberUnit\":\"张\",\"quantity\":200,\"productQuantity\":\"200张\",\"discountAmount\":55.00,\"numberType\":\"\",\"isDianziOrder\":0}]}}");
  78. /*string path = "C:\\Users\\231010\\Downloads\\tids.txt";
  79. string path1 = "C:\\Users\\231010\\Downloads\\tid.txt";
  80. string tids = File.ReadAllText(path);
  81. List<string> list = tids.Split(',').ToList();
  82. int index = 0;
  83. foreach (string item in list)
  84. {
  85. CeErpTrade ceErpTrade = CeErpTrade.Get(item.Replace("'", ""));
  86. try
  87. {
  88. string sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WITH(NOLOCK) WHERE (buyer_nick = '{0}' or buyer_id = '{1}' ) and status = 'COMPLETE' and seller_nick = '{2}' and tid <> '{3}' AND end_time < '{4}' and payment >= 20", ceErpTrade.buyer_nick, ceErpTrade.buyer_id, ceErpTrade.seller_nick, ceErpTrade.tid, ceErpTrade.pay_time);
  89. if (string.IsNullOrEmpty(ceErpTrade.buyer_nick))
  90. {
  91. sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WITH(NOLOCK) WHERE (buyer_id = '{1}' ) and status = 'COMPLETE' and seller_nick = '{2}' and tid <> '{3}' AND end_time < '{4}' and payment >= 20", ceErpTrade.buyer_nick, ceErpTrade.buyer_id, ceErpTrade.seller_nick, ceErpTrade.tid, ceErpTrade.pay_time);
  92. }
  93. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  94. List<string> tidList = new List<string>();
  95. if (dataTable != null && dataTable.Rows.Count > 0)
  96. {
  97. foreach (DataRow row in dataTable.Rows)
  98. {
  99. tidList.Add("'" + row["tid"].ToString() + "'");
  100. }
  101. }
  102. if (tidList.Count > 0)
  103. {
  104. sql = string.Format("SELECT count(*) as number FROM [dbo].[CE_ErpTradeCell] WITH(NOLOCK) WHERE tid in ({0}) AND IsSample = 0 ", string.Join(",", tidList));
  105. dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  106. if (dataTable != null && dataTable.Rows.Count > 0)
  107. {
  108. int count = Convert.ToInt32(dataTable.Rows[0]["number"]);
  109. if (count > 0)
  110. {
  111. Debug.WriteLine(index++);
  112. continue;
  113. }
  114. }
  115. }
  116. File.AppendAllText(path1, ceErpTrade.tid + "\n");
  117. }
  118. catch (Exception e)
  119. {
  120. File.AppendAllText(path1, "e:" + ceErpTrade.tid + "\n");
  121. }
  122. Debug.WriteLine(index++);
  123. }*/
  124. //string a = commonHelper.convertQNMemo("48x61mm-4款各40个-铜版纸-不干胶-覆膜模切-tb963561715-金陵-顺丰到付.粘成品.6.5cm牙签-老客户改稿找金陵拉群-16发", CeErpTradeCell.GetByCtid("2879265072537265386"));
  125. List<string> lw = new List<string>();
  126. string tid = GetPostString("ctid");
  127. string date1 = GetPostString("date1");
  128. //12-1 修改
  129. string urgent = GetPostString("urgent");
  130. string back = GetPostString("back");
  131. string offlineSearch = GetPostString("offlineSearch");
  132. int paramsCount = 0;
  133. if (!string.IsNullOrWhiteSpace(urgent))
  134. {
  135. if (urgent.Equals("true"))
  136. {
  137. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  138. }
  139. }
  140. if (!string.IsNullOrWhiteSpace(back))
  141. {
  142. if (back.Equals("true"))
  143. {
  144. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  145. }
  146. }
  147. if (!string.IsNullOrWhiteSpace(offlineSearch))
  148. {
  149. if (offlineSearch.Equals("true"))
  150. {
  151. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  152. }
  153. }
  154. //end
  155. string date2 = GetPostString("date2");
  156. string buyernick = GetPostString("buyer_nick");
  157. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  158. {
  159. if (tid.Length <= 0 && buyernick.Length <= 0)
  160. {
  161. return;
  162. }
  163. }
  164. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  165. {
  166. if (tid.Length > 0)
  167. {
  168. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(tid);
  169. if (ceErpTradeCell != null)
  170. {
  171. tid = ceErpTradeCell.tid;
  172. }
  173. List<string> select_tid = getTidByCtidMore(tid);
  174. lw.Add(string.Format("tid in ({0})", string.Join(",", select_tid)));
  175. }
  176. if (buyernick.Length > 0)
  177. {
  178. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  179. }
  180. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  181. if (dw.Length > 0)
  182. {
  183. lw.Add(dw);
  184. }
  185. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  186. {
  187. string usershop = CurrentUser.User.pemShop;
  188. lw.Add(string.Format("ShopId in ({0})", usershop));
  189. }
  190. }
  191. else
  192. {
  193. if (ex_psize == 0)
  194. {
  195. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  196. }
  197. if (PKey != "admin" && poscode != "SysAdmin")
  198. {
  199. string usershop = CurrentUser.User.pemShop;
  200. lw.Add(string.Format("ShopId in ({0})", usershop));
  201. paramsCount++;
  202. }
  203. }
  204. string uploaddate1 = GetPostString("uploaddate1");
  205. string uploaddate2 = GetPostString("uploaddate2");
  206. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  207. if (update.Length > 0) lw.Add(update);
  208. string deliverydate1 = GetPostString("deliverydate1");
  209. string deliverydate2 = GetPostString("deliverydate2");
  210. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  211. if (deliverydate.Length > 0)
  212. {
  213. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  214. };
  215. string shopname = GetPostString("shopname");
  216. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  217. string addwechat = GetPostString("addwechat");
  218. if (addwechat.Length > 0)
  219. {
  220. int addWt = Convert.ToInt32(addwechat);
  221. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  222. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  223. }
  224. string customer = GetPostString("customer");
  225. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  226. string design = GetPostString("design");
  227. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  228. string orderState = GetPostString("orderState");
  229. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  230. string address = GetPostString("address");
  231. 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));
  232. string sellermemo = GetPostString("seller_memo");
  233. if (sellermemo.Length > 0)
  234. {
  235. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  236. }
  237. string backReason = GetPostString("backReason");
  238. if (backReason.Length > 0)
  239. {
  240. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  241. }
  242. string apdate1 = GetPostString("apdate1");
  243. string apdate2 = GetPostString("apdate2");
  244. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  245. if (dwap.Length > 0) lw.Add(dwap);
  246. string price1 = GetPostString("price1");
  247. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  248. string price2 = GetPostString("price2");
  249. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  250. string isoldcustomer = GetPostString("isoldcus");
  251. string spudata = GetPostString("spudata");
  252. if ("0".Equals(spudata))
  253. {
  254. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  255. }
  256. if ("1".Equals(spudata))
  257. {
  258. lw.Add(string.Format("spu_id <> ''"));
  259. }
  260. string finishdate1 = GetPostString("finishdate1");
  261. string finishdate2 = GetPostString("finishdate2");
  262. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  263. bool isFinish = false;
  264. if (finishdate.Length > 0)
  265. {
  266. lw.Add(finishdate);
  267. isFinish = true;
  268. paramsCount++;
  269. }
  270. if (isoldcustomer.Length > 0)
  271. {
  272. if ("2".Equals(isoldcustomer))
  273. {
  274. lw.Add(string.Format("VipCustomer=1"));
  275. }
  276. else
  277. {
  278. lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  279. }
  280. }
  281. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  282. if (ex_psize > 0)
  283. {
  284. int UserID = CurrentUser.UserID;
  285. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  286. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  287. {
  288. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  289. }
  290. dStruct.Order = "pay_time desc";
  291. }
  292. string isNew = GetPostString("isNew");
  293. if (isNew == "true")
  294. {
  295. lw.Add(string.Format("IsNew = {0}", 1));
  296. }
  297. string overtime = GetPostString("overtime");
  298. if (overtime == "1")
  299. {
  300. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  301. }
  302. String usePost = CurrentUser.UserPost.Post.Code;
  303. if (usePost.Equals("Operation") == true)
  304. {
  305. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  306. }
  307. else
  308. {
  309. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  310. }
  311. //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";
  312. if (dStruct.PageSize == 100000)
  313. {
  314. dStruct.Order = "";
  315. }
  316. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  317. DataTable dt = null;
  318. string tablename = "view_orderlist";
  319. if (isFinish)
  320. {
  321. tablename = "view_orderlist_end";
  322. }
  323. dt = WebCache.GetData(tablename, dStruct);
  324. if (dt != null && dt.Rows.Count > 0)
  325. {
  326. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  327. foreach (DataRow dr in dt.Rows)
  328. {
  329. try
  330. {
  331. if (dr["refund_fees"] != null)
  332. {
  333. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  334. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  335. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  336. if (payment == refund_fees)
  337. {
  338. dr["refund_fees"] = Math.Round(refund_fees, 2);
  339. }
  340. else if (refund_fees == total_fee)
  341. {
  342. dr["refund_fees"] = payment;
  343. }
  344. else
  345. {
  346. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  347. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  348. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  349. }
  350. }
  351. // 对象操作
  352. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  353. ceErpTradeCell.ctid = dr["ctid"].ToString();
  354. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  355. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  356. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  357. if (dStruct.PageSize != 100000)
  358. {
  359. if (dr["DispatchSort"].ToString() == "2")
  360. {
  361. dr["gongchuang"] = 200;
  362. }
  363. else if ("外协".Equals(dr["ToType"].ToString()))
  364. {
  365. dr["gongchuang"] = 200;
  366. }
  367. else if ("内部".Equals(dr["ToType"].ToString()))
  368. {
  369. dr["gongchuang"] = -1;
  370. }
  371. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  372. {
  373. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  374. dr["gongchuang"] = response.code;
  375. }
  376. }
  377. }
  378. catch (NullReferenceException ex)
  379. {
  380. // 处理空引用异常
  381. dr["refund_fees"] = "0.00";
  382. }
  383. }
  384. }
  385. writeGridDataTableJson(dStruct.TotalCount, dt);
  386. }
  387. public void get_erp_orderlist_sumprice()
  388. {
  389. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  390. return;
  391. List<string> lw = new List<string>();
  392. string tid = GetPostString("ctid");
  393. string date1 = GetPostString("date1");
  394. string date2 = GetPostString("date2");
  395. if (tid.Length > 0 || date1.Length > 0)
  396. {
  397. lw.Add(string.Format("ctid like '%{0}%'", tid));
  398. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  399. if (dw.Length > 0) lw.Add(dw);
  400. }
  401. else
  402. {
  403. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  404. }
  405. string shopname = GetPostString("shopname");
  406. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  407. string buyernick = GetPostString("buyer_nick");
  408. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  409. string customer = GetPostString("customer");
  410. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  411. string design = GetPostString("design");
  412. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  413. string orderState = GetPostString("orderState");
  414. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  415. string address = GetPostString("address");
  416. 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));
  417. string sellermemo = GetPostString("seller_memo");
  418. if (sellermemo.Length > 0)
  419. {
  420. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  421. }
  422. string apdate1 = GetPostString("apdate1");
  423. string apdate2 = GetPostString("apdate2");
  424. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  425. if (dwap.Length > 0) lw.Add(dwap);
  426. string price1 = GetPostString("price1");
  427. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  428. string price2 = GetPostString("price2");
  429. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  430. string isoldcustomer = GetPostString("isoldcus");
  431. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  432. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  433. if (PKey != "admin")
  434. {
  435. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  436. lw.Add(string.Format("shopId in ({0})", usershop));
  437. }
  438. //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";
  439. string mainWhere = string.Join(" and ", lw.ToArray());
  440. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  441. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  442. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  443. decimal total = 0;
  444. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  445. {
  446. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  447. }
  448. var res = new
  449. {
  450. data = total
  451. };
  452. string ro_jsond = JsonConvert.SerializeObject(res);
  453. returnSuccess(ro_jsond);
  454. return;
  455. }
  456. public void get_erp_CustomerServiceGather()
  457. {
  458. string userWhere = "", orderWhere = "";
  459. List<string> lw = new List<string>();
  460. string customer = GetPostString("customer");
  461. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  462. string shopname = GetPostString("shopname");
  463. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  464. string date1 = GetPostString("date1");
  465. string date2 = GetPostString("date2");
  466. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  467. if (dw.Length > 0) lw.Add(dw);
  468. orderWhere = string.Join(" and ", lw.ToArray());
  469. 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 " +
  470. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  471. "left join " +
  472. "( " +
  473. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  474. ") as b on a.ID = b.CustomerUserId " +
  475. "left join " +
  476. "( " +
  477. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  478. ") as d on a.ID = d.CustomerUserId " +
  479. "left join " +
  480. "( " +
  481. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  482. ") as e on a.ID = e.CustomerUserId " +
  483. "left join " +
  484. "( " +
  485. " select CustomerUserId, RefundCount, RefundSum from " +
  486. " ( " +
  487. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  488. " from CE_ErpTradeRefund a " +
  489. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  490. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  491. " group by CustomerUserId " +
  492. " ) as a " +
  493. ") as f on a.ID = f.CustomerUserId " +
  494. "where a.PostCode = 'CustomerService'",
  495. userWhere, orderWhere);
  496. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  497. writeGridDataTableJson(dt.Rows.Count, dt);
  498. //writeGridDataTableJson(dt.Rows.Count, dt);
  499. }
  500. //设计汇总
  501. public void get_erp_DesignerGather()
  502. {
  503. string userWhere = "", orderWhere = "";
  504. List<string> lw = new List<string>();
  505. string Designer = GetPostString("designer");
  506. int org = GetPostInt("org");
  507. if (Designer.Length > 0)
  508. {
  509. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  510. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  511. }
  512. else if (org > 0)
  513. {
  514. userWhere = string.Format(" where OrgID ={0}", org);
  515. }
  516. string shopname = GetPostString("shopname");
  517. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  518. string state = GetPostString("state");
  519. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  520. string OrderArea = GetPostString("order_area");
  521. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  522. string date1 = GetPostString("date1");
  523. string date2 = GetPostString("date2");
  524. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  525. if (dw.Length > 0) lw.Add(dw);
  526. string UpDate1 = GetPostString("UpDate1");
  527. string UpDate2 = GetPostString("UpDate2");
  528. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  529. if (dw.Length > 0) lw.Add(dw);
  530. orderWhere = string.Join(" and ", lw.ToArray());
  531. 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 (" +
  532. "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 " +
  533. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  534. "left join " +
  535. "( " +
  536. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  537. ") as b on a.ID = b.DesignUserId " +
  538. "left join " +
  539. "( " +
  540. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  541. ") as d on a.ID = d.DesignUserId " +
  542. "left join " +
  543. "( " +
  544. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  545. ") as e on a.ID = e.DesignUserId " +
  546. "left join " +
  547. "( " +
  548. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  549. ") as g on a.ID = g.DesignUserId " +
  550. "left join " +
  551. "( " +
  552. " select CustomerUserId, RefundCount, RefundSum from " +
  553. " ( " +
  554. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  555. " from CE_ErpTradeRefund a " +
  556. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  557. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  558. " group by CustomerUserId " +
  559. " ) as a " +
  560. ") as f on a.ID = f.CustomerUserId " +
  561. "where a.PostCode = 'Designer') as z",
  562. userWhere, orderWhere);
  563. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  564. writeGridDataTableJson(dt.Rows.Count, dt);
  565. }
  566. //删除tradecell的订单
  567. public void del_erp_cellorder()
  568. {
  569. if (UrlPostParmsCheck("ctid"))
  570. {
  571. string eid = GetPostString("ctid");
  572. CeErpTradeCell.DelByCtid(eid);
  573. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  574. returnSuccessMsg("删除成功");
  575. }
  576. }
  577. public void clear_erp_refundstate()
  578. {
  579. if (UrlPostParmsCheck("ids"))
  580. {
  581. string eids = GetPostString("ids");
  582. string[] ctidList = eids.Split(',');
  583. foreach (string ctid in ctidList)
  584. {
  585. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  586. if (entity != null)
  587. {
  588. entity.IsRefund = 0;
  589. entity.Update();
  590. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  591. }
  592. else
  593. continue;
  594. }
  595. returnSuccessMsg("操作成功");
  596. return;
  597. }
  598. returnErrorMsg("缺少必要参数");
  599. }
  600. public void set_erp_urgency()
  601. {
  602. if (UrlPostParmsCheck("ctid"))
  603. {
  604. string eid = GetPostString("ctid");
  605. CeErpTradeCell entity = null;
  606. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  607. if (entity != null)
  608. {
  609. double prices = commonHelper.calculationPrice(entity);
  610. if (prices <= 100)
  611. {
  612. returnErrorMsg("此订单金额不足100元,无法加急。");
  613. return;
  614. }
  615. string utime = GetPostString("urgencytime");
  616. if (utime.Length > 0)
  617. {
  618. entity.UrgencyTime = Convert.ToDateTime(utime);
  619. }
  620. else
  621. {
  622. returnErrorMsg("请选择加急时间");
  623. return;
  624. }
  625. if (entity.OrderState <= 4)
  626. {
  627. //entity.seller_memo = entity.seller_memo + "-加急";
  628. string smemo = entity.seller_memo;
  629. int kindex = smemo.IndexOf(")");
  630. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  631. if (lastoneStr != "-")
  632. {
  633. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  634. }
  635. string prememo = smemo.Substring(0, kindex + 2);
  636. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  637. int lastkindex = lastmemo.IndexOf("(");
  638. DateTime urgtime = Convert.ToDateTime(utime);
  639. string newlastmemo = "";
  640. if (lastkindex == 0)
  641. {
  642. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  643. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  644. }
  645. else
  646. {
  647. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  648. }
  649. entity.seller_memo = prememo + newlastmemo;
  650. }
  651. entity.IsUrgency = true;
  652. entity.UpdateTime = DateTime.Now;
  653. entity.Update();
  654. ApiVo apiVo = new ApiVo();
  655. apiVo.orderNumber = entity.ctid;
  656. apiVo.actionName = "changeDesign";
  657. apiVo.orderRemarks = entity.seller_memo;
  658. apiVo.remarkSign = 3;
  659. designHelper.API_WorkCore(apiVo); //changeDesign
  660. CeErpSukuraData.createInfo(entity.ctid, 7);
  661. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  662. returnSuccessMsg("设置成功!");
  663. return;
  664. }
  665. returnErrorMsg("找不到记录");
  666. }
  667. }
  668. public void set_erp_reset()
  669. {
  670. if (UrlPostParmsCheck("ctid"))
  671. {
  672. string eid = GetPostString("ctid");
  673. CeErpTradeCell entity = null;
  674. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  675. if (entity != null)
  676. {
  677. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  678. {
  679. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  680. {
  681. returnErrorMsg("财务要求已下单已发货无法重置");
  682. return;
  683. }
  684. }
  685. entity.IsUrgency = false;
  686. entity.seller_memo = "";
  687. entity.OtherMemo = "";
  688. entity.OrderState = 0;
  689. entity.IsReturn = 0;
  690. //entity.IsRefund = 0;
  691. entity.MemoOpt = 0;
  692. entity.AfterSaleState = 0;
  693. entity.AfterSaleResponsible = "";
  694. entity.AfterSaleUserId = 0;
  695. entity.IsNeedBill = 0;
  696. entity.CustomerUserId = 0;
  697. entity.DesignUserId = 0;
  698. entity.SupplierId = 0;
  699. entity.PlaceUserId = 0;
  700. entity.ptid = "";
  701. entity.IsSample = 0;
  702. entity.IsXianHuo = 0;
  703. entity.isDianziOrder = 0;
  704. entity.DispatchSort = 0;
  705. entity.IsVerifyToSupplier = false;
  706. entity.FinishPlaceTime = null;
  707. entity.Update();
  708. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  709. if (trade != null)
  710. {
  711. trade.seller_memo = "";
  712. trade.Update();
  713. }
  714. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  715. returnSuccessMsg("重置成功!");
  716. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  717. if (desginBill != null)
  718. {
  719. desginBill.isDel = 1;
  720. desginBill.Update();
  721. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  722. }
  723. ApiVo apiVo = new ApiVo();
  724. apiVo.orderNumber = entity.ctid;
  725. apiVo.actionName = "resetDesign";
  726. designHelper.API_WorkCore(apiVo);//resetDesign
  727. return;
  728. }
  729. returnErrorMsg("找不到记录");
  730. }
  731. }
  732. public void save_erp_sellermemo()
  733. {
  734. if (UrlPostParmsCheck("ctid"))
  735. {
  736. string ctid = GetPostString("ctid");
  737. CeErpTradeCell entity = null;
  738. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  739. if (entity != null)
  740. {
  741. string memo = GetPostString("seller_memo");
  742. string qn_memo = GetPostString("qn_memo");
  743. memo = memo.Replace(" ", "");
  744. if (memo.Contains("补差"))
  745. {
  746. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  747. return;
  748. }
  749. List<string> bitList = new List<string>
  750. {
  751. "\\","/",":","*","?", "\"","<" ,">","|"
  752. };
  753. bool isIn = false;
  754. foreach (string bit in bitList)
  755. {
  756. if (memo.Contains(bit))
  757. {
  758. isIn = true;
  759. }
  760. }
  761. if (isIn)
  762. {
  763. returnErrorMsg("不能使用 一些符合作为文件名");
  764. return;
  765. }
  766. if (entity.seller_memo != memo)
  767. {
  768. if (entity.IsSample == 2)
  769. {
  770. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  771. return;
  772. }
  773. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  774. {
  775. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  776. {
  777. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  778. return;
  779. }
  780. /*if (CurrentUser.UserPost.Post.Code != "Place")
  781. {
  782. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  783. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  784. {
  785. returnErrorMsg("售前系统订单无法再此修改!");
  786. return;
  787. }
  788. }*/
  789. }
  790. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  791. }
  792. if (!string.IsNullOrEmpty(qn_memo) && !(entity.IsSample > 0 || entity.ctid.Contains("N_") || entity.seller_memo.Contains("现货") || entity.seller_memo.Contains("礼物")))
  793. {
  794. if (entity.OrderState >= 5)
  795. {
  796. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  797. return;
  798. }
  799. string delMemo = commonHelper.convertQNMemo(qn_memo, ref entity);
  800. if (string.IsNullOrEmpty(delMemo))
  801. {
  802. returnErrorMsg("备注不规范,无法识别");
  803. return;
  804. }
  805. memo = delMemo;
  806. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统千牛修改为:" + memo, entity.OrderState, 1);
  807. }
  808. commonHelper.getCytPrice(entity);
  809. int memoopt = GetPostInt("MemoOpt");
  810. Boolean ismemoopt = false;
  811. if (memoopt > 0)
  812. {
  813. string stropt = "";
  814. if (memoopt == 1)
  815. {
  816. stropt = "“改稿”";
  817. ismemoopt = true;
  818. }
  819. else if (memoopt == 2)
  820. {
  821. stropt = "“定稿”";
  822. }
  823. else if (memoopt == 3)
  824. {
  825. stropt = "“查货”";
  826. CeErpSukuraData.createInfo(entity.ctid, 6);
  827. }
  828. entity.MemoOpt = Convert.ToInt32(memoopt);
  829. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  830. }
  831. if (entity.OrderState < 5)
  832. {
  833. memo = memo.Replace("(", "(");
  834. memo = memo.Replace(")", ")");
  835. }
  836. /* if (entity.OrderState < 3)
  837. {
  838. entity.DispatchSort = 0;
  839. }*/
  840. entity.seller_memo = memo;
  841. entity.UpdateTime = DateTime.Now;
  842. entity.Update();
  843. ApiVo apiVo = new ApiVo();
  844. apiVo.orderNumber = entity.ctid;
  845. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  846. apiVo.orderRemarks = memo;
  847. apiVo.remarkSign = memoopt;
  848. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  849. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  850. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  851. {
  852. dataHelper.api_orderBack(entity.ctid, "0", "");
  853. }
  854. if (entity.seller_memo.Contains("改稿"))
  855. {
  856. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  857. }
  858. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  859. returnSuccessMsg("保存成功!");
  860. return;
  861. }
  862. returnErrorMsg("找不到记录");
  863. }
  864. }
  865. public void ins_erp_checkorder()
  866. {
  867. if (UrlPostParmsCheck("ctid"))
  868. {
  869. string ctid = GetPostString("ctid");
  870. CeErpTradeCell entity = null;
  871. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  872. if (entity != null)
  873. {
  874. if (entity.OrderState < 6)
  875. {
  876. returnErrorMsg("下单完成后才可查货");
  877. return;
  878. }
  879. /*if (entity.OrderState > 6)
  880. {
  881. returnErrorMsg("订单已发货");
  882. return;
  883. }*/
  884. if (entity.FinishPlaceTime != null)
  885. {
  886. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  887. {
  888. returnErrorMsg("下单时间不足,无法查货");
  889. return;
  890. }
  891. }
  892. entity.MemoOpt = 3;
  893. entity.CheckOrderTime = DateTime.Now;
  894. entity.UpdateTime = DateTime.Now;
  895. entity.Update();
  896. CeErpSukuraData.createInfo(entity.ctid, 6);
  897. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  898. returnSuccessMsg("操作成功!");
  899. return;
  900. }
  901. returnErrorMsg("找不到记录");
  902. }
  903. }
  904. public void save_erp_othermemo()
  905. {
  906. if (UrlPostParmsCheck("ctid"))
  907. {
  908. string ctid = GetPostString("ctid");
  909. CeErpTradeCell entity = null;
  910. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  911. if (entity != null)
  912. {
  913. entity.OtherMemo = GetPostString("otherMemo");
  914. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  915. {
  916. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  917. StringBuilder sql = new StringBuilder();
  918. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  919. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  920. if (dt != null && dt.Rows.Count > 0)
  921. {
  922. foreach (DataRow dr in dt.Rows)
  923. {
  924. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  925. {
  926. //品类一直
  927. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  928. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  929. if (ceErpSampleCustomer == null)
  930. {
  931. ceErpSampleCustomer = new CeErpSampleCustomer();
  932. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  933. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  934. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  935. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  936. ceErpSampleCustomer.shopId = entity.ShopId;
  937. }
  938. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  939. ceErpSampleCustomer.lastTid = entity.tid;
  940. if (ceErpSampleCustomer.ID > 0)
  941. {
  942. ceErpSampleCustomer.Update();
  943. }
  944. else
  945. {
  946. ceErpSampleCustomer.Create();
  947. }
  948. }
  949. }
  950. }
  951. }
  952. //if (entity.IsOldCustomer == 1)
  953. //{
  954. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  955. //{
  956. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  957. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  958. //}
  959. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  960. //{
  961. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  962. // {
  963. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  964. // {
  965. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  966. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  967. // }
  968. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  969. // {
  970. // entity.OrderState = 2;
  971. // entity.DesignUserId = 0;
  972. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  973. // }
  974. // else
  975. // {
  976. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  977. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  978. // }
  979. // }
  980. //}
  981. //}
  982. entity.UpdateTime = DateTime.Now;
  983. entity.Update();
  984. returnSuccessMsg("保存成功!");
  985. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  986. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  987. if (entity.OtherMemo.Contains("改稿"))
  988. {
  989. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  990. }
  991. return;
  992. }
  993. returnErrorMsg("找不到记录");
  994. }
  995. }
  996. public void save_erp_customermemo()
  997. {
  998. if (UrlPostParmsCheck("ctid"))
  999. {
  1000. string ctid = GetPostString("ctid");
  1001. CeErpTradeCell entity = null;
  1002. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1003. if (entity != null)
  1004. {
  1005. entity.UpdateTime = DateTime.Now;
  1006. entity.CustomerMemo = GetPostString("CustomerMemo");
  1007. entity.Update();
  1008. ApiVo apiVo = new ApiVo();
  1009. apiVo.orderNumber = entity.ctid;
  1010. apiVo.actionName = "followRemarks";
  1011. apiVo.orderRemarks = entity.CustomerMemo;
  1012. designHelper.API_WorkCore(apiVo);//followRemarks
  1013. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  1014. returnSuccessMsg("保存成功!");
  1015. return;
  1016. }
  1017. returnErrorMsg("找不到记录");
  1018. }
  1019. }
  1020. public void upd_erp_addmemotag()
  1021. {
  1022. if (UrlPostParmsCheck("ctid"))
  1023. {
  1024. ;
  1025. string eid = GetPostString("ctid");
  1026. string sfTagstr = GetPostString("memotag");
  1027. CeErpTradeCell entity = null;
  1028. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1029. if (entity != null)
  1030. {
  1031. ApiVo apiVo = new ApiVo();
  1032. if (entity.OrderState == 0)
  1033. {
  1034. returnErrorMsg("请先领单");
  1035. return;
  1036. }
  1037. //撤销顺丰
  1038. if (sfTagstr == "撤销顺丰")
  1039. {
  1040. entity.IsSF = 0;
  1041. string reMsg = "";
  1042. string oldmemo = entity.seller_memo;
  1043. if (entity.OrderState < 5)
  1044. {
  1045. oldmemo = oldmemo.Replace("顺丰到付", "");
  1046. oldmemo = oldmemo.Replace("顺丰寄付", "");
  1047. entity.seller_memo = oldmemo;
  1048. }
  1049. else
  1050. {
  1051. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  1052. {
  1053. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  1054. }
  1055. }
  1056. entity.Update();
  1057. apiVo.orderNumber = entity.ctid;
  1058. apiVo.actionName = "orderRemarks";
  1059. apiVo.orderRemarks = entity.seller_memo;
  1060. apiVo.isSf = entity.IsSF.ToString();
  1061. designHelper.API_WorkCore(apiVo);//orderRemarks
  1062. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  1063. returnSuccessMsg("撤销成功!" + reMsg);
  1064. return;
  1065. }
  1066. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  1067. {
  1068. //string oldmemo = entity.seller_memo;
  1069. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  1070. string sfStr = GetPostString("memotag");
  1071. string smemo = entity.seller_memo;
  1072. int kindex = smemo.IndexOf(")");
  1073. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  1074. if (lastoneStr != "-")
  1075. {
  1076. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  1077. }
  1078. string prememo = smemo.Substring(0, kindex + 2);
  1079. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  1080. int lastkindex = lastmemo.IndexOf("(");
  1081. string newlastmemo = "";
  1082. if (lastkindex == 0)
  1083. {
  1084. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  1085. newlastmemo = "(" + sfStr + "." + useLastmemo;
  1086. }
  1087. else
  1088. {
  1089. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  1090. }
  1091. entity.seller_memo = prememo + newlastmemo;
  1092. }
  1093. string sfTagMSg = "";
  1094. if (sfTagstr == "顺丰寄付")
  1095. {
  1096. entity.IsSF = 1;
  1097. sfTagMSg = "顺丰寄付";
  1098. }
  1099. else if (sfTagstr == "顺丰到付")
  1100. {
  1101. entity.IsSF = 2;
  1102. sfTagMSg = "顺丰到付";
  1103. }
  1104. entity.Update();
  1105. apiVo = new ApiVo();
  1106. apiVo.orderNumber = entity.ctid;
  1107. apiVo.actionName = "orderRemarks";
  1108. apiVo.orderRemarks = entity.seller_memo;
  1109. apiVo.isSf = entity.IsSF.ToString();
  1110. designHelper.API_WorkCore(apiVo);//orderRemarks
  1111. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1112. returnSuccessMsg("标记成功!");
  1113. return;
  1114. }
  1115. returnErrorMsg("找不到记录");
  1116. }
  1117. }
  1118. public void upd_erp_ordertag()
  1119. {
  1120. if (UrlPostParmsCheck("ctid"))
  1121. {
  1122. string eid = GetPostString("ctid");
  1123. CeErpTradeCell entity = null;
  1124. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1125. if (entity != null)
  1126. {
  1127. int tag = GetPostInt("wechattag");
  1128. //if(tag==4 && entity.IsSample == 2)
  1129. //{
  1130. // returnErrorMsg("补差价单不能标记微信单");
  1131. // return;
  1132. //}
  1133. entity.wechatTag = tag;
  1134. entity.Update();
  1135. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1136. if (tag == 1)
  1137. {
  1138. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1139. if (cash == null)
  1140. {
  1141. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1142. cash = new CeErpReturnCash();
  1143. cash.tid = entity.tid;
  1144. cash.seller_nick = main.seller_nick;
  1145. cash.payment = trade.payment;
  1146. cash.buyer_nick = main.buyer_nick;
  1147. cash.cashstate = 0;
  1148. cash.rtype = "微信返现";
  1149. cash.returnprice = 0;
  1150. cash.created = DateTime.Now;
  1151. cash.con = "订单标记微信单";
  1152. cash.img = "";
  1153. cash.applyuserid = CurrentUser.UserID;
  1154. cash.Create();
  1155. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1156. }
  1157. else
  1158. {
  1159. cash.cashstate = 0;
  1160. cash.Update();
  1161. }
  1162. CeErpSukuraData.createInfo(entity.ctid, 9);
  1163. }
  1164. else if (tag == 2)
  1165. {
  1166. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1167. if (cash == null)
  1168. {
  1169. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1170. cash = new CeErpReturnCash();
  1171. cash.tid = entity.tid;
  1172. cash.seller_nick = main.seller_nick;
  1173. cash.payment = trade.payment;
  1174. cash.buyer_nick = main.buyer_nick;
  1175. cash.cashstate = 0;
  1176. cash.rtype = "推购返现";
  1177. cash.returnprice = 5;
  1178. cash.created = DateTime.Now;
  1179. cash.con = "订单标记推购单";
  1180. cash.img = "";
  1181. cash.applyuserid = CurrentUser.UserID;
  1182. cash.Create();
  1183. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1184. }
  1185. else
  1186. {
  1187. cash.cashstate = 0;
  1188. cash.Update();
  1189. }
  1190. CeErpSukuraData.createInfo(entity.ctid, 9);
  1191. }
  1192. else if (tag == 3)
  1193. {
  1194. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1195. if (pers == null)
  1196. {
  1197. pers = new CeErpPersuade();
  1198. pers.ctid = entity.ctid;
  1199. pers.pstate = 0;
  1200. pers.created = DateTime.Now;
  1201. pers.applyuserid = CurrentUser.UserID;
  1202. pers.Create();
  1203. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1204. }
  1205. else
  1206. {
  1207. pers.pstate = 0;
  1208. pers.Update();
  1209. }
  1210. }
  1211. else if (tag == 4 || tag == 5)
  1212. {
  1213. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1214. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1215. if (pers == null)
  1216. {
  1217. pers = CeErpStayGoods.GetByTid(entity.tid);
  1218. }
  1219. if (pers == null)
  1220. {
  1221. pers = new CeErpStayGoods();
  1222. pers.t_id = entity.tid;
  1223. pers.ctid = entity.ctid;
  1224. pers.status = "待审核";
  1225. pers.audit_type = 0;
  1226. if (tag == 4)
  1227. {
  1228. pers.stay_type = "微信推购";
  1229. }
  1230. else
  1231. {
  1232. pers.stay_type = "旺旺推购";
  1233. }
  1234. if (entity.IsXianHuo == 0)
  1235. {
  1236. pers.product_id = entity.ProductId;
  1237. }
  1238. pers.wangwang = main.buyer_nick;
  1239. pers.shop_name = main.seller_nick;
  1240. pers.creata_time = DateTime.Now;
  1241. pers.create_u_id = CurrentUser.UserID;
  1242. pers.create_u_name = CurrentUser.UserName;
  1243. pers.Create();
  1244. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1245. }
  1246. else
  1247. {
  1248. pers.ctid = entity.ctid;
  1249. pers.audit_type = 0;
  1250. pers.Update();
  1251. }
  1252. CeErpSukuraData.createInfo(entity.ctid, 10);
  1253. }
  1254. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1255. returnSuccessMsg("标记成功!");
  1256. return;
  1257. }
  1258. returnErrorMsg("找不到记录");
  1259. }
  1260. }
  1261. public void upd_erp_ordertag_cancel()
  1262. {
  1263. if (UrlPostParmsCheck("ctid"))
  1264. {
  1265. string eid = GetPostString("ctid");
  1266. CeErpTradeCell entity = null;
  1267. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1268. if (entity != null)
  1269. {
  1270. entity.wechatTag = 0;
  1271. entity.Update();
  1272. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1273. if (pers != null)
  1274. {
  1275. pers.status = "取消推购";
  1276. pers.audit_type = 3;
  1277. pers.Update();
  1278. }
  1279. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1280. returnSuccessMsg("标记成功!");
  1281. return;
  1282. }
  1283. returnErrorMsg("找不到记录");
  1284. }
  1285. }
  1286. public void upd_erp_addweichattag()
  1287. {
  1288. if (UrlPostParmsCheck("ctid"))
  1289. {
  1290. ;
  1291. string eid = GetPostString("ctid");
  1292. CeErpTradeCell entity = null;
  1293. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1294. if (entity != null)
  1295. {
  1296. if (entity.IsAddWechat > 0)
  1297. {
  1298. returnErrorMsg("此单已经标记过了");
  1299. return;
  1300. }
  1301. 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);
  1302. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1303. if (dt.Rows.Count > 0)
  1304. {
  1305. entity.IsAddWechat = 2;
  1306. }
  1307. else
  1308. {
  1309. entity.IsAddWechat = 1;
  1310. }
  1311. entity.Update();
  1312. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1313. returnSuccessMsg("标记成功!");
  1314. return;
  1315. }
  1316. returnErrorMsg("找不到记录");
  1317. }
  1318. }
  1319. public void upd_erp_getmyorder()
  1320. {
  1321. if (UrlPostParmsCheck("ctid"))
  1322. {
  1323. string eid = GetPostString("ctid");
  1324. CeErpTradeCell entity = null;
  1325. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1326. CeErpTrade father = CeErpTrade.Get(entity.tid);
  1327. if (father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip))
  1328. {
  1329. returnErrorMsg("台湾客户需填写身份证号!");
  1330. return;
  1331. }
  1332. if (commonHelper.isFarAddress(father.receiver_state) && father.delivery_paymant == 0)
  1333. {
  1334. returnErrorMsg("偏远地区需要填写物流费!");
  1335. return;
  1336. }
  1337. if (entity != null)
  1338. {
  1339. if (entity.ctid.IndexOf("C") != -1)
  1340. {
  1341. StringBuilder sql = new StringBuilder();
  1342. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1343. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1344. if (dt.Rows.Count > 0)
  1345. {
  1346. decimal total = 0;
  1347. foreach (DataRow dr in dt.Rows)
  1348. {
  1349. total += Convert.ToDecimal(dr["payment"]);
  1350. }
  1351. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1352. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1353. {
  1354. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1355. return;
  1356. }
  1357. }
  1358. }
  1359. if (entity.OrderState == -1)
  1360. {
  1361. returnErrorMsg("待审核订单无法领取!");
  1362. return;
  1363. }
  1364. entity.CustomerUserId = CurrentUser.UserID;
  1365. if (entity.OrderState < 2)
  1366. {
  1367. entity.OrderState = 2;
  1368. if (entity.ShopId != 0)
  1369. {
  1370. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1371. }
  1372. }
  1373. entity.UpdateTime = DateTime.Now;
  1374. entity.Update();
  1375. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1376. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1377. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  1378. {
  1379. dataHelper.api_orderBack(entity.ctid, "0", "");
  1380. }
  1381. returnSuccessMsg("领单成功!");
  1382. return;
  1383. }
  1384. returnErrorMsg("找不到记录");
  1385. }
  1386. }
  1387. public void getmyorder_from_init()
  1388. {
  1389. if (UrlPostParmsCheck("ctid"))
  1390. {
  1391. string eid = GetPostString("ctid");
  1392. CeErpTradeCell entity = null;
  1393. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1394. if (entity != null)
  1395. {
  1396. string sellerMemo = GetPostString("sellerMemo");
  1397. if (sellerMemo.Length > 0)
  1398. {
  1399. entity.seller_memo = sellerMemo;
  1400. }
  1401. string oterhMemo = GetPostString("otherMemo");
  1402. if (oterhMemo.Length > 0)
  1403. {
  1404. entity.OtherMemo = oterhMemo;
  1405. }
  1406. int urg = GetPostInt("urgency");
  1407. entity.IsUrgency = (urg == 1 ? true : false);
  1408. int wechat = GetPostInt("wechat");
  1409. int command = GetPostInt("command");
  1410. if (wechat == 1)
  1411. {
  1412. entity.wechatTag = 1;
  1413. }
  1414. if (command == 1)
  1415. {
  1416. entity.wechatTag = 2;
  1417. }
  1418. string pPro = GetPostString("pprofession");
  1419. if (pPro.Length > 0)
  1420. {
  1421. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1422. string spro = GetPostString("profession");
  1423. if (spro.Length > 0)
  1424. {
  1425. entity.ProfessionId = Convert.ToInt32(spro);
  1426. }
  1427. }
  1428. string proId = GetPostString("productId");
  1429. if (proId.Length > 0)
  1430. {
  1431. entity.ProductId = Convert.ToInt32(proId);
  1432. }
  1433. entity.Material = GetPostString("material");
  1434. entity.Craft = GetPostString("craft");
  1435. entity.CustomerUserId = CurrentUser.UserID;
  1436. if (entity.OrderState < 2)
  1437. {
  1438. entity.OrderState = 2;
  1439. if (entity.ShopId != 0)
  1440. {
  1441. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1442. }
  1443. }
  1444. entity.Update();
  1445. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1446. returnSuccessMsg("领单成功!");
  1447. return;
  1448. }
  1449. returnErrorMsg("找不到记录");
  1450. }
  1451. }
  1452. public void upd_erp_setrelationorder()
  1453. {
  1454. if (UrlPostParmsCheck("ctid"))
  1455. {
  1456. ;
  1457. string eid = GetPostString("ctid");
  1458. string ftid = GetPostString("ftid");
  1459. CeErpTradeCell entity = null;
  1460. CeErpTradeCell fentity = null;
  1461. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1462. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1463. if (fentity == null)
  1464. {
  1465. returnErrorMsg("找不到关联的主订单");
  1466. return;
  1467. }
  1468. if (entity != null)
  1469. {
  1470. if (entity.OrderState >= 5)
  1471. {
  1472. returnErrorMsg("本单已经设计完成无法关联");
  1473. return;
  1474. }
  1475. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1476. {
  1477. returnErrorMsg("线下单续审核后才能关联!");
  1478. return;
  1479. }
  1480. entity.ptid = ftid;
  1481. entity.OrderState = fentity.OrderState;
  1482. //entity.status = fentity.status;
  1483. entity.CustomerUserId = fentity.CustomerUserId;
  1484. entity.DesignUserId = fentity.DesignUserId;
  1485. entity.seller_memo = "补差价单:" + ftid;
  1486. entity.IsSample = 2;
  1487. entity.Update();
  1488. ApiVo apiVo = new ApiVo();
  1489. apiVo.orderNumber = ftid;
  1490. apiVo.payment = entity.payment;
  1491. apiVo.actionName = "repairDesign";
  1492. designHelper.API_WorkCore(apiVo);//repairDesign
  1493. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1494. returnSuccessMsg("关联成功!");
  1495. return;
  1496. }
  1497. else
  1498. returnErrorMsg("找不到记录");
  1499. }
  1500. }
  1501. public void download_erp_neworder()
  1502. {
  1503. string seller = GetPostString("seller_nick");
  1504. string tid = GetPostString("tid");
  1505. if (seller.Length <= 0 || tid.Length <= 0)
  1506. {
  1507. returnErrorMsg("数据错误");
  1508. }
  1509. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1510. //{
  1511. // returnErrorMsg("找不到店铺Sessionkey");
  1512. //}
  1513. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1514. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1515. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1516. if (res.IndexOf("refOid") == -1)
  1517. {
  1518. returnErrorMsg("下载订单数据失败");
  1519. return;
  1520. }
  1521. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1522. returnSuccessMsg("下载完成");
  1523. //tmcHelper.createNewOrder(res);
  1524. //CeErpTrade entr = null;
  1525. //entr = CeErpTrade.Get(tid);
  1526. //if (entr != null)
  1527. //{
  1528. // returnSuccess("下载成功");
  1529. // //下载成功之后,Cell表生成对应的订单;
  1530. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1531. //}
  1532. //else
  1533. //{
  1534. // returnErrorMsg("下载失败或者创建订单失败");
  1535. //}
  1536. }
  1537. public void set_erp_atersale()
  1538. {
  1539. if (UrlPostParmsCheck("ctid"))
  1540. {
  1541. string eid = GetPostString("ctid");
  1542. string reason = GetPostString("AfterSaleReason");
  1543. CeErpTradeCell entity = null;
  1544. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1545. if (entity != null)
  1546. {
  1547. /*if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1548. {
  1549. returnErrorMsg("此订单已经在售后");
  1550. return;
  1551. }*/
  1552. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1553. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1554. entity.AfterSaleTime = DateTime.Now;
  1555. entity.HandleTime = null;
  1556. entity.Update();
  1557. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1558. returnSuccessMsg("转售后成功!");
  1559. return;
  1560. }
  1561. returnErrorMsg("找不到记录");
  1562. }
  1563. }
  1564. public void set_erp_withdraw()
  1565. {
  1566. if (UrlPostParmsCheck("ctid"))
  1567. {
  1568. try
  1569. {
  1570. string eid = GetPostString("ctid");//商品id
  1571. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1572. CeWithdraw ceWithdrawSelect = null;
  1573. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1574. if (ceWithdrawSelect != null)
  1575. {
  1576. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1577. {
  1578. ceWithdrawSelect.status = -1;
  1579. ceWithdrawSelect.Update();
  1580. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1581. returnSuccessMsg("重新发起审核成功");
  1582. return;
  1583. }
  1584. else
  1585. {
  1586. returnSuccessMsg("请勿重复申请!");
  1587. return;
  1588. }
  1589. }
  1590. else
  1591. {
  1592. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1593. if (string.IsNullOrEmpty(CustomerUserId))
  1594. {
  1595. CustomerUserId = "-1";
  1596. }
  1597. int Userid = CurrentUser.UserID;//用户id
  1598. CeWithdraw ceWithdraw = new CeWithdraw();
  1599. ceWithdraw.tid = eid;
  1600. ceWithdraw.userid = Userid;
  1601. ceWithdraw.providerid = CustomerUserId;
  1602. ceWithdraw.status = 3;
  1603. ceWithdraw.creationtime = DateTime.Now;
  1604. ceWithdraw.Create();
  1605. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1606. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1607. return;
  1608. }
  1609. }
  1610. catch
  1611. {
  1612. returnErrorMsg("申请撤回订单失败");
  1613. return;
  1614. }
  1615. }
  1616. }
  1617. public void ins_erp_billinfo()
  1618. {
  1619. if (UrlPostParmsCheck("ctid"))
  1620. {
  1621. string eid = GetPostString("ctid");
  1622. CeErpTradeCell entity = null;
  1623. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1624. if (entity != null)
  1625. {
  1626. CeErpBill bill = CeErpBill.GetByTid(eid);
  1627. bool isHave = false;
  1628. if (bill != null)
  1629. {
  1630. isHave = true;
  1631. if (bill.state != 4)
  1632. {
  1633. returnErrorMsg("此单已经申请过发票了");
  1634. return;
  1635. }
  1636. }
  1637. if (entity.IsNeedBill == 0)
  1638. {
  1639. entity.IsNeedBill = 1;
  1640. }
  1641. entity.Update();
  1642. string errjson = "";
  1643. try
  1644. {
  1645. CeErpBill bill_entity = new CeErpBill();
  1646. bill_entity.tid = entity.tid;
  1647. bill_entity.title = GetPostString("title");
  1648. string taxstr = GetPostString("tax");
  1649. taxstr = taxstr.Replace(" ", "");
  1650. bill_entity.tax = taxstr;
  1651. bill_entity.bank = GetPostString("bank");
  1652. string bankacstr = GetPostString("bankac");
  1653. bankacstr = bankacstr.Replace(" ", "");
  1654. bill_entity.bankac = bankacstr;
  1655. bill_entity.address = GetPostString("address");
  1656. bill_entity.phone = GetPostString("phone");
  1657. bill_entity.price = GetPostString("price");
  1658. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1659. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1660. {
  1661. billCount += 1;
  1662. }
  1663. string prebill = "ltb";
  1664. for (int idx = 1; idx <= billCount; idx++)
  1665. {
  1666. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1667. string billoid = prebill + idx + dtstr;
  1668. bill_entity.billOrderId += billoid;
  1669. if (idx < billCount)
  1670. {
  1671. bill_entity.billOrderId += ",";
  1672. }
  1673. }
  1674. bill_entity.productId = GetPostInt("ProductName");
  1675. bill_entity.num = GetPostInt("num");
  1676. bill_entity.unit = GetPostString("unit");
  1677. bill_entity.type = GetPostString("type");
  1678. bill_entity.sendType = GetPostString("SendType");
  1679. bill_entity.email = GetPostString("email");
  1680. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1681. bill_entity.shopName = GetPostString("ShopName");
  1682. bill_entity.applymemo = GetPostString("applyMemo");
  1683. bill_entity.createTime = DateTime.Now;
  1684. bill_entity.state = 0;
  1685. bill_entity.userId = CurrentUser.UserID;
  1686. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1687. bill_entity.Create();
  1688. }
  1689. catch (Exception ex)
  1690. {
  1691. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1692. returnErrorMsg("创建发票出错!");
  1693. return;
  1694. }
  1695. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1696. returnSuccessMsg("发票申请成功!");
  1697. return;
  1698. }
  1699. returnErrorMsg("找不到记录");
  1700. }
  1701. }
  1702. public void ins_erp_neworder()
  1703. {
  1704. if (UrlPostParmsCheck("receiver_name"))
  1705. {
  1706. CeErpTrade entity = new CeErpTrade();
  1707. string plat_form = GetPostString("platform");
  1708. string preStr = "N_";
  1709. if (plat_form == "拼多多")
  1710. {
  1711. preStr = "P_";
  1712. }
  1713. else if (plat_form == "阿里巴巴")
  1714. {
  1715. preStr = "A_";
  1716. }
  1717. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1718. entity.seller_nick = GetPostString("seller_nick");
  1719. entity.buyer_nick = GetPostString("buyer_nick");
  1720. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1721. entity.total_fee = entity.payment;
  1722. entity.pay_time = DateTime.Now;
  1723. entity.status = "NOT_SHIPPED";
  1724. entity.receiver_name = GetPostString("receiver_name");
  1725. entity.receiver_mobile = GetPostString("receiver_mobile");
  1726. entity.receiver_state = GetPostString("receiver_state");
  1727. entity.receiver_city = GetPostString("receiver_city");
  1728. entity.receiver_district = GetPostString("receiver_district");
  1729. entity.receiver_address = GetPostString("receiver_address");
  1730. if (entity.receiver_state == "" || entity.receiver_city == "")
  1731. {
  1732. returnErrorMsg("收件地址不能为空");
  1733. return;
  1734. }
  1735. int shopId = 0;
  1736. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1737. if (nShop != null)
  1738. {
  1739. shopId = nShop.ID;
  1740. }
  1741. if (shopId != 34 && entity.payment == 0)
  1742. {
  1743. returnErrorMsg("公司自用的单金额才能为0");
  1744. return;
  1745. }
  1746. entity.Create();
  1747. CeErpTradeCell entitycell = new CeErpTradeCell();
  1748. entitycell.ctid = entity.tid;
  1749. entitycell.tid = entity.tid;
  1750. entitycell.ShopId = shopId;
  1751. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1752. entitycell.OrderState = 0;
  1753. entitycell.pay_time = entity.pay_time;
  1754. entitycell.IsOffLineOrder = 1;
  1755. entitycell.Create();
  1756. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1757. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1758. return;
  1759. }
  1760. }
  1761. public void ins_erp_neworder2()
  1762. {
  1763. if (UrlPostParmsCheck("receiver_name"))
  1764. {
  1765. //string plat_form = GetPostString("platform");
  1766. string preStr = "X_";
  1767. string memo = GetPostString("memo");
  1768. string productId = GetPostString("productId");
  1769. string primg = GetPostString("proofimg");
  1770. string sellerNick = GetPostString("seller_nick");
  1771. string addFrom = GetPostString("addfrom");
  1772. if (addFrom == "1")
  1773. {
  1774. preStr = "N_";
  1775. }
  1776. int shopId = 0;
  1777. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1778. if (nShop != null)
  1779. {
  1780. shopId = nShop.ID;
  1781. }
  1782. else
  1783. {
  1784. returnErrorMsg("找不到对应店铺");
  1785. return;
  1786. }
  1787. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1788. {
  1789. returnErrorMsg("必须上传付款凭证");
  1790. return;
  1791. }
  1792. CeErpTrade entity = new CeErpTrade();
  1793. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1794. entity.seller_nick = sellerNick;
  1795. entity.buyer_nick = GetPostString("buyer_nick");
  1796. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1797. entity.total_fee = entity.payment;
  1798. entity.pay_time = DateTime.Now;
  1799. entity.status = "NOT_SHIPPED";
  1800. entity.receiver_name = GetPostString("receiver_name");
  1801. entity.receiver_mobile = GetPostString("receiver_mobile");
  1802. entity.receiver_state = GetPostString("receiver_state");
  1803. entity.receiver_city = GetPostString("receiver_city");
  1804. entity.receiver_district = GetPostString("receiver_district");
  1805. entity.receiver_address = GetPostString("receiver_address");
  1806. entity.seller_memo = memo;
  1807. entity.orderFrom = 20;
  1808. entity.orderType = 15;
  1809. if (entity.receiver_state == "" || entity.receiver_city == "")
  1810. {
  1811. returnErrorMsg("收件地址不能为空");
  1812. return;
  1813. }
  1814. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1815. {
  1816. returnErrorMsg("公司自用的单金额才能为0");
  1817. return;
  1818. }
  1819. entity.Create();
  1820. string toWhere = GetPostString("towhere");
  1821. CeErpTradeCell entitycell = new CeErpTradeCell();
  1822. entitycell.ctid = entity.tid;
  1823. //唯一标识
  1824. entitycell.OrderSn = entity.tid;
  1825. string orderSn = dataHelper.getSaleOrderSn();
  1826. if (orderSn != "")
  1827. {
  1828. entitycell.OrderSn = orderSn;
  1829. }
  1830. entitycell.tid = entity.tid;
  1831. //if (preStr == "X_")
  1832. //{
  1833. entitycell.IsOffLineOrder = 1;
  1834. //}
  1835. entitycell.CustomerUserId = CurrentUser.UserID;
  1836. entitycell.PayProofImg = primg;
  1837. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1838. entitycell.ProductId = Convert.ToInt32(productId);
  1839. entitycell.ShopId = shopId;
  1840. entitycell.UpdateTime = DateTime.Now;
  1841. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1842. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1843. {
  1844. entitycell.IsXianHuo = 1;
  1845. }
  1846. entitycell.pay_time = entity.pay_time;
  1847. if (toWhere == "1")
  1848. {
  1849. entitycell.OrderState = 2;
  1850. }
  1851. else
  1852. {
  1853. entitycell.OrderState = 6;
  1854. entitycell.FinishPlaceTime = entitycell.pay_time;
  1855. }
  1856. if (shopId == 94)
  1857. {
  1858. entitycell.OrderState = 4;
  1859. entitycell.WaitDesignTime = entitycell.pay_time;
  1860. entitycell.StartDesignTime = entitycell.pay_time;
  1861. entitycell.DesignUserId = 218;
  1862. }
  1863. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1864. {
  1865. entitycell.OrderState = -1;//修改12-5
  1866. CeWithdraw ceWithdraw = new CeWithdraw();
  1867. ceWithdraw.tid = entity.tid;
  1868. ceWithdraw.providerid = "-1";
  1869. ceWithdraw.status = -1;
  1870. ceWithdraw.creationtime = DateTime.Now;
  1871. ceWithdraw.userid = 742;
  1872. ceWithdraw.Create();
  1873. }
  1874. entitycell.Create();
  1875. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1876. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1877. {
  1878. addPlaceRegist(entitycell, CurrentUser.UserID);
  1879. }
  1880. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1881. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1882. return;
  1883. }
  1884. }
  1885. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1886. {
  1887. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1888. entity.PlactTime = tradecell.pay_time;
  1889. entity.AddUserId = userid;
  1890. entity.FileName = tradecell.seller_memo;
  1891. entity.Supplier = 24;
  1892. entity.CreateTime = DateTime.Now;
  1893. entity.Did = tradecell.ctid;
  1894. entity.tid = tradecell.tid;
  1895. entity.splitTag = tradecell.SplitTag;
  1896. entity.CurState = "未完成";
  1897. entity.Create();
  1898. }
  1899. public void get_erp_offlinelist()
  1900. {
  1901. DataStruct dStruct = GetPostStruct();
  1902. List<string> lw = new List<string>();
  1903. string tid = GetPostString("ctid");
  1904. string date1 = GetPostString("date1");
  1905. string date2 = GetPostString("date2");
  1906. if (tid.Length > 0 || date1.Length > 0)
  1907. {
  1908. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1909. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1910. if (dw.Length > 0) lw.Add(dw);
  1911. }
  1912. else
  1913. {
  1914. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1915. }
  1916. string shopname = GetPostString("shopname");
  1917. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1918. string buyernick = GetPostString("buyer_nick");
  1919. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1920. string customer = GetPostString("customer");
  1921. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1922. string design = GetPostString("design");
  1923. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1924. string orderState = GetPostString("orderState");
  1925. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1926. string address = GetPostString("address");
  1927. 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));
  1928. string sellermemo = GetPostString("seller_memo");
  1929. if (sellermemo.Length > 0)
  1930. {
  1931. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1932. }
  1933. string price1 = GetPostString("price1");
  1934. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1935. string price2 = GetPostString("price2");
  1936. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1937. //if (PKey != "admin")
  1938. //{
  1939. // string usershop = CurrentUser.User.pemShop;
  1940. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1941. //}
  1942. //if (ex_psize > 0)
  1943. //{
  1944. dStruct.Order = "pay_time desc";
  1945. //}
  1946. //else
  1947. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1948. lw.Add(string.Format("IsOffLineOrder=1"));
  1949. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1950. DataTable dt = null;
  1951. dt = WebCache.GetData("view_erptradecell", dStruct);
  1952. writeGridDataTableJson(dStruct.TotalCount, dt);
  1953. }
  1954. public void get_erp_returncashrecord()
  1955. {
  1956. DataStruct dStruct = GetPostStruct();
  1957. List<string> lw = new List<string>();
  1958. string tid = GetPostString("ctid");
  1959. if (tid.Length > 0)
  1960. {
  1961. lw.Add(string.Format("tid like '%{0}%'", tid));
  1962. dStruct.Order = "id desc";
  1963. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1964. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1965. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1966. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1967. return;
  1968. }
  1969. returnErrorMsg("id数据错误!");
  1970. }
  1971. public void ins_erp_returncashrecord()
  1972. {
  1973. if (UrlPostParmsCheck("tid"))
  1974. {
  1975. string tid = GetPostString("tid");
  1976. string retype = GetPostString("type");
  1977. StringBuilder sql = new StringBuilder();
  1978. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1979. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1980. if (dt.Rows.Count > 0)
  1981. {
  1982. returnErrorMsg("相同返现类型记录已存在");
  1983. return;
  1984. }
  1985. CeErpReturnCash entity = new CeErpReturnCash();
  1986. entity.tid = tid;
  1987. entity.seller_nick = GetPostString("seller_nick");
  1988. string pment = GetPostString("payment");
  1989. if (pment.Length > 0)
  1990. {
  1991. entity.payment = Convert.ToDouble(pment);
  1992. }
  1993. entity.buyer_nick = GetPostString("buyer_nick");
  1994. entity.cashstate = 0;
  1995. entity.rtype = retype;
  1996. string rPrice = GetPostString("returnprice");
  1997. if (rPrice.Length > 0)
  1998. {
  1999. entity.returnprice = Convert.ToDouble(rPrice);
  2000. }
  2001. entity.created = DateTime.Now;
  2002. entity.con = GetPostString("con");
  2003. entity.img = GetPostString("img");
  2004. entity.applyuserid = CurrentUser.UserID;
  2005. entity.Create();
  2006. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  2007. returnSuccessMsg("操作成功!");
  2008. return;
  2009. }
  2010. }
  2011. public void set_erp_predelivery()
  2012. {
  2013. if (UrlPostParmsCheck("ctid"))
  2014. {
  2015. string eid = GetPostString("ctid");
  2016. CeErpTradeCell entity = null;
  2017. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2018. if (entity != null)
  2019. {
  2020. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  2021. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  2022. //{
  2023. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  2024. // return;
  2025. //}
  2026. entity.IsPreDelivery = 1;
  2027. entity.Update();
  2028. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  2029. returnSuccessMsg("预发货成功!");
  2030. return;
  2031. //string shop = GetPostString("seller_nick");
  2032. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  2033. //string comName = GetPostString("comName");
  2034. //string comCode = GetPostString("comCode");
  2035. //string outSid = GetPostString("outSid");//运单号
  2036. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  2037. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  2038. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  2039. //string apires = "";
  2040. //if (deliveryType == "虚拟发货")
  2041. //{
  2042. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  2043. //}
  2044. //else
  2045. //{
  2046. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  2047. //}
  2048. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  2049. ////{
  2050. //if (apires.IndexOf("发货成功") != -1)
  2051. //{
  2052. // if (deliveryType != "虚拟发货")
  2053. // {
  2054. // //还要插入快递信息到 快递信息表
  2055. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  2056. // exinfo.tid = eid;
  2057. // exinfo.out_sid = outSid;
  2058. // exinfo.company_code = comCode;
  2059. // exinfo.company_name = comName;
  2060. // exinfo.delivery_memo = deliveryMemo;
  2061. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  2062. // exinfo.deliveryType = deliveryType;
  2063. // exinfo.Create();
  2064. // }
  2065. // returnSuccessMsg("发货成功!");
  2066. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  2067. //}
  2068. //else
  2069. //{
  2070. // returnErrorMsg("淘宝发货失败!!");
  2071. //}
  2072. //return;
  2073. }
  2074. returnErrorMsg("找不到订单记录");
  2075. }
  2076. }
  2077. public void get_erp_unusuallist()
  2078. {
  2079. DataStruct dStruct = GetPostStruct();
  2080. List<string> lw = new List<string>();
  2081. string tid = GetPostString("ctid");
  2082. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  2083. string shopname = GetPostString("shopname");
  2084. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2085. string buyernick = GetPostString("buyer_nick");
  2086. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2087. string ResponsibleMan = GetPostString("responsible");
  2088. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  2089. string date1 = GetPostString("date1");
  2090. string date2 = GetPostString("date2");
  2091. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2092. if (dw.Length > 0) lw.Add(dw);
  2093. string price1 = GetPostString("price1");
  2094. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2095. string price2 = GetPostString("price2");
  2096. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2097. string orderState = GetPostString("orderState");
  2098. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2099. string sellermemo = GetPostString("seller_memo");
  2100. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2101. lw.Add(string.Format("UnusualTag > 0"));
  2102. lw.Add(string.Format("IsRefund<={0}", 1));
  2103. dStruct.Order = "pay_time desc";
  2104. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2105. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2106. writeGridDataTableJson(dStruct.TotalCount, dt);
  2107. }
  2108. public void set_erp_unusualtonomal()
  2109. {
  2110. if (UrlPostParmsCheck("ctid"))
  2111. {
  2112. string eid = GetPostString("ctid");
  2113. CeErpTradeCell entity = null;
  2114. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2115. if (entity != null)
  2116. {
  2117. entity.UnusualTag = -1;
  2118. entity.Update();
  2119. returnSuccessMsg("忽略成功!");
  2120. return;
  2121. }
  2122. returnErrorMsg("找不到记录");
  2123. }
  2124. }
  2125. public void ins_erp_unusualreason()
  2126. {
  2127. if (UrlPostParmsCheck("ctid"))
  2128. {
  2129. string eid = GetPostString("ctid");
  2130. CeErpTradeCell entity = null;
  2131. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2132. if (entity != null)
  2133. {
  2134. entity.MemoOpt = 4;
  2135. entity.UnusualCon = GetPostString("con");
  2136. entity.Update();
  2137. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2138. if (trade != null)
  2139. {
  2140. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2141. }
  2142. //查货是否超时
  2143. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2144. if (ceErpTradeCellExtend == null)
  2145. {
  2146. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2147. ceErpTradeCellExtend.ctid = entity.ctid;
  2148. }
  2149. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2150. {
  2151. ceErpTradeCellExtend.CheckOut += 1;
  2152. }
  2153. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2154. if (ceErpTradeCellExtend.ID > 0)
  2155. {
  2156. ceErpTradeCellExtend.Update();
  2157. }
  2158. else
  2159. {
  2160. ceErpTradeCellExtend.Create();
  2161. }
  2162. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2163. returnSuccessMsg("操作成功!");
  2164. return;
  2165. }
  2166. returnErrorMsg("找不到记录");
  2167. }
  2168. }
  2169. public void upd_erp_sampleorder()
  2170. {
  2171. if (UrlPostParmsCheck("ctid"))
  2172. {
  2173. string eid = GetPostString("ctid");
  2174. string[] eArr = eid.Split(',');
  2175. if (eArr.Length > 1)
  2176. {
  2177. List<string> eLst = new List<string>();
  2178. for (int i = 0; i < eArr.Length; i++)
  2179. {
  2180. eLst.Add("'" + eArr[i] + "'");
  2181. }
  2182. eid = string.Join(",", eLst.ToArray());
  2183. }
  2184. else
  2185. {
  2186. eid = "'" + eid + "'";
  2187. }
  2188. StringBuilder sql = new StringBuilder();
  2189. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2190. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2191. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2192. if (dt.Rows.Count > 0)
  2193. {
  2194. string errmsg = "";
  2195. foreach (DataRow dr in dt.Rows)
  2196. {
  2197. StringBuilder sqlsb = new StringBuilder();
  2198. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2199. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2200. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2201. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2202. //string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2203. /*if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2204. {
  2205. continue;
  2206. }
  2207. else
  2208. {
  2209. string emsg = commonHelper.KeepChinese(apires);
  2210. errmsg += emsg;
  2211. }*/
  2212. }
  2213. if (errmsg.Length > 0)
  2214. {
  2215. returnErrorMsg(errmsg);
  2216. return;
  2217. }
  2218. returnSuccessMsg("操作成功");
  2219. return;
  2220. }
  2221. returnErrorMsg("找不到记录");
  2222. }
  2223. }
  2224. public void upd_erp_transcustomer()
  2225. {
  2226. if (UrlPostParmsCheck("ctid"))
  2227. {
  2228. string eid = GetPostString("ctid");
  2229. int userid = GetPostInt("CustomerUserId");
  2230. CeErpTradeCell entity = null;
  2231. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2232. if (entity != null)
  2233. {
  2234. //string[] mlist = entity.seller_memo.Split('-');
  2235. //string sql = "select * from view_erpuser where id=" + userid;
  2236. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2237. //if (dt != null && dt.Rows.Count > 0)
  2238. //{
  2239. // string nmemo = "";
  2240. // for(int i = 0; i < mlist.Length - 1; i++)
  2241. // {
  2242. // nmemo += mlist[i];
  2243. // nmemo += "-";
  2244. // }
  2245. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2246. // entity.seller_memo = nmemo;
  2247. //}
  2248. entity.CustomerUserId = userid;
  2249. entity.Update();
  2250. returnSuccessMsg("操作成功!");
  2251. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2252. return;
  2253. }
  2254. returnErrorMsg("找不到记录");
  2255. }
  2256. }
  2257. public void upd_erp_transdesigner()
  2258. {
  2259. if (UrlPostParmsCheck("ctid"))
  2260. {
  2261. string eids = GetPostString("ctid");
  2262. string[] ctidList = eids.Split(',');
  2263. int userid = GetPostInt("DesignUserId");
  2264. foreach (string ctid in ctidList)
  2265. {
  2266. CeErpTradeCell entity = null;
  2267. CeErpDesignerBill entitys = null;
  2268. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2269. entitys = CeErpDesignerBill.GetByTid(ctid);
  2270. if (entity != null)
  2271. {
  2272. if (entity.OrderState > 4)
  2273. {
  2274. continue;
  2275. }
  2276. //存在退款不能流转
  2277. if (entity.IsRefund > 0)
  2278. {
  2279. continue;
  2280. }
  2281. entity.DesignUserId = userid;
  2282. entity.WaitDesignTime = DateTime.Now;
  2283. entity.Update();
  2284. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2285. }
  2286. }
  2287. returnSuccessMsg("操作成功!");
  2288. }
  2289. }
  2290. public void upd_erp_distributedesigner()
  2291. {
  2292. if (UrlPostParmsCheck("ctid"))
  2293. {
  2294. string eid = GetPostString("ctid");
  2295. int userid = GetPostInt("DesignUserId");
  2296. string[] idlist = eid.Split(',');
  2297. if (idlist.Length <= 0)
  2298. {
  2299. returnErrorMsg("订单不能为空");
  2300. return;
  2301. }
  2302. foreach (string ctid in idlist)
  2303. {
  2304. CeErpTradeCell entity = null;
  2305. CeErpDesignerBill entitys = null;
  2306. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2307. else continue;
  2308. if (entity != null)
  2309. {
  2310. if (userid == 2125 || userid == 3542)
  2311. { }
  2312. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2313. {
  2314. returnErrorMsg("金额错误的订单无法指派");
  2315. return;
  2316. }
  2317. if (entity.OrderState >= 5)
  2318. {
  2319. returnErrorMsg("已经设计完成无法指派");
  2320. return;
  2321. }
  2322. if (entity.OrderState == -1)
  2323. {
  2324. returnErrorMsg("审核中的订单无法指派");
  2325. return;
  2326. }
  2327. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2328. {
  2329. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2330. return;
  2331. }
  2332. //157赖橙帆 159林晨 73 静之颖
  2333. if (entity.OrderState > 3 && entity.DispatchSort == 2 && userid != 3542 && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Summarize" && CurrentUser.UserID != 157 && CurrentUser.UserID != 159 && CurrentUser.UserID != 1479 && CurrentUser.UserID != 73)
  2334. {
  2335. returnErrorMsg("指派设计共创无法再次指派!");
  2336. return;
  2337. }
  2338. entity.OrderState = 3;
  2339. if (entity.SupplierId == 0)
  2340. {
  2341. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2342. entity.SupplierId = suid;
  2343. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2344. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2345. }
  2346. if (userid == 2125 && entity.seller_memo != "")
  2347. {
  2348. apiDesign.API_GetPrintData_CreateOrder(entity);
  2349. }
  2350. if (userid == 3542 && entity.seller_memo != "")
  2351. {
  2352. string userPost = CurrentUser.UserPost.Post.Code;
  2353. if (CurrentUser.UserID == 73)
  2354. {
  2355. userPost = "SysAdmin";
  2356. }
  2357. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2358. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2359. if (response.msg != "设计共创:成功")
  2360. {
  2361. returnErrorMsg(response.msg);
  2362. return;
  2363. }
  2364. entity.DispatchSort = 2;
  2365. }
  2366. else
  2367. {
  2368. if (entity.DispatchSort == 2)
  2369. {
  2370. ApiVo apiVo = new ApiVo();
  2371. apiVo.actionName = "closeDesign";
  2372. apiVo.orderNumber = entity.ctid;
  2373. designHelper.API_WorkCore(apiVo);//closeDesign
  2374. }
  2375. entity.DispatchSort = 0;
  2376. }
  2377. entity.DesignUserId = userid;
  2378. entity.WaitDesignTime = DateTime.Now;
  2379. entity.UpdateTime = DateTime.Now;
  2380. entity.Update();
  2381. string name = commonHelper.getUserNameById(userid);
  2382. commonHelper.UpdateRelationOrder(entity.ctid);
  2383. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2384. }
  2385. }
  2386. returnSuccessMsg("操作成功!");
  2387. return;
  2388. }
  2389. }
  2390. public string getTidByCtid(string ctid)
  2391. {
  2392. string tid = "";
  2393. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2394. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2395. if (dataTable != null && dataTable.Rows.Count > 0)
  2396. {
  2397. tid = dataTable.Rows[0]["tid"].ToString();
  2398. }
  2399. return tid;
  2400. }
  2401. public List<string> getTidByCtidMore(string ctid)
  2402. {
  2403. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or tid = '{0}' or orderSn = '{0}' or ( ParentSplitNo = '{0}' and IsSample =2) or (ptid = '{0}' and IsSample =2 ))", ctid);
  2404. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2405. List<string> list = new List<string>();
  2406. if (dataTable != null && dataTable.Rows.Count > 0)
  2407. {
  2408. foreach (DataRow item in dataTable.Rows)
  2409. {
  2410. list.Add("'" + item["tid"].ToString() + "'");
  2411. }
  2412. }
  2413. return list;
  2414. }
  2415. public List<string> getTidByCtidLike(string ctid)
  2416. {
  2417. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2418. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2419. List<string> list = new List<string>();
  2420. if (dataTable != null && dataTable.Rows.Count > 0)
  2421. {
  2422. foreach (DataRow item in dataTable.Rows)
  2423. {
  2424. list.Add("'" + item["tid"].ToString() + "'");
  2425. }
  2426. }
  2427. return list;
  2428. }
  2429. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2430. {
  2431. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2432. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2433. List<string> list = new List<string>();
  2434. if (dataTable != null && dataTable.Rows.Count > 0)
  2435. {
  2436. foreach (DataRow item in dataTable.Rows)
  2437. {
  2438. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2439. {
  2440. continue;
  2441. }
  2442. list.Add("'" + item["receiverId"].ToString() + "'");
  2443. }
  2444. }
  2445. return list;
  2446. }
  2447. public void get_erp_myorderlist()
  2448. {
  2449. DataStruct dStruct = GetPostStruct();
  2450. List<string> lw = new List<string>();
  2451. string tid = GetPostString("ctid");
  2452. if (tid.Length > 0)
  2453. {
  2454. string select_tid = getTidByCtid(tid);
  2455. lw.Add(string.Format("tid='{0}'", select_tid));
  2456. }
  2457. else
  2458. {
  2459. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2460. }
  2461. //12-1 修改
  2462. string urgent = GetPostString("urgent");
  2463. string back = GetPostString("back");
  2464. string offlineSearch = GetPostString("offlineSearch");
  2465. if (!string.IsNullOrWhiteSpace(urgent))
  2466. {
  2467. if (urgent.Equals("true"))
  2468. {
  2469. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2470. }
  2471. }
  2472. if (!string.IsNullOrWhiteSpace(back))
  2473. {
  2474. if (back.Equals("true"))
  2475. {
  2476. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2477. }
  2478. }
  2479. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2480. {
  2481. if (offlineSearch.Equals("true"))
  2482. {
  2483. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2484. }
  2485. }
  2486. //end
  2487. string shopname = GetPostString("shopname");
  2488. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2489. string buyernick = GetPostString("buyer_nick");
  2490. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2491. string design = GetPostString("design");
  2492. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2493. string orderState = GetPostString("orderState");
  2494. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2495. string sellermemo = GetPostString("seller_memo");
  2496. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2497. string date1 = GetPostString("date1");
  2498. string date2 = GetPostString("date2");
  2499. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2500. if (dw.Length > 0) lw.Add(dw);
  2501. string price1 = GetPostString("price1");
  2502. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2503. string price2 = GetPostString("price2");
  2504. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2505. string urgency = GetPostString("urgency");
  2506. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2507. string after = GetPostString("after");
  2508. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2509. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2510. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2511. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2512. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2513. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2514. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2515. if (dt != null && dt.Rows.Count > 0)
  2516. {
  2517. foreach (DataRow dr in dt.Rows)
  2518. {
  2519. try
  2520. {
  2521. // 对象操作
  2522. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2523. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2524. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2525. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2526. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2527. if (dStruct.PageSize != 100000)
  2528. {
  2529. if (dr["DispatchSort"].ToString() == "2")
  2530. {
  2531. dr["gongchuang"] = 200;
  2532. }
  2533. else if ("外协".Equals(dr["ToType"].ToString()))
  2534. {
  2535. dr["gongchuang"] = 200;
  2536. }
  2537. else if ("内部".Equals(dr["ToType"].ToString()))
  2538. {
  2539. dr["gongchuang"] = -1;
  2540. }
  2541. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2542. {
  2543. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2544. dr["gongchuang"] = response.code;
  2545. }
  2546. }
  2547. }
  2548. catch (NullReferenceException ex)
  2549. {
  2550. }
  2551. }
  2552. }
  2553. writeGridDataTableJson(dStruct.TotalCount, dt);
  2554. }
  2555. public void get_erp_myreturnorderlist()
  2556. {
  2557. DataStruct dStruct = GetPostStruct();
  2558. List<string> lw = new List<string>();
  2559. string tid = GetPostString("ctid");
  2560. if (tid.Length > 0)
  2561. {
  2562. string select_tid = getTidByCtid(tid);
  2563. lw.Add(string.Format("tid='{0}'", select_tid));
  2564. }
  2565. else
  2566. {
  2567. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2568. }
  2569. string shopname = GetPostString("shopname");
  2570. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2571. string buyernick = GetPostString("buyer_nick");
  2572. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2573. string design = GetPostString("design");
  2574. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2575. string orderState = GetPostString("orderState");
  2576. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2577. string sellermemo = GetPostString("seller_memo");
  2578. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2579. string date1 = GetPostString("date1");
  2580. string date2 = GetPostString("date2");
  2581. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2582. if (dw.Length > 0) lw.Add(dw);
  2583. string price1 = GetPostString("price1");
  2584. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2585. string price2 = GetPostString("price2");
  2586. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2587. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  2588. {
  2589. lw.Add(string.Format("CusOrgID = 94"));
  2590. }
  2591. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2592. {
  2593. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2594. }
  2595. else
  2596. {
  2597. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2598. }
  2599. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2600. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2601. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2602. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2603. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2604. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2605. if (dt != null && dt.Rows.Count > 0)
  2606. {
  2607. foreach (DataRow dr in dt.Rows)
  2608. {
  2609. try
  2610. {
  2611. // 对象操作
  2612. if (dStruct.PageSize != 100000)
  2613. {
  2614. if (dr["DispatchSort"].ToString() == "2")
  2615. {
  2616. dr["gongchuang"] = 200;
  2617. }
  2618. else if ("外协".Equals(dr["ToType"].ToString()))
  2619. {
  2620. dr["gongchuang"] = 200;
  2621. }
  2622. else if ("内部".Equals(dr["ToType"].ToString()))
  2623. {
  2624. dr["gongchuang"] = -1;
  2625. }
  2626. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2627. {
  2628. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2629. dr["gongchuang"] = response.code;
  2630. }
  2631. }
  2632. }
  2633. catch (NullReferenceException ex)
  2634. {
  2635. // 处理空引用异常
  2636. }
  2637. }
  2638. }
  2639. writeGridDataTableJson(dStruct.TotalCount, dt);
  2640. }
  2641. public void get_erp_myorderlist_pregather()
  2642. {
  2643. string date1 = GetPostString("date1");
  2644. string date2 = GetPostString("date2");
  2645. int userId = CurrentUser.UserID; //客服id
  2646. string orderWhere = "";
  2647. List<string> lw = new List<string>();
  2648. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2649. if (dw.Length > 0) lw.Add(dw);
  2650. lw.Add(string.Format("CustomerUserId={0}", userId));
  2651. lw.Add(string.Format("OrderState<9"));
  2652. orderWhere = string.Join(" and ", lw.ToArray());
  2653. string orderWhere2 = "";
  2654. List<string> lw2 = new List<string>();
  2655. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2656. if (dw2.Length > 0) lw2.Add(dw2);
  2657. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2658. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2659. string sql = string.Format("select *" +
  2660. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2661. "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 " +
  2662. "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 " +
  2663. "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");
  2664. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2665. //writeGridDataTableJson(dt.Rows.Count, dt);
  2666. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2667. }
  2668. public void upd_erp_publishorder()
  2669. {
  2670. if (UrlPostParmsCheck("ctid"))
  2671. {
  2672. string eid = GetPostString("ctid");
  2673. CeErpTradeCell entity = null;
  2674. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2675. if (entity != null)
  2676. {
  2677. entity.OrderState = 0; //发布后,变为待抢单
  2678. entity.Update();
  2679. commonHelper.UpdateRelationOrder(entity.ctid);
  2680. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2681. returnSuccessMsg("发布成功!");
  2682. return;
  2683. }
  2684. returnErrorMsg("找不到记录");
  2685. }
  2686. }
  2687. public void get_erp_my_tiporder()
  2688. {
  2689. StringBuilder sql = new StringBuilder();
  2690. int userId = 0;
  2691. if (CurrentUser != null) userId = CurrentUser.UserID;
  2692. string posCode = CurrentUser.UserPost.Post.Code;
  2693. string isTipedAfterSaleVerify = GetPostString("af");
  2694. DataTable dt = new DataTable();
  2695. if (posCode != "Supplier")
  2696. {
  2697. if (posCode == "CustomerService" || posCode == "Director")
  2698. {
  2699. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2700. }
  2701. else if (posCode == "Place" || posCode == "PlaceMr")
  2702. {
  2703. }
  2704. else
  2705. {
  2706. string teamIds = CurrentUser.User.TeamIds;
  2707. if (teamIds == "")
  2708. {
  2709. teamIds = "0";
  2710. }
  2711. 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);
  2712. }
  2713. if (sql.Length > 0)
  2714. {
  2715. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2716. }
  2717. }
  2718. if (dt.Rows.Count <= 0)
  2719. {
  2720. string key = "aftersale_order_" + userId;
  2721. if (RedisHelper.HasKey(key))
  2722. {
  2723. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2724. dt.Columns.Add("ctid", typeof(string));
  2725. dt.Columns.Add("IsReadTag", typeof(int));
  2726. foreach (var i in list)
  2727. {
  2728. DataRow data = dt.NewRow();
  2729. data["ctid"] = i;
  2730. data["IsReadTag"] = 4;
  2731. dt.Rows.Add(data);
  2732. }
  2733. RedisHelper.StringDelete(key);
  2734. }
  2735. }
  2736. if (dt.Rows.Count <= 0)
  2737. {
  2738. sql = new StringBuilder();
  2739. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2740. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2741. }
  2742. if (posCode == "Supplier")
  2743. {
  2744. string ids = CurrentUser.User.pemVend;
  2745. if (ids != null && ids.Length > 0)
  2746. {
  2747. string[] ids_list = ids.Split(',');
  2748. foreach (var item in ids_list)
  2749. {
  2750. string key = "return_order_" + item;
  2751. if (RedisHelper.HasKey(key))
  2752. {
  2753. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2754. dt.Columns.Add("ctid", typeof(string));
  2755. dt.Columns.Add("IsReadTag", typeof(int));
  2756. foreach (var i in list)
  2757. {
  2758. DataRow data = dt.NewRow();
  2759. data["ctid"] = i;
  2760. data["IsReadTag"] = 1;
  2761. dt.Rows.Add(data);
  2762. }
  2763. RedisHelper.StringDelete(key);
  2764. }
  2765. }
  2766. }
  2767. if (dt.Rows.Count <= 0)
  2768. {
  2769. sql = new StringBuilder();
  2770. 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);
  2771. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2772. }
  2773. }
  2774. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2775. }
  2776. public void reset_erp_tiporder()
  2777. {
  2778. string ids = GetPostString("ids");
  2779. string[] ctidList = ids.Split(',');
  2780. foreach (string ctid in ctidList)
  2781. {
  2782. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2783. if (enty != null)
  2784. {
  2785. enty.IsReadTag = 0;
  2786. enty.Update();
  2787. }
  2788. }
  2789. returnSuccessMsg("成功!");
  2790. return;
  2791. }
  2792. public void get_erp_designlist()
  2793. {
  2794. DataStruct dStruct = GetPostStruct();
  2795. List<string> lw = new List<string>();
  2796. string tid = GetPostString("ctid");
  2797. if (tid.Length > 0)
  2798. {
  2799. string select_tid = getTidByCtid(tid);
  2800. lw.Add(string.Format("tid='{0}'", select_tid));
  2801. }
  2802. string shopname = GetPostString("shopname");
  2803. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2804. string buyernick = GetPostString("buyer_nick");
  2805. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2806. string customer = GetPostString("customer");
  2807. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2808. string design = GetPostString("design");
  2809. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2810. string orderState = GetPostString("orderState");
  2811. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2812. lw.Add(string.Format("OrderState<6"));
  2813. string address = GetPostString("address");
  2814. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2815. string sellermemo = GetPostString("seller_memo");
  2816. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2817. string date1 = GetPostString("date1");
  2818. string date2 = GetPostString("date2");
  2819. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2820. if (dw.Length > 0) lw.Add(dw);
  2821. string apdate1 = GetPostString("apdate1");
  2822. string apdate2 = GetPostString("apdate2");
  2823. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2824. if (dwap.Length > 0) lw.Add(dwap);
  2825. string price1 = GetPostString("price1");
  2826. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2827. string price2 = GetPostString("price2");
  2828. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2829. string designTime = GetPostString("designtime");
  2830. if (designTime.Length > 0)
  2831. {
  2832. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2833. }
  2834. string usershop = CurrentUser.User.pemShop;
  2835. if (usershop.Length > 0)
  2836. {
  2837. lw.Add(string.Format("shopId in ({0})", usershop));
  2838. }
  2839. int myOrgid = CurrentUser.UserPost.OrgID;
  2840. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2841. if (myOrgCode.IndexOf("Designer") != -1)
  2842. {
  2843. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2844. {
  2845. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2846. }
  2847. else
  2848. {
  2849. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2850. }
  2851. }
  2852. else
  2853. {
  2854. string orgId = GetPostString("designerhd");
  2855. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2856. }
  2857. if (tid.Length > 0 || buyernick.Length > 0)
  2858. {
  2859. lw.Add(string.Format("OrderState >= 3"));
  2860. }
  2861. else
  2862. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2863. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2864. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2865. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2866. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2867. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2868. if (dt != null && dt.Rows.Count > 0)
  2869. {
  2870. foreach (DataRow dr in dt.Rows)
  2871. {
  2872. try
  2873. {
  2874. // 对象操作
  2875. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2876. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2877. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2878. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2879. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2880. if (dStruct.PageSize != 100000)
  2881. {
  2882. if (dr["DispatchSort"].ToString() == "2")
  2883. {
  2884. dr["gongchuang"] = 200;
  2885. }
  2886. else if ("外协".Equals(dr["ToType"].ToString()))
  2887. {
  2888. dr["gongchuang"] = 200;
  2889. }
  2890. else if ("内部".Equals(dr["ToType"].ToString()))
  2891. {
  2892. dr["gongchuang"] = -1;
  2893. }
  2894. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2895. {
  2896. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2897. dr["gongchuang"] = response.code;
  2898. }
  2899. }
  2900. }
  2901. catch (NullReferenceException ex)
  2902. {
  2903. }
  2904. }
  2905. }
  2906. writeGridDataTableJson(dStruct.TotalCount, dt);
  2907. }
  2908. public void get_erp_mydesignlist()
  2909. {
  2910. DataStruct dStruct = GetPostStruct();
  2911. List<string> lw = new List<string>();
  2912. string tid = GetPostString("ctid");
  2913. if (tid.Length > 0)
  2914. {
  2915. string select_tid = getTidByCtid(tid);
  2916. lw.Add(string.Format("tid='{0}'", select_tid));
  2917. }
  2918. string shopname = GetPostString("shopname");
  2919. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2920. string buyernick = GetPostString("buyer_nick");
  2921. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2922. string customer = GetPostString("customer");
  2923. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2924. string orderState = GetPostString("orderState");
  2925. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2926. //lw.Add(string.Format("OrderState<6"));
  2927. string date1 = GetPostString("date1");
  2928. string date2 = GetPostString("date2");
  2929. string dw = GetDateWhere("pay_time", date1, date2);
  2930. if (dw.Length > 0) lw.Add(dw);
  2931. string apdate1 = GetPostString("apdate1");
  2932. string apdate2 = GetPostString("apdate2");
  2933. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2934. if (dwap.Length > 0) lw.Add(dwap);
  2935. string price1 = GetPostString("price1");
  2936. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2937. string price2 = GetPostString("price2");
  2938. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2939. string olddownload = GetPostString("olddown");
  2940. if (olddownload == "1")
  2941. {
  2942. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2943. }
  2944. else if (olddownload == "2")
  2945. {
  2946. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2947. }
  2948. string sellermemo = GetPostString("seller_memo");
  2949. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2950. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2951. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2952. {
  2953. if (CurrentUser.User.TeamIds.Length > 0)
  2954. {
  2955. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2956. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2957. else
  2958. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2959. }
  2960. else
  2961. {
  2962. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2963. }
  2964. }
  2965. if (tid.Length <= 0)
  2966. {
  2967. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2968. }
  2969. lw.Add(string.Format("IsReturn!=3"));
  2970. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2971. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2972. string teamids = CurrentUser.User.TeamIds.ToString();
  2973. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2974. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2975. if (dt != null && dt.Rows.Count > 0)
  2976. {
  2977. foreach (DataRow dr in dt.Rows)
  2978. {
  2979. try
  2980. {
  2981. // 对象操作
  2982. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2983. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2984. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2985. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2986. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2987. if (dStruct.PageSize != 100000)
  2988. {
  2989. if (dr["DispatchSort"].ToString() == "2")
  2990. {
  2991. dr["gongchuang"] = 200;
  2992. }
  2993. else if ("外协".Equals(dr["ToType"].ToString()))
  2994. {
  2995. dr["gongchuang"] = 200;
  2996. }
  2997. else if ("内部".Equals(dr["ToType"].ToString()))
  2998. {
  2999. dr["gongchuang"] = -1;
  3000. }
  3001. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  3002. {
  3003. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  3004. dr["gongchuang"] = response.code;
  3005. }
  3006. }
  3007. }
  3008. catch (NullReferenceException ex)
  3009. {
  3010. }
  3011. }
  3012. }
  3013. writeGridDataTableJson(dStruct.TotalCount, dt);
  3014. }
  3015. public void set_erp_startdesign()
  3016. {
  3017. if (UrlPostParmsCheck("ctid"))
  3018. {
  3019. string eid = GetPostString("ctid");
  3020. CeErpTradeCell entity = null;
  3021. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3022. if (entity != null)
  3023. {
  3024. if (entity.OrderState != 3)
  3025. {
  3026. returnErrorMsg("请刷新,订单已经设计了");
  3027. return;
  3028. }
  3029. entity.StartDesignTime = DateTime.Now;
  3030. entity.OrderState = 4;
  3031. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  3032. {
  3033. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3034. entity.SupplierId = suid;
  3035. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3036. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3037. }
  3038. entity.UpdateTime = DateTime.Now;
  3039. //entity.MakeSupplier = suname;
  3040. entity.Update();
  3041. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3042. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3043. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  3044. commonHelper.getCytPrice(entity);
  3045. returnSuccessMsg("操作成功!");
  3046. return;
  3047. }
  3048. returnErrorMsg("找不到记录");
  3049. }
  3050. }
  3051. public void ins_erp_designselfmemo()
  3052. {
  3053. if (UrlPostParmsCheck("ctid"))
  3054. {
  3055. string eid = GetPostString("ctid");
  3056. string con = GetPostString("con");
  3057. CeErpTradeCell entity = null;
  3058. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3059. if (entity != null)
  3060. {
  3061. entity.DesignSelfMemo = con;
  3062. entity.Update();
  3063. returnSuccessMsg("操作成功!");
  3064. return;
  3065. }
  3066. returnErrorMsg("找不到记录");
  3067. }
  3068. }
  3069. public void ins_erp_designprice()
  3070. {
  3071. if (UrlPostParmsCheck("ctid"))
  3072. {
  3073. string eid = GetPostString("ctid");
  3074. int uid = CurrentUser.UserID;
  3075. string userName = CurrentUser.UserName;
  3076. CeErpTradeCell entity = null;
  3077. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  3078. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3079. if (entitys == null)
  3080. {
  3081. entitys = new CeErpDesignerBill();
  3082. }
  3083. if (entity != null)
  3084. {
  3085. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  3086. //entity.Number = Convert.ToInt32(GetPostString("number"));
  3087. entity.StartDesignTime = DateTime.Now;
  3088. entity.OrderState = 4;
  3089. string suname = "";
  3090. if (entity.SupplierId == 0)
  3091. {
  3092. int sid = commonHelper.autoDistributeToSupplier(entity);
  3093. entity.SupplierId = sid;
  3094. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3095. }
  3096. entity.Update();
  3097. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  3098. if (ceErpUserPost != null)
  3099. {
  3100. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  3101. if (ceErpPost != null)
  3102. {
  3103. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  3104. {
  3105. entitys.tid = entity.ctid;
  3106. entitys.oid = entity.tid;
  3107. entitys.uid = uid;
  3108. entitys.userName = userName;
  3109. entitys.designerType = 1;
  3110. entitys.designerTypeText = "内部设计师";
  3111. entitys.price = Convert.ToDouble(GetPostString("price"));
  3112. entitys.designNum = GetPostInt("designNum");
  3113. entitys.modifyNum = GetPostInt("modifyNum");
  3114. entitys.designSize = GetPostString("designSize");
  3115. entitys.modifySize = GetPostString("modifySize");
  3116. if (CeErpDesignerBill.GetByTid("ctid") == null)
  3117. {
  3118. entitys.create_time = DateTime.Now;
  3119. entitys.create_u_id = uid;
  3120. entitys.create_u_name = userName;
  3121. entitys.Save();
  3122. }
  3123. else
  3124. {
  3125. entitys.update_time = DateTime.Now;
  3126. entitys.update_u_id = uid;
  3127. entitys.update_u_name = userName;
  3128. entitys.Update();
  3129. }
  3130. }
  3131. }
  3132. }
  3133. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3134. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3135. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  3136. if (suname != "")
  3137. {
  3138. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3139. }
  3140. commonHelper.getCytPrice(entity);
  3141. returnSuccessMsg("操作成功!");
  3142. return;
  3143. }
  3144. returnErrorMsg("找不到记录");
  3145. }
  3146. }
  3147. public void upload_erp_filecomplete()
  3148. {
  3149. if (UrlPostParmsCheck("ctid"))
  3150. {
  3151. string eid = GetPostString("ctid");
  3152. CeErpTradeCell entity = null;
  3153. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3154. if (entity != null)
  3155. {
  3156. entity.OrderState = 5; //设计完成
  3157. entity.Update();
  3158. returnSuccessMsg(eid + "上传成功,设计完成!");
  3159. return;
  3160. }
  3161. returnErrorMsg("找不到订单记录");
  3162. }
  3163. }
  3164. public void get_erp_designovertimelist()
  3165. {
  3166. DataStruct dStruct = GetPostStruct();
  3167. List<string> lw = new List<string>();
  3168. string tid = GetPostString("ctid");
  3169. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3170. string shopname = GetPostString("shopname");
  3171. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3172. string buyernick = GetPostString("buyer_nick");
  3173. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3174. string ResponsibleMan = GetPostString("responsible");
  3175. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3176. string date1 = GetPostString("date1");
  3177. string date2 = GetPostString("date2");
  3178. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3179. if (dw.Length > 0) lw.Add(dw);
  3180. string price1 = GetPostString("price1");
  3181. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3182. string price2 = GetPostString("price2");
  3183. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3184. string orderState = GetPostString("orderState");
  3185. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3186. string sellermemo = GetPostString("seller_memo");
  3187. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3188. lw.Add(string.Format("UnusualTag=3"));
  3189. lw.Add(string.Format("IsRefund<={0}", 1));
  3190. dStruct.Order = "WaitDesignTime desc";
  3191. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3192. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3193. writeGridDataTableJson(dStruct.TotalCount, dt);
  3194. }
  3195. //设计管理 获取抢单大厅列表
  3196. public void get_erp_grabinglist()
  3197. {
  3198. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3199. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3200. bool oldOrder = false;
  3201. if (org != null)
  3202. {
  3203. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3204. }
  3205. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3206. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3207. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3208. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3209. //先处理订单数据
  3210. if (dt.Rows.Count > 0)
  3211. {
  3212. Dictionary<string, int> design = null;
  3213. int count = 0;
  3214. foreach (DataRow row in dt.Rows)
  3215. {
  3216. if (map.ContainsKey(row["ShopId"].ToString()))
  3217. {
  3218. map.TryGetValue(row["ShopId"].ToString(), out design);
  3219. }
  3220. else
  3221. {
  3222. design = new Dictionary<string, int>();
  3223. }
  3224. if (design.ContainsKey(row["ProductId"].ToString()))
  3225. {
  3226. design.TryGetValue(row["ProductId"].ToString(), out count);
  3227. }
  3228. count++;
  3229. design[row["ProductId"].ToString()] = count;
  3230. map[row["ShopId"].ToString()] = design;
  3231. }
  3232. }
  3233. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3234. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3235. //把店铺排序和技能排序分类
  3236. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3237. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3238. if (design_dt.Rows.Count > 0)
  3239. {
  3240. Dictionary<string, string> design = null;
  3241. List<string> shopIds = null;
  3242. foreach (DataRow row in design_dt.Rows)
  3243. {
  3244. if ("0".Equals(row["designId"].ToString()))
  3245. {
  3246. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3247. {
  3248. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3249. }
  3250. else
  3251. {
  3252. shopIds = new List<string>();
  3253. }
  3254. shopIds.Add(row["shopId"].ToString());
  3255. shop_orders[row["orders"].ToString()] = shopIds;
  3256. }
  3257. else
  3258. {
  3259. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3260. {
  3261. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3262. }
  3263. else
  3264. {
  3265. design = new Dictionary<string, string>();
  3266. }
  3267. design[row["orders"].ToString()] = row["designId"].ToString();
  3268. design_orders[row["shopId"].ToString()] = design;
  3269. }
  3270. }
  3271. //处理成key value后根据key排序
  3272. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3273. foreach (List<string> val in shop_orders.Values)
  3274. {
  3275. if (val != null)
  3276. {
  3277. foreach (string key in val)
  3278. {
  3279. if (design_orders.ContainsKey(key.ToString()))
  3280. {
  3281. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3282. }
  3283. }
  3284. }
  3285. }
  3286. }
  3287. //校验哪个优先级有订单
  3288. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3289. foreach (string key in shop_orders.Keys)
  3290. {
  3291. List<string> ids = null;
  3292. shop_orders.TryGetValue(key, out ids);
  3293. //id为shopid
  3294. foreach (string id in ids)
  3295. {
  3296. Dictionary<string, int> list = null;
  3297. Dictionary<string, string> desing = null;
  3298. map.TryGetValue(id, out list);
  3299. design_orders.TryGetValue(id, out desing);
  3300. if (list != null && desing != null)
  3301. {
  3302. foreach (var item in desing)
  3303. {
  3304. int count = 0;
  3305. if (list.ContainsKey(item.Value))
  3306. {
  3307. list.TryGetValue(item.Value, out count);
  3308. if (count > 0)
  3309. {
  3310. designIds[id] = item.Value;
  3311. break;
  3312. }
  3313. }
  3314. }
  3315. }
  3316. }
  3317. if (designIds.Count > 0)
  3318. {
  3319. break;
  3320. }
  3321. }
  3322. DataTable table = new DataTable();
  3323. table.Columns.Add("tid", typeof(string));
  3324. table.Columns.Add("ctid", typeof(string));
  3325. table.Columns.Add("seller_nick", typeof(string));
  3326. table.Columns.Add("productName", typeof(string));
  3327. table.Columns.Add("pay_time", typeof(string));
  3328. table.Columns.Add("seller_memo", typeof(string));
  3329. if (designIds.Count > 0)
  3330. {
  3331. string shopId = "";
  3332. string productId = "";
  3333. foreach (var designInfo in designIds)
  3334. {
  3335. shopId = designInfo.Key;
  3336. productId = designInfo.Value;
  3337. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3338. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3339. if (dt.Rows.Count > 0)
  3340. {
  3341. foreach (DataRow row in dt.Rows)
  3342. {
  3343. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3344. {
  3345. DataRow data = table.NewRow();
  3346. data["ctid"] = row["ctid"].ToString();
  3347. data["tid"] = row["tid"].ToString();
  3348. data["seller_nick"] = ceErpShop.ShopName;
  3349. data["pay_time"] = row["pay_time"].ToString();
  3350. data["seller_memo"] = row["seller_memo"].ToString();
  3351. data["productName"] = ceErpProduct.PType;
  3352. table.Rows.Add(data);
  3353. }
  3354. }
  3355. }
  3356. }
  3357. }
  3358. writeGridDataTableJson(table.Rows.Count, table);
  3359. }
  3360. private object rushLockObject = new object();
  3361. public void set_erp_grabingorder()
  3362. {
  3363. if (UrlPostParmsCheck("ctid"))
  3364. {
  3365. int total = CurrentUser.User.Person.Total;
  3366. int userId = CurrentUser.User.ID;
  3367. int noFinish = CurrentUser.User.Person.NoFinish;
  3368. int finalization = CurrentUser.User.Person.Finalization;
  3369. string eids = GetPostString("ctid");
  3370. string key = "RushKey_" + userId;
  3371. int count = 0;
  3372. if (erpRedis.RedisHelper.KeyExists(key))
  3373. {
  3374. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3375. if (redisCount != null)
  3376. {
  3377. count = Convert.ToInt32(redisCount);
  3378. }
  3379. }
  3380. if (count >= total)
  3381. {
  3382. returnErrorMsg("半小时内已经抢" + total + "单");
  3383. return;
  3384. }
  3385. string[] ctidlist = eids.Split(',');
  3386. if (count + ctidlist.Length > total)
  3387. {
  3388. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3389. return;
  3390. }
  3391. int itag = 0;
  3392. lock (rushLockObject)
  3393. {
  3394. if (ctidlist.Length > 0)
  3395. {
  3396. string[] dtList = new string[ctidlist.Length];
  3397. for (int i = 0; i < ctidlist.Length; i++)
  3398. {
  3399. dtList[i] = "'" + ctidlist[i] + "'";
  3400. }
  3401. 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"));
  3402. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3403. if (dt_user.Rows.Count > 0)
  3404. {
  3405. int doing = 0;//未定稿
  3406. int finish = 0;//已完成
  3407. foreach (DataRow dr in dt_user.Rows)
  3408. {
  3409. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3410. {
  3411. doing++;
  3412. }
  3413. else
  3414. {
  3415. finish++;
  3416. }
  3417. }
  3418. if (doing >= noFinish)
  3419. {
  3420. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3421. return;
  3422. }
  3423. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3424. {
  3425. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3426. return;
  3427. }
  3428. }
  3429. //校验选择单子状态
  3430. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3431. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3432. if (dt.Rows.Count > 0)
  3433. {
  3434. List<string> list = new List<string>();
  3435. foreach (DataRow dr in dt.Rows)
  3436. {
  3437. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3438. {
  3439. list.Add(dr["ctid"].ToString());
  3440. }
  3441. }
  3442. if (list.Count > 0)
  3443. {
  3444. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3445. return;
  3446. }
  3447. }
  3448. foreach (string ctid in ctidlist)
  3449. {
  3450. CeErpTradeCell entity = null;
  3451. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3452. if (entity != null)
  3453. {
  3454. entity.OrderState = 3;
  3455. entity.DesignUserId = CurrentUser.UserID;
  3456. entity.WaitDesignTime = DateTime.Now;
  3457. entity.StartDesignTime = DateTime.Now;
  3458. entity.Update();
  3459. commonHelper.UpdateRelationOrder(entity.ctid);
  3460. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3461. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3462. itag++;
  3463. }
  3464. }
  3465. }
  3466. }
  3467. count += ctidlist.Length;
  3468. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3469. if (itag == 0)
  3470. returnErrorMsg("没有找到相关订单");
  3471. else
  3472. returnSuccessMsg("抢单成功!");
  3473. return;
  3474. }
  3475. }
  3476. public void get_erp_waitorderlist()
  3477. {
  3478. DataStruct dStruct = GetPostStruct();
  3479. List<string> lw = new List<string>();
  3480. string tid = GetPostString("ctid");
  3481. if (tid.Length > 0)
  3482. {
  3483. string select_tid = getTidByCtid(tid);
  3484. lw.Add(string.Format("tid='{0}'", select_tid));
  3485. }
  3486. string shopname = GetPostString("shopname");
  3487. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3488. string buyernick = GetPostString("buyer_nick");
  3489. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3490. string customer = GetPostString("customer");
  3491. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3492. string design = GetPostString("design");
  3493. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3494. string orderState = GetPostString("orderState");
  3495. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3496. string supplier = GetPostString("supplier");
  3497. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3498. string sellermemo = GetPostString("seller_memo");
  3499. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3500. string otherMemo = GetPostString("otherMemo");
  3501. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3502. string address = GetPostString("address");
  3503. 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));
  3504. string date1 = GetPostString("date1");
  3505. string date2 = GetPostString("date2");
  3506. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3507. if (dw.Length > 0) lw.Add(dw);
  3508. string price1 = GetPostString("price1");
  3509. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3510. string price2 = GetPostString("price2");
  3511. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3512. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3513. lw.Add(string.Format("IsSample != 2 "));
  3514. lw.Add(string.Format("OrderState = 5 "));
  3515. lw.Add(string.Format("IsRefund<={0}", 1));
  3516. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3517. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3518. string pagesize = GetPostString("pagesize");
  3519. if (pagesize != null)
  3520. {
  3521. dStruct.PageSize = 200;
  3522. }
  3523. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3524. List<string> tids = new List<string>();
  3525. if (dt != null)
  3526. {
  3527. dt.Columns.Add("compenPrice", typeof(double));
  3528. foreach (DataRow dr in dt.Rows)
  3529. {
  3530. if (Convert.IsDBNull(dr["compenPrice"]))
  3531. {
  3532. dr["compenPrice"] = 0;
  3533. }
  3534. tids.Add("'" + dr["tid"].ToString() + "'");
  3535. 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();
  3536. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3537. {
  3538. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3539. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3540. entity.SupplierId = suid;
  3541. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3542. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3543. entity.Update();
  3544. }
  3545. }
  3546. }
  3547. if (tids.Count > 0)
  3548. {
  3549. string sql = string.Format("select ptid,payment from CE_ErpTradeCell where ptid in (" + string.Join(",", tids) + ") and IsSample = 2");
  3550. DataTable dt_price = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3551. if (dt_price != null && dt_price.Rows.Count > 0)
  3552. {
  3553. foreach (DataRow dr in dt_price.Rows)
  3554. {
  3555. foreach (DataRow row in dt.Rows)
  3556. {
  3557. if (row["tid"].Equals(dr["ptid"]))
  3558. {
  3559. row["compenPrice"] = Convert.ToDouble(row["compenPrice"]) + Convert.ToDouble(dr["payment"]);
  3560. break;
  3561. }
  3562. }
  3563. }
  3564. }
  3565. }
  3566. writeGridDataTableJson(dStruct.TotalCount, dt);
  3567. }
  3568. public void get_erp_supplierwaitorderlist()
  3569. {
  3570. DataStruct dStruct = GetPostStruct();
  3571. List<string> lw = new List<string>();
  3572. string tid = GetPostString("ctid");
  3573. if (tid.Length > 0)
  3574. {
  3575. string select_tid = getTidByCtid(tid);
  3576. lw.Add(string.Format("tid='{0}'", select_tid));
  3577. }
  3578. string shopname = GetPostString("shopname");
  3579. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3580. string sellermemo = GetPostString("seller_memo");
  3581. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3582. string date1 = GetPostString("date1");
  3583. string date2 = GetPostString("date2");
  3584. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3585. if (dw.Length > 0) lw.Add(dw);
  3586. lw.Add(string.Format("OrderState = 5 "));
  3587. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3588. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3589. {
  3590. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3591. }
  3592. string supplier = GetPostString("supplier");
  3593. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3594. {
  3595. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3596. }
  3597. lw.Add(string.Format("IsRefund<={0}", 1));
  3598. dStruct.Order = "FinishDesignTime desc";
  3599. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3600. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3601. if (dt != null)
  3602. {
  3603. foreach (DataRow dr in dt.Rows)
  3604. {
  3605. 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();
  3606. }
  3607. }
  3608. writeGridDataTableJson(dStruct.TotalCount, dt);
  3609. }
  3610. public void upd_erp_verifytosupplier()
  3611. {
  3612. if (UrlPostParmsCheck("ctid"))
  3613. {
  3614. string eids = GetPostString("ctid");
  3615. CeErpTradeCell entity = null;
  3616. string[] eidsList = eids.Split(',');
  3617. if (eidsList.Length <= 0)
  3618. {
  3619. returnErrorMsg("订单号不能空");
  3620. return;
  3621. }
  3622. List<string> tLst = new List<string>();
  3623. foreach (string ctidstr in eidsList)
  3624. {
  3625. tLst.Add("'" + ctidstr + "'");
  3626. CeErpDataSendOrderInfo.createObject(ctidstr);
  3627. }
  3628. string needtids = string.Join(",", tLst.ToArray());
  3629. StringBuilder sql = new StringBuilder();
  3630. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3631. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1},IsHaveNewOrder=0 where SupplierId!=0 AND OrderState = 5 and ctid in ({0});", needtids, CurrentUser.UserID);
  3632. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3633. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3634. returnSuccessMsg("操作成功!");
  3635. return;
  3636. /**foreach (string ctidstr in eidsList)
  3637. {
  3638. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3639. if (entity != null)
  3640. {
  3641. if (entity.SupplierId == 0)
  3642. {
  3643. continue;
  3644. }
  3645. entity.IsVerifyToSupplier = true;
  3646. if (entity.IsReturn == 1) //1是供应商打回
  3647. {
  3648. entity.IsReturn = 0;
  3649. }
  3650. entity.FinishPlaceTime = DateTime.Now;
  3651. entity.PlaceUserId = CurrentUser.UserID;
  3652. entity.Update();
  3653. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3654. }
  3655. }
  3656. returnSuccessMsg("操作成功!");
  3657. return;**/
  3658. }
  3659. }
  3660. public void upd_erp_supplierback()
  3661. {
  3662. if (UrlPostParmsCheck("ctid"))
  3663. {
  3664. string eid = GetPostString("ctid");
  3665. string reason = GetPostString("returnreason");
  3666. CeErpTradeCell entity = null;
  3667. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3668. if (entity != null)
  3669. {
  3670. string message = "操作成功!";
  3671. string isDown = "";
  3672. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  3673. {
  3674. message = "订单有被点击下载。请注意沟通是否已下载完!";
  3675. isDown = "被点击下载";
  3676. }
  3677. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3678. {
  3679. string key = "return_order_" + entity.SupplierId;
  3680. List<string> list = new List<string>();
  3681. if (RedisHelper.HasKey(key))
  3682. {
  3683. object data = RedisHelper.StringGet(key);
  3684. list = Convert.ToString(data).Split(',').ToList();
  3685. }
  3686. list.Add(eid);
  3687. RedisHelper.StringSet(key, string.Join(",", list));
  3688. }
  3689. entity.IsVerifyToSupplier = false;
  3690. entity.IsReturn = 1;
  3691. entity.IsHaveNewOrder = 0;
  3692. entity.ReturnTime = DateTime.Now;
  3693. entity.ReturnReason = reason;
  3694. if (entity.OrderState == 6)
  3695. {
  3696. entity.OrderState = 5;
  3697. }
  3698. entity.Update();
  3699. CeErpSukuraData.createInfo(entity.ctid, 5);
  3700. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason + "-" + isDown, entity.OrderState);
  3701. returnSuccessMsg(message);
  3702. return;
  3703. }
  3704. returnErrorMsg("找不到订单记录");
  3705. }
  3706. }
  3707. public void upd_erp_toaftersaleorder()
  3708. {
  3709. if (UrlPostParmsCheck("ctid"))
  3710. {
  3711. string eid = GetPostString("ctid");
  3712. string reason = GetPostString("returnreason");
  3713. CeErpTradeCell entity = null;
  3714. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3715. if (entity != null)
  3716. {
  3717. if (entity.isAfterSaleOrder != 1)
  3718. {
  3719. returnErrorMsg("带S的售后单才能打回给售后");
  3720. return;
  3721. }
  3722. if (entity.OrderState >= 5)
  3723. {
  3724. returnErrorMsg("已经设计完成了不能打回给售后");
  3725. return;
  3726. }
  3727. entity.OrderState = 0;
  3728. entity.IsReturn = 3;
  3729. entity.ReturnTime = DateTime.Now;
  3730. entity.UpdateTime = DateTime.Now;
  3731. entity.ReturnReason = reason;
  3732. entity.Update();
  3733. CeErpSukuraData.createInfo(entity.ctid, 5);
  3734. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3735. returnSuccessMsg("操作成功!");
  3736. return;
  3737. }
  3738. returnErrorMsg("找不到订单记录");
  3739. }
  3740. }
  3741. public void upd_erp_aftersaletodesign()
  3742. {
  3743. if (UrlPostParmsCheck("ctid"))
  3744. {
  3745. string eid = GetPostString("ctid");
  3746. CeErpTradeCell entity = null;
  3747. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3748. if (entity != null)
  3749. {
  3750. entity.OrderState = 3;
  3751. entity.IsReturn = 0;
  3752. entity.UpdateTime = DateTime.Now;
  3753. entity.Update();
  3754. CeErpSukuraData.createInfo(entity.ctid, 5);
  3755. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3756. returnSuccessMsg("操作成功!");
  3757. return;
  3758. }
  3759. returnErrorMsg("找不到订单记录");
  3760. }
  3761. }
  3762. public void assign_erp_supplier()
  3763. {
  3764. if (UrlPostParmsCheck("ctid"))
  3765. {
  3766. string eids = GetPostString("ctid");
  3767. int sid = GetPostInt("SupplierName");
  3768. string fromTag = GetPostString("tag");
  3769. string[] eidList = eids.Split(',');
  3770. if (eidList.Length <= 0)
  3771. {
  3772. returnErrorMsg("指派不能为空");
  3773. return;
  3774. }
  3775. string errMsg = "";
  3776. string suname = commonHelper.getSupplierNameById(sid);
  3777. foreach (string ctid in eidList)
  3778. {
  3779. CeErpTradeCell entity = null;
  3780. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3781. if (entity != null)
  3782. {
  3783. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3784. {
  3785. errMsg += (ctid + "指派失败!!!");
  3786. continue;
  3787. }
  3788. entity.SupplierId = sid;
  3789. entity.Update();
  3790. commonHelper.UpdateRelationOrder(entity.ctid);
  3791. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3792. if (entity.OrderState >= 6)
  3793. {
  3794. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3795. //{
  3796. // string msl = entity.MakeSupplier;
  3797. // string[] mslist = msl.Split(',');
  3798. // 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);
  3799. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3800. //}
  3801. //else
  3802. //{
  3803. StringBuilder sql = new StringBuilder();
  3804. 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);
  3805. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3806. //}
  3807. }
  3808. }
  3809. else
  3810. {
  3811. continue;
  3812. }
  3813. }
  3814. if (errMsg.Length > 0)
  3815. {
  3816. returnErrorMsg(errMsg);
  3817. return;
  3818. }
  3819. returnSuccessMsg("操作成功!");
  3820. return;
  3821. }
  3822. }
  3823. public void assign_erp_makesupplier()
  3824. {
  3825. if (UrlPostParmsCheck("ctid"))
  3826. {
  3827. string eids = GetPostString("ctid");
  3828. string sname = GetPostString("SupplierName");
  3829. string[] eidList = eids.Split(',');
  3830. if (eidList.Length <= 0)
  3831. {
  3832. returnErrorMsg("指派不能为空");
  3833. return;
  3834. }
  3835. List<string> tLst = new List<string>();
  3836. foreach (string ctid in eidList)
  3837. {
  3838. CeErpTradeCell entity = null;
  3839. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3840. if (entity != null)
  3841. {
  3842. entity.MakeSupplier = sname;
  3843. entity.Update();
  3844. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3845. tLst.Add("'" + ctid + "'");
  3846. }
  3847. else
  3848. {
  3849. continue;
  3850. }
  3851. }
  3852. string ctids = string.Join(",", tLst.ToArray());
  3853. StringBuilder sql2 = new StringBuilder();
  3854. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3855. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3856. returnSuccessMsg("操作成功!");
  3857. return;
  3858. }
  3859. }
  3860. public void ins_erp_returnreason()
  3861. {
  3862. if (UrlPostParmsCheck("ctid"))
  3863. {
  3864. string eid = GetPostString("ctid");
  3865. CeErpTradeCell entity = null;
  3866. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3867. string userpost = CurrentUser.UserPost.Post.Code;
  3868. if (entity != null)
  3869. {
  3870. bool isPlace = false;
  3871. if (entity.OrderState > 6)
  3872. {
  3873. returnErrorMsg("已发货无法打回!");
  3874. return;
  3875. }
  3876. if (entity.OrderState == 6)
  3877. {
  3878. isPlace = true;
  3879. }
  3880. bool isNeedUpdateCell2 = false;
  3881. if (entity.OrderState >= 6)
  3882. {
  3883. isNeedUpdateCell2 = true;
  3884. }
  3885. int returnTag = 2;
  3886. if (userpost == "Supplier")
  3887. {
  3888. returnTag = 1;
  3889. }
  3890. int toType = GetPostInt("totype");
  3891. string fromType = "3";
  3892. if (entity.OrderState < 5)
  3893. {
  3894. fromType = "3";
  3895. }
  3896. else
  3897. {
  3898. fromType = "4";
  3899. }
  3900. if (entity.IsXianHuo == 0)
  3901. {
  3902. if (returnTag == 2)
  3903. {
  3904. if (toType == 1)
  3905. {
  3906. entity.OrderState = 0;
  3907. entity.ReturnUserType = 1;
  3908. string clearman = GetPostString("clearman");
  3909. if (!string.IsNullOrEmpty(clearman))
  3910. {
  3911. entity.DesignUserId = 0;
  3912. }
  3913. }
  3914. else
  3915. {
  3916. entity.OrderState = 3;
  3917. entity.ReturnUserType = 2;
  3918. }
  3919. entity.IsReadTag = 1;
  3920. }
  3921. else if (returnTag == 1)
  3922. {
  3923. entity.OrderState = 5;
  3924. }
  3925. entity.IsVerifyToSupplier = false;
  3926. }
  3927. if (entity.IsXianHuo == 1)
  3928. {
  3929. entity.OrderState = 5;
  3930. }
  3931. entity.UnusualTag = 0;
  3932. entity.UnusualTime = null;
  3933. entity.UnusualCon = "";
  3934. entity.IsReturn = returnTag;
  3935. entity.ReturnTime = DateTime.Now;
  3936. entity.UpdateTime = DateTime.Now;
  3937. entity.ReturnReason = GetPostString("returnreason");
  3938. entity.Update();
  3939. if (entity.OrderState == 3)
  3940. {
  3941. ApiVo apiVo = new ApiVo();
  3942. apiVo.orderNumber = entity.ctid;
  3943. apiVo.actionName = "rebutDesign";
  3944. apiVo.orderRemarks = entity.ReturnReason;
  3945. designHelper.API_WorkCore(apiVo);//rebutDesign
  3946. }
  3947. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3948. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3949. {
  3950. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3951. }
  3952. CeErpSukuraData.createInfo(entity.ctid, 5);
  3953. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3954. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3955. if (isPlace)
  3956. {
  3957. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3958. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3959. if (dth != null && dth.Rows.Count > 0)
  3960. {
  3961. dataSendOrderBean dataSendOrderBean = null;
  3962. foreach (DataRow item in dth.Rows)
  3963. {
  3964. try
  3965. {
  3966. dataSendOrderBean = new dataSendOrderBean();
  3967. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3968. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3969. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3970. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3971. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3972. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3973. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3974. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3975. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3976. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3977. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3978. dataSendOrderBean.Radio1723534706288 = "打回";
  3979. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3980. if (result != null)
  3981. {
  3982. if ("0".Equals(result.errcode))
  3983. {
  3984. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3985. }
  3986. else
  3987. {
  3988. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3989. }
  3990. }
  3991. }
  3992. catch (Exception ex)
  3993. {
  3994. }
  3995. }
  3996. }
  3997. }
  3998. if (isNeedUpdateCell2)
  3999. {
  4000. if (entity.MakeSupplier.IndexOf(",") != -1)
  4001. {
  4002. StringBuilder sql2 = new StringBuilder();
  4003. 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);
  4004. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4005. }
  4006. else
  4007. {
  4008. StringBuilder sql2 = new StringBuilder();
  4009. 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);
  4010. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4011. }
  4012. }
  4013. returnSuccessMsg("操作成功!");
  4014. return;
  4015. }
  4016. returnErrorMsg("找不到订单记录");
  4017. }
  4018. }
  4019. public void cyt_erp_returnreason()
  4020. {
  4021. if (UrlPostParmsCheck("ctid"))
  4022. {
  4023. string eid = GetPostString("ctid");
  4024. CeErpTradeCell entity = null;
  4025. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4026. string userpost = CurrentUser.UserPost.Post.Code;
  4027. if (entity != null)
  4028. {
  4029. if (entity.OrderState > 6)
  4030. {
  4031. returnErrorMsg("已发货无法打回!");
  4032. return;
  4033. }
  4034. JObject jsonObject = new JObject
  4035. {
  4036. { "Userid", "77886" },
  4037. { "Pwd", "lt666888" },
  4038. { "LTOrderId",eid }
  4039. };
  4040. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  4041. JObject jsonObjects = JObject.Parse(response);
  4042. string msg = (string)jsonObjects["msg"];
  4043. if (msg != "取消成功")
  4044. {
  4045. returnErrorMsg(msg);
  4046. return;
  4047. }
  4048. bool isNeedUpdateCell2 = false;
  4049. if (entity.OrderState >= 6)
  4050. {
  4051. isNeedUpdateCell2 = true;
  4052. }
  4053. int returnTag = 2;
  4054. if (userpost == "Supplier")
  4055. {
  4056. returnTag = 1;
  4057. }
  4058. if (entity.IsXianHuo == 0)
  4059. {
  4060. if (returnTag == 2)
  4061. {
  4062. int toType = GetPostInt("totype");
  4063. if (toType == 1)
  4064. {
  4065. entity.OrderState = 0;
  4066. entity.ReturnUserType = 1;
  4067. }
  4068. else
  4069. {
  4070. entity.OrderState = 4;
  4071. entity.ReturnUserType = 2;
  4072. }
  4073. entity.IsReadTag = 1;
  4074. }
  4075. else if (returnTag == 1)
  4076. {
  4077. entity.OrderState = 5;
  4078. }
  4079. entity.IsVerifyToSupplier = false;
  4080. }
  4081. entity.UnusualTag = 0;
  4082. entity.UnusualTime = null;
  4083. entity.UnusualCon = "";
  4084. entity.IsReturn = returnTag;
  4085. entity.ReturnTime = DateTime.Now;
  4086. entity.ReturnReason = GetPostString("returnreason");
  4087. entity.Update();
  4088. if (entity.OrderState == 4)
  4089. {
  4090. ApiVo apiVo = new ApiVo();
  4091. apiVo.orderNumber = entity.ctid;
  4092. apiVo.actionName = "rebutDesign";
  4093. apiVo.orderRemarks = entity.ReturnReason;
  4094. designHelper.API_WorkCore(apiVo);//rebutDesign
  4095. }
  4096. CeErpSukuraData.createInfo(entity.ctid, 5);
  4097. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4098. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4099. if (isNeedUpdateCell2)
  4100. {
  4101. if (entity.MakeSupplier.IndexOf(",") != -1)
  4102. {
  4103. StringBuilder sql2 = new StringBuilder();
  4104. 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);
  4105. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4106. }
  4107. else
  4108. {
  4109. StringBuilder sql2 = new StringBuilder();
  4110. 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);
  4111. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4112. }
  4113. }
  4114. returnSuccessMsg("操作成功!");
  4115. return;
  4116. }
  4117. returnErrorMsg("找不到订单记录");
  4118. }
  4119. }
  4120. public void upd_erp_xianhuoreturntag()
  4121. {
  4122. if (UrlPostParmsCheck("ctid"))
  4123. {
  4124. string eids = GetPostString("ctid");
  4125. string[] ctids = eids.Split(',');
  4126. foreach (string ctid in ctids)
  4127. {
  4128. CeErpTradeCell entity = null;
  4129. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4130. if (entity != null)
  4131. {
  4132. entity.IsReturn = 0;
  4133. entity.Update();
  4134. CeErpSukuraData.createInfo(entity.ctid, 5);
  4135. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  4136. }
  4137. }
  4138. returnSuccessMsg("操作成功!");
  4139. return;
  4140. }
  4141. }
  4142. public void get_erp_waitdeliverylist()
  4143. {
  4144. DataStruct dStruct = GetPostStruct();
  4145. List<string> lw = new List<string>();
  4146. string tid = GetPostString("ctid");
  4147. if (tid.Length > 0)
  4148. {
  4149. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4150. if (tid.Length > 5)
  4151. {
  4152. List<string> tids = getTidByCtidLike(tid);
  4153. if (tids.Count > 0 && tids.Count < 10)
  4154. {
  4155. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4156. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4157. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4158. {
  4159. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4160. }*/
  4161. }
  4162. }
  4163. lw.Add(tid_sql);
  4164. }
  4165. string shopname = GetPostString("shopname");
  4166. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4167. string buyernick = GetPostString("buyer_nick");
  4168. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4169. //if (tid.Length == 0 && buyernick.Length == 0)
  4170. //{
  4171. // lw.Add(string.Format("IsRefund<={0}", 1));
  4172. //}
  4173. string customer = GetPostString("customer");
  4174. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4175. string design = GetPostString("design");
  4176. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4177. string orderState = GetPostString("orderState");
  4178. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4179. string address = GetPostString("address");
  4180. 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));
  4181. string sellermemo = GetPostString("seller_memo");
  4182. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4183. string supplier = GetPostString("supplier");
  4184. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4185. string OrderArea = GetPostString("order_area");
  4186. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4187. string placedate1 = GetPostString("placedate1");
  4188. string placedate2 = GetPostString("placedate2");
  4189. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4190. if (fdw.Length > 0) lw.Add(fdw);
  4191. string price1 = GetPostString("price1");
  4192. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4193. string price2 = GetPostString("price2");
  4194. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4195. string unusualCon = GetPostString("unusualcon");
  4196. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4197. string otherMemo = GetPostString("otherMemo");
  4198. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4199. string posTag = CurrentUser.UserPost.Post.Code;
  4200. if (posTag == "Supplier")
  4201. {
  4202. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4203. }
  4204. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4205. lw.Add(string.Format("type != 'PDD' "));
  4206. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4207. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4208. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4209. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4210. writeGridDataTableJson(dStruct.TotalCount, dt);
  4211. }
  4212. public void get_erp_changedeliverylist()
  4213. {
  4214. DataStruct dStruct = GetPostStruct();
  4215. List<string> lw = new List<string>();
  4216. string tid = GetPostString("ctid");
  4217. if (tid.Length > 0)
  4218. {
  4219. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4220. if (tid.Length > 5)
  4221. {
  4222. List<string> tids = getTidByCtidLike(tid);
  4223. if (tids.Count > 0 && tids.Count < 10)
  4224. {
  4225. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4226. }
  4227. }
  4228. lw.Add(tid_sql);
  4229. }
  4230. string shopname = GetPostString("shopname");
  4231. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4232. string buyernick = GetPostString("buyer_nick");
  4233. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4234. //if (tid.Length == 0 && buyernick.Length == 0)
  4235. //{
  4236. // lw.Add(string.Format("IsRefund<={0}", 1));
  4237. //}
  4238. string customer = GetPostString("customer");
  4239. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4240. string design = GetPostString("design");
  4241. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4242. string orderState = GetPostString("orderState");
  4243. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4244. string address = GetPostString("address");
  4245. 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));
  4246. string sellermemo = GetPostString("seller_memo");
  4247. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4248. string supplier = GetPostString("supplier");
  4249. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4250. string OrderArea = GetPostString("order_area");
  4251. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4252. string placedate1 = GetPostString("placedate1");
  4253. string placedate2 = GetPostString("placedate2");
  4254. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4255. if (fdw.Length > 0) lw.Add(fdw);
  4256. string price1 = GetPostString("price1");
  4257. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4258. string price2 = GetPostString("price2");
  4259. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4260. string unusualCon = GetPostString("unusualcon");
  4261. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4262. string otherMemo = GetPostString("otherMemo");
  4263. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4264. string posTag = CurrentUser.UserPost.Post.Code;
  4265. if (posTag == "Supplier")
  4266. {
  4267. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4268. }
  4269. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4270. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4271. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4272. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4273. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4274. /*if (tid.Length > 0)
  4275. {
  4276. List<string> tids = new List<string>();
  4277. if (dt != null && dt.Rows.Count > 0)
  4278. {
  4279. foreach (DataRow item in dt.Rows)
  4280. {
  4281. tids.Add("'" + item["tid"] + "'");
  4282. }
  4283. }
  4284. if (tids.Count > 0)
  4285. {
  4286. lw.RemoveAt(0);
  4287. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4288. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4289. dt = WebCache.GetData("view_erptradecell", dStruct);
  4290. }
  4291. }*/
  4292. writeGridDataTableJson(dStruct.TotalCount, dt);
  4293. }
  4294. public void get_erp_pddderiving()
  4295. {
  4296. DataStruct dStruct = GetPostStruct();
  4297. List<string> lw = new List<string>();
  4298. string tid = GetPostString("ctid");
  4299. if (tid.Length > 0)
  4300. {
  4301. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4302. if (tid.Length > 5)
  4303. {
  4304. List<string> tids = getTidByCtidLike(tid);
  4305. if (tids.Count > 0 && tids.Count < 10)
  4306. {
  4307. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4308. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4309. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4310. {
  4311. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4312. }*/
  4313. }
  4314. }
  4315. lw.Add(tid_sql);
  4316. }
  4317. string shopname = GetPostString("shopname");
  4318. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4319. string buyernick = GetPostString("buyer_nick");
  4320. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4321. //if (tid.Length == 0 && buyernick.Length == 0)
  4322. //{
  4323. // lw.Add(string.Format("IsRefund<={0}", 1));
  4324. //}
  4325. string customer = GetPostString("customer");
  4326. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4327. string design = GetPostString("design");
  4328. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4329. string orderState = GetPostString("orderState");
  4330. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4331. string address = GetPostString("address");
  4332. 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));
  4333. string sellermemo = GetPostString("seller_memo");
  4334. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4335. string supplier = GetPostString("supplier");
  4336. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4337. string OrderArea = GetPostString("order_area");
  4338. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4339. string placedate1 = GetPostString("placedate1");
  4340. string placedate2 = GetPostString("placedate2");
  4341. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4342. if (fdw.Length > 0) lw.Add(fdw);
  4343. string price1 = GetPostString("price1");
  4344. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4345. string price2 = GetPostString("price2");
  4346. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4347. string unusualCon = GetPostString("unusualcon");
  4348. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4349. string posTag = CurrentUser.UserPost.Post.Code;
  4350. if (posTag == "Supplier")
  4351. {
  4352. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4353. }
  4354. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4355. lw.Add(string.Format("type = 'PDD' "));
  4356. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4357. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4358. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4359. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4360. /*if (tid.Length > 0)
  4361. {
  4362. List<string> tids = new List<string>();
  4363. if (dt != null && dt.Rows.Count > 0)
  4364. {
  4365. foreach (DataRow item in dt.Rows)
  4366. {
  4367. tids.Add("'" + item["tid"] + "'");
  4368. }
  4369. }
  4370. if (tids.Count > 0)
  4371. {
  4372. lw.RemoveAt(0);
  4373. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4374. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4375. dt = WebCache.GetData("view_erptradecell", dStruct);
  4376. }
  4377. }*/
  4378. writeGridDataTableJson(dStruct.TotalCount, dt);
  4379. }
  4380. public void get_erp_jdderiving()
  4381. {
  4382. DataStruct dStruct = GetPostStruct();
  4383. List<string> lw = new List<string>();
  4384. string tid = GetPostString("ctid");
  4385. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4386. string shopname = GetPostString("shopname");
  4387. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4388. string buyernick = GetPostString("buyer_nick");
  4389. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4390. //if (tid.Length == 0 && buyernick.Length == 0)
  4391. //{
  4392. // lw.Add(string.Format("IsRefund<={0}", 1));
  4393. //}
  4394. string customer = GetPostString("customer");
  4395. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4396. string design = GetPostString("design");
  4397. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4398. string orderState = GetPostString("orderState");
  4399. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4400. string address = GetPostString("address");
  4401. 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));
  4402. string sellermemo = GetPostString("seller_memo");
  4403. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4404. string supplier = GetPostString("supplier");
  4405. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4406. string OrderArea = GetPostString("order_area");
  4407. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4408. string placedate1 = GetPostString("placedate1");
  4409. string placedate2 = GetPostString("placedate2");
  4410. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4411. if (fdw.Length > 0) lw.Add(fdw);
  4412. string price1 = GetPostString("price1");
  4413. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4414. string price2 = GetPostString("price2");
  4415. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4416. string unusualCon = GetPostString("unusualcon");
  4417. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4418. string posTag = CurrentUser.UserPost.Post.Code;
  4419. if (posTag == "Supplier")
  4420. {
  4421. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4422. }
  4423. lw.Add(string.Format("OrderState = 6 "));
  4424. lw.Add(string.Format("type = 'JD' "));
  4425. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4426. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4427. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4428. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4429. writeGridDataTableJson(dStruct.TotalCount, dt);
  4430. }
  4431. public void get_erp_demoorderlist()
  4432. {
  4433. DataStruct dStruct = GetPostStruct();
  4434. List<string> lw = new List<string>();
  4435. string tid = GetPostString("ctid");
  4436. if (tid.Length > 0)
  4437. {
  4438. string select_tid = getTidByCtid(tid);
  4439. lw.Add(string.Format("tid='{0}'", select_tid));
  4440. }
  4441. string shopname = GetPostString("shopname");
  4442. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4443. string buyernick = GetPostString("buyer_nick");
  4444. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4445. string customer = GetPostString("customer");
  4446. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4447. string design = GetPostString("design");
  4448. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4449. string orderState = GetPostString("orderState");
  4450. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4451. string address = GetPostString("address");
  4452. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4453. string sellermemo = GetPostString("seller_memo");
  4454. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4455. string supplier = GetPostString("supplier");
  4456. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4457. string OrderArea = GetPostString("order_area");
  4458. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4459. string date1 = GetPostString("date1");
  4460. string date2 = GetPostString("date2");
  4461. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4462. if (dw.Length > 0) lw.Add(dw);
  4463. string price1 = GetPostString("price1");
  4464. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4465. string price2 = GetPostString("price2");
  4466. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4467. string posTag = CurrentUser.UserPost.Post.Code;
  4468. if (posTag == "Supplier")
  4469. {
  4470. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4471. }
  4472. //lw.Add(string.Format("OrderState = 6 "));
  4473. lw.Add(string.Format("IsSample={0}", 3));
  4474. lw.Add(string.Format("IsRefund<={0}", 1));
  4475. dStruct.Order = "pay_time desc";
  4476. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4477. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4478. writeGridDataTableJson(dStruct.TotalCount, dt);
  4479. }
  4480. public void save_erp_checkmemo()
  4481. {
  4482. if (UrlPostParmsCheck("ctid"))
  4483. {
  4484. string ctid = GetPostString("ctid");
  4485. CeErpTradeCell entity = null;
  4486. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4487. if (entity != null)
  4488. {
  4489. entity.CheckMemo = GetPostString("CheckMemo");
  4490. entity.Update();
  4491. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4492. if (trade != null)
  4493. {
  4494. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4495. }
  4496. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4497. returnSuccessMsg("保存成功!");
  4498. return;
  4499. }
  4500. returnErrorMsg("找不到记录");
  4501. }
  4502. }
  4503. public void get_erp_returnlist()
  4504. {
  4505. DataStruct dStruct = GetPostStruct();
  4506. List<string> lw = new List<string>();
  4507. string tid = GetPostString("ctid");
  4508. if (tid.Length > 0)
  4509. {
  4510. string select_tid = getTidByCtid(tid);
  4511. lw.Add(string.Format("tid='{0}'", select_tid));
  4512. }
  4513. string shopname = GetPostString("shopname");
  4514. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4515. string buyernick = GetPostString("buyer_nick");
  4516. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4517. string customer = GetPostString("customer");
  4518. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4519. string design = GetPostString("design");
  4520. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4521. string orderState = GetPostString("orderState");
  4522. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4523. string address = GetPostString("address");
  4524. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4525. string sellermemo = GetPostString("seller_memo");
  4526. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4527. string supplier = GetPostString("supplier");
  4528. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4529. string date1 = GetPostString("date1");
  4530. string date2 = GetPostString("date2");
  4531. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4532. if (dw.Length > 0) lw.Add(dw);
  4533. string bdate1 = GetPostString("backdate1");
  4534. string bdate2 = GetPostString("backdate2");
  4535. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4536. if (dw_back.Length > 0) lw.Add(dw_back);
  4537. string price1 = GetPostString("price1");
  4538. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4539. string price2 = GetPostString("price2");
  4540. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4541. lw.Add(string.Format("IsReturn>0"));
  4542. lw.Add(string.Format("IsXianHuo=0"));
  4543. lw.Add(string.Format("IsReturn!=3"));
  4544. string backtype = GetPostString("backtype");
  4545. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4546. dStruct.Order = "FinishDesignTime desc";
  4547. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4548. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4549. writeGridDataTableJson(dStruct.TotalCount, dt);
  4550. }
  4551. public void get_erp_today_sumreturn()
  4552. {
  4553. DataStruct dStruct = GetPostStruct();
  4554. List<string> lw = new List<string>();
  4555. string bdate1 = GetPostString("returnTimeS");
  4556. string bdate2 = GetPostString("returnTimeE");
  4557. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4558. if (dw_back.Length > 0) lw.Add(dw_back);
  4559. lw.Add(string.Format("IsReturn=0"));
  4560. lw.Add(string.Format("IsXianHuo=0"));
  4561. string mainWhere = string.Join(" and ", lw.ToArray());
  4562. string sql = "";
  4563. if (dw_back.Length > 0)
  4564. {
  4565. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4566. }
  4567. else
  4568. {
  4569. 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 + "'";
  4570. }
  4571. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4572. decimal total = 0, today_finish = 0;
  4573. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4574. {
  4575. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4576. }
  4577. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4578. {
  4579. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4580. }
  4581. var res = new
  4582. {
  4583. data = total,
  4584. data1 = today_finish,
  4585. };
  4586. string ro_jsond = JsonConvert.SerializeObject(res);
  4587. returnSuccess(ro_jsond);
  4588. return;
  4589. }
  4590. public void get_erp_allreturnlist()
  4591. {
  4592. DataStruct dStruct = GetPostStruct();
  4593. List<string> lw = new List<string>();
  4594. string tid = GetPostString("ctid");
  4595. if (tid.Length > 0)
  4596. {
  4597. string select_tid = getTidByCtid(tid);
  4598. lw.Add(string.Format("tid='{0}'", select_tid));
  4599. }
  4600. string shopname = GetPostString("shopname");
  4601. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4602. string buyernick = GetPostString("buyer_nick");
  4603. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4604. string customer = GetPostString("customer");
  4605. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4606. string design = GetPostString("design");
  4607. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4608. string orderState = GetPostString("orderState");
  4609. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4610. string address = GetPostString("address");
  4611. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4612. string sellermemo = GetPostString("seller_memo");
  4613. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4614. string supplier = GetPostString("supplier");
  4615. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4616. string date1 = GetPostString("date1");
  4617. string date2 = GetPostString("date2");
  4618. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4619. if (dw.Length > 0) lw.Add(dw);
  4620. string bdate1 = GetPostString("backdate1");
  4621. string bdate2 = GetPostString("backdate2");
  4622. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4623. if (dw_back.Length > 0) lw.Add(dw_back);
  4624. string price1 = GetPostString("price1");
  4625. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4626. string price2 = GetPostString("price2");
  4627. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4628. string backreason = GetPostString("backreason");
  4629. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4630. lw.Add(string.Format("IsXianHuo=0"));
  4631. lw.Add(string.Format("ReturnTime != ''"));
  4632. string backtype = GetPostString("backtype");
  4633. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4634. dStruct.Order = "FinishDesignTime desc";
  4635. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4636. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4637. writeGridDataTableJson(dStruct.TotalCount, dt);
  4638. }
  4639. public void get_erp_aftersalereturnlist()
  4640. {
  4641. DataStruct dStruct = GetPostStruct();
  4642. List<string> lw = new List<string>();
  4643. string tid = GetPostString("ctid");
  4644. if (tid.Length > 0)
  4645. {
  4646. string select_tid = getTidByCtid(tid);
  4647. lw.Add(string.Format("tid='{0}'", select_tid));
  4648. }
  4649. string shopname = GetPostString("shopname");
  4650. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4651. string buyernick = GetPostString("buyer_nick");
  4652. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4653. string customer = GetPostString("customer");
  4654. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4655. string design = GetPostString("design");
  4656. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4657. string orderState = GetPostString("orderState");
  4658. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4659. string address = GetPostString("address");
  4660. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4661. string sellermemo = GetPostString("seller_memo");
  4662. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4663. string supplier = GetPostString("supplier");
  4664. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4665. string date1 = GetPostString("date1");
  4666. string date2 = GetPostString("date2");
  4667. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4668. if (dw.Length > 0) lw.Add(dw);
  4669. string bdate1 = GetPostString("backdate1");
  4670. string bdate2 = GetPostString("backdate2");
  4671. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4672. if (dw_back.Length > 0) lw.Add(dw_back);
  4673. string price1 = GetPostString("price1");
  4674. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4675. string price2 = GetPostString("price2");
  4676. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4677. lw.Add(string.Format("IsReturn=3"));
  4678. string backtype = GetPostString("backtype");
  4679. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4680. string backreason = GetPostString("backreason");
  4681. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4682. dStruct.Order = "ReturnTime desc";
  4683. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4684. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4685. writeGridDataTableJson(dStruct.TotalCount, dt);
  4686. }
  4687. public void get_erp_xianhuoreturnlist()
  4688. {
  4689. DataStruct dStruct = GetPostStruct();
  4690. List<string> lw = new List<string>();
  4691. string tid = GetPostString("ctid");
  4692. if (tid.Length > 0)
  4693. {
  4694. string select_tid = getTidByCtid(tid);
  4695. lw.Add(string.Format("tid='{0}'", select_tid));
  4696. }
  4697. string shopname = GetPostString("shopname");
  4698. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4699. string buyernick = GetPostString("buyer_nick");
  4700. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4701. string customer = GetPostString("customer");
  4702. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4703. string design = GetPostString("design");
  4704. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4705. string orderState = GetPostString("orderState");
  4706. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4707. string address = GetPostString("address");
  4708. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4709. string sellermemo = GetPostString("seller_memo");
  4710. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4711. string supplier = GetPostString("supplier");
  4712. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4713. string OrderArea = GetPostString("order_area");
  4714. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4715. string date1 = GetPostString("date1");
  4716. string date2 = GetPostString("date2");
  4717. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4718. if (dw.Length > 0) lw.Add(dw);
  4719. string price1 = GetPostString("price1");
  4720. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4721. string price2 = GetPostString("price2");
  4722. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4723. string posTag = CurrentUser.UserPost.Post.Code;
  4724. if (posTag == "Supplier")
  4725. {
  4726. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4727. }
  4728. lw.Add(string.Format("OrderState=6 "));
  4729. lw.Add(string.Format("IsXianHuo=1 "));
  4730. lw.Add(string.Format("IsReturn>0 "));
  4731. lw.Add(string.Format("IsReturn!=3"));
  4732. lw.Add(string.Format("IsRefund<={0}", 1));
  4733. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4734. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4735. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4736. writeGridDataTableJson(dStruct.TotalCount, dt);
  4737. }
  4738. public void set_erp_orderdelivery()
  4739. {
  4740. if (UrlPostParmsCheck("ctid"))
  4741. {
  4742. string eid = GetPostString("ctid");
  4743. CeErpTradeCell entity = null;
  4744. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4745. if (entity != null)
  4746. {
  4747. if (entity.OrderState >= 7)
  4748. {
  4749. returnErrorMsg("此单已发货,无需重复发货");
  4750. return;
  4751. }
  4752. if (entity.OrderState != 6)
  4753. {
  4754. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4755. return;
  4756. }
  4757. string shop = GetPostString("seller_nick");
  4758. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4759. string comName = GetPostString("comName");
  4760. string comCode = GetPostString("comCode");
  4761. string outSid = GetPostString("outSid");
  4762. string deliveryType = GetPostString("deliveryType");
  4763. string deliveryMemo = GetPostString("deliveryMemo");
  4764. outSid = outSid.Trim();
  4765. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4766. if (mainEn == null)
  4767. {
  4768. returnErrorMsg("找不到原始订单记录");
  4769. return;
  4770. }
  4771. bool isInitOrderDeliv = false;
  4772. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4773. {
  4774. isInitOrderDeliv = true;
  4775. }
  4776. string apires = "";
  4777. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4778. 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)
  4779. {
  4780. apires = "发货成功true";
  4781. }
  4782. else
  4783. {
  4784. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4785. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4786. }
  4787. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4788. {
  4789. entity.OrderState = 7;//发货后订单已发货
  4790. entity.OutSid = outSid;
  4791. entity.MemoOpt = 0;
  4792. entity.UpdateTime = DateTime.Now;
  4793. entity.FinishDeliveryTime = DateTime.Now;
  4794. entity.Update();
  4795. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4796. commonHelper.UpdateRelationOrder(entity.ctid);
  4797. //还要插入快递信息到 快递信息表
  4798. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4799. exinfo.tid = eid;
  4800. exinfo.out_sid = outSid;
  4801. exinfo.company_code = comCode;
  4802. exinfo.company_name = comName;
  4803. exinfo.delivery_memo = deliveryMemo;
  4804. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4805. exinfo.deliveryType = deliveryType;
  4806. exinfo.Create();
  4807. returnSuccessMsg("发货操作成功!");
  4808. commonHelper.UpdateRelationOrder(entity.ctid);
  4809. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4810. CeErpSukuraData.createInfo(entity.ctid, 4);
  4811. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  4812. {
  4813. commonHelper.sendCytExpress(exinfo);
  4814. }
  4815. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4816. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid + ",备注:" + deliveryMemo, entity.OrderState);
  4817. }
  4818. else
  4819. {
  4820. string errmsg = commonHelper.KeepChinese(apires);
  4821. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4822. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4823. }
  4824. return;
  4825. }
  4826. returnErrorMsg("找不到订单记录");
  4827. }
  4828. }
  4829. public void set_erp_multidelivery()
  4830. {
  4831. string eids = GetPostString("tids");
  4832. string[] eidList = eids.Split(',');
  4833. if (eidList.Length <= 0)
  4834. {
  4835. returnErrorMsg("发货不能为空");
  4836. return;
  4837. }
  4838. foreach (string ctid in eidList)
  4839. {
  4840. if (ctid.Length <= 0) continue;
  4841. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4842. if (expInfo != null)
  4843. {
  4844. StringBuilder sql = new StringBuilder();
  4845. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4846. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4847. if (dt.Rows.Count > 0)
  4848. {
  4849. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4850. {
  4851. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4852. expInfo.state = "异常";
  4853. expInfo.isMultiDelivery = 1;
  4854. expInfo.Update();
  4855. continue;
  4856. }
  4857. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4858. {
  4859. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4860. expInfo.state = "异常";
  4861. expInfo.Update();
  4862. continue;
  4863. }
  4864. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4865. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4866. bool isInitOrderDeliv = false;
  4867. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4868. {
  4869. isInitOrderDeliv = true;
  4870. expInfo.isMultiDelivery = 1;
  4871. }
  4872. if (ctid.IndexOf("N") != -1)
  4873. {
  4874. StringBuilder sqlbucha = new StringBuilder();
  4875. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4876. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4877. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4878. commonHelper.UpdateRelationOrder(ctid);
  4879. expInfo.delivery_memo = "发货成功";
  4880. expInfo.state = "发货成功";
  4881. expInfo.isMultiDelivery = 1;
  4882. expInfo.Update();
  4883. }
  4884. else
  4885. {
  4886. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4887. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4888. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4889. {
  4890. expInfo.delivery_memo = "发货成功";
  4891. expInfo.state = "发货成功";
  4892. expInfo.isMultiDelivery = 1;
  4893. expInfo.Update();
  4894. commonHelper.UpdateRelationOrder(ctid);
  4895. CeErpSukuraData.createInfo(ctid, 4);
  4896. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4897. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4898. }
  4899. else
  4900. {
  4901. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4902. expInfo.state = "异常";
  4903. expInfo.Update();
  4904. }
  4905. }
  4906. }
  4907. }
  4908. }
  4909. returnSuccessMsg("操作完成");
  4910. }
  4911. public void reset_erp_memoopt()
  4912. {
  4913. if (UrlPostParmsCheck("ctid"))
  4914. {
  4915. string eid = GetPostString("ctid");
  4916. CeErpTradeCell entity = null;
  4917. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4918. if (entity != null)
  4919. {
  4920. string stropt = "";
  4921. if (entity.MemoOpt == 1)
  4922. {
  4923. stropt = "“改稿”";
  4924. }
  4925. else if (entity.MemoOpt == 2)
  4926. {
  4927. stropt = "“定稿”";
  4928. }
  4929. else if (entity.MemoOpt == 3)
  4930. {
  4931. stropt = "“完成查货”";
  4932. CeErpSukuraData.createInfo(entity.ctid, 6);
  4933. }
  4934. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4935. entity.UpdateTime = DateTime.Now;
  4936. entity.MemoOpt = 0;
  4937. entity.Update();
  4938. returnSuccessMsg("操作成功!");
  4939. return;
  4940. }
  4941. returnErrorMsg("找不到记录");
  4942. }
  4943. }
  4944. public void get_erp_deliveryunusual()
  4945. {
  4946. DataStruct dStruct = GetPostStruct();
  4947. List<string> lw = new List<string>();
  4948. string tid = GetPostString("ctid");
  4949. if (tid.Length > 0)
  4950. {
  4951. string select_tid = getTidByCtid(tid);
  4952. lw.Add(string.Format("tid='{0}'", select_tid));
  4953. }
  4954. string shopname = GetPostString("shopname");
  4955. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4956. string buyernick = GetPostString("buyer_nick");
  4957. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4958. string customer = GetPostString("customer");
  4959. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4960. string design = GetPostString("design");
  4961. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4962. string sellermemo = GetPostString("seller_memo");
  4963. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4964. string supplier = GetPostString("supplier");
  4965. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4966. string date1 = GetPostString("date1");
  4967. string date2 = GetPostString("date2");
  4968. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4969. if (dw.Length > 0) lw.Add(dw);
  4970. string placedate1 = GetPostString("placedate1");
  4971. string placedate2 = GetPostString("placedate2");
  4972. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4973. if (dw_place.Length > 0) lw.Add(dw_place);
  4974. string price1 = GetPostString("price1");
  4975. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4976. string price2 = GetPostString("price2");
  4977. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4978. string unusualCon = GetPostString("unusualcon");
  4979. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4980. string posTag = CurrentUser.UserPost.Post.Code;
  4981. if (posTag == "Supplier")
  4982. {
  4983. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4984. }
  4985. lw.Add(string.Format("OrderState = 6"));
  4986. lw.Add(string.Format("UnusualTag = 5"));
  4987. lw.Add(string.Format("IsRefund<={0}", 1));
  4988. dStruct.Order = "FinishPlaceTime desc";
  4989. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4990. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4991. writeGridDataTableJson(dStruct.TotalCount, dt);
  4992. }
  4993. public void get_erp_deliveryedlist()
  4994. {
  4995. DataStruct dStruct = GetPostStruct();
  4996. List<string> lw = new List<string>();
  4997. string tid = GetPostString("ctid");
  4998. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4999. string shopname = GetPostString("shopname");
  5000. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5001. string buyernick = GetPostString("buyer_nick");
  5002. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5003. string customer = GetPostString("customer");
  5004. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5005. string design = GetPostString("design");
  5006. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5007. string sellermemo = GetPostString("seller_memo");
  5008. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5009. string logistics = GetPostString("logistics");
  5010. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5011. string date1 = GetPostString("date1");
  5012. string date2 = GetPostString("date2");
  5013. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5014. //if (dw.Length > 0) lw.Add(dw);
  5015. string placedate1 = GetPostString("placedate1");
  5016. string placedate2 = GetPostString("placedate2");
  5017. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5018. if (fdw.Length > 0) lw.Add(fdw);
  5019. string devdate1 = GetPostString("deliverydate1");
  5020. string devdate2 = GetPostString("deliverydate2");
  5021. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5022. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5023. string price1 = GetPostString("price1");
  5024. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5025. string price2 = GetPostString("price2");
  5026. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5027. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5028. {
  5029. if (tid.Length > 0)
  5030. {
  5031. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5032. if (tid.Length > 5)
  5033. {
  5034. List<string> tids = getTidByCtidLike(tid);
  5035. if (tids.Count > 0 && tids.Count < 10)
  5036. {
  5037. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5038. }
  5039. }
  5040. lw.Add(tid_sql);
  5041. }
  5042. if (buyernick.Length > 0)
  5043. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5044. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5045. if (dw.Length > 0) lw.Add(dw);
  5046. }
  5047. else
  5048. {
  5049. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  5050. }
  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. else
  5057. {
  5058. string supplier = GetPostString("supplier");
  5059. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5060. }
  5061. lw.Add(string.Format(" OrderState IN (7, 8)"));
  5062. lw.Add(string.Format("type != 'PDD' "));
  5063. lw.Add(string.Format("IsRefund!={0}", 2));
  5064. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5065. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5066. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5067. /*if (tid.Length > 0)
  5068. {
  5069. List<string> tids = new List<string>();
  5070. if (dt != null && dt.Rows.Count > 0)
  5071. {
  5072. foreach (DataRow item in dt.Rows)
  5073. {
  5074. tids.Add("'" + item["tid"] + "'");
  5075. }
  5076. }
  5077. if (tids.Count > 0)
  5078. {
  5079. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5080. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5081. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5082. dt = WebCache.GetData("view_erptradecell", dStruct);
  5083. }
  5084. }*/
  5085. if (dt != null)
  5086. {
  5087. foreach (DataRow dr in dt.Rows)
  5088. {
  5089. 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();
  5090. }
  5091. }
  5092. writeGridDataTableJson(dStruct.TotalCount, dt);
  5093. }
  5094. public void get_erp_pdddeliveryed()
  5095. {
  5096. DataStruct dStruct = GetPostStruct();
  5097. List<string> lw = new List<string>();
  5098. string tid = GetPostString("ctid");
  5099. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5100. string shopname = GetPostString("shopname");
  5101. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5102. string buyernick = GetPostString("buyer_nick");
  5103. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5104. string customer = GetPostString("customer");
  5105. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5106. string design = GetPostString("design");
  5107. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5108. string sellermemo = GetPostString("seller_memo");
  5109. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5110. string logistics = GetPostString("logistics");
  5111. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5112. string date1 = GetPostString("date1");
  5113. string date2 = GetPostString("date2");
  5114. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5115. //if (dw.Length > 0) lw.Add(dw);
  5116. string placedate1 = GetPostString("placedate1");
  5117. string placedate2 = GetPostString("placedate2");
  5118. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5119. if (fdw.Length > 0) lw.Add(fdw);
  5120. string devdate1 = GetPostString("deliverydate1");
  5121. string devdate2 = GetPostString("deliverydate2");
  5122. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5123. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5124. string price1 = GetPostString("price1");
  5125. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5126. string price2 = GetPostString("price2");
  5127. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5128. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5129. {
  5130. if (tid.Length > 0)
  5131. {
  5132. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5133. if (tid.Length > 5)
  5134. {
  5135. List<string> tids = getTidByCtidLike(tid);
  5136. if (tids.Count > 0 && tids.Count < 10)
  5137. {
  5138. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5139. }
  5140. }
  5141. lw.Add(tid_sql);
  5142. }
  5143. if (buyernick.Length > 0)
  5144. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5145. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5146. if (dw.Length > 0) lw.Add(dw);
  5147. }
  5148. else
  5149. {
  5150. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  5151. }
  5152. string posTag = CurrentUser.UserPost.Post.Code;
  5153. if (posTag == "Supplier")
  5154. {
  5155. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5156. }
  5157. else
  5158. {
  5159. string supplier = GetPostString("supplier");
  5160. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5161. }
  5162. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5163. lw.Add(string.Format("type = 'PDD' "));
  5164. lw.Add(string.Format("IsRefund!={0}", 2));
  5165. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5166. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5167. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5168. /* if (tid.Length > 0)
  5169. {
  5170. List<string> tids = new List<string>();
  5171. if (dt != null && dt.Rows.Count > 0)
  5172. {
  5173. foreach (DataRow item in dt.Rows)
  5174. {
  5175. tids.Add("'" + item["tid"] + "'");
  5176. }
  5177. }
  5178. if (tids.Count > 0)
  5179. {
  5180. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5181. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5182. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5183. dt = WebCache.GetData("view_erptradecell", dStruct);
  5184. }
  5185. }*/
  5186. foreach (DataRow dr in dt.Rows)
  5187. {
  5188. 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();
  5189. }
  5190. writeGridDataTableJson(dStruct.TotalCount, dt);
  5191. }
  5192. public void get_erp_jddeliveryed()
  5193. {
  5194. DataStruct dStruct = GetPostStruct();
  5195. List<string> lw = new List<string>();
  5196. string tid = GetPostString("ctid");
  5197. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5198. string shopname = GetPostString("shopname");
  5199. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5200. string buyernick = GetPostString("buyer_nick");
  5201. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5202. string customer = GetPostString("customer");
  5203. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5204. string design = GetPostString("design");
  5205. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5206. string sellermemo = GetPostString("seller_memo");
  5207. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5208. string date1 = GetPostString("date1");
  5209. string date2 = GetPostString("date2");
  5210. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5211. //if (dw.Length > 0) lw.Add(dw);
  5212. string placedate1 = GetPostString("placedate1");
  5213. string placedate2 = GetPostString("placedate2");
  5214. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5215. if (fdw.Length > 0) lw.Add(fdw);
  5216. string devdate1 = GetPostString("deliverydate1");
  5217. string devdate2 = GetPostString("deliverydate2");
  5218. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5219. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5220. string price1 = GetPostString("price1");
  5221. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5222. string price2 = GetPostString("price2");
  5223. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5224. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5225. {
  5226. if (tid.Length > 0)
  5227. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5228. if (buyernick.Length > 0)
  5229. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5230. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5231. if (dw.Length > 0) lw.Add(dw);
  5232. }
  5233. else
  5234. {
  5235. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5236. }
  5237. string posTag = CurrentUser.UserPost.Post.Code;
  5238. if (posTag == "Supplier")
  5239. {
  5240. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5241. }
  5242. else
  5243. {
  5244. string supplier = GetPostString("supplier");
  5245. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5246. }
  5247. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5248. lw.Add(string.Format("type = 'JD' "));
  5249. lw.Add(string.Format("IsRefund!={0}", 2));
  5250. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5251. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5252. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5253. foreach (DataRow dr in dt.Rows)
  5254. {
  5255. 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();
  5256. }
  5257. writeGridDataTableJson(dStruct.TotalCount, dt);
  5258. }
  5259. public void get_erp_allplacelist()
  5260. {
  5261. DataStruct dStruct = GetPostStruct();
  5262. List<string> lw = new List<string>();
  5263. string tid = GetPostString("ctid");
  5264. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5265. string shopname = GetPostString("shopname");
  5266. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5267. string buyernick = GetPostString("buyer_nick");
  5268. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5269. string customer = GetPostString("customer");
  5270. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5271. string design = GetPostString("design");
  5272. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5273. string sellermemo = GetPostString("seller_memo");
  5274. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5275. string supplier = GetPostString("supplier");
  5276. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5277. string date1 = GetPostString("date1");
  5278. string date2 = GetPostString("date2");
  5279. string pldate1 = GetPostString("placedate1");
  5280. string pldate2 = GetPostString("placedate2");
  5281. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5282. //if (dw.Length > 0) lw.Add(dw);
  5283. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5284. {
  5285. if (tid.Length > 0)
  5286. {
  5287. string select_tid = getTidByCtid(tid);
  5288. lw.Add(string.Format("tid='{0}'", select_tid));
  5289. }
  5290. if (buyernick.Length > 0)
  5291. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5292. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5293. if (dw.Length > 0) lw.Add(dw);
  5294. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5295. if (dw_place.Length > 0) lw.Add(dw_place);
  5296. }
  5297. else
  5298. {
  5299. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5300. {
  5301. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5302. }
  5303. }
  5304. string price1 = GetPostString("price1");
  5305. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5306. string price2 = GetPostString("price2");
  5307. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5308. string posTag = CurrentUser.UserPost.Post.Code;
  5309. if (posTag == "Supplier")
  5310. {
  5311. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5312. }
  5313. lw.Add(string.Format("OrderState >= 6"));
  5314. lw.Add(string.Format("IsSample != 2 "));
  5315. //lw.Add(string.Format("isDianziOrder = 0 "));
  5316. lw.Add(string.Format("SupplierId > 0 "));
  5317. //lw.Add(string.Format("IsRefund<={0}", 1));
  5318. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5319. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5320. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5321. foreach (DataRow dr in dt.Rows)
  5322. {
  5323. 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();
  5324. }
  5325. writeGridDataTableJson(dStruct.TotalCount, dt);
  5326. }
  5327. public void get_erp_financeallplacelist()
  5328. {
  5329. DataStruct dStruct = GetPostStruct();
  5330. List<string> lw = new List<string>();
  5331. string tid = GetPostString("ctid");
  5332. string shopname = GetPostString("shopname");
  5333. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5334. string buyernick = GetPostString("buyer_nick");
  5335. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5336. string customer = GetPostString("customer");
  5337. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5338. string design = GetPostString("design");
  5339. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5340. string sellermemo = GetPostString("seller_memo");
  5341. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5342. string supplier = GetPostString("supplier");
  5343. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5344. string date1 = GetPostString("date1");
  5345. string date2 = GetPostString("date2");
  5346. string pldate1 = GetPostString("placedate1");
  5347. string pldate2 = GetPostString("placedate2");
  5348. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5349. {
  5350. if (tid.Length > 0)
  5351. {
  5352. string select_tid = getTidByCtid(tid);
  5353. lw.Add(string.Format("tid='{0}'", select_tid));
  5354. }
  5355. if (buyernick.Length > 0)
  5356. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5357. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5358. if (dw.Length > 0) lw.Add(dw);
  5359. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5360. if (dw_place.Length > 0) lw.Add(dw_place);
  5361. }
  5362. else
  5363. {
  5364. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5365. {
  5366. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5367. }
  5368. }
  5369. string price1 = GetPostString("price1");
  5370. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5371. string price2 = GetPostString("price2");
  5372. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5373. string posTag = CurrentUser.UserPost.Post.Code;
  5374. if (posTag == "Supplier")
  5375. {
  5376. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5377. }
  5378. //lw.Add(string.Format("OrderState >= 6"));
  5379. lw.Add(string.Format("IsSample != 2 "));
  5380. lw.Add(string.Format("isDianziOrder = 0 "));
  5381. //lw.Add(string.Format("IsRefund<={0}", 1));
  5382. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5383. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5384. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5385. foreach (DataRow dr in dt.Rows)
  5386. {
  5387. 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();
  5388. }
  5389. writeGridDataTableJson(dStruct.TotalCount, dt);
  5390. }
  5391. public void get_erp_expresslist()
  5392. {
  5393. int listtype = GetInt("ltype");
  5394. DataStruct dStruct = GetPostStruct();
  5395. List<string> lw = new List<string>();
  5396. string tid = GetPostString("tid");
  5397. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5398. string outsid = GetPostString("out_sid");
  5399. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5400. string importer = GetPostString("ImportUserName");
  5401. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5402. string file = GetPostString("import_file");
  5403. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5404. string printman = GetPostString("printman");
  5405. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5406. string date1 = GetPostString("date1");
  5407. string date2 = GetPostString("date2");
  5408. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5409. if (dw.Length > 0) lw.Add(dw);
  5410. string fdate1 = GetPostString("finishdate1");
  5411. string fdate2 = GetPostString("finishdate2");
  5412. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5413. if (fdw.Length > 0) lw.Add(fdw);
  5414. string supplierId = GetPostString("supplierId");
  5415. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5416. if (listtype == 1)
  5417. {
  5418. lw.Add(string.Format("importUserId !=0"));
  5419. }
  5420. string posTag = CurrentUser.UserPost.Post.Code;
  5421. if (posTag == "Supplier")
  5422. {
  5423. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5424. }
  5425. if (dStruct.PageSize != 100000)
  5426. {
  5427. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5428. }
  5429. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5430. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5431. writeGridDataTableJson(dStruct.TotalCount, dt);
  5432. }
  5433. public void set_erp_buchaorderdelivery()
  5434. {
  5435. if (UrlPostParmsCheck("ctid"))
  5436. {
  5437. string eid = GetPostString("ctid");
  5438. CeErpTradeCell entity = null;
  5439. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5440. if (entity != null)
  5441. {
  5442. if (entity.IsSample != 2)
  5443. {
  5444. returnErrorMsg("补差价单才能标记为已发货");
  5445. return;
  5446. }
  5447. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5448. entity.OrderState = 7;
  5449. entity.Update();
  5450. returnSuccessMsg("操作成功!");
  5451. return;
  5452. }
  5453. returnErrorMsg("找不到记录");
  5454. }
  5455. }
  5456. public void get_stdtemplates()
  5457. {
  5458. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5459. //string res = taobaoHelper.test();
  5460. string res = apiHelper.API_PrintTemplate();
  5461. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5462. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5463. {
  5464. int sidx = res.IndexOf("error_code");
  5465. int eidx = res.IndexOf("success");
  5466. string msg = res.Substring(sidx, eidx - sidx);
  5467. returnErrorMsg(msg);
  5468. return;
  5469. }
  5470. if (res.Length <= 0)
  5471. {
  5472. returnErrorMsg("模板数据为空!");
  5473. return;
  5474. }
  5475. ReturnSuccess(res);
  5476. }
  5477. public void cancel_print_order()
  5478. {
  5479. if (UrlPostParmsCheck("ctid"))
  5480. {
  5481. string ctid = GetPostString("ctid");
  5482. CeErpTradeCell entity = null;
  5483. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5484. if (entity != null)
  5485. {
  5486. string res = "";
  5487. string code = entity.LastBillWaybillCode;
  5488. if (code == "")
  5489. {
  5490. code = entity.OutSid;
  5491. }
  5492. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5493. XLog.SaveLog(0, "取消面单" + res);
  5494. }
  5495. }
  5496. }
  5497. public void set_erp_printwaybill()
  5498. {
  5499. if (UrlPostParmsCheck("ctid"))
  5500. {
  5501. string ctid = GetPostString("ctid");
  5502. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5503. string cpName = GetPostString("cpname");
  5504. string isTogether = GetPostString("together");
  5505. string printType = GetPostString("printType");
  5506. //var res_obj = new
  5507. //{
  5508. // restype = 1,
  5509. // 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\"}"
  5510. //};
  5511. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5512. //ReturnSuccess(ro_json);
  5513. //return;
  5514. bool isUseLastWayBillCode = false;
  5515. CeErpTradeCell entity = null;
  5516. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5517. if (entity != null)
  5518. {
  5519. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5520. {
  5521. isUseLastWayBillCode = true;
  5522. }
  5523. if (entity.OrderState == 7 && "delivering".Equals(printType))
  5524. {
  5525. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5526. return;
  5527. }
  5528. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5529. {
  5530. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5531. return;
  5532. }
  5533. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5534. {
  5535. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5536. return;
  5537. }
  5538. }
  5539. string res = "";
  5540. Api_waybill_code_response_Obj fullObj = null;
  5541. string pData_str = "";
  5542. string curUseWayBillCode = "";
  5543. if (isUseLastWayBillCode == false)
  5544. {
  5545. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5546. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5547. if (res.IndexOf("failure") != -1)
  5548. {
  5549. //int idx = res.IndexOf("sub_message");
  5550. //int idx2 = res.IndexOf("flag");
  5551. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5552. string errMsgNeed = commonHelper.KeepChinese(res);
  5553. var res_objd = new
  5554. {
  5555. restype = 0,
  5556. data = "获取面单失败" + errMsgNeed
  5557. };
  5558. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5559. returnSuccess(ro_jsond);
  5560. if (res.IndexOf("停发") != -1)
  5561. {
  5562. entity.UnusualCon = "物流停发";
  5563. entity.Update();
  5564. }
  5565. //returnErrorMsg("获取面单失败,"+emsg);
  5566. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5567. return;
  5568. }
  5569. else if (res.IndexOf("errorMsg") != -1)
  5570. {
  5571. //int idx = res.IndexOf("errorMsg");
  5572. //int idx2 = res.IndexOf("}]}");
  5573. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5574. string errMsgNeed = commonHelper.KeepChinese(res);
  5575. var res_objf = new
  5576. {
  5577. restype = 0,
  5578. data = "获取面单失败2" + errMsgNeed
  5579. };
  5580. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5581. if (res.IndexOf("停发") != -1)
  5582. {
  5583. entity.UnusualCon = "物流停发";
  5584. entity.Update();
  5585. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5586. if (trade != null)
  5587. {
  5588. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5589. }
  5590. }
  5591. returnSuccess(ro_jsonf);
  5592. //returnErrorMsg("获取面单失败," + emsg);
  5593. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5594. return;
  5595. }
  5596. try
  5597. {
  5598. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5599. //res = res.Replace(" ", "");
  5600. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5601. }
  5602. catch (Exception ex)
  5603. {
  5604. XLog.SaveLog(0, "生成fullObj" + res);
  5605. var res_objf = new
  5606. {
  5607. restype = 0,
  5608. data = "生成fullObj发生错误" + ex.Message
  5609. };
  5610. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5611. returnSuccess(ro_jsonf);
  5612. return;
  5613. }
  5614. if (fullObj.response.data.content.Count > 0)
  5615. {
  5616. ContentItem codeObj = fullObj.response.data.content[0];
  5617. if (cpCode.IndexOf("SFFQ-") != -1)
  5618. {
  5619. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5620. }
  5621. else
  5622. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5623. curUseWayBillCode = codeObj.waybillCode;
  5624. }
  5625. else
  5626. {
  5627. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5628. var res_objf = new
  5629. {
  5630. restype = 0,
  5631. data = "生成fullObj找不到快递单号waybillCode"
  5632. };
  5633. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5634. returnSuccess(ro_jsonf);
  5635. return;
  5636. }
  5637. }
  5638. else
  5639. {
  5640. //使用上次打印的快递单号
  5641. if (cpCode == "SFFQ-LY")
  5642. {
  5643. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5644. }
  5645. else
  5646. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5647. curUseWayBillCode = entity.LastBillWaybillCode;
  5648. }
  5649. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5650. {
  5651. var res_obje = new
  5652. {
  5653. restype = 0,
  5654. data = "获取加密打印数据失败"
  5655. };
  5656. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5657. returnSuccess(ro_jsone);
  5658. entity.LastBillCpCode = cpCode;
  5659. entity.LastBillWaybillCode = curUseWayBillCode;
  5660. entity.Update();
  5661. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5662. //returnErrorMsg("获取加密打印数据失败");
  5663. return;
  5664. }
  5665. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5666. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5667. string btnType = "";
  5668. string errorMsg = "";
  5669. if (entity != null)
  5670. {
  5671. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5672. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5673. //cpcode是 YTO-CAINIAO
  5674. //string comCode = cpCode.Split('-')[0].ToString();
  5675. string apires = "";
  5676. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5677. //isTogether=2是新的合包弹窗
  5678. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5679. {
  5680. if (ctid.IndexOf("N") != -1)
  5681. {
  5682. apires = "发货成功";
  5683. }
  5684. else
  5685. {
  5686. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5687. }
  5688. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5689. //打单后发货
  5690. StringBuilder sql = new StringBuilder();
  5691. sql.AppendFormat("select ctid from CE_ErpTradeCell where SupplierId={0} ", entity.SupplierId);
  5692. if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) > 0)
  5693. {
  5694. sql.AppendFormat(" and tid = '{0}'", mainEn.tid);
  5695. }
  5696. else
  5697. {
  5698. sql.AppendFormat(" and ctid = '{0}'", entity.ctid);
  5699. }
  5700. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5701. foreach (DataRow row in dt.Rows)
  5702. {
  5703. entity = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5704. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5705. {
  5706. try
  5707. {
  5708. btnType = "待发货";
  5709. entity.OutSid = curUseWayBillCode;
  5710. entity.OrderState = 7;
  5711. entity.IsUrgency = false;
  5712. entity.LastBillCpCode = "";
  5713. entity.LastBillWaybillCode = "";
  5714. entity.FinishDeliveryTime = DateTime.Now;
  5715. entity.IsReturn = 0;
  5716. entity.MemoOpt = 0;
  5717. entity.UpdateTime = DateTime.Now;
  5718. entity.Update();
  5719. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5720. //还要插入快递信息到 快递信息表
  5721. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5722. exinfo.tid = entity.ctid;
  5723. exinfo.out_sid = curUseWayBillCode;
  5724. exinfo.company_code = cpCode;
  5725. exinfo.company_name = cpName;
  5726. exinfo.supplierUserName = supplierName;
  5727. exinfo.deliveryType = "发货成功";
  5728. exinfo.print_time = DateTime.Now;
  5729. exinfo.printUser = CurrentUser.UserName;
  5730. exinfo.postData = pData_str;
  5731. exinfo.Create();
  5732. commonHelper.UpdateRelationOrder(entity.ctid);
  5733. CeErpSukuraData.createInfo(ctid, 4);
  5734. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5735. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5736. {
  5737. commonHelper.sendCytExpress(exinfo);
  5738. }
  5739. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5740. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5741. }
  5742. catch (Exception ex)
  5743. {
  5744. XLog.SaveLog(0, "发货成功后更新数据失败," + ex);
  5745. }
  5746. }
  5747. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5748. {
  5749. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5750. if (entity.OrderState == 6)
  5751. {
  5752. entity.OrderState = 7;
  5753. }
  5754. entity.UpdateTime = DateTime.Now;
  5755. entity.FinishDeliveryTime = DateTime.Now;
  5756. btnType = "已发货";
  5757. entity.Update();
  5758. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5759. exinfo.tid = entity.ctid;
  5760. exinfo.out_sid = curUseWayBillCode;
  5761. exinfo.company_code = cpCode;
  5762. exinfo.company_name = cpName;
  5763. exinfo.supplierUserName = supplierName;
  5764. exinfo.deliveryType = "发货成功";
  5765. exinfo.print_time = DateTime.Now;
  5766. exinfo.printUser = CurrentUser.UserName;
  5767. exinfo.postData = pData_str;
  5768. exinfo.Create();
  5769. commonHelper.UpdateRelationOrder(entity.ctid);
  5770. CeErpSukuraData.createInfo(entity.ctid, 4);
  5771. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5772. {
  5773. commonHelper.sendCytExpress(exinfo);
  5774. }
  5775. //不处理
  5776. }
  5777. else
  5778. {
  5779. entity.UpdateTime = DateTime.Now;
  5780. entity.LastBillCpCode = cpCode;
  5781. entity.LastBillWaybillCode = curUseWayBillCode;
  5782. entity.Update();
  5783. string errmsg = commonHelper.KeepChinese(apires);
  5784. var res_objz = new
  5785. {
  5786. restype = 0,
  5787. data = "打单后发货失败"
  5788. };
  5789. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5790. returnSuccess(ro_jsonz);
  5791. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5792. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5793. return;
  5794. }
  5795. }
  5796. }
  5797. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5798. {
  5799. string ctids = GetPostString("ctids");
  5800. DataTable dt = commonHelper.getSameOrderList(entity, mainEn);
  5801. List<string> list = new List<string>();
  5802. List<string> send_list = new List<string>();
  5803. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5804. CeErpTrade ceErpTrade = new CeErpTrade();
  5805. //可合包的合并一起发货
  5806. if (dt == null && string.IsNullOrEmpty(ctids))
  5807. {
  5808. var res_objz = new
  5809. {
  5810. restype = 0,
  5811. data = "打单后发货失败"
  5812. };
  5813. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5814. returnSuccess(ro_jsonz);
  5815. return;
  5816. }
  5817. if (!string.IsNullOrEmpty(ctids))
  5818. {
  5819. StringBuilder sql = new StringBuilder();
  5820. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  5821. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5822. }
  5823. foreach (DataRow row in dt.Rows)
  5824. {
  5825. list.Add("'" + row["ctid"] + "'");
  5826. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5827. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5828. if (ctid.IndexOf("N") != -1)
  5829. {
  5830. apires = "发货成功";
  5831. }
  5832. else
  5833. {
  5834. if (!send_list.Contains(ceErpTrade.tid))
  5835. {
  5836. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5837. }
  5838. else
  5839. {
  5840. apires = "发货成功";
  5841. }
  5842. }
  5843. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5844. {
  5845. send_list.Add(ceErpTrade.tid);
  5846. try
  5847. {
  5848. btnType = "待发货";
  5849. ceErpTradeCell.OutSid = curUseWayBillCode;
  5850. ceErpTradeCell.OrderState = 7;
  5851. ceErpTradeCell.IsUrgency = false;
  5852. ceErpTradeCell.LastBillCpCode = "";
  5853. ceErpTradeCell.LastBillWaybillCode = "";
  5854. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5855. ceErpTradeCell.IsReturn = 0;
  5856. ceErpTradeCell.MemoOpt = 0;
  5857. ceErpTradeCell.UpdateTime = DateTime.Now;
  5858. ceErpTradeCell.Update();
  5859. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5860. //还要插入快递信息到 快递信息表
  5861. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5862. exinfo.tid = ceErpTradeCell.ctid;
  5863. exinfo.out_sid = curUseWayBillCode;
  5864. exinfo.company_code = cpCode;
  5865. exinfo.company_name = cpName;
  5866. exinfo.supplierUserName = supplierName;
  5867. exinfo.deliveryType = "发货成功";
  5868. exinfo.print_time = DateTime.Now;
  5869. exinfo.printUser = CurrentUser.UserName;
  5870. exinfo.postData = pData_str;
  5871. exinfo.Create();
  5872. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5873. CeErpSukuraData.createInfo(ctid, 4);
  5874. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5875. if (ceErpTradeCell.SupplierId == 64 || ceErpTradeCell.SupplierId == 80)
  5876. {
  5877. commonHelper.sendCytExpress(exinfo);
  5878. }
  5879. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5880. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5881. }
  5882. catch (Exception ex)
  5883. {
  5884. XLog.SaveLog(0, "发货成功后更新数据失败," + ex);
  5885. }
  5886. }
  5887. else
  5888. {
  5889. ceErpTradeCell.UpdateTime = DateTime.Now;
  5890. ceErpTradeCell.LastBillCpCode = cpCode;
  5891. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5892. ceErpTradeCell.Update();
  5893. string errmsg = commonHelper.KeepChinese(apires);
  5894. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5895. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5896. }
  5897. }
  5898. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5899. }
  5900. }
  5901. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5902. var res_obj = new
  5903. {
  5904. restype = 1,
  5905. data = pData_str,
  5906. errorMsg
  5907. };
  5908. string ro_json = JsonConvert.SerializeObject(res_obj);
  5909. ReturnSuccess(ro_json);
  5910. return;
  5911. }
  5912. }
  5913. private string GetUTF8String(byte[] vs)
  5914. {
  5915. throw new NotImplementedException();
  5916. }
  5917. public void set_erp_printwaybill_cn()
  5918. {
  5919. if (UrlPostParmsCheck("ctid"))
  5920. {
  5921. string ctid = GetPostString("ctid");
  5922. string cpCode = GetPostString("cpcode");
  5923. string cpName = GetPostString("cpname");
  5924. string tempUrl = GetPostString("tempurl");
  5925. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5926. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5927. //string res = taobaoHelper.test();
  5928. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5929. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5930. {
  5931. int sidx = res.IndexOf("errorMsg");
  5932. int eidx = res.IndexOf("}");
  5933. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5934. var res_objzxx = new
  5935. {
  5936. restype = 0,
  5937. data = msg
  5938. };
  5939. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5940. returnSuccess(ro_jsonzxx);
  5941. //returnErrorMsg(msg);
  5942. return;
  5943. }
  5944. int idx = res.IndexOf("waybillCode");
  5945. int idx2 = res.IndexOf("printData");
  5946. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5947. string eid = GetPostString("ctid");
  5948. CeErpTradeCell entity = null;
  5949. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5950. if (entity != null)
  5951. {
  5952. string osid = entity.OutSid;
  5953. entity.OutSid = osid + "," + outsid;
  5954. entity.FinishDeliveryTime = DateTime.Now;
  5955. entity.OrderState = 7;
  5956. entity.UpdateTime = DateTime.Now;
  5957. entity.IsReturn = 0;
  5958. entity.Update();
  5959. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5960. exinfo.tid = entity.ctid;
  5961. exinfo.out_sid = outsid;
  5962. exinfo.company_code = cpCode;
  5963. exinfo.company_name = cpName;
  5964. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5965. exinfo.deliveryType = "发货成功";
  5966. exinfo.print_time = DateTime.Now;
  5967. exinfo.printUser = CurrentUser.UserName;
  5968. exinfo.Create();
  5969. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5970. {
  5971. commonHelper.sendCytExpress(exinfo);
  5972. }
  5973. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5974. }
  5975. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5976. var res_objz = new
  5977. {
  5978. restype = 1,
  5979. data = res
  5980. };
  5981. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5982. returnSuccess(ro_jsonz);
  5983. //ReturnSuccess(res);
  5984. }
  5985. }
  5986. ////打单,打印面单 获取面单号
  5987. //public void set_erp_printwaybill()
  5988. //{
  5989. // if (UrlPostParmsCheck("ctid"))
  5990. // {
  5991. // string ctid = GetPostString("ctid");
  5992. // string cpCode = GetPostString("cpcode");
  5993. // string tempUrl = GetPostString("tempurl");
  5994. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5995. // //string res = taobaoHelper.test();
  5996. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5997. // if (res.IndexOf("error_response") != -1)
  5998. // {
  5999. // int sidx = res.IndexOf("sub_msg");
  6000. // int eidx = res.IndexOf("request_id");
  6001. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  6002. // returnErrorMsg(msg);
  6003. // return;
  6004. // }
  6005. // int idx = res.IndexOf("waybill_code");
  6006. // int idx2 = res.IndexOf("}]}");
  6007. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  6008. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  6009. // ReturnSuccess(res);
  6010. // }
  6011. //}
  6012. public void cancel_erp_aftersale()
  6013. {
  6014. if (UrlPostParmsCheck("ctid"))
  6015. {
  6016. string eid = GetPostString("ctid");
  6017. CeErpTradeCell entity = null;
  6018. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6019. if (entity != null)
  6020. {
  6021. //有过处理的售后,取消也不能删除 售 字,保留
  6022. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  6023. {
  6024. entity.AfterSaleState = 4;
  6025. }
  6026. else
  6027. entity.AfterSaleState = 0;
  6028. entity.UpdateTime = DateTime.Now;
  6029. entity.Update();
  6030. returnSuccessMsg("操作成功!");
  6031. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  6032. return;
  6033. }
  6034. returnErrorMsg("找不到订单记录");
  6035. }
  6036. }
  6037. public void get_erp_aftersalelist()
  6038. {
  6039. DataStruct dStruct = GetPostStruct();
  6040. List<string> lw = new List<string>();
  6041. int st = GetInt("st");
  6042. string tid = GetPostString("ctid");
  6043. if (st == 3)
  6044. {
  6045. if (tid.Length > 0)
  6046. {
  6047. string select_tid = getTidByCtid(tid);
  6048. lw.Add(string.Format("tid='{0}'", select_tid));
  6049. }
  6050. }
  6051. else
  6052. {
  6053. if (tid.Length > 0)
  6054. {
  6055. string select_tid = getTidByCtid(tid);
  6056. lw.Add(string.Format("tid='{0}'", select_tid));
  6057. }
  6058. }
  6059. string shopname = GetPostString("shopname");
  6060. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6061. string buyernick = GetPostString("buyer_nick");
  6062. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  6063. string sellermemo = GetPostString("seller_memo");
  6064. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6065. string orderState = GetPostString("orderState");
  6066. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  6067. string afterState = GetPostString("afterstate");
  6068. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6069. string date1 = GetPostString("date1");
  6070. string date2 = GetPostString("date2");
  6071. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6072. if (dw.Length > 0) lw.Add(dw);
  6073. string price1 = GetPostString("price1");
  6074. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6075. string price2 = GetPostString("price2");
  6076. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6077. //lw.Add(string.Format("IsRefund!={0}", 1));
  6078. string reason = GetPostString("reason");
  6079. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6080. string method = GetPostString("method");
  6081. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6082. string handler = GetPostString("handler");
  6083. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6084. string handledate1 = GetPostString("handledate1");
  6085. string handledate2 = GetPostString("handledate2");
  6086. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6087. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6088. string finish1 = GetPostString("finishdate1");
  6089. string finish2 = GetPostString("finishdate2");
  6090. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6091. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6092. string afterdate1 = GetPostString("afterdate1");
  6093. string afterdate2 = GetPostString("afterdate2");
  6094. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6095. if (afterDate.Length > 0) lw.Add(afterDate);
  6096. string supplier = GetPostString("supplier");
  6097. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6098. string responsible = GetPostString("responsibleman");
  6099. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6100. string customer = GetPostString("customer");
  6101. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6102. string design = GetPostString("design");
  6103. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6104. string afterMemoType = GetPostString("aftermemotype");
  6105. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6106. string posCode = CurrentUser.UserPost.Post.Code;
  6107. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  6108. //{
  6109. // string vstate = GetPostString("vstate");
  6110. // if (vstate.Length > 0)
  6111. // {
  6112. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6113. // }
  6114. // if (posCode == "Supplier")
  6115. // {
  6116. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6117. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6118. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6119. // }
  6120. // else
  6121. // {
  6122. // lw.Add(string.Format("AfterSaleState = {0}", st));
  6123. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  6124. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  6125. // {
  6126. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  6127. // }
  6128. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  6129. // {
  6130. // int orgid = CurrentUser.UserPost.OrgID;
  6131. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  6132. // }
  6133. // else if (CurrentUser.UserPost.Post.Code == "Director")
  6134. // {
  6135. // string shopid = CurrentUser.User.pemShop;
  6136. // lw.Add(string.Format("shopId in ({0})", shopid));
  6137. // }
  6138. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6139. // //{
  6140. // // int org_id = CurrentUser.UserPost.OrgID;
  6141. // // lw.Add(string.Format("OrgID={0}", org_id));
  6142. // //}
  6143. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  6144. // }
  6145. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6146. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6147. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6148. //}
  6149. if (st == 5)
  6150. {
  6151. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  6152. {
  6153. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  6154. {
  6155. string shopid = CurrentUser.User.pemShop;
  6156. lw.Add(string.Format("shopId in ({0})", shopid));
  6157. }
  6158. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  6159. {
  6160. int mrOrgid = CurrentUser.UserPost.OrgID;
  6161. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  6162. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  6163. }
  6164. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  6165. //{
  6166. // int mrOrgid = CurrentUser.UserPost.OrgID;
  6167. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  6168. //}
  6169. else
  6170. {
  6171. string userIdStr = "";
  6172. if (posCode == "CustomerService")
  6173. {
  6174. userIdStr = CurrentUser.UserID + "_k";
  6175. }
  6176. else if (posCode == "Designer" || posCode == "wxDesigner")
  6177. {
  6178. userIdStr = CurrentUser.UserID + "_s";
  6179. }
  6180. else if (posCode == "Place")
  6181. {
  6182. userIdStr = CurrentUser.UserID + "_x";
  6183. }
  6184. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6185. }
  6186. }
  6187. string placedate1 = GetPostString("placedate1");
  6188. string placedate2 = GetPostString("placedate2");
  6189. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6190. if (dwplace.Length > 0) lw.Add(dwplace);
  6191. string supState = GetPostString("supState");
  6192. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6193. string searchType = GetPostString("searchType");
  6194. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6195. {
  6196. lw.Add(string.Format("BackNum>1"));
  6197. }
  6198. lw.Add(string.Format("AfterSaleState>0"));
  6199. if (ex_psize > 0)
  6200. {
  6201. if (CurrentUser.UserPost.Post.Code == "Finance")
  6202. dStruct.Order = "pay_time desc";
  6203. else
  6204. dStruct.Order = "HandleTime desc";
  6205. }
  6206. else
  6207. dStruct.Order = "HandleTime desc";
  6208. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6209. DataTable dt = WebCache.GetData("view_test", dStruct);
  6210. writeGridDataTableJson(dStruct.TotalCount, dt);
  6211. }
  6212. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6213. //{
  6214. // lw.Add(string.Format("AfterSaleState=4"));
  6215. // string code = CurrentUser.UserPost.Post.Code;
  6216. // if (code == "CustomerService")
  6217. // {
  6218. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6219. // }
  6220. // else if (code == "Designer" || code == "DesignerMr")
  6221. // {
  6222. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6223. // }
  6224. // else if (code == "Place" || code == "PlaceMr")
  6225. // {
  6226. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6227. // }
  6228. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6229. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6230. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6231. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6232. //}
  6233. //else //处理中的售后,待处理和处理中合并
  6234. //{
  6235. // if (afterState.Length <= 0)
  6236. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6237. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6238. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6239. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6240. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6241. //}
  6242. }
  6243. public void get_erp_disagreeftersalelist()
  6244. {
  6245. DataStruct dStruct = GetPostStruct();
  6246. List<string> lw = new List<string>();
  6247. int st = 2;
  6248. string tid = GetPostString("ctid");
  6249. if (tid.Length > 0)
  6250. {
  6251. string select_tid = getTidByCtid(tid);
  6252. lw.Add(string.Format("tid='{0}'", select_tid));
  6253. }
  6254. string shopname = GetPostString("shopname");
  6255. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6256. string buyernick = GetPostString("buyer_nick");
  6257. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6258. string sellermemo = GetPostString("seller_memo");
  6259. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6260. string orderState = GetPostString("orderState");
  6261. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6262. string afterState = GetPostString("afterstate");
  6263. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6264. string date1 = GetPostString("date1");
  6265. string date2 = GetPostString("date2");
  6266. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6267. if (dw.Length > 0) lw.Add(dw);
  6268. string price1 = GetPostString("price1");
  6269. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6270. string price2 = GetPostString("price2");
  6271. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6272. //lw.Add(string.Format("IsRefund!={0}", 1));
  6273. string reason = GetPostString("reason");
  6274. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6275. string method = GetPostString("method");
  6276. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6277. string handler = GetPostString("handler");
  6278. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6279. string handledate1 = GetPostString("handledate1");
  6280. string handledate2 = GetPostString("handledate2");
  6281. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6282. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6283. string afterdate1 = GetPostString("afterdate1");
  6284. string afterdate2 = GetPostString("afterdate2");
  6285. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6286. if (afterDate.Length > 0) lw.Add(afterDate);
  6287. string backdate1 = GetPostString("backdate1");
  6288. string backdate2 = GetPostString("backdate2");
  6289. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6290. if (backDate.Length > 0) lw.Add(backDate);
  6291. string supplier = GetPostString("supplier");
  6292. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6293. string responsible = GetPostString("responsibleman");
  6294. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6295. string customer = GetPostString("customer");
  6296. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6297. string design = GetPostString("design");
  6298. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6299. string afterSaleMemo = GetPostString("afterSaleMemo");
  6300. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6301. string afterMemoType = GetPostString("aftermemotype");
  6302. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6303. string aftersakereason = GetPostString("aftersakereason");
  6304. if (aftersakereason.Length > 0)
  6305. {
  6306. if (aftersakereason == "1")
  6307. {
  6308. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6309. }
  6310. if (aftersakereason == "2")
  6311. {
  6312. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6313. }
  6314. }
  6315. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6316. string poscode = CurrentUser.UserPost.Post.Code;
  6317. if (poscode != "SysAdmin")
  6318. {
  6319. string shopid = CurrentUser.User.pemShop;
  6320. lw.Add(string.Format("shopId in ({0})", shopid));
  6321. }
  6322. string searchType = GetPostString("searchType");
  6323. if (searchType == "wait")
  6324. {
  6325. lw.Add(string.Format("HandleTime is null"));
  6326. }
  6327. if (searchType == "handling")
  6328. {
  6329. lw.Add(string.Format("HandleTime is not null "));
  6330. }
  6331. if (searchType == "back" || searchType == "puBack")
  6332. {
  6333. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6334. }
  6335. if (searchType == "reBack")
  6336. {
  6337. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6338. }
  6339. if (searchType == "moreBack")
  6340. {
  6341. lw.Add(string.Format("backNum > 1"));
  6342. }
  6343. lw.Add(string.Format("(AfterSaleState=5)"));
  6344. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6345. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6346. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6347. writeGridDataTableJson(dStruct.TotalCount, dt);
  6348. }
  6349. public void get_erp_handlingaftersalelist()
  6350. {
  6351. DataStruct dStruct = GetPostStruct();
  6352. List<string> lw = new List<string>();
  6353. int st = 2;
  6354. string tid = GetPostString("ctid");
  6355. if (tid.Length > 0)
  6356. {
  6357. string select_tid = getTidByCtid(tid);
  6358. lw.Add(string.Format("tid='{0}'", select_tid));
  6359. }
  6360. string shopname = GetPostString("shopname");
  6361. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6362. string buyernick = GetPostString("buyer_nick");
  6363. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6364. string sellermemo = GetPostString("seller_memo");
  6365. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6366. string orderState = GetPostString("orderState");
  6367. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6368. string afterState = GetPostString("afterstate");
  6369. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6370. string date1 = GetPostString("date1");
  6371. string date2 = GetPostString("date2");
  6372. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6373. if (dw.Length > 0) lw.Add(dw);
  6374. string price1 = GetPostString("price1");
  6375. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6376. string price2 = GetPostString("price2");
  6377. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6378. //lw.Add(string.Format("IsRefund!={0}", 1));
  6379. string reason = GetPostString("reason");
  6380. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6381. string method = GetPostString("method");
  6382. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6383. string handler = GetPostString("handler");
  6384. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6385. string handledate1 = GetPostString("handledate1");
  6386. string handledate2 = GetPostString("handledate2");
  6387. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6388. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6389. string afterdate1 = GetPostString("afterdate1");
  6390. string afterdate2 = GetPostString("afterdate2");
  6391. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6392. if (afterDate.Length > 0) lw.Add(afterDate);
  6393. string supplier = GetPostString("supplier");
  6394. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6395. string responsible = GetPostString("responsibleman");
  6396. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6397. string customer = GetPostString("customer");
  6398. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6399. string design = GetPostString("design");
  6400. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6401. string afterSaleMemo = GetPostString("afterSaleMemo");
  6402. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6403. string afterMemoType = GetPostString("aftermemotype");
  6404. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6405. string afterresult = GetPostString("afterresult");
  6406. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6407. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6408. string poscode = CurrentUser.UserPost.Post.Code;
  6409. if (poscode != "SysAdmin")
  6410. {
  6411. string shopid = CurrentUser.User.pemShop;
  6412. lw.Add(string.Format("shopId in ({0})", shopid));
  6413. }
  6414. string searchType = GetPostString("searchType");
  6415. if (searchType == "wait")
  6416. {
  6417. lw.Add(string.Format("HandleTime is null"));
  6418. }
  6419. if (searchType == "documentary")
  6420. {
  6421. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6422. }
  6423. if (searchType == "handling")
  6424. {
  6425. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6426. }
  6427. if (searchType == "back" || searchType == "puBack")
  6428. {
  6429. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6430. }
  6431. if (searchType == "reBack")
  6432. {
  6433. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6434. }
  6435. if (afterState.Length <= 0)
  6436. {
  6437. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6438. }
  6439. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6440. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6441. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6442. writeGridDataTableJson(dStruct.TotalCount, dt);
  6443. }
  6444. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6445. //public void get_erp_back_handlingaftersalelist()
  6446. //{
  6447. // DataStruct dStruct = GetPostStruct();
  6448. // List<string> lw = new List<string>();
  6449. // string tid = GetPostString("ctid");
  6450. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6451. // string shopname = GetPostString("shopname");
  6452. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6453. // string buyernick = GetPostString("buyer_nick");
  6454. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6455. // string sellermemo = GetPostString("seller_memo");
  6456. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6457. // string orderState = GetPostString("orderState");
  6458. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6459. // string afterState = GetPostString("afterstate");
  6460. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6461. // string date1 = GetPostString("date1");
  6462. // string date2 = GetPostString("date2");
  6463. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6464. // if (dw.Length > 0) lw.Add(dw);
  6465. // string price1 = GetPostString("price1");
  6466. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6467. // string price2 = GetPostString("price2");
  6468. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6469. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6470. // string reason = GetPostString("reason");
  6471. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6472. // string method = GetPostString("method");
  6473. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6474. // string handler = GetPostString("handler");
  6475. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6476. // string handledate1 = GetPostString("handledate1");
  6477. // string handledate2 = GetPostString("handledate2");
  6478. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6479. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6480. // string afterdate1 = GetPostString("afterdate1");
  6481. // string afterdate2 = GetPostString("afterdate2");
  6482. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6483. // if (afterDate.Length > 0) lw.Add(afterDate);
  6484. // string supplier = GetPostString("supplier");
  6485. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6486. // string responsible = GetPostString("responsibleman");
  6487. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6488. // string customer = GetPostString("customer");
  6489. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6490. // string design = GetPostString("design");
  6491. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6492. // string afterMemoType = GetPostString("aftermemotype");
  6493. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6494. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6495. // if (afterState.Length <= 0)
  6496. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6497. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6498. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6499. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6500. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6501. //}
  6502. public void get_erp_aftersaleverifylist()
  6503. {
  6504. DataStruct dStruct = GetPostStruct();
  6505. List<string> lw = new List<string>();
  6506. string tid = GetPostString("ctid");
  6507. if (tid.Length > 0)
  6508. {
  6509. string select_tid = getTidByCtid(tid);
  6510. lw.Add(string.Format("otid='{0}'", select_tid));
  6511. }
  6512. string shopname = GetPostString("shopname");
  6513. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6514. string buyernick = GetPostString("buyer_nick");
  6515. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6516. string sellermemo = GetPostString("seller_memo");
  6517. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6518. string orderState = GetPostString("orderState");
  6519. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6520. //lw.Add(string.Format("IsRefund!={0}", 1));
  6521. string reason = GetPostString("reason");
  6522. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6523. string method = GetPostString("method");
  6524. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6525. string handler = GetPostString("handler");
  6526. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6527. string handledate1 = GetPostString("handledate1");
  6528. string handledate2 = GetPostString("handledate2");
  6529. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6530. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6531. string finish1 = GetPostString("finishdate1");
  6532. string finish2 = GetPostString("finishdate2");
  6533. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6534. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6535. string supplier = GetPostString("supplier");
  6536. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6537. string responsible = GetPostString("responsibleman");
  6538. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6539. string posCode = CurrentUser.UserPost.Post.Code;
  6540. string vstate = GetPostString("vstate");
  6541. if (vstate.Length > 0)
  6542. {
  6543. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6544. }
  6545. if (posCode == "Supplier")
  6546. {
  6547. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6548. lw.Add(string.Format("VerifyState = 0"));
  6549. lw.Add("type = 1");
  6550. lw.Add(string.Format("AfterSaleState={0}", 3));
  6551. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6552. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6553. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6554. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6555. writeGridDataTableJson(dStruct.TotalCount, dt);
  6556. }
  6557. else if (posCode == "logistics")
  6558. {
  6559. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6560. lw.Add(string.Format("VerifyState = 0"));
  6561. lw.Add("type = 2");
  6562. lw.Add(string.Format("AfterSaleState={0}", 3));
  6563. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6564. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6565. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6566. writeGridDataTableJson(dStruct.TotalCount, dt);
  6567. }
  6568. else
  6569. {
  6570. lw.Add(string.Format("(AfterSaleState = 3)"));
  6571. lw.Add("type = 0");
  6572. string reasonState = GetPostString("reasonState");
  6573. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "Summarize" || posCode == "Finance")
  6574. {
  6575. if (reasonState == "2")
  6576. {
  6577. lw.Add("VerifyState = 3");
  6578. }
  6579. else if (reasonState == "1")
  6580. {
  6581. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6582. }
  6583. else
  6584. {
  6585. lw.Add("VerifyState in (0,3)");
  6586. }
  6587. //不加条件,可以看全部
  6588. }
  6589. 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")
  6590. {
  6591. int orgid = CurrentUser.UserPost.OrgID;
  6592. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6593. if (string.IsNullOrEmpty(manageOrgId))
  6594. {
  6595. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6596. }
  6597. else
  6598. {
  6599. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6600. }
  6601. if (reasonState == "1")
  6602. {
  6603. lw.Add("VerifyState = 3");
  6604. }
  6605. else if (reasonState == "2")
  6606. {
  6607. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6608. }
  6609. else
  6610. {
  6611. }
  6612. }
  6613. else
  6614. {
  6615. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6616. }
  6617. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6618. //{
  6619. // int org_id = CurrentUser.UserPost.OrgID;
  6620. // lw.Add(string.Format("OrgID={0}", org_id));
  6621. //}
  6622. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6623. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6624. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6625. writeGridDataTableJson(dStruct.TotalCount, dt);
  6626. }
  6627. }
  6628. public void get_erp_finishaftersalelist()
  6629. {
  6630. DataStruct dStruct = GetPostStruct();
  6631. List<string> lw = new List<string>();
  6632. int st = 4;
  6633. string tid = GetPostString("ctid");
  6634. if (tid.Length > 0)
  6635. {
  6636. string select_tid = getTidByCtid(tid);
  6637. lw.Add(string.Format("otid='{0}'", select_tid));
  6638. }
  6639. string shopname = GetPostString("shopname");
  6640. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6641. //lw.Add(string.Format("IsRefund!={0}", 1));
  6642. string reason = GetPostString("reason");
  6643. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6644. string method = GetPostString("method");
  6645. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6646. string buyernick = GetPostString("buyer_nick");
  6647. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6648. string handler = GetPostString("handler");
  6649. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6650. string handledate1 = GetPostString("handledate1");
  6651. string handledate2 = GetPostString("handledate2");
  6652. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6653. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6654. string finish1 = GetPostString("finishdate1");
  6655. string finish2 = GetPostString("finishdate2");
  6656. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6657. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6658. string supplier = GetPostString("supplier");
  6659. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6660. string responsible = GetPostString("responsibleman");
  6661. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6662. string vstate = GetPostString("vstate");
  6663. if (vstate.Length > 0)
  6664. {
  6665. if ("3".Equals(vstate))
  6666. {
  6667. lw.Add(string.Format("IsTem=1"));
  6668. }
  6669. else
  6670. {
  6671. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6672. }
  6673. }
  6674. lw.Add(string.Format("AfterSaleState=4"));
  6675. string code = CurrentUser.UserPost.Post.Code;
  6676. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6677. {
  6678. //不加条件,可以看全部
  6679. }
  6680. else if (code == "Supplier")
  6681. {
  6682. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6683. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6684. lw.Add("type = 1");
  6685. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6686. }
  6687. else if (code == "logistics")
  6688. {
  6689. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6690. lw.Add("type = 2");
  6691. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6692. }
  6693. 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")
  6694. {
  6695. lw.Add("type = 0");
  6696. int orgid = CurrentUser.UserPost.OrgID;
  6697. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6698. if (string.IsNullOrEmpty(manageOrgIds))
  6699. {
  6700. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6701. }
  6702. else
  6703. {
  6704. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6705. }
  6706. }
  6707. else
  6708. {
  6709. lw.Add("type = 0");
  6710. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6711. }
  6712. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6713. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6714. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6715. writeGridDataTableJson(dStruct.TotalCount, dt);
  6716. }
  6717. public void handle_erp_aftersale()
  6718. {
  6719. if (UrlPostParmsCheck("ctid"))
  6720. {
  6721. string eid = GetPostString("ctid");
  6722. string responStr = GetPostString("AfterSaleResponsible");
  6723. if (responStr.Length <= 0)
  6724. {
  6725. returnErrorMsg("售后责任人不能为空");
  6726. return;
  6727. }
  6728. bool isDesign = false;
  6729. double designFree = 0.00;
  6730. int responsibleId = 0;
  6731. CeErpTradeCell entity = null;
  6732. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6733. if (entity != null)
  6734. {
  6735. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6736. string afterMethod = GetPostString("AfterSaleMethod");
  6737. if (isNeedNewOrder == 1)
  6738. {
  6739. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6740. bool ishav = true;
  6741. if (newentity == null)
  6742. {
  6743. newentity = entity.Clone() as CeErpTradeCell;
  6744. ishav = false;
  6745. newentity.ctid = "S_" + entity.ctid;
  6746. newentity.OrderState = 0;
  6747. //唯一标识
  6748. newentity.OrderSn = newentity.ctid;
  6749. string orderSn = dataHelper.getSaleOrderSn();
  6750. if (orderSn != "")
  6751. {
  6752. newentity.OrderSn = orderSn;
  6753. }
  6754. }
  6755. newentity.UpdateTime = DateTime.Now;
  6756. newentity.AfterSaleState = 0;
  6757. newentity.AfterSaleMethod = afterMethod;
  6758. if (!ishav)
  6759. {
  6760. string memo_str = newentity.seller_memo;
  6761. memo_str = memo_str.Replace("(", "(");
  6762. memo_str = memo_str.Replace(")", ")");
  6763. int sIndex = memo_str.IndexOf("(");
  6764. int eIndex = memo_str.IndexOf(")");
  6765. if (sIndex == -1 || eIndex == -1)
  6766. {
  6767. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6768. return;
  6769. }
  6770. string first = memo_str.Substring(0, sIndex + 1);
  6771. string memoCtid = newentity.OrderSn;
  6772. //if (memoCtid.IndexOf("C") != -1)
  6773. //{
  6774. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6775. //if (CIdx.IndexOf("+") != -1)
  6776. //{
  6777. //CIdx = "C" + CIdx.Split('+')[1];
  6778. //}
  6779. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6780. //}
  6781. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6782. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6783. string newMemo = first + memoCtid + last;
  6784. newentity.seller_memo = newMemo;
  6785. newentity.FinishPlaceTime = null;
  6786. newentity.UnusualTag = 0;
  6787. newentity.UnusualCon = "";
  6788. newentity.UnusualTime = null;
  6789. newentity.AfterSaleMemo = "";
  6790. newentity.AfterSaleMethod = afterMethod;
  6791. newentity.AfterSalePreTime = null;
  6792. newentity.AfterSaleReason = "";
  6793. newentity.AfterSaleResponsible = "";
  6794. newentity.AfterSaleState = 0;
  6795. newentity.AfterSaleTime = null;
  6796. newentity.AfterSaleUserId = 0;
  6797. newentity.AfterSaleSupplierState = 0;
  6798. newentity.LastBillWaybillCode = "";
  6799. newentity.LastBillCpCode = "";
  6800. newentity.FinishAfterSaleTime = null;
  6801. newentity.HandleTime = null;
  6802. newentity.IsSF = 0;
  6803. newentity.IsOldCustomer = 0;
  6804. newentity.UrgencyTime = null;
  6805. newentity.ResponsibleUserId = "";
  6806. newentity.IsVerifyToSupplier = false;
  6807. newentity.payment = 0;
  6808. newentity.CheckMemo = "";
  6809. newentity.OutSid = "";
  6810. newentity.CheckOrderTime = null;
  6811. newentity.MemoOpt = 0;
  6812. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6813. }
  6814. newentity.isAfterSaleOrder = 1;
  6815. newentity.IsRefund = 0;
  6816. string receiveMobile = GetPostString("receiver_mobile");
  6817. if (receiveMobile.Length > 0)
  6818. {
  6819. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6820. if (trade != null)
  6821. {
  6822. trade.receiver_name = GetPostString("receiver_name");
  6823. trade.receiver_mobile = receiveMobile;
  6824. trade.receiver_state = GetPostString("receiver_state");
  6825. trade.receiver_city = GetPostString("receiver_city");
  6826. trade.receiver_district = GetPostString("receiver_district");
  6827. trade.receiver_address = GetPostString("receiver_address");
  6828. newentity.IsOffLineOrder = 1;
  6829. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6830. }
  6831. }
  6832. string st = GetPostString("ToState");
  6833. if (st.Length > 0)
  6834. {
  6835. if (newentity.OrderState <= 3)
  6836. {
  6837. newentity.WaitDesignTime = DateTime.Now;
  6838. newentity.StartDesignTime = null;
  6839. newentity.FinishDesignTime = null;
  6840. newentity.OrderState = 3;
  6841. if (st == "下单员")
  6842. {
  6843. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6844. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6845. {
  6846. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6847. }
  6848. }
  6849. else
  6850. {
  6851. newentity.WaitDesignTime = DateTime.Now;
  6852. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6853. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6854. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6855. {
  6856. DataRow user = dt1.Rows[0];
  6857. //找主管
  6858. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6859. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6860. if (dt != null && dt.Rows.Count > 0)
  6861. {
  6862. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6863. newentity.DesignUserId = designMr;
  6864. string key = "aftersale_order_" + designMr;
  6865. if (RedisHelper.HasKey(key))
  6866. {
  6867. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6868. list.Add(newentity.ctid);
  6869. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6870. }
  6871. }
  6872. //账号正常
  6873. if (user["State"].ToString() == "0")
  6874. {
  6875. newentity.DesignUserId = entity.DesignUserId;
  6876. string key = "aftersale_order_" + entity.DesignUserId;
  6877. if (RedisHelper.HasKey(key))
  6878. {
  6879. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6880. list.Add(newentity.ctid);
  6881. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6882. }
  6883. }
  6884. }
  6885. }
  6886. }
  6887. if (entity.IsXianHuo == 1)
  6888. {
  6889. newentity.OrderState = 6;
  6890. entity.FinishPlaceTime = DateTime.Now;
  6891. }
  6892. }
  6893. if (ishav)
  6894. {
  6895. newentity.Update();
  6896. }
  6897. else
  6898. {
  6899. newentity.Create();
  6900. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6901. newCellExtend.ctid = newentity.ctid;
  6902. newCellExtend.orderFrom = 20;
  6903. newCellExtend.orderType = 30;
  6904. if (st == "下单员")
  6905. {
  6906. }
  6907. else
  6908. {
  6909. newCellExtend.ReprintTime = DateTime.Now;
  6910. }
  6911. newCellExtend.Create();
  6912. }
  6913. if (st != "下单员")
  6914. {
  6915. if (entity.DispatchSort == 2)
  6916. {
  6917. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  6918. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  6919. }
  6920. }
  6921. }
  6922. //处理售后扩展
  6923. string resIdStr = GetPostString("ResponsibleUserId");
  6924. string refundFees = GetPostString("refundFrees");
  6925. int IsComplain = GetPostInt("isComplain");
  6926. int IsBad = GetPostInt("isBad");
  6927. string IsOriginal = GetPostString("isOriginal");
  6928. double diffResultPrice = GetPostDouble("diffResultPrice");
  6929. string textResult = GetPostString("textResult");
  6930. string supplierResponsible = GetPostString("supplierResponsible");
  6931. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6932. if (ceErpTradeAfterSaleExtend == null)
  6933. {
  6934. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6935. ceErpTradeAfterSaleExtend.tid = eid;
  6936. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6937. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6938. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6939. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6940. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6941. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6942. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6943. ceErpTradeAfterSaleExtend.Create();
  6944. }
  6945. else
  6946. {
  6947. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6948. {
  6949. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6950. }
  6951. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6952. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6953. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6954. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6955. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6956. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6957. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6958. ceErpTradeAfterSaleExtend.Update();
  6959. }
  6960. int gysid = GetPostInt("ResponsibleSupId");
  6961. if (entity.AfterSaleUserId == 0)
  6962. {
  6963. entity.AfterSaleUserId = CurrentUser.UserID;
  6964. }
  6965. entity.ResponsibleUserId = resIdStr;
  6966. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6967. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6968. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6969. {
  6970. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6971. int backNum = 0;
  6972. if (number != null)
  6973. {
  6974. backNum = number.BackNum;
  6975. }
  6976. char[] separator = { ',' };
  6977. string[] sArray = resIdStr.Split(separator);
  6978. string[] refundFreeList = { };
  6979. if (refundFees.Length > 0)
  6980. {
  6981. refundFreeList = refundFees.Split(separator);
  6982. }
  6983. int index = -1;
  6984. List<int> responsibleIds = new List<int>();
  6985. foreach (string i in sArray)
  6986. {
  6987. index++;
  6988. if (i.Length <= 0) continue;
  6989. char[] separator2 = { '_' };
  6990. string idstr = i.Split(separator2)[0];
  6991. string idtype = i.Split(separator2)[1];
  6992. double refudFree = 0;
  6993. if (refundFreeList.Length > 0)
  6994. {
  6995. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6996. }
  6997. if (idtype == "s")
  6998. {
  6999. isDesign = true;
  7000. designFree = refudFree;
  7001. }
  7002. int userId = Convert.ToInt32(idstr);
  7003. int type = 0;
  7004. if (idtype == "g")
  7005. {
  7006. type = 1;
  7007. }
  7008. if (idtype == "w")
  7009. {
  7010. type = 2;
  7011. }
  7012. if (idtype == "t")
  7013. {
  7014. type = 3;
  7015. }
  7016. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  7017. if (ceErpTradeResponsible == null)
  7018. {
  7019. ceErpTradeResponsible = new CeErpTradeResponsible();
  7020. ceErpTradeResponsible.tid = eid;
  7021. ceErpTradeResponsible.UserId = userId;
  7022. ceErpTradeResponsible.createdTime = DateTime.Now;
  7023. ceErpTradeResponsible.type = type;
  7024. if (type == 1)
  7025. {
  7026. ceErpTradeResponsible.IsSup = 1;
  7027. }
  7028. if (type == 2)
  7029. {
  7030. ceErpTradeResponsible.IsFlow = 1;
  7031. }
  7032. }
  7033. int state = 0;
  7034. //已认可的不需要再次认可
  7035. if (sArray.Length > 1 && ceErpTradeResponsible.VerifyState == 1)
  7036. {
  7037. state = 1;
  7038. }
  7039. ceErpTradeResponsible.RefundFee = refudFree;
  7040. ceErpTradeResponsible.VerifyState = state;
  7041. if (userId == 2125 || idtype == "w")
  7042. {
  7043. ceErpTradeResponsible.VerifyState = 1;
  7044. }
  7045. if (idtype == "w" && userId == 101)
  7046. {
  7047. ceErpTradeResponsible.VerifyState = state;
  7048. }
  7049. if (ceErpTradeResponsible.ID > 0)
  7050. {
  7051. ceErpTradeResponsible.Update();
  7052. }
  7053. else
  7054. {
  7055. ceErpTradeResponsible.Create();
  7056. }
  7057. if (isDesign)
  7058. {
  7059. responsibleId = ceErpTradeResponsible.ID;
  7060. }
  7061. responsibleIds.Add(ceErpTradeResponsible.ID);
  7062. }
  7063. CeErpTradeResponsible.ExecuteNonQuery(string.Format("update CE_ErpTradeResponsible set VerifyState =-1 where tid='" + eid + "' and ID NOT IN (" + string.Join(",", responsibleIds) + ")"));
  7064. CeErpTradeResponsible.NumByTid(backNum, eid);
  7065. }
  7066. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  7067. if (ceErpTradeCellExtend != null)
  7068. {
  7069. ceErpTradeCellExtend.returnVisit = 0;
  7070. ceErpTradeCellExtend.Update();
  7071. }
  7072. if (entity.HandleTime != null)
  7073. {
  7074. if (entity.AfterSaleState == 1)
  7075. {
  7076. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  7077. }
  7078. else
  7079. {
  7080. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  7081. }
  7082. }
  7083. else
  7084. {
  7085. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  7086. entity.HandleTime = DateTime.Now;
  7087. }
  7088. bool isCompale = false;
  7089. if (entity.AfterSaleState == 5)
  7090. {
  7091. isCompale = true;
  7092. entity.AfterSaleState = 3;
  7093. }
  7094. entity.AfterSaleSupplierState = 0;
  7095. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  7096. {
  7097. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  7098. }
  7099. string sImgs = GetPostString("img");
  7100. entity.AfterSaleSupplierImg = sImgs;
  7101. entity.supRefundType = GetPostString("supRefundType");
  7102. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  7103. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  7104. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  7105. entity.AfterSaleMemoType = GetPostString("MemoType");
  7106. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  7107. {
  7108. //entity.AfterSaleSupplierState = 2;
  7109. }
  7110. string df = GetPostString("DeductFee");
  7111. if (df == "")
  7112. {
  7113. df = "0";
  7114. }
  7115. string rf = GetPostString("RefundFee");
  7116. if (rf == "")
  7117. {
  7118. rf = "0";
  7119. }
  7120. string pm = GetPostString("AfterSalePayment");
  7121. if (pm == "")
  7122. {
  7123. pm = "0";
  7124. }
  7125. entity.AfterSalePayment = Convert.ToDouble(pm);
  7126. entity.DeductFee = Convert.ToDouble(df);
  7127. entity.RefundFee = Convert.ToDouble(rf);
  7128. entity.UpdateTime = DateTime.Now;
  7129. entity.Update();
  7130. string toState = GetPostString("ToState");
  7131. string original = GetPostString("isOriginal");
  7132. ApiVo apiVo = new ApiVo();
  7133. apiVo.orderNumber = entity.ctid;
  7134. apiVo.actionName = "afterDesign";
  7135. apiVo.orderRemarks = entity.AfterSaleMethod;
  7136. apiVo.reasonRemarks = entity.AfterSaleReason;
  7137. apiVo.isDesign = isDesign;
  7138. apiVo.designFree = designFree;
  7139. apiVo.responsibleId = responsibleId;
  7140. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  7141. if (toState == "设计师")
  7142. {
  7143. apiVo.isOriginal = Convert.ToBoolean(original);
  7144. }
  7145. designHelper.API_WorkCore(apiVo);//afterDesign
  7146. CeErpMethod methodSql = new CeErpMethod();
  7147. methodSql.con = entity.AfterSaleMethod;
  7148. methodSql.addTime = DateTime.Now;
  7149. methodSql.Create();
  7150. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  7151. CeErpMethod.ExecuteNonQuery(delsql);
  7152. if (isCompale)
  7153. {
  7154. aftersale_data_change(entity.ctid);
  7155. }
  7156. returnSuccessMsg("操作成功!");
  7157. return;
  7158. }
  7159. returnErrorMsg("找不到订单记录");
  7160. }
  7161. }
  7162. public void ins_erp_toresponsible()
  7163. {
  7164. if (UrlPostParmsCheck("ctid"))
  7165. {
  7166. string eid = GetPostString("ctid");
  7167. CeErpTradeCell entity = null;
  7168. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7169. if (entity != null)
  7170. {
  7171. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7172. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7173. {
  7174. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7175. return;
  7176. }
  7177. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7178. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7179. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7180. if (entity.AfterSalePreTime == null)
  7181. {
  7182. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7183. {
  7184. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7185. }
  7186. }
  7187. entity.AfterSalePreTime = DateTime.Now;
  7188. //预完成给售后主管审核客户问题直接完成
  7189. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7190. {
  7191. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7192. {
  7193. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7194. }
  7195. }
  7196. ceErpTradeAfterSaleExtend.Update();
  7197. entity.AfterSaleState = 2;
  7198. entity.UpdateTime = DateTime.Now;
  7199. entity.Update();
  7200. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7201. aftersale_data_change(entity.ctid);
  7202. returnSuccessMsg("操作成功!");
  7203. return;
  7204. }
  7205. returnErrorMsg("找不到订单记录");
  7206. }
  7207. }
  7208. public void cancel_erp_aftersaleanddelnew()
  7209. {
  7210. if (UrlPostParmsCheck("ctid"))
  7211. {
  7212. string eid = GetPostString("ctid");
  7213. CeErpTradeCell entity = null;
  7214. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7215. if (entity != null)
  7216. {
  7217. entity.AfterSaleState = 0;
  7218. entity.AfterSaleReason = "";
  7219. entity.AfterSaleMethod = "";
  7220. entity.AfterSaleMemo = "";
  7221. entity.AfterSaleResponsible = "";
  7222. entity.ResponsibleUserId = "";
  7223. entity.DeductFee = 0;
  7224. entity.RefundFee = 0;
  7225. entity.IsArbitrate = 0;
  7226. CeErpTradeResponsible.DelByTid(eid, -1);
  7227. entity.Update();
  7228. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7229. if (after != null)
  7230. {
  7231. if (after.OrderState < 5)
  7232. CeErpTradeCell.DelByCtid("S_" + eid);
  7233. }
  7234. returnSuccessMsg("操作成功!");
  7235. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7236. return;
  7237. }
  7238. returnErrorMsg("找不到订单记录");
  7239. }
  7240. }
  7241. public void get_erp_aftersale_pregather()
  7242. {
  7243. List<string> lw = new List<string>();
  7244. int st = GetInt("st");
  7245. string tid = GetPostString("ctid");
  7246. if (tid.Length > 0)
  7247. {
  7248. string select_tid = getTidByCtid(tid);
  7249. lw.Add(string.Format("tid='{0}'", select_tid));
  7250. }
  7251. string shopname = GetPostString("shopname");
  7252. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7253. string buyernick = GetPostString("buyer_nick");
  7254. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7255. string sellermemo = GetPostString("seller_memo");
  7256. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7257. string orderState = GetPostString("orderState");
  7258. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7259. string reason = GetPostString("reason");
  7260. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7261. string method = GetPostString("method");
  7262. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7263. string handler = GetPostString("handler");
  7264. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7265. string handledate1 = GetPostString("handledate1");
  7266. string handledate2 = GetPostString("handledate2");
  7267. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7268. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7269. string supplier = GetPostString("supplier");
  7270. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7271. string responsible = GetPostString("responsibleman");
  7272. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7273. string customer = GetPostString("customer");
  7274. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7275. string design = GetPostString("design");
  7276. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7277. string afterMemoType = GetPostString("aftermemotype");
  7278. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7279. string afterSaleMemo = GetPostString("afterSaleMemo");
  7280. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7281. string afterresult = GetPostString("afterresult");
  7282. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7283. string poscode = CurrentUser.UserPost.Post.Code;
  7284. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7285. {
  7286. string shopid = CurrentUser.User.pemShop;
  7287. lw.Add(string.Format("shopId in ({0})", shopid));
  7288. }
  7289. var mainwhere = string.Join(" and ", lw.ToArray());
  7290. string ro_json = "";
  7291. string type = GetPostString("gather_type");
  7292. int number = 0;
  7293. if (poscode == "AfterSale")
  7294. {
  7295. //处理中
  7296. if (type == "Handling")
  7297. {
  7298. 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) : ""));
  7299. DataTable dt = null;
  7300. try
  7301. {
  7302. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7303. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7304. }
  7305. catch (Exception e)
  7306. {
  7307. dt = new DataTable();
  7308. }
  7309. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7310. return;
  7311. }
  7312. if (type == "Wait")
  7313. {
  7314. //待处理
  7315. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7316. DataTable dt1 = null;
  7317. try
  7318. {
  7319. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7320. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7321. }
  7322. catch (Exception e)
  7323. {
  7324. dt1 = new DataTable();
  7325. }
  7326. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7327. return;
  7328. }
  7329. if (type == "back")
  7330. {
  7331. //打回
  7332. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7333. DataTable dt2 = null;
  7334. try
  7335. {
  7336. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7337. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7338. }
  7339. catch (Exception e)
  7340. {
  7341. dt2 = new DataTable();
  7342. }
  7343. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7344. return;
  7345. }
  7346. if (type == "preCompletion")
  7347. {
  7348. //预完成
  7349. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7350. DataTable dt3 = null;
  7351. try
  7352. {
  7353. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7354. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7355. }
  7356. catch (Exception e)
  7357. {
  7358. dt3 = new DataTable();
  7359. }
  7360. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7361. return;
  7362. }
  7363. if (type == "documentary")
  7364. {
  7365. //跟单中
  7366. 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) : ""));
  7367. DataTable dt4 = null;
  7368. try
  7369. {
  7370. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7371. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7372. }
  7373. catch (Exception e)
  7374. {
  7375. dt4 = new DataTable();
  7376. }
  7377. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7378. return;
  7379. }
  7380. if (type == "reBack")
  7381. {
  7382. //被打回
  7383. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7384. DataTable dt1 = null;
  7385. try
  7386. {
  7387. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7388. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7389. }
  7390. catch (Exception e)
  7391. {
  7392. dt1 = new DataTable();
  7393. }
  7394. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7395. return;
  7396. }
  7397. }
  7398. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7399. {
  7400. if (type == "puBack")
  7401. {
  7402. //退回
  7403. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7404. DataTable dt = null;
  7405. try
  7406. {
  7407. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7408. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7409. }
  7410. catch (Exception e)
  7411. {
  7412. dt = new DataTable();
  7413. }
  7414. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7415. return;
  7416. }
  7417. if (type == "reBack")
  7418. {
  7419. //打回
  7420. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7421. DataTable dt1 = null;
  7422. try
  7423. {
  7424. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7425. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7426. }
  7427. catch (Exception e)
  7428. {
  7429. dt1 = new DataTable();
  7430. }
  7431. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7432. return;
  7433. }
  7434. if (type == "examEd")
  7435. {
  7436. //已审核
  7437. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7438. DataTable dt2 = null;
  7439. try
  7440. {
  7441. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7442. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7443. }
  7444. catch (Exception e)
  7445. {
  7446. dt2 = new DataTable();
  7447. }
  7448. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7449. return;
  7450. }
  7451. if (type == "waitExam")
  7452. {
  7453. //待审核
  7454. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7455. DataTable dt3 = null;
  7456. try
  7457. {
  7458. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7459. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7460. }
  7461. catch (Exception e)
  7462. {
  7463. dt3 = new DataTable();
  7464. }
  7465. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7466. return;
  7467. }
  7468. if (type == "Handling")
  7469. {
  7470. //处理中
  7471. 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) : ""));
  7472. DataTable dt4 = null;
  7473. try
  7474. {
  7475. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7476. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7477. }
  7478. catch (Exception e)
  7479. {
  7480. dt4 = new DataTable();
  7481. }
  7482. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7483. return;
  7484. }
  7485. if (type == "Wait")
  7486. {
  7487. //待处理
  7488. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7489. DataTable dt5 = null;
  7490. try
  7491. {
  7492. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7493. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7494. }
  7495. catch (Exception e)
  7496. {
  7497. dt5 = new DataTable();
  7498. }
  7499. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7500. return;
  7501. }
  7502. if (type == "documentary")
  7503. {
  7504. //跟单中
  7505. 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) : ""));
  7506. DataTable dt6 = null;
  7507. try
  7508. {
  7509. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7510. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7511. }
  7512. catch (Exception e)
  7513. {
  7514. dt6 = new DataTable();
  7515. }
  7516. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7517. return;
  7518. }
  7519. }
  7520. returnSuccess(ro_json);
  7521. }
  7522. public void end_erp_aftersale()
  7523. {
  7524. if (UrlPostParmsCheck("ctid"))
  7525. {
  7526. string eid = GetPostString("ctid");
  7527. CeErpTradeCell entity = null;
  7528. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7529. if (entity != null)
  7530. {
  7531. string stype = GetPostString("stype");
  7532. string typeStr = stype;
  7533. entity.AfterSaleState = 4;
  7534. entity.FinishAfterSaleTime = DateTime.Now;
  7535. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7536. entity.Update();
  7537. ApiVo apiVo = new ApiVo();
  7538. apiVo.orderNumber = entity.ctid;
  7539. apiVo.actionName = "afterOver";
  7540. designHelper.API_WorkCore(apiVo); //afterOver
  7541. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7542. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7543. CeErpSukuraData.createInfo(entity.ctid, 8);
  7544. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7545. returnSuccessMsg("操作成功!");
  7546. return;
  7547. }
  7548. returnErrorMsg("找不到订单记录");
  7549. }
  7550. }
  7551. public void ins_erp_finishaftersale()
  7552. {
  7553. if (UrlPostParmsCheck("id"))
  7554. {
  7555. string eid = GetPostString("id");
  7556. CeErpTradeResponsible entity = null;
  7557. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7558. if (entity != null)
  7559. {
  7560. entity.VerifyState = 1;
  7561. entity.VerifyTime = DateTime.Now;
  7562. entity.Update();
  7563. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7564. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7565. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7566. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7567. if (dt.Rows.Count <= 0)
  7568. {
  7569. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7570. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7571. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7572. CeErpSukuraData.createInfo(entity.tid, 8);
  7573. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7574. {
  7575. CeErpDesignerBill.Del(entity.tid);
  7576. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7577. }
  7578. }
  7579. returnSuccessMsg("操作成功!");
  7580. return;
  7581. }
  7582. returnErrorMsg("找不到订单记录");
  7583. }
  7584. }
  7585. public void upd_erp_arbitrateaftersale()
  7586. {
  7587. if (UrlPostParmsCheck("id"))
  7588. {
  7589. string eid = GetPostString("id");
  7590. CeErpTradeResponsible entity = null;
  7591. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7592. if (entity != null)
  7593. {
  7594. entity.IsArbitrate = 1;
  7595. entity.ArbitradeMemo = GetPostString("reason");
  7596. entity.VerifyState = 2;
  7597. entity.Update();
  7598. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7599. if (tradecell != null)
  7600. {
  7601. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7602. tradecell.IsArbitrate = 1;
  7603. tradecell.Update();
  7604. }
  7605. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7606. returnSuccessMsg("操作成功!");
  7607. return;
  7608. }
  7609. returnErrorMsg("找不到订单记录");
  7610. }
  7611. }
  7612. public void upd_erp_backaftersale()
  7613. {
  7614. if (UrlPostParmsCheck("tid"))
  7615. {
  7616. string eid = GetPostString("tid");
  7617. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7618. int backNum = 0;
  7619. if (number != null)
  7620. {
  7621. backNum = number.BackNum;
  7622. }
  7623. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7624. CeErpTradeCell entity = null;
  7625. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7626. if (entity != null)
  7627. {
  7628. entity.AfterSaleBackReason = GetPostString("backreason");
  7629. entity.AfterSaleState = 1;
  7630. entity.AfterSaleSupplierState = 0;
  7631. entity.UpdateTime = DateTime.Now;
  7632. entity.Update();
  7633. returnSuccessMsg("操作成功!");
  7634. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7635. return;
  7636. }
  7637. returnErrorMsg("找不到订单记录");
  7638. }
  7639. }
  7640. public void get_erp_supplieraftersalelist()
  7641. {
  7642. DataStruct dStruct = GetPostStruct();
  7643. List<string> lw = new List<string>();
  7644. string tid = GetPostString("ctid");
  7645. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7646. string shopname = GetPostString("shopname");
  7647. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7648. string buyernick = GetPostString("buyer_nick");
  7649. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7650. string sellermemo = GetPostString("seller_memo");
  7651. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7652. string orderState = GetPostString("orderState");
  7653. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7654. string afterState = GetPostString("afterstate");
  7655. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7656. string date1 = GetPostString("date1");
  7657. string date2 = GetPostString("date2");
  7658. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7659. if (dw.Length > 0) lw.Add(dw);
  7660. string price1 = GetPostString("price1");
  7661. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7662. string price2 = GetPostString("price2");
  7663. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7664. string reason = GetPostString("reason");
  7665. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7666. string method = GetPostString("method");
  7667. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7668. string handledate1 = GetPostString("handledate1");
  7669. string handledate2 = GetPostString("handledate2");
  7670. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7671. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7672. string handler = GetPostString("handler");
  7673. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7674. string afterdate1 = GetPostString("afterdate1");
  7675. string afterdate2 = GetPostString("afterdate2");
  7676. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7677. if (afterDate.Length > 0) lw.Add(afterDate);
  7678. string customer = GetPostString("customer");
  7679. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7680. string design = GetPostString("design");
  7681. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7682. string afterMemoType = GetPostString("aftermemotype");
  7683. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7684. string vstate = GetPostString("vstate");
  7685. if (vstate.Length > 0)
  7686. {
  7687. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7688. }
  7689. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7690. string supplier = GetPostString("supplier");
  7691. int supid = commonHelper.getSupplierIDByName(supplier);
  7692. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7693. string posCode = CurrentUser.UserPost.Post.Code;
  7694. if (posCode == "Supplier")
  7695. {
  7696. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7697. }
  7698. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7699. {
  7700. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7701. }
  7702. else
  7703. {
  7704. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7705. }
  7706. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7707. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7708. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7709. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7710. writeGridDataTableJson(dStruct.TotalCount, dt);
  7711. }
  7712. public void upd_erp_supverifyaftersale()
  7713. {
  7714. if (UrlPostParmsCheck("id"))
  7715. {
  7716. string id = GetPostString("id");
  7717. int st = GetPostInt("afterstate");
  7718. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7719. CeErpTradeCell entity = null;
  7720. if (ceErpTradeResponsible != null)
  7721. {
  7722. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7723. }
  7724. string afmemo = GetPostString("supmemo");
  7725. string image = GetPostString("image");
  7726. if (entity != null)
  7727. {
  7728. entity.AfterSaleSupplierState = st;
  7729. entity.AfterSaleSupplierMemo = afmemo;
  7730. if (st == 1)
  7731. {
  7732. ceErpTradeResponsible.VerifyState = 1;
  7733. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7734. ceErpTradeResponsible.Update();
  7735. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7736. if (isAll)
  7737. {
  7738. entity.AfterSaleState = 4;
  7739. entity.FinishAfterSaleTime = DateTime.Now;
  7740. }
  7741. }
  7742. else
  7743. {
  7744. CeErpTradeResponsible.dateByTid(entity.ctid);
  7745. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7746. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7747. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7748. if (num <= 1)
  7749. {
  7750. entity.AfterSaleState = 1;
  7751. }
  7752. else
  7753. {
  7754. entity.AfterSaleState = 5;
  7755. }
  7756. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7757. if (ceErpTradeAfterSaleExtend != null)
  7758. {
  7759. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7760. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7761. ceErpTradeAfterSaleExtend.Update();
  7762. }
  7763. else
  7764. {
  7765. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7766. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7767. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7768. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7769. ceErpTradeAfterSaleExtend.Create();
  7770. }
  7771. }
  7772. if (entity.AfterSaleState == 4)
  7773. {
  7774. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7775. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7776. {
  7777. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7778. }
  7779. ApiVo apiVo = new ApiVo();
  7780. apiVo.orderNumber = entity.ctid;
  7781. apiVo.actionName = "afterOver";
  7782. designHelper.API_WorkCore(apiVo); //afterOver
  7783. }
  7784. entity.UpdateTime = DateTime.Now;
  7785. entity.Update();
  7786. returnSuccessMsg("操作成功!");
  7787. CeErpSukuraData.createInfo(entity.ctid, 8);
  7788. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7789. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7790. return;
  7791. }
  7792. returnErrorMsg("找不到订单记录");
  7793. }
  7794. }
  7795. public void upd_erp_masteraftersale()
  7796. {
  7797. if (UrlPostParmsCheck("id"))
  7798. {
  7799. string id = GetPostString("id");
  7800. int st = GetPostInt("afterstate");
  7801. string afmemo = GetPostString("supmemo");
  7802. string image = GetPostString("image");
  7803. string textResult = GetPostString("textResult");
  7804. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7805. if (ceErpTradeResponsible != null)
  7806. {
  7807. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7808. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7809. ceErpTradeResponsible.Update();
  7810. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7811. if (entity != null)
  7812. {
  7813. entity.AfterSaleSupplierState = st;
  7814. entity.AfterSaleSupplierMemo = afmemo;
  7815. if (st == 1)
  7816. {
  7817. }
  7818. else
  7819. {
  7820. CeErpTradeResponsible.dateByTid(entity.ctid);
  7821. //退回到售后
  7822. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7823. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7824. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7825. if (num <= 1)
  7826. {
  7827. entity.AfterSaleState = 1;
  7828. }
  7829. else
  7830. {
  7831. entity.AfterSaleState = 5;
  7832. }
  7833. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7834. if (ceErpTradeAfterSaleExtend != null)
  7835. {
  7836. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7837. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7838. ceErpTradeAfterSaleExtend.Update();
  7839. }
  7840. else
  7841. {
  7842. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7843. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7844. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7845. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7846. ceErpTradeAfterSaleExtend.Create();
  7847. }
  7848. }
  7849. entity.UpdateTime = DateTime.Now;
  7850. entity.Update();
  7851. returnSuccessMsg("操作成功!");
  7852. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7853. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7854. return;
  7855. }
  7856. }
  7857. returnErrorMsg("找不到订单记录");
  7858. }
  7859. }
  7860. public void upd_erp_personaftersale()
  7861. {
  7862. if (UrlPostParmsCheck("id"))
  7863. {
  7864. //林小连
  7865. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7866. {
  7867. upd_erp_masteraftersale();
  7868. return;
  7869. }
  7870. string id = GetPostString("id");
  7871. int st = GetPostInt("afterstate");
  7872. string afmemo = GetPostString("supmemo");
  7873. string image = GetPostString("image");
  7874. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7875. if (ceErpTradeResponsible != null)
  7876. {
  7877. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7878. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7879. ceErpTradeResponsible.Update();
  7880. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7881. if (entity != null)
  7882. {
  7883. entity.AfterSaleSupplierMemo = afmemo;
  7884. entity.AfterSaleSupplierState = st;
  7885. if (st == 1)
  7886. {
  7887. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7888. if (isAll)
  7889. {
  7890. entity.AfterSaleState = 4;
  7891. entity.FinishAfterSaleTime = DateTime.Now;
  7892. }
  7893. }
  7894. else
  7895. {
  7896. CeErpTradeResponsible.dateByTid(entity.ctid);
  7897. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7898. if (ceErpTradeAfterSaleExtend != null)
  7899. {
  7900. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7901. ceErpTradeAfterSaleExtend.Update();
  7902. }
  7903. else
  7904. {
  7905. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7906. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7907. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7908. ceErpTradeAfterSaleExtend.Create();
  7909. }
  7910. //退回到主管
  7911. //entity.AfterSaleState = 2;
  7912. }
  7913. if (entity.AfterSaleState == 4)
  7914. {
  7915. ApiVo apiVo = new ApiVo();
  7916. apiVo.orderNumber = entity.ctid;
  7917. apiVo.actionName = "afterOver";
  7918. designHelper.API_WorkCore(apiVo); //afterOver
  7919. }
  7920. entity.UpdateTime = DateTime.Now;
  7921. entity.Update();
  7922. returnSuccessMsg("操作成功!");
  7923. CeErpSukuraData.createInfo(entity.ctid, 8);
  7924. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7925. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7926. return;
  7927. }
  7928. }
  7929. returnErrorMsg("找不到订单记录");
  7930. }
  7931. }
  7932. public void set_erp_supplierrefundtag()
  7933. {
  7934. if (UrlPostParmsCheck("ctid"))
  7935. {
  7936. string eid = GetPostString("ctid");
  7937. CeErpTradeCell entity = null;
  7938. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7939. if (entity != null)
  7940. {
  7941. entity.IsSupplierRefund = GetPostInt("tag");
  7942. entity.Update();
  7943. returnSuccessMsg("操作成功!");
  7944. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7945. return;
  7946. }
  7947. returnErrorMsg("找不到订单记录");
  7948. }
  7949. }
  7950. public void get_erp_refundlist()
  7951. {
  7952. DataStruct dStruct = GetPostStruct();
  7953. List<string> lw = new List<string>();
  7954. string tid = GetPostString("tid");
  7955. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7956. //string rid = GetPostString("refund_id");
  7957. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7958. string shopname = GetPostString("shopname");
  7959. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7960. string buyernick = GetPostString("buyer_nick");
  7961. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7962. string customer = GetPostString("customer");
  7963. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7964. string design = GetPostString("design");
  7965. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7966. string sellermemo = GetPostString("seller_memo");
  7967. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7968. //string date1 = GetPostString("date1");
  7969. //string date2 = GetPostString("date2");
  7970. //string dateType = GetPostString("dateType");
  7971. //if (dateType.Length > 0)
  7972. //{
  7973. // if (dateType == "1001") dateType = "0";
  7974. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7975. // if (searchDT.Count == 2)
  7976. // {
  7977. // date1 = searchDT[0].ToString();
  7978. // date2 = searchDT[1].ToString();
  7979. // }
  7980. //}
  7981. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7982. //if (dw.Length > 0) lw.Add(dw);
  7983. string redate1 = GetPostString("refunddate1");
  7984. string redate2 = GetPostString("refunddate2");
  7985. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7986. if (dwdate.Length > 0) lw.Add(dwdate);
  7987. string price1 = GetPostString("price1");
  7988. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7989. string price2 = GetPostString("price2");
  7990. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7991. string ispartrefund = GetPostString("ispartrefund");
  7992. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7993. string refundState = GetPostString("refundvstate");
  7994. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7995. int st = GetInt("st");
  7996. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7997. {
  7998. string responsible = GetPostString("responsibleman");
  7999. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8000. lw.Add(string.Format("RefundState>={0}", st));
  8001. string code = CurrentUser.UserPost.Post.Code;
  8002. if (code == "CustomerService")
  8003. {
  8004. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  8005. }
  8006. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  8007. {
  8008. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  8009. }
  8010. else if (code == "Place" || code == "PlaceMr")
  8011. {
  8012. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  8013. }
  8014. dStruct.Order = "RefundState asc,created desc";
  8015. }
  8016. else if (st == 10)
  8017. {
  8018. string responsible = GetPostString("responsibleman");
  8019. if (responsible == "空白")
  8020. {
  8021. lw.Add(string.Format("ResponsibleUserName = ''"));
  8022. }
  8023. else if (responsible.Length > 0)
  8024. {
  8025. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8026. }
  8027. lw.Add(string.Format("RefundState>=0"));
  8028. dStruct.Order = "created desc";
  8029. }
  8030. else
  8031. {
  8032. string responsible = GetPostString("responsibleman");
  8033. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8034. lw.Add(string.Format("RefundState={0}", st));
  8035. dStruct.Order = "created desc";
  8036. }
  8037. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8038. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  8039. dt.Columns.Add("refund_fees");
  8040. foreach (DataRow dr in dt.Rows)
  8041. {
  8042. String status = dr["status"].ToString();
  8043. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8044. {
  8045. dr["refund_fees"] = dr["refund_fee"];
  8046. }
  8047. else
  8048. {
  8049. dr["refund_fees"] = "0.0";
  8050. }
  8051. }
  8052. writeGridDataTableJson(dStruct.TotalCount, dt);
  8053. }
  8054. public void get_erp_refunddesignlist()
  8055. {
  8056. DataStruct dStruct = GetPostStruct();
  8057. List<string> lw = new List<string>();
  8058. string tid = GetPostString("tid");
  8059. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8060. string shopname = GetPostString("shopname");
  8061. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8062. string buyernick = GetPostString("buyer_nick");
  8063. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8064. string customer = GetPostString("customer");
  8065. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8066. string design = GetPostString("design");
  8067. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  8068. string sellermemo = GetPostString("seller_memo");
  8069. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  8070. string redate1 = GetPostString("refunddate1");
  8071. string redate2 = GetPostString("refunddate2");
  8072. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  8073. if (dwdate.Length > 0) lw.Add(dwdate);
  8074. string price1 = GetPostString("price1");
  8075. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8076. string price2 = GetPostString("price2");
  8077. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8078. string ispartrefund = GetPostString("ispartrefund");
  8079. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  8080. string designerorg = GetPostString("designerorg");
  8081. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  8082. string refundState = GetPostString("refundState");
  8083. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  8084. int myOrgid = CurrentUser.UserPost.OrgID;
  8085. string myOrgCode = CurrentUser.UserPost.Post.Code;
  8086. if ("Designer".Equals(myOrgCode))//设计师能看到的
  8087. {
  8088. if (CurrentUser.User.TeamIds.Length > 0)
  8089. {
  8090. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  8091. }
  8092. else
  8093. {
  8094. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  8095. }
  8096. }
  8097. else if ("SysAdmin".Equals(myOrgCode))
  8098. {
  8099. }
  8100. else
  8101. {
  8102. if (CurrentUser.User.ManageOrgIds.Length > 0)
  8103. {
  8104. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  8105. }
  8106. else
  8107. {
  8108. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  8109. }
  8110. }
  8111. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  8112. dStruct.Order = "created desc";
  8113. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8114. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  8115. dt.Columns.Add("refund_fees");
  8116. foreach (DataRow dr in dt.Rows)
  8117. {
  8118. String status = dr["status"].ToString();
  8119. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8120. {
  8121. dr["refund_fees"] = dr["refund_fee"];
  8122. }
  8123. else
  8124. {
  8125. dr["refund_fees"] = "0.0";
  8126. }
  8127. }
  8128. writeGridDataTableJson(dStruct.TotalCount, dt);
  8129. }
  8130. public void handle_erp_refundtag()
  8131. {
  8132. if (UrlPostParmsCheck("refund_id"))
  8133. {
  8134. string eid = GetPostString("refund_id");
  8135. string respMan = GetPostString("ResponsibleName");
  8136. if (respMan.Length <= 0)
  8137. {
  8138. returnErrorMsg("责任人不能为空");
  8139. return;
  8140. }
  8141. CeErpTradeRefund entity = null;
  8142. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8143. if (entity != null)
  8144. {
  8145. entity.ResponsibleUserName = respMan;
  8146. string userid = GetPostString("ResponsibleUserId");
  8147. if (userid.Length > 0)
  8148. {
  8149. entity.ResponsibleUserId = userid;
  8150. }
  8151. entity.Memo = GetPostString("Memo");
  8152. if (respMan.IndexOf("客服") != -1 ||
  8153. respMan.IndexOf("设计师") != -1 ||
  8154. respMan.IndexOf("下单员") != -1)
  8155. {
  8156. entity.RefundState = 2;
  8157. }
  8158. else
  8159. {
  8160. entity.RefundState = 3;
  8161. }
  8162. entity.modified = DateTime.Now;
  8163. entity.Update();
  8164. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  8165. returnSuccessMsg("操作成功!");
  8166. return;
  8167. }
  8168. returnErrorMsg("找不到订单记录");
  8169. }
  8170. }
  8171. public void handle_erp_designrefundtag()
  8172. {
  8173. if (UrlPostParmsCheck("refund_id"))
  8174. {
  8175. string eid = GetPostString("refund_id");
  8176. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8177. if (ceErpTradeCellExtend == null)
  8178. {
  8179. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8180. ceErpTradeCellExtend.ctid = eid;
  8181. }
  8182. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8183. if (ceErpTradeCellExtend.ID > 0)
  8184. {
  8185. ceErpTradeCellExtend.Update();
  8186. }
  8187. else
  8188. {
  8189. ceErpTradeCellExtend.Create();
  8190. }
  8191. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8192. returnSuccessMsg("操作成功!");
  8193. return;
  8194. }
  8195. returnErrorMsg("找不到订单记录");
  8196. }
  8197. public void upd_erp_refundverify()
  8198. {
  8199. if (UrlPostParmsCheck("refund_id"))
  8200. {
  8201. string eid = GetPostString("refund_id");
  8202. CeErpTradeRefund entity = null;
  8203. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8204. if (entity != null)
  8205. {
  8206. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8207. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8208. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8209. {
  8210. entity.RefundState = 2;
  8211. }
  8212. else
  8213. {
  8214. entity.RefundState = 3;
  8215. }
  8216. entity.Update();
  8217. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8218. returnSuccessMsg("操作成功!");
  8219. return;
  8220. }
  8221. returnErrorMsg("找不到订单记录");
  8222. }
  8223. }
  8224. public void upd_erp_refundapprove()
  8225. {
  8226. if (UrlPostParmsCheck("refund_id"))
  8227. {
  8228. string eid = GetPostString("refund_id");
  8229. CeErpTradeRefund entity = null;
  8230. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8231. if (entity != null)
  8232. {
  8233. int apr = GetPostInt("approve");
  8234. if (apr == 0)
  8235. {
  8236. entity.RefundState = 1;
  8237. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8238. }
  8239. else if (apr == 1)
  8240. {
  8241. entity.RefundState = 3;
  8242. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8243. }
  8244. entity.modified = DateTime.Now;
  8245. entity.Update();
  8246. returnSuccessMsg("操作成功!");
  8247. return;
  8248. }
  8249. returnErrorMsg("找不到订单记录");
  8250. }
  8251. }
  8252. public void get_erp_billlist()
  8253. {
  8254. DataStruct dStruct = GetPostStruct();
  8255. List<string> lw = new List<string>();
  8256. string title = GetPostString("title");
  8257. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8258. string tid = GetPostString("tid");
  8259. string tids = GetPostString("tids");
  8260. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8261. if (tids.Length > 0)
  8262. {
  8263. tids = "'" + tids + "'";
  8264. tids = tids.Replace(",", "','");
  8265. lw.Add(string.Format("tid in ({0})", tids));
  8266. }
  8267. string shopname = GetPostString("shopname");
  8268. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8269. string buyernick = GetPostString("buyer_nick");
  8270. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8271. string customer = GetPostString("customer");
  8272. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8273. string date1 = GetPostString("date1");
  8274. string date2 = GetPostString("date2");
  8275. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8276. if (dw.Length > 0) lw.Add(dw);
  8277. string price1 = GetPostString("price1");
  8278. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8279. string price2 = GetPostString("price2");
  8280. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8281. string returndate1 = GetPostString("returndate1");
  8282. string returndate2 = GetPostString("returndate2");
  8283. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8284. if (dw1.Length > 0) lw.Add(dw1);
  8285. string billtype = GetPostString("billtype");
  8286. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8287. string billstate = GetPostString("billstate");
  8288. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8289. string usershop = CurrentUser.User.pemShop;
  8290. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8291. dStruct.Order = "createTime desc";
  8292. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8293. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8294. //foreach (DataRow dr in dt.Rows)
  8295. //{
  8296. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8297. //}
  8298. writeGridDataTableJson(dStruct.TotalCount, dt);
  8299. }
  8300. public void modify_erp_billinfo()
  8301. {
  8302. if (UrlPostParmsCheck("ID"))
  8303. {
  8304. string eid = GetPostString("ID");
  8305. CeErpBill bill_entity = null;
  8306. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8307. if (bill_entity != null)
  8308. {
  8309. bill_entity.tid = GetPostString("tid");
  8310. bill_entity.title = GetPostString("title");
  8311. bill_entity.tax = GetPostString("tax");
  8312. bill_entity.bank = GetPostString("bank");
  8313. bill_entity.bankac = GetPostString("bankac");
  8314. bill_entity.address = GetPostString("address");
  8315. bill_entity.phone = GetPostString("phone");
  8316. bill_entity.price = GetPostString("price");
  8317. bill_entity.productId = GetPostInt("ProductName");
  8318. bill_entity.num = GetPostInt("num");
  8319. bill_entity.unit = GetPostString("unit");
  8320. bill_entity.type = GetPostString("type");
  8321. bill_entity.sendType = GetPostString("SendType");
  8322. bill_entity.email = GetPostString("email");
  8323. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8324. bill_entity.shopName = GetPostString("ShopName");
  8325. bill_entity.applymemo = GetPostString("applymemo");
  8326. bill_entity.modifyTime = DateTime.Now;
  8327. bill_entity.createTime = DateTime.Now;
  8328. bill_entity.state = 0;
  8329. bill_entity.Update();
  8330. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8331. returnSuccessMsg("发票修改成功!");
  8332. return;
  8333. }
  8334. returnErrorMsg("找不到对应记录");
  8335. }
  8336. }
  8337. public void set_erp_invoicing()
  8338. {
  8339. if (UrlPostParmsCheck("id"))
  8340. {
  8341. try
  8342. {
  8343. string eid = GetPostString("id");
  8344. CeErpBill bill_entity = null;
  8345. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8346. if (bill_entity != null)
  8347. {
  8348. int ComId = GetPostInt("ComId");
  8349. //string memo = GetPostString("Memo");
  8350. int allInfo = GetPostInt("allinfo");
  8351. string clert = CurrentUser.User.Name;
  8352. //string detailValue = GetPostString("detailvalue");
  8353. string billId = bill_entity.billOrderId;
  8354. string[] billIdList = billId.Split(',');
  8355. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8356. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8357. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8358. {
  8359. billCount += 1;
  8360. }
  8361. if (billId.Length <= 0 || billIdList.Length != billCount)
  8362. {
  8363. bill_entity.billOrderId = "";
  8364. string prebill = "ltb";
  8365. for (int idx = 1; idx <= billCount; idx++)
  8366. {
  8367. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8368. string billoid = prebill + idx + dtstr;
  8369. bill_entity.billOrderId += billoid;
  8370. if (idx < billCount)
  8371. {
  8372. bill_entity.billOrderId += ",";
  8373. }
  8374. }
  8375. }
  8376. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8377. if (bill_entity.state == 5)
  8378. {
  8379. string errMsg = bill_entity.failerror;
  8380. string[] errlist = errMsg.Split('|');
  8381. string[] errTags = new string[errlist.Length];
  8382. for (int itag = 0; itag < errlist.Length; itag++)
  8383. {
  8384. if (errlist[itag].Length <= 0) continue;
  8385. errTags[itag] = errlist[itag].Split('&')[0];
  8386. }
  8387. for (int iii = 0; iii < errTags.Length; iii++)
  8388. {
  8389. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8390. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8391. if (billOrderList.Length >= erroBillOrderTag)
  8392. {
  8393. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8394. if (needModifyBillId.Length <= 19)
  8395. {
  8396. needModifyBillId = needModifyBillId + "1";
  8397. }
  8398. else
  8399. {
  8400. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8401. last = last + 1;
  8402. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8403. }
  8404. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8405. }
  8406. }
  8407. }
  8408. bool isHaveBillSucces = false;
  8409. string totalRes = "";
  8410. bill_entity.failerror = "";
  8411. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8412. {
  8413. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8414. totalRes += res;
  8415. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8416. {
  8417. isHaveBillSucces = true;
  8418. bill_entity.comId = ComId;
  8419. bill_entity.state = 1;
  8420. bill_entity.executeTime = DateTime.Now;
  8421. bill_entity.executeUser = clert;
  8422. }
  8423. else
  8424. {
  8425. bill_entity.state = 5;
  8426. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8427. }
  8428. }
  8429. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8430. bill_entity.Update();
  8431. if (isHaveBillSucces)
  8432. {
  8433. StringBuilder sql = new StringBuilder();
  8434. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8435. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8436. }
  8437. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8438. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8439. {
  8440. returnErrorMsg("开票失败");
  8441. }
  8442. else
  8443. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8444. return;
  8445. }
  8446. returnErrorMsg("找不到对应记录");
  8447. }
  8448. catch (Exception ex)
  8449. {
  8450. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8451. returnErrorMsg("操作失败");
  8452. }
  8453. }
  8454. }
  8455. public void get_erp_invoicing_back()
  8456. {
  8457. if (UrlPostParmsCheck("id"))
  8458. {
  8459. try
  8460. {
  8461. string id = GetPostString("id");
  8462. CeErpBill entiy = CeErpBill.Get(id);
  8463. if (entiy != null)
  8464. {
  8465. if (entiy.state == 0)
  8466. {
  8467. returnErrorMsg("发票还未开具");
  8468. return;
  8469. }
  8470. string[] billOrderList = entiy.billOrderId.Split(',');
  8471. int iTag = 0;
  8472. entiy.fplsh = "";
  8473. entiy.fpdm = "";
  8474. entiy.fphm = "";
  8475. foreach (string billOrderId in billOrderList)
  8476. {
  8477. iTag++;
  8478. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8479. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8480. {
  8481. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8482. try
  8483. {
  8484. Invoicing_get_response_Obj iObj = null;
  8485. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8486. if (iObj != null)
  8487. {
  8488. entiy.state = 2;
  8489. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8490. entiy.fpdm += iObj.list[0].c_fpdm;
  8491. entiy.fphm += iObj.list[0].c_fphm;
  8492. if (iTag < billOrderList.Length)
  8493. {
  8494. entiy.fplsh += ",";
  8495. entiy.fpdm += ",";
  8496. entiy.fphm += ",";
  8497. }
  8498. entiy.Update();
  8499. }
  8500. StringBuilder sql = new StringBuilder();
  8501. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8502. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8503. returnSuccessMsg("开票成功");
  8504. }
  8505. catch (Exception ex)
  8506. {
  8507. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8508. }
  8509. return;
  8510. }
  8511. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8512. {
  8513. var res_obj = new
  8514. {
  8515. data = "开票中"
  8516. };
  8517. string ro_json = JsonConvert.SerializeObject(res_obj);
  8518. returnSuccess(ro_json);
  8519. return;
  8520. }
  8521. else
  8522. {
  8523. int eidx = res.IndexOf("c_resultmsg");
  8524. int lidx = res.IndexOf("c_status");
  8525. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8526. entiy.state = 5;
  8527. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8528. entiy.Update();
  8529. returnErrorMsg("开票失败");
  8530. return;
  8531. }
  8532. }
  8533. }
  8534. }
  8535. catch (Exception ex)
  8536. {
  8537. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8538. }
  8539. return;
  8540. }
  8541. }
  8542. public void get_erp_invoicing()
  8543. {
  8544. if (UrlPostParmsCheck("id"))
  8545. {
  8546. try
  8547. {
  8548. string id = GetPostString("id");
  8549. CeErpBill entiy = CeErpBill.Get(id);
  8550. if (entiy != null)
  8551. {
  8552. if (entiy.state == 0)
  8553. {
  8554. returnErrorMsg("发票还未开具");
  8555. return;
  8556. }
  8557. if (entiy.sendType == "纸质发票")
  8558. {
  8559. if (entiy.img.Length <= 0)
  8560. {
  8561. returnErrorMsg("查无纸质发票");
  8562. return;
  8563. }
  8564. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8565. returnSuccess(returnres);
  8566. return;
  8567. }
  8568. string[] billOrderList = entiy.billOrderId.Split(',');
  8569. int iTag = 0;
  8570. string fpUrl = "";
  8571. entiy.fplsh = "";
  8572. entiy.fpdm = "";
  8573. entiy.fphm = "";
  8574. foreach (string billOrderId in billOrderList)
  8575. {
  8576. iTag++;
  8577. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8578. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8579. {
  8580. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8581. Invoicing_get_response_Obj iObj = null;
  8582. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8583. if (iObj != null)
  8584. {
  8585. //entiy.state = 2;
  8586. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8587. entiy.fpdm += iObj.list[0].c_fpdm;
  8588. entiy.fphm += iObj.list[0].c_fphm;
  8589. if (iTag < billOrderList.Length)
  8590. {
  8591. entiy.fplsh += ",";
  8592. entiy.fpdm += ",";
  8593. entiy.fphm += ",";
  8594. }
  8595. entiy.Update();
  8596. fpUrl += iObj.list[0].c_url + ",";
  8597. }
  8598. //returnSuccess(res);
  8599. StringBuilder sql = new StringBuilder();
  8600. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8601. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8602. }
  8603. else
  8604. {
  8605. int eidx = res.IndexOf("c_resultmsg");
  8606. //int lidx = res.IndexOf("c_status");
  8607. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8608. //开票失败
  8609. entiy.state = 5;
  8610. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8611. entiy.Update();
  8612. returnErrorMsg("开票失败");
  8613. return;
  8614. }
  8615. }
  8616. var returnObj = new
  8617. {
  8618. data = fpUrl
  8619. };
  8620. string ro_json = JsonConvert.SerializeObject(returnObj);
  8621. returnSuccess(ro_json);
  8622. }
  8623. }
  8624. catch (Exception ex)
  8625. {
  8626. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8627. }
  8628. return;
  8629. }
  8630. }
  8631. public void save_erp_billimg()
  8632. {
  8633. if (UrlPostParmsCheck("id"))
  8634. {
  8635. string eid = GetPostString("id");
  8636. CeErpBill bill_entity = null;
  8637. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8638. if (bill_entity != null)
  8639. {
  8640. bill_entity.img = GetPostString("img");
  8641. bill_entity.executeTime = DateTime.Now;
  8642. bill_entity.state = 2;
  8643. bill_entity.Update();
  8644. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8645. returnSuccessMsg("保存成功");
  8646. }
  8647. return;
  8648. }
  8649. }
  8650. public void upd_erp_billreturnback()
  8651. {
  8652. if (UrlPostParmsCheck("id"))
  8653. {
  8654. int eid = GetPostInt("id");
  8655. CeErpBill bill_entity = null;
  8656. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8657. if (bill_entity != null)
  8658. {
  8659. bill_entity.state = 3;
  8660. bill_entity.returnReason = GetPostString("reason");
  8661. bill_entity.Update();
  8662. returnSuccessMsg("驳回成功!");
  8663. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8664. }
  8665. return;
  8666. }
  8667. }
  8668. public void cancel_erp_bill()
  8669. {
  8670. if (UrlPostParmsCheck("id"))
  8671. {
  8672. int eid = GetPostInt("id");
  8673. int detailValue = GetPostInt("detailvalue");
  8674. CeErpBill bill_entity = null;
  8675. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8676. string cres = "";
  8677. string gres = "";
  8678. if (bill_entity != null)
  8679. {
  8680. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8681. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8682. {
  8683. int iTag = 0;
  8684. bill_entity.fplsh = "";
  8685. bill_entity.fpdm = "";
  8686. bill_entity.fphm = "";
  8687. foreach (string billOrderId in billOrderList)
  8688. {
  8689. iTag++;
  8690. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8691. if (gres.IndexOf("success") != -1)
  8692. {
  8693. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8694. Invoicing_get_response_Obj iObj = null;
  8695. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8696. if (iObj != null)
  8697. {
  8698. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8699. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8700. bill_entity.fphm += iObj.list[0].c_fphm;
  8701. if (iTag < billOrderList.Length)
  8702. {
  8703. bill_entity.fplsh += ",";
  8704. bill_entity.fpdm += ",";
  8705. bill_entity.fphm += ",";
  8706. }
  8707. bill_entity.Update();
  8708. }
  8709. }
  8710. else
  8711. {
  8712. returnErrorMsg(gres);
  8713. return;
  8714. }
  8715. }
  8716. }
  8717. if (bill_entity.sendType == "纸质发票")
  8718. {
  8719. //作废
  8720. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8721. //if (DateTime.Now.Month == extime.Month)
  8722. //{
  8723. //cres = taobaoHelper.cancel_invoicing(eid);
  8724. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8725. //{
  8726. bill_entity.state = 4;//已作废
  8727. bill_entity.Update();
  8728. returnSuccessMsg("发票已作废");
  8729. return;
  8730. //}
  8731. //else
  8732. //{
  8733. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8734. // bill_entity.Update();
  8735. // returnErrorMsg(cres);
  8736. // return;
  8737. //}
  8738. //}
  8739. //else
  8740. //{
  8741. // returnErrorMsg("纸质发票只能作废本月的发票");
  8742. // return;
  8743. //}
  8744. }
  8745. //红冲
  8746. int redTag = 0;
  8747. string[] fpdmList = bill_entity.fpdm.Split(',');
  8748. string[] fphmList = bill_entity.fphm.Split(',');
  8749. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8750. {
  8751. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8752. return;
  8753. }
  8754. foreach (string billOrderId in billOrderList)
  8755. {
  8756. redTag++;
  8757. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8758. cres += onecres;
  8759. cres += ",";
  8760. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8761. {
  8762. bill_entity.state = 4;//已作废
  8763. //bill_entity.Update();
  8764. //returnSuccessMsg("发票已红冲");
  8765. }
  8766. else if (onecres.IndexOf("重复冲红") != -1)
  8767. {
  8768. bill_entity.state = 4;//已作废
  8769. //bill_entity.Update();
  8770. //returnSuccessMsg("发票已红冲");
  8771. }
  8772. else
  8773. {
  8774. string errmsg = commonHelper.KeepChinese(onecres);
  8775. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8776. }
  8777. }
  8778. bill_entity.Update();
  8779. if (cres.IndexOf("失败") != -1)
  8780. returnErrorMsg("红冲失败");
  8781. else
  8782. returnSuccessMsg("发票已红冲");
  8783. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8784. return;
  8785. }
  8786. return;
  8787. }
  8788. }
  8789. public void del_erp_billorder()
  8790. {
  8791. if (UrlPostParmsCheck("id"))
  8792. {
  8793. string eid = GetPostString("id");
  8794. CeErpBill.Del(eid);
  8795. CeErpBill bill = CeErpBill.Get(eid);
  8796. if (bill != null)
  8797. {
  8798. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8799. }
  8800. returnSuccessMsg("删除成功");
  8801. }
  8802. }
  8803. public void finish_erp_bill()
  8804. {
  8805. if (UrlPostParmsCheck("ids"))
  8806. {
  8807. string eids = GetPostString("ids");
  8808. string[] list = eids.Split(',');
  8809. foreach (string eid in list)
  8810. {
  8811. CeErpBill bill = CeErpBill.Get(eid);
  8812. if (bill != null)
  8813. {
  8814. bill.state = 2;
  8815. bill.Update();
  8816. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8817. }
  8818. }
  8819. returnSuccessMsg("操作成功");
  8820. }
  8821. }
  8822. public void get_erp_returncash()
  8823. {
  8824. DataStruct dStruct = GetPostStruct();
  8825. List<string> lw = new List<string>();
  8826. string tid = GetPostString("tid");
  8827. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8828. string shopname = GetPostString("shopname");
  8829. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8830. string buyernick = GetPostString("buyer_nick");
  8831. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8832. string customer = GetPostString("customer");
  8833. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8834. string returndate1 = GetPostString("returndate1");
  8835. string returndate2 = GetPostString("returndate2");
  8836. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8837. if (dw.Length > 0) lw.Add(dw);
  8838. string finishDate1 = GetPostString("finishdate1");
  8839. string finishDate2 = GetPostString("finishdate2");
  8840. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8841. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8842. string returntype = GetPostString("returntype");
  8843. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8844. string returnvstate = GetPostString("returnvstate");
  8845. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8846. dStruct.Order = "created desc";
  8847. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8848. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8849. writeGridDataTableJson(dStruct.TotalCount, dt);
  8850. }
  8851. public void get_erp_staygoods()
  8852. {
  8853. DataStruct dStruct = GetPostStruct();
  8854. List<string> lw = new List<string>();
  8855. string tid = GetPostString("tid");
  8856. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8857. string shopname = GetPostString("shopname");
  8858. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8859. string wangwang = GetPostString("wangwang");
  8860. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8861. string customer = GetPostString("customer");
  8862. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8863. string returndate1 = GetPostString("returndate1");
  8864. string returndate2 = GetPostString("returndate2");
  8865. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8866. if (dw.Length > 0) lw.Add(dw);
  8867. string finishDate1 = GetPostString("finishdate1");
  8868. string finishDate2 = GetPostString("finishdate2");
  8869. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8870. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8871. string returnvstate = GetPostString("returnvstate");
  8872. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8873. string persuadetype = GetPostString("persuadetype");
  8874. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8875. string customerOrg = GetPostString("customerOrg");
  8876. if (customerOrg.Length > 0)
  8877. {
  8878. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8879. }
  8880. string designerorg = GetPostString("designerorg");
  8881. if (designerorg.Length > 0)
  8882. {
  8883. lw.Add(string.Format("OrgID = {0}", designerorg));
  8884. }
  8885. dStruct.Order = "creata_time desc";
  8886. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8887. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8888. writeGridDataTableJson(dStruct.TotalCount, dt);
  8889. }
  8890. public void upd_erp_staygoods()
  8891. {
  8892. if (UrlPostParmsCheck("id"))
  8893. {
  8894. int eid = GetPostInt("id");
  8895. CeErpStayGoods entity = null;
  8896. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8897. if (entity != null)
  8898. {
  8899. entity.audit_type = 1;
  8900. entity.audit_time = DateTime.Now;
  8901. entity.audit_u_id = CurrentUser.UserID;
  8902. entity.audit_u_name = CurrentUser.UserName;
  8903. entity.Update();
  8904. returnSuccessMsg("审核成功!");
  8905. return;
  8906. }
  8907. returnErrorMsg("找不到订单记录");
  8908. }
  8909. }
  8910. public void upd_erp_stayGoodsback()
  8911. {
  8912. if (UrlPostParmsCheck("id"))
  8913. {
  8914. int eid = GetPostInt("id");
  8915. CeErpStayGoods entity = null;
  8916. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8917. if (entity != null)
  8918. {
  8919. entity.audit_text = GetPostString("reason");
  8920. entity.audit_type = 2;
  8921. entity.audit_time = DateTime.Now;
  8922. entity.audit_u_id = CurrentUser.UserID;
  8923. entity.audit_u_name = CurrentUser.UserName;
  8924. entity.Update();
  8925. returnSuccessMsg("退回成功!");
  8926. return;
  8927. }
  8928. returnErrorMsg("找不到订单记录");
  8929. }
  8930. }
  8931. public void upd_erp_returncashverify()
  8932. {
  8933. if (UrlPostParmsCheck("ID"))
  8934. {
  8935. int eid = GetPostInt("ID");
  8936. CeErpReturnCash entity = null;
  8937. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8938. if (entity != null)
  8939. {
  8940. entity.cashstate = 1;
  8941. entity.verifytime = DateTime.Now;
  8942. entity.verifyuserid = CurrentUser.UserID;
  8943. entity.Update();
  8944. returnSuccessMsg("审核成功!");
  8945. return;
  8946. }
  8947. returnErrorMsg("找不到订单记录");
  8948. }
  8949. }
  8950. public void upd_all_erp_returncashverify()
  8951. {
  8952. if (UrlPostParmsCheck("ID"))
  8953. {
  8954. String[] list = GetPostString("ID").Split(',');
  8955. CeErpReturnCash entity = null;
  8956. for (int i = 0; i < list.Length; i++)
  8957. {
  8958. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8959. if (entity != null)
  8960. {
  8961. if (entity.cashstate == 1)
  8962. {
  8963. returnErrorMsg("已审核过的订单不需要在审核!");
  8964. return;
  8965. }
  8966. entity.cashstate = 1;
  8967. entity.verifytime = DateTime.Now;
  8968. entity.verifyuserid = CurrentUser.UserID;
  8969. entity.Update();
  8970. }
  8971. }
  8972. returnSuccessMsg("审核成功!");
  8973. return;
  8974. }
  8975. }
  8976. public void upd_erp_returncashback()
  8977. {
  8978. if (UrlPostParmsCheck("ID"))
  8979. {
  8980. int eid = GetPostInt("ID");
  8981. CeErpReturnCash entity = null;
  8982. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8983. if (entity != null)
  8984. {
  8985. entity.backreason = GetPostString("reason");
  8986. entity.cashstate = 2;
  8987. entity.verifytime = DateTime.Now;
  8988. entity.verifyuserid = CurrentUser.UserID;
  8989. entity.Update();
  8990. returnSuccessMsg("退回成功!");
  8991. return;
  8992. }
  8993. returnErrorMsg("找不到订单记录");
  8994. }
  8995. }
  8996. public void upd_erp_returnprice()
  8997. {
  8998. if (UrlPostParmsCheck("ID"))
  8999. {
  9000. int eid = GetPostInt("ID");
  9001. CeErpReturnCash entity = null;
  9002. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9003. if (entity != null)
  9004. {
  9005. if (entity.cashstate == 1)
  9006. {
  9007. returnErrorMsg("审核通过了不能改");
  9008. return;
  9009. }
  9010. entity.returnprice = GetPostDouble("returnprice");
  9011. entity.Update();
  9012. returnSuccessMsg("修改成功!");
  9013. return;
  9014. }
  9015. returnErrorMsg("找不到订单记录");
  9016. }
  9017. }
  9018. public void del_erp_returncash()
  9019. {
  9020. if (UrlPostParmsCheck("ID"))
  9021. {
  9022. int eid = GetPostInt("ID");
  9023. CeErpReturnCash.Del(eid);
  9024. returnSuccessMsg("操作成功");
  9025. return;
  9026. }
  9027. }
  9028. public void test_for_do_sql()
  9029. {
  9030. string sql = GetPostString("sqlstr");
  9031. if (sql.Length > 0)
  9032. {
  9033. try
  9034. {
  9035. DbHelper.DbConn.ExecuteNonQuery(sql);
  9036. var res_obj = new
  9037. {
  9038. data = "成功",
  9039. };
  9040. string ro_json = JsonConvert.SerializeObject(res_obj);
  9041. returnSuccess(ro_json);
  9042. }
  9043. catch (Exception ex)
  9044. {
  9045. var res_obj = new
  9046. {
  9047. data = ex.Message,
  9048. };
  9049. string ro_json = JsonConvert.SerializeObject(res_obj);
  9050. returnSuccess(ro_json);
  9051. }
  9052. }
  9053. }
  9054. public void get_user_info()
  9055. {
  9056. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  9057. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  9058. }
  9059. public void get_total_data()
  9060. {
  9061. int userId = CurrentUser.UserID;
  9062. string sql = "";
  9063. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9064. {
  9065. 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);
  9066. }
  9067. else
  9068. {
  9069. 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 " +
  9070. "(select ID from CE_ErpUser where ID = {0}) d " +
  9071. "left join " +
  9072. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  9073. ") a on d.ID = a.id left join " +
  9074. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  9075. ") b on a.id = b.id1 left join" +
  9076. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  9077. ") c on a.id = c.id2;", userId);
  9078. }
  9079. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9080. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9081. }
  9082. public void get_date_area_total_data2()
  9083. {
  9084. int userId = CurrentUser.UserID;
  9085. string date_type = GetPostString("timetype");
  9086. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9087. string sql = "";
  9088. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9089. {
  9090. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  9091. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  9092. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9093. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9094. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9095. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  9096. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9097. ") a on e.ID = a.id left join " +
  9098. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  9099. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9100. ") b on a.id = b.id1 " +
  9101. "left join " +
  9102. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9103. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9104. ") c on a.id = c.id2 " +
  9105. "left join " +
  9106. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9107. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9108. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9109. }
  9110. else
  9111. {
  9112. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  9113. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9114. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9115. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9116. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  9117. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  9118. ") a on e.ID = a.id left join " +
  9119. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9120. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  9121. ") c on a.id = c.id2 " +
  9122. "left join " +
  9123. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9124. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9125. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9126. }
  9127. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9128. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9129. }
  9130. public void get_date_area_total_data()
  9131. {
  9132. int userId = CurrentUser.UserID;
  9133. string date_type = GetPostString("timetype");
  9134. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9135. string date1 = searchDT[0].ToString();
  9136. string date2 = searchDT[1].ToString();
  9137. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9138. {
  9139. SqlParameter[] sqlParameter ={
  9140. new SqlParameter("@userId", SqlDbType.Int,4),
  9141. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9142. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9143. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9144. };
  9145. sqlParameter[0].Value = userId;
  9146. sqlParameter[1].Value = date1;
  9147. sqlParameter[2].Value = date2;
  9148. sqlParameter[3].Direction = ParameterDirection.Output;
  9149. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  9150. string res = sqlParameter[3].Value.ToString();
  9151. var res_obj = new
  9152. {
  9153. data = res
  9154. };
  9155. string ro_json = JsonConvert.SerializeObject(res_obj);
  9156. returnSuccess(ro_json);
  9157. }
  9158. else
  9159. {
  9160. SqlParameter[] sqlParameter ={
  9161. new SqlParameter("@userId", SqlDbType.Int,4),
  9162. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9163. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9164. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9165. };
  9166. sqlParameter[0].Value = userId;
  9167. sqlParameter[1].Value = date1;
  9168. sqlParameter[2].Value = date2;
  9169. sqlParameter[3].Direction = ParameterDirection.Output;
  9170. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  9171. string res = sqlParameter[3].Value.ToString();
  9172. var res_obj = new
  9173. {
  9174. data = res
  9175. };
  9176. string ro_json = JsonConvert.SerializeObject(res_obj);
  9177. returnSuccess(ro_json);
  9178. }
  9179. //writeGridDataViewJson(dt.Rows.Count, dv);
  9180. }
  9181. public void get_order_list()
  9182. {
  9183. string strFields = GetPostString("paraFields");
  9184. string strOrder = GetPostString("paraOrder");
  9185. string strWhere = GetPostString("paraWhere");
  9186. string strPageSize = GetPostString("paraPageSize");
  9187. DataStruct dStruct = GetPostStruct();
  9188. dStruct.PageSize = int.Parse(strPageSize);
  9189. dStruct.Fileds = strFields;
  9190. dStruct.Order = strOrder;
  9191. dStruct.MainWhere = strWhere;
  9192. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9193. writeGridDataTableJson(dStruct.TotalCount, dt);
  9194. }
  9195. ////获取待开始订单列表
  9196. //public void get_wait_design_order_list()
  9197. //{
  9198. // string date_type = GetPostString("date_type");
  9199. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9200. // DataStruct dStruct = GetPostStruct();
  9201. // dStruct.PageSize = 1000;
  9202. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9203. // List<string> lw = new List<string>();
  9204. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9205. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9206. // dStruct.Order = "WaitDesignTime asc";
  9207. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9208. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9209. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9210. //}
  9211. //获取完成单量排名
  9212. public void get_finish_order_count_ranking()
  9213. {
  9214. /* string date_type = GetPostString("date_type");
  9215. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9216. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9217. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9218. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9219. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9220. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9221. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9222. writeGridDataTableJson(0, new DataTable());
  9223. }
  9224. public void get_finish_order_amount_ranking()
  9225. {
  9226. /*string date_type = GetPostString("date_type");
  9227. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9228. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9229. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9230. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9231. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9232. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9233. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9234. writeGridDataTableJson(0, new DataTable());
  9235. }
  9236. public void get_finish_refund_count_ranking()
  9237. {
  9238. string date_type = GetPostString("date_type");
  9239. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9240. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9241. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9242. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9243. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9244. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9245. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9246. writeGridDataTableJson(dt.Rows.Count, dt);
  9247. }
  9248. public void get_finish_refund_amount_ranking()
  9249. {
  9250. string date_type = GetPostString("date_type");
  9251. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9252. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9253. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9254. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9255. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9256. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9257. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9258. writeGridDataTableJson(dt.Rows.Count, dt);
  9259. }
  9260. public void set_erp_finishorder_director()
  9261. {
  9262. if (UrlPostParmsCheck("ctid"))
  9263. {
  9264. string eid = GetPostString("ctid");
  9265. CeErpTradeCell entity = null;
  9266. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9267. if (entity != null)
  9268. {
  9269. entity.OrderState = 8;
  9270. entity.Update();
  9271. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9272. returnSuccessMsg("操作成功!");
  9273. return;
  9274. }
  9275. returnErrorMsg("找不到记录");
  9276. }
  9277. }
  9278. public void get_erp_placeregistlist()
  9279. {
  9280. DataStruct dStruct = GetPostStruct();
  9281. List<string> lw = new List<string>();
  9282. string outsid = GetPostString("outsid");
  9283. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9284. string memo = GetPostString("memo");
  9285. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9286. string filename = GetPostString("filename");
  9287. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9288. string islate = GetPostString("islate");
  9289. if (islate.Length > 0)
  9290. {
  9291. if (islate == "1")
  9292. lw.Add(string.Format("OutLate>0"));
  9293. else
  9294. lw.Add(string.Format("OutLate=0"));
  9295. }
  9296. string placedate1 = GetPostString("placedate1");
  9297. string placedate2 = GetPostString("placedate2");
  9298. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9299. if (dw.Length > 0) lw.Add(dw);
  9300. string deliveryDate1 = GetPostString("deliverydate1");
  9301. string deliveryDate2 = GetPostString("deliverydate2");
  9302. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9303. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9304. dStruct.Order = "ID desc";
  9305. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9306. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9307. writeGridDataTableJson(dStruct.TotalCount, dt);
  9308. }
  9309. public void ins_erp_placeregist()
  9310. {
  9311. if (UrlPostParmsCheck("id"))
  9312. {
  9313. string eid = GetPostString("id");
  9314. CeErpPlaceRegister entity = null;
  9315. if (eid == "0")//新增
  9316. {
  9317. entity = new CeErpPlaceRegister();
  9318. string xdTime = GetPostString("placeTime");
  9319. if (xdTime.Length > 0)
  9320. {
  9321. entity.PlactTime = Convert.ToDateTime(xdTime);
  9322. }
  9323. string fhTime = GetPostString("deliveryTime");
  9324. if (fhTime.Length > 0)
  9325. {
  9326. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9327. }
  9328. string preTime = GetPostString("preOutTime");
  9329. if (preTime.Length > 0)
  9330. {
  9331. entity.PreOutTime = Convert.ToDateTime(preTime);
  9332. }
  9333. entity.DeliveryCount = GetPostInt("deliveryCount");
  9334. entity.ReceiveCount = GetPostInt("receiveCount");
  9335. entity.OutSid = GetPostString("outSid");
  9336. entity.FileName = GetPostString("fileName");
  9337. entity.Memo = GetPostString("memo");
  9338. entity.AddUserId = CurrentUser.UserID;
  9339. entity.CreateTime = DateTime.Now;
  9340. entity.Img = GetPostString("img");
  9341. entity.Supplier = GetPostInt("supplier");
  9342. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9343. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9344. {
  9345. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9346. DateTime dt2 = (DateTime)entity.PreOutTime;
  9347. TimeSpan span = dt1.Subtract(dt2);
  9348. if (span.Days > 0)
  9349. {
  9350. entity.OutLate = span.Days;
  9351. }
  9352. }
  9353. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9354. entity.Create();
  9355. returnSuccessMsg("添加成功!");
  9356. return;
  9357. }
  9358. else //修改
  9359. {
  9360. entity = CeErpPlaceRegister.Get(eid);
  9361. if (entity != null)
  9362. {
  9363. string xdTime = GetPostString("placeTime");
  9364. if (xdTime.Length > 0)
  9365. {
  9366. entity.PlactTime = Convert.ToDateTime(xdTime);
  9367. }
  9368. string fhTime = GetPostString("deliveryTime");
  9369. if (fhTime.Length > 0)
  9370. {
  9371. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9372. }
  9373. string preTime = GetPostString("preOutTime");
  9374. if (preTime.Length > 0)
  9375. {
  9376. entity.PreOutTime = Convert.ToDateTime(preTime);
  9377. }
  9378. entity.DeliveryCount = GetPostInt("deliveryCount");
  9379. entity.ReceiveCount = GetPostInt("receiveCount");
  9380. if (entity.DeliveryCount == entity.ReceiveCount)
  9381. {
  9382. entity.CurState = "已完成";
  9383. }
  9384. else
  9385. {
  9386. entity.CurState = "未完成";
  9387. }
  9388. entity.OutSid = GetPostString("outSid");
  9389. entity.FileName = GetPostString("fileName");
  9390. entity.Memo = GetPostString("memo");
  9391. entity.Img = GetPostString("img");
  9392. entity.Supplier = GetPostInt("supplier");
  9393. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9394. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9395. {
  9396. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9397. DateTime dt2 = (DateTime)entity.PreOutTime;
  9398. TimeSpan span = dt1.Subtract(dt2);
  9399. if (span.Days > 0)
  9400. {
  9401. entity.OutLate = span.Days;
  9402. }
  9403. }
  9404. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9405. entity.Update();
  9406. returnSuccessMsg("修改成功");
  9407. return;
  9408. }
  9409. returnErrorMsg("找不到对应的记录");
  9410. return;
  9411. }
  9412. }
  9413. returnErrorMsg("缺少必要参数");
  9414. }
  9415. public void del_erp_placeregist()
  9416. {
  9417. string eid = GetPostString("id");
  9418. CeErpPlaceRegister.Del(eid);
  9419. returnSuccessMsg("删除成功!");
  9420. return;
  9421. }
  9422. public void ins_erp_placeregistbyorder()
  9423. {
  9424. string ctid = GetPostString("ctid");
  9425. if (ctid.Length > 0)
  9426. {
  9427. StringBuilder sql = new StringBuilder();
  9428. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9429. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9430. if (dt.Rows.Count > 0)
  9431. {
  9432. foreach (DataRow dr in dt.Rows)
  9433. {
  9434. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9435. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9436. entity.AddUserId = CurrentUser.UserID;
  9437. entity.tid = dr["tid"].ToString();
  9438. entity.Did = Convert.ToString(dr["ctid"]);
  9439. entity.splitTag = dr["SplitTag"].ToString();
  9440. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9441. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9442. if (pre_ctid.Length > 0)
  9443. {
  9444. sellmemo = sellmemo.Replace(pre_ctid, "");
  9445. }
  9446. sellmemo = sellmemo.Replace("[", "");
  9447. sellmemo = sellmemo.Replace("]", "");
  9448. entity.FileName = sellmemo;
  9449. string count = dr["ProductCount"].ToString();
  9450. int usecount = commonHelper.getIntCountFromString(count);
  9451. entity.DeliveryCount = usecount;
  9452. entity.CurState = "未完成";
  9453. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9454. {
  9455. entity.Supplier = 24;//dl手提袋定制
  9456. }
  9457. else
  9458. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9459. entity.CreateTime = DateTime.Now;
  9460. entity.Create();
  9461. }
  9462. returnSuccessMsg("操作成功");
  9463. return;
  9464. }
  9465. returnErrorMsg("没有找到对应订单");
  9466. return;
  9467. }
  9468. returnErrorMsg("缺少订单编号");
  9469. return;
  9470. }
  9471. public void get_erp_persuadelist()
  9472. {
  9473. DataStruct dStruct = GetPostStruct();
  9474. List<string> lw = new List<string>();
  9475. string ctid = GetPostString("ctid");
  9476. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9477. string shopname = GetPostString("shopname");
  9478. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9479. string buyernick = GetPostString("buyer_nick");
  9480. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9481. string customer = GetPostString("customer");
  9482. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9483. string returndate1 = GetPostString("returndate1");
  9484. string returndate2 = GetPostString("returndate2");
  9485. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9486. if (dw.Length > 0) lw.Add(dw);
  9487. string finishDate1 = GetPostString("finishdate1");
  9488. string finishDate2 = GetPostString("finishdate2");
  9489. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9490. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9491. string persuadetype = GetPostString("persuadetype");
  9492. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9493. string returnvstate = GetPostString("returnvstate");
  9494. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9495. dStruct.Order = "created desc";
  9496. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9497. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9498. writeGridDataTableJson(dStruct.TotalCount, dt);
  9499. }
  9500. public void upd_erp_returnpersuadeback()
  9501. {
  9502. if (UrlPostParmsCheck("ID"))
  9503. {
  9504. int eid = GetPostInt("ID");
  9505. CeErpPersuade entity = null;
  9506. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9507. if (entity != null)
  9508. {
  9509. entity.backreason = GetPostString("reason");
  9510. entity.pstate = 2;
  9511. entity.verifytime = DateTime.Now;
  9512. entity.verifyuserid = CurrentUser.UserID;
  9513. entity.Update();
  9514. returnSuccessMsg("退回成功!");
  9515. return;
  9516. }
  9517. returnErrorMsg("找不到订单记录");
  9518. }
  9519. }
  9520. public void upd_erp_returnpersuadeverify()
  9521. {
  9522. if (UrlPostParmsCheck("ID"))
  9523. {
  9524. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9525. {
  9526. returnErrorMsg("暂无权限审核");
  9527. return;
  9528. }
  9529. int eid = GetPostInt("ID");
  9530. CeErpPersuade entity = null;
  9531. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9532. if (entity != null)
  9533. {
  9534. entity.pstate = 1;
  9535. entity.verifytime = DateTime.Now;
  9536. entity.verifyuserid = CurrentUser.UserID;
  9537. entity.Update();
  9538. returnSuccessMsg("审核成功!");
  9539. return;
  9540. }
  9541. returnErrorMsg("找不到订单记录");
  9542. }
  9543. }
  9544. public void del_erp_persuade()
  9545. {
  9546. if (UrlPostParmsCheck("ID"))
  9547. {
  9548. int eid = GetPostInt("ID");
  9549. CeErpPersuade.Del(eid);
  9550. returnSuccessMsg("操作成功");
  9551. return;
  9552. }
  9553. }
  9554. public void get_erp_oldcustoupload()
  9555. {
  9556. DataStruct dStruct = GetPostStruct();
  9557. List<string> lw = new List<string>();
  9558. string buyernick = GetPostString("buyer_nick");
  9559. if (buyernick.Length > 0)
  9560. {
  9561. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9562. }
  9563. else
  9564. return;
  9565. dStruct.Order = "pay_time desc";
  9566. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9567. DataTable dt = null;
  9568. dt = WebCache.GetData("view_erptradecell", dStruct);
  9569. writeGridDataTableJson(dStruct.TotalCount, dt);
  9570. }
  9571. public void get_erp_checkorderlist()
  9572. {
  9573. DataStruct dStruct = GetPostStruct();
  9574. List<string> lw = new List<string>();
  9575. string tid = GetPostString("ctid");
  9576. if (tid.Length > 0)
  9577. {
  9578. string select_tid = getTidByCtid(tid);
  9579. lw.Add(string.Format("tid='{0}'", select_tid));
  9580. }
  9581. string shopname = GetPostString("shopname");
  9582. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9583. string buyernick = GetPostString("buyer_nick");
  9584. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9585. string customer = GetPostString("customer");
  9586. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9587. string design = GetPostString("design");
  9588. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9589. string orderState = GetPostString("orderState");
  9590. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9591. string address = GetPostString("address");
  9592. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9593. string sellermemo = GetPostString("seller_memo");
  9594. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9595. string supplier = GetPostString("supplier");
  9596. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9597. {
  9598. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9599. }
  9600. else
  9601. {
  9602. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9603. }
  9604. string date1 = GetPostString("date1");
  9605. string date2 = GetPostString("date2");
  9606. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9607. if (dw.Length > 0) lw.Add(dw);
  9608. string placedate1 = GetPostString("placedate1");
  9609. string placedate2 = GetPostString("placedate2");
  9610. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9611. if (fdw.Length > 0) lw.Add(fdw);
  9612. string price1 = GetPostString("price1");
  9613. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9614. string price2 = GetPostString("price2");
  9615. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9616. string checkst = GetPostString("checkstate");
  9617. if (checkst.Length > 0 && "10".Equals(checkst))
  9618. {
  9619. lw.Add(string.Format("CheckOut>0"));
  9620. }
  9621. else
  9622. {
  9623. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9624. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9625. }
  9626. if (CurrentUser.UserPost.Post.Code == "AfterSale")
  9627. {
  9628. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  9629. }
  9630. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9631. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9632. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9633. writeGridDataTableJson(dStruct.TotalCount, dt);
  9634. }
  9635. public void ins_erp_startCheck()
  9636. {
  9637. if (UrlPostParmsCheck("ctid"))
  9638. {
  9639. string eid = GetPostString("ctid");
  9640. CeErpTradeCell entity = null;
  9641. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9642. if (entity != null)
  9643. {
  9644. entity.MemoOpt = 4;
  9645. entity.UpdateTime = DateTime.Now;
  9646. entity.Update();
  9647. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9648. CeErpSukuraData.createInfo(entity.ctid, 6);
  9649. returnSuccessMsg("操作成功!");
  9650. return;
  9651. }
  9652. returnErrorMsg("找不到记录");
  9653. }
  9654. }
  9655. public void upd_erp_sendXlw()
  9656. {
  9657. if (UrlPostParmsCheck("ctid"))
  9658. {
  9659. string eid = GetPostString("ctid");
  9660. CeErpTradeCell entity = null;
  9661. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9662. if (entity != null)
  9663. {
  9664. if (entity.IsSendGift == 1)
  9665. {
  9666. returnErrorMsg("请勿重复标记");
  9667. return;
  9668. }
  9669. entity.IsSendGift = 1;
  9670. entity.Update();
  9671. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9672. returnSuccessMsg("操作成功!");
  9673. return;
  9674. }
  9675. returnErrorMsg("找不到记录");
  9676. }
  9677. }
  9678. public void cancel_sendXlw()
  9679. {
  9680. if (UrlPostParmsCheck("ctid"))
  9681. {
  9682. string eid = GetPostString("ctid");
  9683. CeErpTradeCell entity = null;
  9684. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9685. if (entity != null)
  9686. {
  9687. if (entity.IsSendGift == 0)
  9688. {
  9689. returnErrorMsg("未标记小礼物");
  9690. return;
  9691. }
  9692. entity.IsSendGift = 0;
  9693. entity.Update();
  9694. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9695. returnSuccessMsg("操作成功!");
  9696. return;
  9697. }
  9698. returnErrorMsg("找不到记录");
  9699. }
  9700. }
  9701. public void get_erp_designbill()
  9702. {
  9703. DataStruct dStruct = GetPostStruct();
  9704. List<string> lw = new List<string>();
  9705. int isMy = GetInt("my");
  9706. if (isMy == 1)
  9707. {
  9708. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9709. }
  9710. string tid = GetPostString("tid");
  9711. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9712. string userName = GetPostString("design");
  9713. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9714. string price1 = GetPostString("price1");
  9715. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9716. string price2 = GetPostString("price2");
  9717. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9718. string rePrice1 = GetPostString("rePrice1");
  9719. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9720. string rePrice2 = GetPostString("rePrice2");
  9721. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9722. string designerType = GetPostString("designerType");
  9723. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9724. string orderState = GetPostString("orderState");
  9725. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9726. string endTime1 = GetPostString("endTime1");
  9727. string endTime2 = GetPostString("endTime2");
  9728. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9729. if (dw.Length > 0) lw.Add(dw);
  9730. string isDk = GetPostString("isDk");
  9731. if (isDk == "1")
  9732. {
  9733. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9734. }
  9735. else if (isDk == "0")
  9736. {
  9737. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9738. }
  9739. dStruct.Order = "oid, create_time desc";
  9740. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9741. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9742. writeGridDataTableJson(dStruct.TotalCount, dt);
  9743. }
  9744. public void upd_erp_designerbill()
  9745. {
  9746. if (UrlPostParmsCheck("ID"))
  9747. {
  9748. string eid = GetPostString("ID");
  9749. CeErpDesignerBill entity = null;
  9750. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9751. if (entity != null)
  9752. {
  9753. if (GetPostDouble("designerpirce") > 0)
  9754. {
  9755. entity.realPrice = GetPostDouble("designerpirce");
  9756. entity.update_time = DateTime.Now;
  9757. entity.update_u_id = CurrentUser.UserID;
  9758. entity.update_u_name = CurrentUser.UserName;
  9759. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9760. entity.Update();
  9761. returnSuccessMsg("操作成功!");
  9762. return;
  9763. }
  9764. else
  9765. {
  9766. entity.price = GetPostDouble("price");
  9767. entity.update_time = DateTime.Now;
  9768. entity.update_u_id = CurrentUser.UserID;
  9769. entity.update_u_name = CurrentUser.UserName;
  9770. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9771. entity.Update();
  9772. returnSuccessMsg("操作成功!");
  9773. return;
  9774. }
  9775. }
  9776. returnErrorMsg("找不到记录");
  9777. }
  9778. }
  9779. public void audit_erp_designerbill()
  9780. {
  9781. if (UrlPostParmsCheck("ID"))
  9782. {
  9783. string eid = GetPostString("ID");
  9784. CeErpDesignerBill entity = null;
  9785. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9786. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9787. if (entity != null)
  9788. {
  9789. entity.realPrice = GetPostDouble("designerpirce");
  9790. entity.update_time = DateTime.Now;
  9791. entity.update_u_id = CurrentUser.UserID;
  9792. entity.update_u_name = CurrentUser.UserName;
  9793. entity.isAudit = 1;
  9794. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9795. entity.Update();
  9796. if (orderEntity != null)
  9797. {
  9798. orderEntity.IsReadTag = 3;
  9799. orderEntity.Update();
  9800. }
  9801. returnSuccessMsg("操作成功!");
  9802. return;
  9803. }
  9804. returnErrorMsg("找不到记录");
  9805. }
  9806. }
  9807. public void all_audit_erp_designerbill()
  9808. {
  9809. if (UrlPostParmsCheck("idList"))
  9810. {
  9811. string[] list = GetPostString("idList").Split(',');
  9812. CeErpDesignerBill entity = null;
  9813. for (int i = 0; i < list.Length; i++)
  9814. {
  9815. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9816. if (entity == null) return;
  9817. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9818. if (orderEntity == null) return;
  9819. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9820. entity.update_time = DateTime.Now;
  9821. entity.update_u_id = CurrentUser.UserID;
  9822. entity.update_u_name = CurrentUser.UserName;
  9823. entity.isAudit = 1;
  9824. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9825. entity.Update();
  9826. orderEntity.IsReadTag = 3;
  9827. orderEntity.Update();
  9828. }
  9829. returnSuccessMsg("操作成功!");
  9830. return;
  9831. }
  9832. }
  9833. public void get_erp_sameorders()
  9834. {
  9835. if (UrlPostParmsCheck("ctid"))
  9836. {
  9837. string eid = GetPostString("ctid");
  9838. CeErpTradeCell entity = null;
  9839. entity = CeErpTradeCell.GetByCtid(eid);
  9840. if (entity != null)
  9841. {
  9842. StringBuilder sql = new StringBuilder();
  9843. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9844. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9845. var res = new
  9846. {
  9847. data = dt.Rows.Count
  9848. };
  9849. string ro_jsond = JsonConvert.SerializeObject(res);
  9850. returnSuccess(ro_jsond);
  9851. return;
  9852. }
  9853. returnErrorMsg("未找到订单");
  9854. return;
  9855. }
  9856. returnErrorMsg("缺少必要的参数");
  9857. }
  9858. public void get_erp_islasthavesameorder()
  9859. {
  9860. if (UrlPostParmsCheck("ctid"))
  9861. {
  9862. string eid = GetPostString("ctid");
  9863. string[] ctidList = eid.Split(',');
  9864. StringBuilder sql = new StringBuilder();
  9865. string tisCtid = "";
  9866. foreach (string ctid in ctidList)
  9867. {
  9868. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9869. if (entity != null)
  9870. {
  9871. sql = new StringBuilder();
  9872. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9873. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9874. if (dth.Rows.Count > 0)
  9875. {
  9876. tisCtid += entity.ctid;
  9877. tisCtid += ",";
  9878. }
  9879. }
  9880. }
  9881. if (tisCtid.Length > 0)
  9882. {
  9883. var res = new
  9884. {
  9885. data = tisCtid
  9886. };
  9887. string ro_jsond = JsonConvert.SerializeObject(res);
  9888. returnSuccess(ro_jsond);
  9889. }
  9890. else
  9891. {
  9892. var res = new
  9893. {
  9894. data = ""
  9895. };
  9896. string ro_jsond = JsonConvert.SerializeObject(res);
  9897. returnSuccess(ro_jsond);
  9898. }
  9899. return;
  9900. }
  9901. returnErrorMsg("缺少必要的参数");
  9902. }
  9903. public void file_client_down_url()
  9904. {
  9905. if (!UrlPostParmsCheck("userId"))
  9906. {
  9907. returnErrorMsg("缺少必要的参数");
  9908. }
  9909. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9910. }
  9911. public void checkout_form_data()
  9912. {
  9913. if (!UrlPostParmsCheck("tid"))
  9914. {
  9915. returnErrorMsg("缺少必要的参数");
  9916. }
  9917. string tid = GetPostString("tid");
  9918. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9919. if (ceErpOrderFormData != null)
  9920. {
  9921. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9922. returnSuccess(ro_jsond);
  9923. return;
  9924. }
  9925. returnErrorMsg("尚未有文件!");
  9926. }
  9927. public void back_supplier_audit()
  9928. {
  9929. int userId = CurrentUser.UserID;
  9930. StringBuilder sql = new StringBuilder();
  9931. 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);
  9932. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9933. if (dt.Rows.Count > 0)
  9934. {
  9935. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9936. }
  9937. else
  9938. {
  9939. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9940. }
  9941. }
  9942. public void back_supplier_query()
  9943. {
  9944. string eid = GetPostString("ctid");
  9945. if (eid != "")
  9946. {
  9947. StringBuilder sql = new StringBuilder();
  9948. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9949. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9950. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9951. }
  9952. else
  9953. {
  9954. returnErrorMsg("找不到订单记录");
  9955. return;
  9956. }
  9957. }
  9958. public void verified_to_order()
  9959. {
  9960. int userId = CurrentUser.UserID;
  9961. StringBuilder sql = new StringBuilder();
  9962. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9963. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9964. if (dt.Rows.Count > 0)
  9965. {
  9966. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9967. }
  9968. else
  9969. {
  9970. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9971. }
  9972. }
  9973. public void upd_supplier_audit()
  9974. {
  9975. if (UrlPostParmsCheck("ctid"))
  9976. {
  9977. string eid = GetPostString("ctid");
  9978. string reason = GetPostString("returnreason");
  9979. CeErpTradeCell entity = null;
  9980. CeWithdraw withdraw = null;
  9981. withdraw = CeWithdraw.GetByTid(eid);
  9982. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9983. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9984. {
  9985. if (withdraw != null)
  9986. {
  9987. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9988. {
  9989. returnSuccessMsg("您没有权限操作!");
  9990. return;
  9991. }
  9992. else
  9993. {
  9994. if (reason.Equals("1"))
  9995. {
  9996. if (entity.OrderState == -1)
  9997. {
  9998. if (entity.FinishPlaceTime == null)
  9999. {
  10000. entity.OrderState = 2;
  10001. }
  10002. else
  10003. {
  10004. entity.OrderState = 6;
  10005. }
  10006. }
  10007. entity.Update();
  10008. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10009. if (withdraw != null)
  10010. {
  10011. withdraw.status = int.Parse(reason);
  10012. withdraw.Update();
  10013. }
  10014. returnSuccessMsg("操作成功!");
  10015. return;
  10016. }
  10017. else
  10018. {
  10019. withdraw.status = int.Parse(reason);
  10020. withdraw.acknowledgingtime = DateTime.Now;
  10021. withdraw.Update();
  10022. returnSuccessMsg("查看详细请点击线下订单查询");
  10023. return;
  10024. }
  10025. }
  10026. }
  10027. // 第一个字符是 'N'
  10028. }
  10029. if (eid[0] != 'N')
  10030. {
  10031. }
  10032. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  10033. {
  10034. entity.IsVerifyToSupplier = false;
  10035. entity.IsReturn = 1;
  10036. entity.ReturnTime = DateTime.Now;
  10037. entity.ReturnReason = reason;
  10038. if (entity.OrderState == 6)
  10039. {
  10040. entity.OrderState = 5;
  10041. }
  10042. entity.Update();
  10043. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  10044. if (withdraw != null)
  10045. {
  10046. withdraw.status = int.Parse(reason);
  10047. withdraw.Update();
  10048. }
  10049. returnSuccessMsg("操作成功!");
  10050. return;
  10051. }
  10052. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  10053. {
  10054. ;
  10055. if (withdraw != null)
  10056. {
  10057. withdraw.status = int.Parse(reason);
  10058. withdraw.acknowledgingtime = DateTime.Now;
  10059. withdraw.Update();
  10060. returnSuccessMsg("供应商取消撤回!");
  10061. return;
  10062. }
  10063. }
  10064. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  10065. {
  10066. if (entity.OrderState == -1)
  10067. {
  10068. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  10069. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10070. if (!string.IsNullOrEmpty(ceErpTrade.receiver_state) && ceErpTrade.receiver_state.Contains("台湾") && string.IsNullOrEmpty(ceErpTrade.receiver_zip))
  10071. {
  10072. returnErrorMsg("台湾客户需填写身份证!");
  10073. return;
  10074. }
  10075. if (commonHelper.isFarAddress(ceErpTrade.receiver_state) && ceErpTrade.delivery_paymant == 0 && entity.IsSF != 2)
  10076. {
  10077. returnErrorMsg("偏远地区需要填写物流费!");
  10078. return;
  10079. }
  10080. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  10081. {
  10082. returnErrorMsg("订单spu没有确认无法通过审核!");
  10083. return;
  10084. }
  10085. if (entity.FinishPlaceTime == null)
  10086. {
  10087. entity.OrderState = 2;
  10088. }
  10089. else
  10090. {
  10091. entity.OrderState = 3;
  10092. }
  10093. commonHelper.getCytPrice(entity);
  10094. if ((entity.OtherMemo.Contains("老客户") || entity.OtherMemo.Contains("老顾客")) && entity.OtherMemo.Contains("改稿"))
  10095. {
  10096. tmcHelper.dealOldCustomerEntityTag(ref entity, ceErpTrade);
  10097. }
  10098. if (entity.IsSample > 1 || entity.seller_memo.Contains("现货") || entity.seller_memo.Contains("礼物"))
  10099. {
  10100. entity.OrderState = 6;
  10101. }
  10102. }
  10103. entity.Update();
  10104. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10105. if (withdraw != null)
  10106. {
  10107. withdraw.status = int.Parse(reason);
  10108. withdraw.Update();
  10109. }
  10110. returnSuccessMsg("操作成功!");
  10111. return;
  10112. }
  10113. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  10114. {
  10115. if (withdraw == null)
  10116. {
  10117. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  10118. return;
  10119. }
  10120. }
  10121. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  10122. {
  10123. if (withdraw != null)
  10124. {
  10125. withdraw.status = int.Parse(reason);
  10126. withdraw.acknowledgingtime = DateTime.Now;
  10127. withdraw.Update();
  10128. returnSuccessMsg("查看详细请点击线下订单查询");
  10129. return;
  10130. }
  10131. }
  10132. return;
  10133. }
  10134. }
  10135. //校验报价
  10136. public void refund_order_tip()
  10137. {
  10138. int userid = CurrentUser.UserID;
  10139. int sectionId = CurrentUser.UserPost.OrgID;
  10140. StringBuilder sql = new StringBuilder();
  10141. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  10142. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10143. List<string> ids = new List<string>();
  10144. if (dth.Rows.Count > 0)
  10145. {
  10146. foreach (DataRow dr in dth.Rows)
  10147. {
  10148. ids.Add(dr["ID"].ToString());
  10149. }
  10150. try
  10151. {
  10152. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  10153. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  10154. }
  10155. catch (Exception ex)
  10156. {
  10157. }
  10158. }
  10159. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10160. }
  10161. public void refund_order_Design()
  10162. {
  10163. int userid = CurrentUser.UserID;
  10164. int sectionId = CurrentUser.UserPost.OrgID;
  10165. StringBuilder sql = new StringBuilder();
  10166. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  10167. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10168. List<string> ids = new List<string>();
  10169. if (dth.Rows.Count > 0)
  10170. {
  10171. foreach (DataRow dr in dth.Rows)
  10172. {
  10173. ids.Add(dr["ID"].ToString());
  10174. }
  10175. try
  10176. {
  10177. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10178. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10179. }
  10180. catch (Exception ex)
  10181. {
  10182. }
  10183. }
  10184. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10185. }
  10186. public void change_order_info()
  10187. {
  10188. int userid = CurrentUser.UserID;
  10189. StringBuilder sql = new StringBuilder();
  10190. 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);
  10191. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10192. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  10193. }
  10194. public void change_win_mome()
  10195. {
  10196. if (UrlPostParmsCheck("id,ctid"))
  10197. {
  10198. string id = GetPostString("id");
  10199. string ctid = GetPostString("ctid");
  10200. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10201. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10202. if (ce == null || ceErpMessageTip == null)
  10203. {
  10204. returnSuccessMsg("未找到对应的订单!");
  10205. return;
  10206. }
  10207. if (ce.OrderState >= 5)
  10208. {
  10209. ceErpMessageTip.isVisit = true;
  10210. ceErpMessageTip.Update();
  10211. returnSuccessMsg("已上传文件无法修改!");
  10212. return;
  10213. }
  10214. int type = GetPostInt("type");
  10215. string content = GetPostString("content");
  10216. if (type == 0)
  10217. {
  10218. content = content.Replace("(", "(");
  10219. content = content.Replace(")", ")");
  10220. string check = MidStrEx(content, "(", ")").Trim();
  10221. if (string.IsNullOrEmpty(check))
  10222. {
  10223. returnSuccessMsg("文件名格式不正确");
  10224. return;
  10225. }
  10226. }
  10227. ce.seller_memo = content;
  10228. ce.Update();
  10229. ceErpMessageTip.isVisit = true;
  10230. ceErpMessageTip.Update();
  10231. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10232. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10233. ApiVo apiVo = new ApiVo();
  10234. apiVo.orderNumber = ce.ctid;
  10235. apiVo.actionName = "demandDesign";
  10236. apiVo.orderRemarks = content;
  10237. apiVo.demandExamine = type + 1;
  10238. designHelper.API_WorkCore(apiVo);//demandDesign
  10239. returnSuccessMsg("修改成功!");
  10240. }
  10241. }
  10242. public static string MidStrEx(string sourse, string startstr, string endstr)
  10243. {
  10244. string result = string.Empty;
  10245. int startindex, endindex;
  10246. try
  10247. {
  10248. startindex = sourse.IndexOf(startstr);
  10249. if (startindex == -1)
  10250. return result;
  10251. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10252. endindex = tmpstr.IndexOf(endstr);
  10253. if (endindex == -1)
  10254. return result;
  10255. result = tmpstr.Remove(endindex);
  10256. }
  10257. catch (Exception ex)
  10258. {
  10259. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10260. }
  10261. return result;
  10262. }
  10263. public void refund_order_list()
  10264. {
  10265. int userid = CurrentUser.UserID;
  10266. int sectionId = CurrentUser.UserPost.OrgID;
  10267. StringBuilder sql = new StringBuilder();
  10268. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10269. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10270. DataStruct dStruct = GetPostStruct();
  10271. DataTable dt = null;
  10272. List<string> ids = new List<string>();
  10273. List<string> tids = new List<string>();
  10274. if (dth.Rows.Count > 0)
  10275. {
  10276. foreach (DataRow dr in dth.Rows)
  10277. {
  10278. tids.Add("'" + dr["tid"].ToString() + "'");
  10279. ids.Add(dr["id"].ToString());
  10280. }
  10281. try
  10282. {
  10283. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10284. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10285. List<string> lw = new List<string>();
  10286. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10287. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10288. dt = WebCache.GetData("view_orderlist", dStruct);
  10289. }
  10290. catch (Exception ex)
  10291. {
  10292. }
  10293. }
  10294. writeGridDataTableJson(dStruct.TotalCount, dt);
  10295. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10296. }
  10297. //新增
  10298. public void order_batch_downloads()
  10299. {
  10300. string ceid = GetPostString("tid");
  10301. String[] tid = ceid.Split(',');
  10302. order_batch_caiyingtong(tid);
  10303. /* (string success, string errors) = UploadFiles(tid);
  10304. returnSuccessMsg(success + errors);*/
  10305. return;
  10306. }
  10307. //报价接口
  10308. public void Get_To_Quote()
  10309. {
  10310. string ceid = GetPostString("ctid");
  10311. if (ceid != null)
  10312. {
  10313. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10314. if (entity != null)
  10315. {
  10316. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10317. {
  10318. return;
  10319. }
  10320. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10321. double price = 0;
  10322. if (cp == null)
  10323. {
  10324. JObject jsonObject12 = new JObject
  10325. {
  10326. { "UserId", "77886" },
  10327. { "Pwd", "lt666888" },
  10328. { "Filename", entity.seller_memo }
  10329. };
  10330. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10331. JObject jsonObjects1 = JObject.Parse(response1);
  10332. string ms1g = (string)jsonObjects1["msg"];
  10333. if (ms1g == "报价成功")
  10334. {
  10335. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10336. string data = (string)jsonObject1["price"];
  10337. 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 + "');";
  10338. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10339. returnSuccessMsg("获取报价成功:" + data);
  10340. price = Convert.ToDouble(data);
  10341. }
  10342. else
  10343. {
  10344. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10345. return;
  10346. }
  10347. }
  10348. String[] beizhu = entity.seller_memo.Split('-');
  10349. String chanp = "";
  10350. if (beizhu.Length > 0)
  10351. {
  10352. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10353. }
  10354. else
  10355. {
  10356. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10357. }
  10358. JObject jsonObject = new JObject
  10359. {
  10360. { "UserId", "77886" },
  10361. { "Pwd", "lt666888" },
  10362. { "Filename", chanp }
  10363. };
  10364. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10365. JObject jsonObjects = JObject.Parse(response);
  10366. string msg = (string)jsonObjects["msg"];
  10367. if (msg == "报价成功")
  10368. {
  10369. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10370. string data = (string)jsonObject1["price"];
  10371. 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 + "');";
  10372. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10373. returnSuccessMsg("获取报价成功:" + data);
  10374. price = Convert.ToDouble(data);
  10375. }
  10376. else
  10377. {
  10378. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10379. return;
  10380. }
  10381. if (price > 0)
  10382. {
  10383. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10384. if (ceErpTradeCellExtend == null)
  10385. {
  10386. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10387. ceErpTradeCellExtend.ctid = entity.ctid;
  10388. ceErpTradeCellExtend.payment_cyt = price;
  10389. ceErpTradeCellExtend.Create();
  10390. }
  10391. else
  10392. {
  10393. ceErpTradeCellExtend.payment_cyt = price;
  10394. ceErpTradeCellExtend.Update();
  10395. }
  10396. }
  10397. return;
  10398. }
  10399. }
  10400. else
  10401. {
  10402. returnErrorMsg("请至少选择一条数据");
  10403. return;
  10404. }
  10405. }
  10406. //新增
  10407. public void order_To_Supplier()
  10408. {
  10409. string ceid = GetPostString("tid");
  10410. String[] tid = ceid.Split(',');
  10411. if (tid.Length > 0)
  10412. {
  10413. try
  10414. {
  10415. for (int i = 0; i < tid.Length; i++)
  10416. {
  10417. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10418. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10419. entity.SupplierId = suid;
  10420. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10421. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10422. entity.Update();
  10423. }
  10424. }
  10425. catch (Exception ex)
  10426. {
  10427. returnErrorMsg("自动匹配供应商失败");
  10428. return;
  10429. }
  10430. }
  10431. else
  10432. {
  10433. returnErrorMsg("请至少选择一条数据");
  10434. return;
  10435. }
  10436. returnSuccessMsg("自动匹配供应商成功");
  10437. return;
  10438. }
  10439. public (string, string) UploadFiles(string[] urls)
  10440. {
  10441. string success = "";
  10442. string errors = "";
  10443. int userid = CurrentUser.UserID;
  10444. foreach (string url in urls)
  10445. {
  10446. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10447. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10448. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10449. {
  10450. JObject jsonObject = new JObject
  10451. {
  10452. { "Userid", "77886" },
  10453. { "pwd", "cyt86435015" },
  10454. { "content", base64FileContent },
  10455. { "ext", Path.GetExtension(fileName) }
  10456. };
  10457. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10458. JObject jsonObjects = JObject.Parse(response);
  10459. string msg = (string)jsonObjects["msg"];
  10460. if (msg.Equals("上传成功"))
  10461. {
  10462. success += url + " 上传成功";
  10463. }
  10464. else
  10465. {
  10466. errors += url + " 上传失败";
  10467. }
  10468. }
  10469. else
  10470. {
  10471. errors += url + " 格式出现问题";
  10472. }
  10473. }
  10474. if (urls.Length == 0)
  10475. {
  10476. return (success, errors);
  10477. }
  10478. return (success, errors);
  10479. }
  10480. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10481. {
  10482. return true; //总是接受
  10483. }
  10484. public static string HttpPost(string url, string param = null)
  10485. {
  10486. HttpWebRequest request;
  10487. //如果是发送HTTPS请求
  10488. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10489. {
  10490. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10491. request = WebRequest.Create(url) as HttpWebRequest;
  10492. request.ProtocolVersion = HttpVersion.Version10;
  10493. }
  10494. else
  10495. {
  10496. request = WebRequest.Create(url) as HttpWebRequest;
  10497. }
  10498. request.Method = "POST";
  10499. request.ContentType = "application/json";
  10500. request.Accept = "*/*";
  10501. request.Timeout = 120000;
  10502. request.AllowAutoRedirect = false;
  10503. StreamWriter requestStream = null;
  10504. WebResponse response = null;
  10505. string responseStr = null;
  10506. try
  10507. {
  10508. requestStream = new StreamWriter(request.GetRequestStream());
  10509. requestStream.Write(param);
  10510. requestStream.Close();
  10511. response = request.GetResponse();
  10512. if (response != null)
  10513. {
  10514. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10515. responseStr = reader.ReadToEnd();
  10516. reader.Close();
  10517. }
  10518. }
  10519. catch (Exception ex)
  10520. {
  10521. return ex.Message;
  10522. }
  10523. finally
  10524. {
  10525. request = null;
  10526. requestStream = null;
  10527. response = null;
  10528. }
  10529. return responseStr;
  10530. }
  10531. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10532. {
  10533. string base64FileContent;
  10534. string fileName;
  10535. using (WebClient webClient = new WebClient())
  10536. {
  10537. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10538. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10539. {
  10540. using (Stream stream = response.GetResponseStream())
  10541. {
  10542. using (MemoryStream memoryStream = new MemoryStream())
  10543. {
  10544. stream.CopyTo(memoryStream);
  10545. byte[] fileBytes = memoryStream.ToArray();
  10546. base64FileContent = Convert.ToBase64String(fileBytes);
  10547. fileName = response.Headers["Content-Disposition"];
  10548. if (!string.IsNullOrEmpty(fileName))
  10549. {
  10550. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10551. if (index >= 0)
  10552. {
  10553. fileName = fileName.Substring(index + 9).Trim('\"');
  10554. }
  10555. }
  10556. else
  10557. {
  10558. fileName = Path.GetFileName(downloadUrl);
  10559. }
  10560. }
  10561. }
  10562. }
  10563. }
  10564. return (fileName, base64FileContent);
  10565. }
  10566. //新增
  10567. public void order_batch_caiyingtong(string[] downloadUrls)
  10568. {
  10569. try
  10570. {
  10571. //遍历文件
  10572. DataStruct dStruct = GetPostStruct();
  10573. DataTable dt = null;
  10574. int userid = CurrentUser.UserID;
  10575. List<string> ids = new List<string>();//失败组
  10576. List<string> tids = new List<string>();
  10577. using (WebClient webClient = new WebClient())
  10578. {
  10579. foreach (var url in downloadUrls)
  10580. {
  10581. try
  10582. {
  10583. tids.Add("'" + url + "'");
  10584. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10585. if (entity != null)
  10586. {
  10587. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10588. if (cp == null)
  10589. {
  10590. JObject jsonObject = new JObject
  10591. {
  10592. { "Userid", "77886" },
  10593. { "pwd", "lt666888" },
  10594. { "Filename",entity.seller_memo }
  10595. };
  10596. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10597. JObject jsonObjects = JObject.Parse(response);
  10598. string msg = (string)jsonObjects["msg"];
  10599. if (msg == "报价成功")
  10600. {
  10601. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10602. DownloadAndConvertToBase64(url1);
  10603. }
  10604. else
  10605. {
  10606. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10607. }
  10608. }
  10609. else
  10610. {
  10611. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10612. JObject jsonObject = new JObject
  10613. {
  10614. { "Userid", "77886" },
  10615. { "pwd", "lt666888" },
  10616. { "Filename",chanp }
  10617. };
  10618. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10619. JObject jsonObjects = JObject.Parse(response);
  10620. string msg = (string)jsonObjects["msg"];
  10621. if (msg == "报价成功")
  10622. {
  10623. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10624. DownloadAndConvertToBase64(url1);
  10625. }
  10626. else
  10627. {
  10628. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10629. }
  10630. }
  10631. }
  10632. // 上传文件到FTP
  10633. }
  10634. catch (Exception ex)
  10635. {
  10636. Console.WriteLine($"An error occurred: {ex.Message}");
  10637. }
  10638. }
  10639. List<string> lw = new List<string>();
  10640. lw.Add(string.Format("( OrderState < 6 )"));
  10641. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10642. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10643. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10644. if (dt.Rows.Count > 0)
  10645. {
  10646. foreach (DataRow dr in dt.Rows)
  10647. {
  10648. ids.Add(dr["ctid"].ToString());
  10649. }
  10650. }
  10651. String ErrorMsgs = "";
  10652. foreach (String id in ids)
  10653. {
  10654. ErrorMsgs += id + ",";
  10655. }
  10656. if (ErrorMsgs.Length > 1)
  10657. {
  10658. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10659. }
  10660. if (ErrorMsgs.Length < 1)
  10661. {
  10662. ErrorMsgs = "上传成功";
  10663. returnSuccessMsg(ErrorMsgs);
  10664. }
  10665. else
  10666. {
  10667. returnErrorMsg("以下订单" + ErrorMsgs);
  10668. }
  10669. }
  10670. // 删除文件夹及其内容
  10671. /* Directory.Delete(localDirectory, true);*/
  10672. }
  10673. catch { }
  10674. }
  10675. public void get_center_data()
  10676. {
  10677. int userId = CurrentUser.UserID;
  10678. string postCode = CurrentUser.UserPost.Post.Code;
  10679. List<string> lw = new List<string>();
  10680. List<string> ww = new List<string>();
  10681. DateTime currentTime = DateTime.Now;
  10682. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10683. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10684. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10685. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10686. string sql = " SELECT ";
  10687. string startTime = "2023-10-01 11:22:31";
  10688. //设计
  10689. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10690. {
  10691. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10692. 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));
  10693. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10694. 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));
  10695. }
  10696. //客服
  10697. else if (postCode == "CustomerService" || postCode == "Director")
  10698. {
  10699. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10700. 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));
  10701. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10702. 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));
  10703. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10704. 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));
  10705. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10706. 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));
  10707. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10708. 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));
  10709. }
  10710. //售后
  10711. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10712. {
  10713. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10714. 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));
  10715. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10716. 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));
  10717. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10718. 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));
  10719. }
  10720. //下单部
  10721. else if (postCode == "Place" || postCode == "PlaceMr")
  10722. {
  10723. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10724. 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));
  10725. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10726. 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));
  10727. }
  10728. //车间
  10729. else if (postCode == "Supplier")
  10730. {
  10731. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10732. 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));
  10733. }
  10734. DataTable dt = new DataTable();
  10735. if (lw.Count > 0)
  10736. {
  10737. sql += string.Join(" , ", lw);
  10738. sql += " FROM ";
  10739. sql += string.Join(" , ", ww);
  10740. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10741. }
  10742. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10743. }
  10744. public void get_center_data_list()
  10745. {
  10746. int userId = CurrentUser.UserID;
  10747. string postCode = CurrentUser.UserPost.Post.Code;
  10748. string shopIds = CurrentUser.User.pemShop;
  10749. DataStruct dStruct = GetPostStruct();
  10750. List<string> lw = new List<string>();
  10751. DateTime currentTime = DateTime.Now;
  10752. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10753. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10754. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10755. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10756. string startTime = "2023-10-01 11:22:31";
  10757. int order_type = GetPostInt("order_type");
  10758. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10759. {
  10760. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10761. if (order_type == 0)
  10762. {
  10763. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10764. }
  10765. else if (order_type == 3)
  10766. {
  10767. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10768. }
  10769. else
  10770. {
  10771. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10772. }
  10773. }
  10774. //客服
  10775. if (postCode == "CustomerService" || postCode == "Director")
  10776. {
  10777. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10778. if (order_type == 0)
  10779. {
  10780. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10781. }
  10782. else if (order_type == 1)
  10783. {
  10784. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10785. }
  10786. else if (order_type == 2)
  10787. {
  10788. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10789. }
  10790. else if (order_type == 3)
  10791. {
  10792. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10793. }
  10794. else if (order_type == 4)
  10795. {
  10796. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10797. }
  10798. else
  10799. {
  10800. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10801. }
  10802. }
  10803. //售后
  10804. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10805. {
  10806. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10807. if (shopIds != "")
  10808. {
  10809. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10810. }
  10811. if (order_type == 2)
  10812. {
  10813. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10814. }
  10815. else if (order_type == 4)
  10816. {
  10817. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10818. }
  10819. else if (order_type == 5)
  10820. {
  10821. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10822. }
  10823. else
  10824. {
  10825. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10826. }
  10827. }
  10828. //下单部
  10829. if (postCode == "Place" || postCode == "PlaceMr")
  10830. {
  10831. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10832. if (shopIds != "")
  10833. {
  10834. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10835. }
  10836. else if (order_type == 1)
  10837. {
  10838. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10839. }
  10840. else if (order_type == 2)
  10841. {
  10842. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10843. }
  10844. else
  10845. {
  10846. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10847. }
  10848. }
  10849. //车间
  10850. if (postCode == "Supplier")
  10851. {
  10852. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10853. if (order_type == 5)
  10854. {
  10855. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10856. }
  10857. else
  10858. {
  10859. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10860. }
  10861. }
  10862. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10863. dStruct.Fileds = "tid,ctid";
  10864. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10865. writeGridDataTableJson(dStruct.TotalCount, dt);
  10866. }
  10867. public void aftersale_audit_master()
  10868. {
  10869. if (UrlPostParmsCheck("ctid"))
  10870. {
  10871. string ctid = GetPostString("ctid");
  10872. if (ctid.Length > 0)
  10873. {
  10874. bool result = aftersale_data_change(ctid);
  10875. if (result)
  10876. {
  10877. returnSuccessMsg("修改成功!");
  10878. return;
  10879. }
  10880. }
  10881. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10882. }
  10883. }
  10884. public void aftersale_batch_audit_master()
  10885. {
  10886. if (UrlPostParmsCheck("ctids"))
  10887. {
  10888. string ctids = GetPostString("ctids");
  10889. if (ctids.Length > 0)
  10890. {
  10891. List<string> list = new List<string>();
  10892. string[] ctid_list = ctids.Split(',');
  10893. foreach (var item in ctid_list)
  10894. {
  10895. bool result = aftersale_data_change(item);
  10896. if (!result)
  10897. {
  10898. list.Add(item);
  10899. }
  10900. }
  10901. if (list.Count > 0)
  10902. {
  10903. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10904. return;
  10905. }
  10906. returnSuccessMsg("修改成功!");
  10907. return;
  10908. }
  10909. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10910. }
  10911. }
  10912. public bool aftersale_data_change(string ctid)
  10913. {
  10914. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10915. if (ceErpTradeCell != null)
  10916. {
  10917. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10918. ceErpTradeCell.AfterSaleSupplierState = 0;
  10919. StringBuilder sql = new StringBuilder();
  10920. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10921. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10922. CeErpTradeResponsible.DelByTid(ctid, 0);
  10923. 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 == "不理赔")
  10924. {
  10925. CeErpTradeResponsible.DelByTid(ctid, 1);
  10926. ceErpTradeCell.AfterSaleSupplierState = 1;
  10927. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10928. ceErpTradeCell.AfterSaleState = 4;
  10929. }
  10930. else
  10931. {
  10932. ceErpTradeCell.AfterSaleState = 3;
  10933. }
  10934. bool needCyt = false;
  10935. if (dt != null)
  10936. {
  10937. if (dt.Rows.Count == 1)
  10938. {
  10939. bool isEnd = false;
  10940. foreach (DataRow dr in dt.Rows)
  10941. {
  10942. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10943. {
  10944. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10945. isEnd = true;
  10946. }
  10947. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10948. {
  10949. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10950. isEnd = true;
  10951. }
  10952. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  10953. {
  10954. needCyt = true;
  10955. }
  10956. }
  10957. if (isEnd)
  10958. {
  10959. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10960. ceErpTradeCell.AfterSaleState = 4;
  10961. ceErpTradeCell.AfterSaleSupplierState = 1;
  10962. }
  10963. }
  10964. else
  10965. {
  10966. bool isAll = true;
  10967. foreach (DataRow dr in dt.Rows)
  10968. {
  10969. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10970. {
  10971. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10972. continue;
  10973. }
  10974. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10975. {
  10976. string path = "";
  10977. int OrgID = 0;
  10978. if (!Convert.IsDBNull(dr["OrgPath"]))
  10979. {
  10980. path = dr["OrgPath"].ToString();
  10981. }
  10982. if (!Convert.IsDBNull(dr["OrgID"]))
  10983. {
  10984. OrgID = Convert.ToInt32(dr["OrgID"]);
  10985. }
  10986. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10987. {
  10988. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10989. continue;
  10990. }
  10991. }
  10992. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  10993. {
  10994. needCyt = true;
  10995. }
  10996. isAll = false;
  10997. }
  10998. if (isAll)
  10999. {
  11000. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11001. ceErpTradeCell.AfterSaleState = 4;
  11002. ceErpTradeCell.AfterSaleSupplierState = 1;
  11003. }
  11004. }
  11005. }
  11006. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  11007. {
  11008. commonHelper.sendCytAfterSale(ceErpTradeCell);
  11009. }
  11010. if (ceErpTradeCell.AfterSaleState == 4)
  11011. {
  11012. ApiVo apiVo = new ApiVo();
  11013. apiVo.orderNumber = ceErpTradeCell.ctid;
  11014. apiVo.actionName = "afterOver";
  11015. designHelper.API_WorkCore(apiVo); //afterOver
  11016. }
  11017. ceErpTradeCell.Update();
  11018. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  11019. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  11020. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  11021. return true;
  11022. }
  11023. return false;
  11024. }
  11025. public void get_erp_wechatorder()
  11026. {
  11027. DataStruct dStruct = GetPostStruct();
  11028. List<string> lw = new List<string>();
  11029. string tid = GetPostString("tid");
  11030. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  11031. string shopname = GetPostString("shopname");
  11032. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11033. string buyernick = GetPostString("buyer_nick");
  11034. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11035. string customer = GetPostString("customer");
  11036. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  11037. string returndate1 = GetPostString("returndate1");
  11038. string returndate2 = GetPostString("returndate2");
  11039. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  11040. if (dw.Length > 0) lw.Add(dw);
  11041. string finishDate1 = GetPostString("finishdate1");
  11042. string finishDate2 = GetPostString("finishdate2");
  11043. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  11044. if (dw_finish.Length > 0) lw.Add(dw_finish);
  11045. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  11046. dStruct.Order = "created desc";
  11047. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11048. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  11049. writeGridDataTableJson(dStruct.TotalCount, dt);
  11050. }
  11051. public void get_erp_wechatlist_sumprice()
  11052. {
  11053. DataStruct dStruct = GetPostStruct();
  11054. List<string> lw = new List<string>();
  11055. string tid = GetPostString("tid");
  11056. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  11057. string shopname = GetPostString("shopname");
  11058. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11059. string buyernick = GetPostString("buyer_nick");
  11060. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11061. string customer = GetPostString("customer");
  11062. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  11063. string returndate1 = GetPostString("returndate1");
  11064. string returndate2 = GetPostString("returndate2");
  11065. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  11066. if (dw.Length > 0) lw.Add(dw);
  11067. string finishDate1 = GetPostString("finishdate1");
  11068. string finishDate2 = GetPostString("finishdate2");
  11069. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  11070. if (dw_finish.Length > 0) lw.Add(dw_finish);
  11071. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  11072. string mainWhere = string.Join(" and ", lw.ToArray());
  11073. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  11074. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  11075. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  11076. decimal total = 0;
  11077. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  11078. {
  11079. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  11080. }
  11081. var res = new
  11082. {
  11083. data = total
  11084. };
  11085. string ro_jsond = JsonConvert.SerializeObject(res);
  11086. returnSuccess(ro_jsond);
  11087. return;
  11088. }
  11089. public void get_erp_qr_waitdeliverylist()
  11090. {
  11091. DataStruct dStruct = GetPostStruct();
  11092. List<string> lw = new List<string>();
  11093. string tid = GetPostString("ctid");
  11094. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  11095. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11096. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  11097. var res_objz = new
  11098. {
  11099. restype = 1,
  11100. data = dt
  11101. };
  11102. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  11103. returnSuccess(ro_jsonz);
  11104. }
  11105. public void get_erp_yield_list()
  11106. {
  11107. DataStruct dStruct = GetPostStruct();
  11108. List<string> lw = new List<string>();
  11109. string tid = GetPostString("ctid");
  11110. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  11111. string shopname = GetPostString("shopname");
  11112. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  11113. string buyernick = GetPostString("buyer_nick");
  11114. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  11115. //if (tid.Length == 0 && buyernick.Length == 0)
  11116. //{
  11117. // lw.Add(string.Format("IsRefund<={0}", 1));
  11118. //}
  11119. string customer = GetPostString("customer");
  11120. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11121. string design = GetPostString("design");
  11122. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11123. string orderState = GetPostString("orderState");
  11124. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  11125. string address = GetPostString("address");
  11126. 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));
  11127. string sellermemo = GetPostString("seller_memo");
  11128. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11129. string supplier = GetPostString("supplier");
  11130. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11131. string OrderArea = GetPostString("order_area");
  11132. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  11133. string placedate1 = GetPostString("placedate1");
  11134. string placedate2 = GetPostString("placedate2");
  11135. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  11136. if (fdw.Length > 0) lw.Add(fdw);
  11137. string price1 = GetPostString("price1");
  11138. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  11139. string price2 = GetPostString("price2");
  11140. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  11141. string unusualCon = GetPostString("unusualcon");
  11142. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  11143. string posTag = CurrentUser.UserPost.Post.Code;
  11144. if (posTag == "Supplier")
  11145. {
  11146. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  11147. }
  11148. lw.Add(string.Format("OrderState = 6 "));
  11149. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  11150. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  11151. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11152. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  11153. writeGridDataTableJson(dStruct.TotalCount, dt);
  11154. }
  11155. public void change_erp_sup_state()
  11156. {
  11157. if (UrlPostParmsCheck("ctid"))
  11158. {
  11159. string ctid = GetPostString("ctid");
  11160. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11161. if (ceErpTradeCell != null)
  11162. {
  11163. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11164. if (ceErpTradeCellExtend == null)
  11165. {
  11166. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11167. ceErpTradeCellExtend.ctid = ctid;
  11168. ceErpTradeCellExtend.SupState = 1;
  11169. ceErpTradeCellExtend.Create();
  11170. }
  11171. else
  11172. {
  11173. ceErpTradeCellExtend.SupState = 1;
  11174. ceErpTradeCellExtend.Update();
  11175. }
  11176. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  11177. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  11178. return;
  11179. }
  11180. returnErrorMsg("找不到订单");
  11181. }
  11182. }
  11183. public void supplier_all_downs()
  11184. {
  11185. if (UrlPostParmsCheck("tids"))
  11186. {
  11187. string tids = GetPostString("tids");
  11188. if (tids != null && tids.Length > 0)
  11189. {
  11190. StringBuilder sql = new StringBuilder();
  11191. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  11192. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11193. sql = new StringBuilder();
  11194. 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, "下载设计文件");
  11195. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11196. string[] list = tids.Split(',');
  11197. foreach (string ctid in list)
  11198. {
  11199. CeErpSukuraData.createInfo(ctid, 3);
  11200. }
  11201. designHelper.api_approveDesign(tids); //approveDesign
  11202. returnSuccessMsg("下载成功!");
  11203. return;
  11204. }
  11205. returnErrorMsg("下载订单更新失败");
  11206. }
  11207. }
  11208. public void uploaderFileSuccess()
  11209. {
  11210. if (UrlPostParmsCheck("fileName"))
  11211. {
  11212. string fileName = GetPostString("fileName");
  11213. ApiVo apiVo = new ApiVo();
  11214. apiVo.orderNumber = fileName;
  11215. apiVo.actionName = "finishDesign";
  11216. designHelper.API_WorkCore(apiVo);//finishDesign
  11217. returnSuccessMsg("");
  11218. }
  11219. }
  11220. public void get_sample2_order()
  11221. {
  11222. if (UrlPostParmsCheck("ctid"))
  11223. {
  11224. string ctid = GetPostString("ctid");
  11225. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11226. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11227. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11228. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11229. double total = 0.0;
  11230. double order_price = 0.0;
  11231. if (dt_bu.Rows.Count > 0)
  11232. {
  11233. foreach (DataRow dr in dt_bu.Rows)
  11234. {
  11235. total += Convert.ToDouble(dr["payment"]);
  11236. }
  11237. }
  11238. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11239. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11240. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11241. string tid = ctid.Replace("S_", "");
  11242. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11243. double paymant = 0.0;
  11244. if (entity != null)
  11245. {
  11246. paymant = entity.payment;
  11247. }
  11248. string return_reason = "";
  11249. if (dt_after != null && dt_after.Rows.Count > 0)
  11250. {
  11251. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11252. }
  11253. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11254. }
  11255. }
  11256. public void get_erp_design_status()
  11257. {
  11258. string designName = GetPostString("designName");
  11259. DataStruct dStruct = GetPostStruct();
  11260. if (designName.Length > 0)
  11261. {
  11262. 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";
  11263. sql_user += " and Name like '%" + designName + "%'";
  11264. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11265. List<string> ids_list = new List<string>();
  11266. if (user_table.Rows.Count > 0)
  11267. {
  11268. foreach (DataRow item in user_table.Rows)
  11269. {
  11270. ids_list.Add(item["id"].ToString());
  11271. string ids_s = item["TeamIds"].ToString();
  11272. if (ids_s.Length > 0)
  11273. {
  11274. ids_list.AddRange(ids_s.Split(','));
  11275. }
  11276. }
  11277. }
  11278. HashSet<string> set = new HashSet<string>(ids_list);
  11279. ids_list = set.ToList();
  11280. if (ids_list.Count > 0)
  11281. {
  11282. 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));
  11283. dStruct.MainWhere = sql;
  11284. DataTable dt = null;
  11285. dt = WebCache.GetData("view_ErpUser", dStruct);
  11286. writeGridDataTableJson(dStruct.TotalCount, dt);
  11287. }
  11288. }
  11289. }
  11290. public void change_erp_order_price()
  11291. {
  11292. string ctid = GetPostString("ctid");
  11293. double price = GetPostDouble("price");
  11294. if (ctid.Length > 0)
  11295. {
  11296. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11297. if (ceErpTradeCellExtend == null)
  11298. {
  11299. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11300. ceErpTradeCellExtend.ctid = ctid;
  11301. ceErpTradeCellExtend.payment_cyt = price;
  11302. ceErpTradeCellExtend.Create();
  11303. }
  11304. else
  11305. {
  11306. ceErpTradeCellExtend.payment_cyt = price;
  11307. ceErpTradeCellExtend.Update();
  11308. }
  11309. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11310. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11311. {
  11312. ceErpDataSendOrderInfo.isSync = false;
  11313. ceErpDataSendOrderInfo.Update();
  11314. }
  11315. if (ceErpDataSendOrderInfo == null)
  11316. {
  11317. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11318. ceErpDataSendOrderInfo.isSync = false;
  11319. ceErpDataSendOrderInfo.ctid = ctid;
  11320. ceErpDataSendOrderInfo.Create();
  11321. }
  11322. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11323. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11324. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11325. if (dth != null && dth.Rows.Count > 0 && ceErpTradeCellExtend.payment_cyt > 0)
  11326. {
  11327. dataSendOrderBean dataSendOrderBean = null;
  11328. foreach (DataRow item in dth.Rows)
  11329. {
  11330. try
  11331. {
  11332. dataSendOrderBean = new dataSendOrderBean();
  11333. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11334. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11335. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11336. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11337. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11338. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11339. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11340. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11341. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11342. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11343. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11344. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11345. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11346. if (result != null)
  11347. {
  11348. if ("0".Equals(result.errcode))
  11349. {
  11350. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11351. }
  11352. else
  11353. {
  11354. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11355. }
  11356. }
  11357. }
  11358. catch (Exception ex)
  11359. {
  11360. }
  11361. }
  11362. }
  11363. returnSuccessMsg("修改成功!");
  11364. return;
  11365. }
  11366. returnErrorMsg("找不到订单");
  11367. }
  11368. public void find_he_together()
  11369. {
  11370. string ctid = GetPostString("ctid");
  11371. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11372. List<string> list = new List<string>();
  11373. if (ceErpTradeCell != null)
  11374. {
  11375. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11376. {
  11377. 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);
  11378. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11379. if (table != null && table.Rows.Count > 0)
  11380. {
  11381. foreach (TableRow row in table.Rows)
  11382. {
  11383. }
  11384. }
  11385. }
  11386. }
  11387. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11388. }
  11389. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11390. {
  11391. //chy----19
  11392. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11393. //GD-CYT-----64
  11394. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11395. //ZHX----3
  11396. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11397. //JK----97
  11398. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11399. //ZT----70
  11400. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11401. //LHCY-----98
  11402. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11403. //XD-----90
  11404. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11405. //CYCY-----14
  11406. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11407. };
  11408. //其他改名
  11409. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11410. {
  11411. {15,"滴塑" }, {119,"数码" }, {121,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11412. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11413. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11414. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11415. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11416. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11417. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11418. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11419. };
  11420. //不统计
  11421. List<int> no_suppliers = new List<int>()
  11422. {
  11423. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11424. };
  11425. //配件单
  11426. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11427. {
  11428. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11429. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11430. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11431. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11432. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11433. {"旗杆",new List<string>(){ "班旗" } },
  11434. {"牙签",new List<string>(){ "不干胶" } }
  11435. };
  11436. public void get_place_order_data()
  11437. {
  11438. string date1 = GetPostString("date1");
  11439. string date2 = GetPostString("date2");
  11440. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11441. DateTime start = DateTime.Parse(starttime);
  11442. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11443. DateTime end = DateTime.Parse(endtime);
  11444. if (date1 != null && date1.Length > 0)
  11445. {
  11446. DateTime dateTime = DateTime.Parse(date1);
  11447. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11448. start = DateTime.Parse(starttime);
  11449. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11450. end = DateTime.Parse(endtime);
  11451. }
  11452. if (date2 != null && date2.Length > 0)
  11453. {
  11454. DateTime dateTime = DateTime.Parse(date2);
  11455. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11456. end = DateTime.Parse(endtime);
  11457. }
  11458. 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);
  11459. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11460. //不干胶-----1,卡片-----29
  11461. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11462. foreach (DataRow row in data.Rows)
  11463. {
  11464. int productId = Convert.ToInt32(row["ProductId"]);
  11465. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11466. if (no_suppliers.Contains(supplierId))
  11467. {
  11468. continue;
  11469. }
  11470. string seller_memo = row["seller_memo"].ToString();
  11471. bool ispj = false;//是否配件单
  11472. bool isfirst = true;//第一个配
  11473. maps.Keys.ForEach(key =>
  11474. {
  11475. //备注包含配件
  11476. if (seller_memo.Contains(key) && isfirst)
  11477. {
  11478. List<string> list = maps[key];
  11479. ispj = true;
  11480. isfirst = false;
  11481. for (int i = 0; i < list.Count; i++)
  11482. {
  11483. if (seller_memo.Contains(list[i]))
  11484. {
  11485. ispj = false;
  11486. break;
  11487. }
  11488. }
  11489. }
  11490. });
  11491. if (ispj)
  11492. {
  11493. continue;
  11494. }
  11495. seller_memo = seller_memo.Replace("UV", "uv");
  11496. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11497. //吊牌归到卡片
  11498. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11499. seller_memo = seller_memo.Replace("卡套", "卡片");
  11500. seller_memo = seller_memo.Replace("封套", "卡片");
  11501. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11502. seller_memo = seller_memo.Replace("腰封", "卡片");
  11503. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11504. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11505. seller_memo = seller_memo.Replace("横幅", "条幅");
  11506. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11507. string map_key = "";
  11508. string type = "";
  11509. if (supplierMap.ContainsKey(supplierId))
  11510. {
  11511. foreach (var kvp in supplierMap[supplierId])
  11512. {
  11513. if (seller_memo.Contains(kvp.Key))
  11514. {
  11515. map_key = kvp.Value;
  11516. type = kvp.Value;
  11517. break;
  11518. }
  11519. }
  11520. }
  11521. if (map_key == "")
  11522. {
  11523. type = "其他";
  11524. map_key = "其他";
  11525. }
  11526. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11527. {
  11528. map_key = suppliers[supplierId];
  11529. }
  11530. if (supplierId == 70)
  11531. {
  11532. supplierId = 70;
  11533. }
  11534. map_key += "_" + row["SupplierName"].ToString();
  11535. Dictionary<string, int> map = null;
  11536. if (other_map.ContainsKey(map_key))
  11537. {
  11538. other_map.TryGetValue(map_key, out map);
  11539. }
  11540. else
  11541. {
  11542. map = new Dictionary<string, int>();
  11543. map.Add("dayDev", 0);//当天出货
  11544. map.Add("dayTotal", 0);//下单总数
  11545. map.Add("payTotal", 0);//500以上
  11546. map.Add("today", 0);//当天出货数量
  11547. map.Add("unusua", 0);//异常数
  11548. other_map.Add(map_key, map);
  11549. other_map.TryGetValue(map_key, out map);
  11550. }
  11551. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11552. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11553. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11554. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11555. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11556. {
  11557. map["dayTotal"]++;
  11558. if (supplierId == 97)
  11559. {
  11560. supplierId = 97;
  11561. }
  11562. }
  11563. if (Convert.ToDecimal(row["payment"]) >= 500)
  11564. {
  11565. map["payTotal"]++;
  11566. }
  11567. bool istoday = false;
  11568. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11569. {
  11570. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11571. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11572. {
  11573. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11574. {
  11575. map["today"]++;
  11576. }
  11577. }
  11578. else
  11579. {
  11580. if (supplierId == 80)
  11581. {
  11582. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11583. {
  11584. map["today"]++;
  11585. }
  11586. }
  11587. else if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11588. {
  11589. map["today"]++;
  11590. istoday = true;
  11591. }
  11592. }
  11593. }
  11594. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11595. {
  11596. map["unusua"]++;
  11597. }
  11598. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11599. //GD-CYT-----64
  11600. DateTime two = palceTimeStart.AddHours(14);
  11601. DateTime three = palceTimeStart.AddHours(15);
  11602. DateTime four = palceTimeStart.AddHours(16);
  11603. DateTime six = palceTimeStart.AddHours(18);
  11604. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11605. {
  11606. //下午四点前 500-1000
  11607. string count = row["ProductCount"].ToString();
  11608. if (count != null && count.Length > 0)
  11609. {
  11610. int productCount = commonHelper.getPlaceProductCount(count);
  11611. if (productCount >= 500 && productCount <= 1000)
  11612. {
  11613. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11614. {
  11615. map["dayDev"]++;
  11616. }
  11617. }
  11618. }
  11619. }
  11620. //UV
  11621. else if ("uv".Equals(type))
  11622. {
  11623. //ZT----70
  11624. //ZHX----3
  11625. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11626. {
  11627. map["dayDev"]++;
  11628. }
  11629. //JK----97
  11630. //HZX----105
  11631. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11632. {
  11633. map["dayDev"]++;
  11634. }
  11635. }
  11636. //帆布---52|条幅---27
  11637. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11638. {
  11639. //LHCY-----98
  11640. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11641. {
  11642. map["dayDev"]++;
  11643. }
  11644. }
  11645. //条幅
  11646. else if ("条幅".Equals(type))
  11647. {
  11648. //XD-----90
  11649. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11650. {
  11651. map["dayDev"]++;
  11652. }
  11653. }
  11654. //桌布
  11655. else if ("桌布".Equals(type))
  11656. {
  11657. //XD-----90
  11658. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11659. {
  11660. map["dayDev"]++;
  11661. }
  11662. }
  11663. //DL---10
  11664. //AYTW---119
  11665. //FS-CYT-DY ----80
  11666. //JK----97
  11667. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11668. {
  11669. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11670. {
  11671. map["dayDev"]++;
  11672. if (supplierId == 80 && istoday)
  11673. {
  11674. Debug.WriteLine(seller_memo);
  11675. }
  11676. }
  11677. }
  11678. // QC---121
  11679. else if (supplierId == 121)
  11680. {
  11681. if (DateTime.Compare(FinishPlaceTime, six) < 0)
  11682. {
  11683. map["dayDev"]++;
  11684. }
  11685. }
  11686. }
  11687. DataTable dt = new DataTable();
  11688. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11689. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11690. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11691. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11692. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11693. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11694. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11695. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11696. other_map.Keys.ForEach(key =>
  11697. {
  11698. DataRow dr = dt.NewRow();
  11699. Dictionary<string, int> map = other_map[key];
  11700. string[] key_list = key.Split('_');
  11701. dr[0] = key_list[0];
  11702. dr[1] = key_list[1];
  11703. if (key_list.Length > 2)
  11704. {
  11705. dr[1] += "(" + key_list[2] + ")";
  11706. }
  11707. dr[2] = map["dayTotal"];
  11708. dr[3] = map["payTotal"];
  11709. dr[4] = map["today"];
  11710. dr[5] = map["unusua"];
  11711. dr[6] = map["dayDev"];
  11712. double rate = 0.00;
  11713. if (map["dayDev"] > 0)
  11714. {
  11715. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11716. }
  11717. dr[7] = rate.ToString();
  11718. dt.Rows.Add(dr);
  11719. });
  11720. DataView dv = new DataView(dt);
  11721. dv.Sort = "SupplierName";
  11722. //dv.Sort = "AllOrder desc";
  11723. DataTable dtNew = dv.ToTable();
  11724. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11725. }
  11726. public void check_order_desing_info()
  11727. {
  11728. string ctid = GetPostString("ctid");
  11729. if (!string.IsNullOrEmpty(ctid))
  11730. {
  11731. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11732. if (ceErpTradeCell != null)
  11733. {
  11734. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11735. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11736. return;
  11737. }
  11738. returnErrorMsg("找不到订单");
  11739. return;
  11740. }
  11741. returnErrorMsg("找不到订单");
  11742. }
  11743. public void get_timeout_detail()
  11744. {
  11745. string poscode = CurrentUser.UserPost.Post.Code;
  11746. DataStruct dStruct = GetPostStruct();
  11747. List<string> lw = new List<string>();
  11748. string id = GetPostString("id");
  11749. string pay_date1 = GetPostString("pay_date1");
  11750. string pay_date2 = GetPostString("pay_date2");
  11751. int type = GetPostInt("type");
  11752. if (type == 0)
  11753. {
  11754. if (pay_date1.Length > 0)
  11755. {
  11756. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11757. }
  11758. if (pay_date2.Length > 0)
  11759. {
  11760. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11761. }
  11762. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11763. }
  11764. if (type == 1)
  11765. {
  11766. if (pay_date1.Length > 0)
  11767. {
  11768. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11769. }
  11770. if (pay_date2.Length > 0)
  11771. {
  11772. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11773. }
  11774. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11775. }
  11776. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11777. DataTable dt = null;
  11778. dt = WebCache.GetData("view_orderlist", dStruct);
  11779. writeGridDataTableJson(dStruct.TotalCount, dt);
  11780. }
  11781. public void saveUrgentChargePrice()
  11782. {
  11783. string ctid = GetPostString("ctid");
  11784. if (!string.IsNullOrEmpty(ctid))
  11785. {
  11786. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11787. if (ceErpTradeCell != null)
  11788. {
  11789. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  11790. if (prices <= 100)
  11791. {
  11792. returnErrorMsg("此订单金额不足100元,无法加急。");
  11793. return;
  11794. }
  11795. double price = GetPostDouble("price");
  11796. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11797. if (ceErpTradeCellExtend == null)
  11798. {
  11799. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11800. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11801. }
  11802. ceErpTradeCellExtend.urgentCharge = price;
  11803. if (ceErpTradeCellExtend.ID > 0)
  11804. {
  11805. ceErpTradeCellExtend.Update();
  11806. }
  11807. else
  11808. {
  11809. ceErpTradeCellExtend.Save();
  11810. }
  11811. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  11812. returnSuccessMsg("修改成功!");
  11813. return;
  11814. }
  11815. returnErrorMsg("找不到订单");
  11816. return;
  11817. }
  11818. returnErrorMsg("找不到订单");
  11819. }
  11820. public void finish_erp_order()
  11821. {
  11822. string ctid = GetPostString("ctid");
  11823. if (!string.IsNullOrEmpty(ctid))
  11824. {
  11825. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11826. {
  11827. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11828. if (ceErpTradeCell != null)
  11829. {
  11830. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11831. ceErpTradeCell.Update();
  11832. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11833. returnSuccessMsg("修改成功!");
  11834. return;
  11835. }
  11836. }
  11837. }
  11838. returnErrorMsg("找不到订单");
  11839. }
  11840. public void get_trade_order_list()
  11841. {
  11842. string tid = GetPostString("tid");
  11843. if (!string.IsNullOrEmpty(tid))
  11844. {
  11845. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11846. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11847. writeGridDataTableJson(data.Rows.Count, data);
  11848. return;
  11849. }
  11850. returnErrorMsg("找不到订单");
  11851. }
  11852. public void save_cell_spu()
  11853. {
  11854. string ctid = GetPostString("ctid");
  11855. string spu_id = GetPostString("spu_id");
  11856. if (!string.IsNullOrEmpty(ctid))
  11857. {
  11858. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11859. if (ceErpTradeCellExtend == null)
  11860. {
  11861. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11862. ceErpTradeCellExtend.ctid = ctid;
  11863. }
  11864. ceErpTradeCellExtend.spu_id = spu_id;
  11865. if (!string.IsNullOrEmpty(spu_id))
  11866. {
  11867. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11868. ceErpTradeCellExtend = commonHelper.sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  11869. }
  11870. if (ceErpTradeCellExtend.ID == 0)
  11871. {
  11872. ceErpTradeCellExtend.Create();
  11873. }
  11874. else
  11875. {
  11876. ceErpTradeCellExtend.Update();
  11877. }
  11878. returnSuccessMsg("修改成功!");
  11879. return;
  11880. }
  11881. returnErrorMsg("找不到订单");
  11882. }
  11883. public void change_express_info()
  11884. {
  11885. string ctid = GetPostString("ctid");
  11886. string transNo = GetPostString("transNo");
  11887. string transCom = GetPostString("transCom");
  11888. if (!string.IsNullOrEmpty(ctid))
  11889. {
  11890. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11891. if (ceErpTradeCellExtend == null)
  11892. {
  11893. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11894. ceErpTradeCellExtend.ctid = ctid;
  11895. }
  11896. ceErpTradeCellExtend.modExpressNo = transNo;
  11897. ceErpTradeCellExtend.modExpressCom = transCom;
  11898. ceErpTradeCellExtend.readMod = 2;
  11899. if (ceErpTradeCellExtend.ID == 0)
  11900. {
  11901. ceErpTradeCellExtend.Create();
  11902. }
  11903. else
  11904. {
  11905. ceErpTradeCellExtend.Update();
  11906. }
  11907. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11908. returnSuccessMsg("修改成功!");
  11909. return;
  11910. }
  11911. returnErrorMsg("找不到订单");
  11912. }
  11913. public void get_change_express_list()
  11914. {
  11915. DataStruct dStruct = GetPostStruct();
  11916. List<string> lw = new List<string>();
  11917. int st = 2;
  11918. string tid = GetPostString("ctid");
  11919. if (tid.Length > 0)
  11920. {
  11921. string select_tid = getTidByCtid(tid);
  11922. lw.Add(string.Format("tid='{0}'", select_tid));
  11923. }
  11924. string shopname = GetPostString("shopname");
  11925. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11926. string buyernick = GetPostString("buyer_nick");
  11927. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11928. string sellermemo = GetPostString("seller_memo");
  11929. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11930. string supplier = GetPostString("supplier");
  11931. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11932. string customer = GetPostString("customer");
  11933. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11934. string design = GetPostString("design");
  11935. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11936. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11937. string poscode = CurrentUser.UserPost.Post.Code;
  11938. if (poscode != "SysAdmin")
  11939. {
  11940. string shopid = CurrentUser.User.pemShop;
  11941. lw.Add(string.Format("shopId in ({0})", shopid));
  11942. }
  11943. lw.Add("readMod = 2");
  11944. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11945. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11946. writeGridDataTableJson(dStruct.TotalCount, dt);
  11947. }
  11948. public void deal_express_complete()
  11949. {
  11950. string ctid = GetPostString("ctid");
  11951. if (!string.IsNullOrEmpty(ctid))
  11952. {
  11953. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11954. if (ceErpTradeCellExtend == null)
  11955. {
  11956. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11957. ceErpTradeCellExtend.ctid = ctid;
  11958. }
  11959. ceErpTradeCellExtend.readMod = 1;
  11960. if (ceErpTradeCellExtend.ID == 0)
  11961. {
  11962. ceErpTradeCellExtend.Create();
  11963. }
  11964. else
  11965. {
  11966. ceErpTradeCellExtend.Update();
  11967. }
  11968. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11969. returnSuccessMsg("修改成功!");
  11970. return;
  11971. }
  11972. returnErrorMsg("找不到订单");
  11973. }
  11974. public void aftersale_return_visit()
  11975. {
  11976. string ctid = GetPostString("ctid");
  11977. if (!string.IsNullOrEmpty(ctid))
  11978. {
  11979. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11980. if (ceErpTradeCellExtend == null)
  11981. {
  11982. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11983. ceErpTradeCellExtend.ctid = ctid;
  11984. }
  11985. ceErpTradeCellExtend.returnVisit = 1;
  11986. if (ceErpTradeCellExtend.ID == 0)
  11987. {
  11988. ceErpTradeCellExtend.Create();
  11989. }
  11990. else
  11991. {
  11992. ceErpTradeCellExtend.Update();
  11993. }
  11994. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11995. if (ceErpTradeAfterSaleExtend != null)
  11996. {
  11997. ceErpTradeAfterSaleExtend.TextResult = "";
  11998. ceErpTradeAfterSaleExtend.Update();
  11999. }
  12000. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  12001. returnSuccessMsg("修改成功!");
  12002. return;
  12003. }
  12004. returnErrorMsg("找不到订单");
  12005. }
  12006. public void orderPlaceInfo()
  12007. {
  12008. string ctids = GetPostString("ctids");
  12009. string[] list = ctids.Split(',');
  12010. foreach (string ctid in list)
  12011. {
  12012. CeErpSukuraData.createInfo(ctid, 3);
  12013. }
  12014. StringBuilder sql = new StringBuilder();
  12015. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  12016. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  12017. designHelper.api_approveDesign(ctids); //approveDesign
  12018. returnSuccessMsg("");
  12019. }
  12020. public void get_issue_list()
  12021. {
  12022. DataStruct dStruct = GetPostStruct();
  12023. List<string> lw = new List<string>();
  12024. int st = 2;
  12025. string tid = GetPostString("ctid");
  12026. if (tid.Length > 0)
  12027. {
  12028. string select_tid = getTidByCtid(tid);
  12029. lw.Add(string.Format("tid='{0}'", select_tid));
  12030. }
  12031. string shopname = GetPostString("shopname");
  12032. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  12033. string buyernick = GetPostString("buyer_nick");
  12034. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  12035. string sellermemo = GetPostString("seller_memo");
  12036. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  12037. string supplier = GetPostString("supplier");
  12038. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  12039. string customer = GetPostString("customer");
  12040. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  12041. string design = GetPostString("design");
  12042. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  12043. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  12044. string poscode = CurrentUser.UserPost.Post.Code;
  12045. if (poscode != "SysAdmin")
  12046. {
  12047. string shopid = CurrentUser.User.pemShop;
  12048. lw.Add(string.Format("shopId in ({0})", shopid));
  12049. }
  12050. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  12051. {
  12052. lw.Add("IssueState = 1");
  12053. }
  12054. else
  12055. {
  12056. string iisstate = GetPostString("iisstate");
  12057. if ("1".Equals(iisstate))
  12058. {
  12059. lw.Add("IssueState =1");
  12060. }
  12061. else if ("2".Equals(iisstate))
  12062. {
  12063. lw.Add("IssueState = 2");
  12064. }
  12065. else
  12066. {
  12067. lw.Add("IssueState > 0");
  12068. }
  12069. }
  12070. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12071. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  12072. writeGridDataTableJson(dStruct.TotalCount, dt);
  12073. }
  12074. public void saveIssueContent()
  12075. {
  12076. string ctid = GetPostString("ctid");
  12077. if (!string.IsNullOrEmpty(ctid))
  12078. {
  12079. string content = GetPostString("content");
  12080. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12081. if (ceErpTradeAfterSaleExtend == null)
  12082. {
  12083. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  12084. ceErpTradeAfterSaleExtend.tid = ctid;
  12085. }
  12086. ceErpTradeAfterSaleExtend.IssueContent = content;
  12087. ceErpTradeAfterSaleExtend.IssueState = 1;
  12088. if (ceErpTradeAfterSaleExtend.ID > 0)
  12089. {
  12090. ceErpTradeAfterSaleExtend.Update();
  12091. }
  12092. else
  12093. {
  12094. ceErpTradeAfterSaleExtend.Create();
  12095. }
  12096. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  12097. returnSuccessMsg("添加成功!");
  12098. return;
  12099. }
  12100. returnErrorMsg("找不到订单");
  12101. }
  12102. public void dealIssueContent()
  12103. {
  12104. string ctid = GetPostString("ctid");
  12105. if (!string.IsNullOrEmpty(ctid))
  12106. {
  12107. string content = GetPostString("content");
  12108. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12109. if (ceErpTradeAfterSaleExtend != null)
  12110. {
  12111. ceErpTradeAfterSaleExtend.IssueState = 2;
  12112. ceErpTradeAfterSaleExtend.Update();
  12113. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  12114. returnSuccessMsg("修改完成!");
  12115. return;
  12116. }
  12117. }
  12118. returnErrorMsg("找不到订单");
  12119. }
  12120. public void set_tid_attachments()
  12121. {
  12122. string tid = GetPostString("tid");
  12123. string atta = GetPostString("atta");
  12124. if (!string.IsNullOrEmpty(tid))
  12125. {
  12126. if (string.IsNullOrEmpty(atta))
  12127. {
  12128. returnErrorMsg("文件地址为空");
  12129. return;
  12130. }
  12131. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12132. if (ceErpTradeCell != null)
  12133. {
  12134. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12135. if (ceErpTrade == null)
  12136. {
  12137. returnErrorMsg("找不到订单");
  12138. return;
  12139. }
  12140. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  12141. bool isSend = false;
  12142. if (dt != null && dt.Rows.Count > 0)
  12143. {
  12144. foreach (DataRow row in dt.Rows)
  12145. {
  12146. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  12147. {
  12148. isSend = true;
  12149. }
  12150. }
  12151. if (isSend)
  12152. {
  12153. returnErrorMsg("已发货无法修改");
  12154. return;
  12155. }
  12156. ceErpTrade.Attachments = atta;
  12157. ceErpTrade.Update();
  12158. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  12159. returnSuccessMsg("上传成功!");
  12160. return;
  12161. }
  12162. }
  12163. }
  12164. returnErrorMsg("找不到订单");
  12165. }
  12166. public void get_tid_attachments()
  12167. {
  12168. string tid = GetPostString("tid");
  12169. if (!string.IsNullOrEmpty(tid))
  12170. {
  12171. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12172. if (ceErpTradeCell != null)
  12173. {
  12174. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12175. if (ceErpTrade == null)
  12176. {
  12177. returnErrorMsg("找不到订单");
  12178. return;
  12179. }
  12180. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  12181. return;
  12182. }
  12183. }
  12184. returnErrorMsg("找不到订单");
  12185. }
  12186. public void check_erp_sameorders()
  12187. {
  12188. if (UrlPostParmsCheck("ctid"))
  12189. {
  12190. string eid = GetPostString("ctid");
  12191. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12192. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12193. if (entity != null && ceErpTrade != null)
  12194. {
  12195. if (entity.OrderState > 6)
  12196. {
  12197. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12198. return;
  12199. }
  12200. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12201. List<string> ids = new List<string>();
  12202. if (dt != null && dt.Rows.Count > 1)
  12203. {
  12204. bool needhe = true;
  12205. foreach (DataRow dr in dt.Rows)
  12206. {
  12207. ids.Add("'" + dr["ctid"] + "'");
  12208. /* //备注有合包
  12209. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12210. {
  12211. needhe = true;
  12212. }
  12213. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12214. {
  12215. needhe = true;
  12216. }
  12217. //顺丰快递
  12218. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12219. {
  12220. needhe = true;
  12221. }*/
  12222. }
  12223. if (!needhe)
  12224. {
  12225. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12226. return;
  12227. }
  12228. StringBuilder sql = new StringBuilder();
  12229. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12230. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12231. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12232. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12233. foreach (DataRow dr in dt.Rows)
  12234. {
  12235. dr["dstate"] = 0;
  12236. dr["dnumber"] = 0;
  12237. foreach (DataRow row in dt1.Rows)
  12238. {
  12239. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12240. {
  12241. dr["dstate"] = 2;
  12242. dr["default"] = 1;
  12243. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12244. }
  12245. }
  12246. if (eid.Equals(dr["ctid"].ToString()))
  12247. {
  12248. dr["dstate"] = 1;
  12249. dr["default"] = 1;
  12250. }
  12251. }
  12252. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12253. return;
  12254. }
  12255. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12256. return;
  12257. }
  12258. returnErrorMsg("未找到订单");
  12259. return;
  12260. }
  12261. returnErrorMsg("缺少必要的参数");
  12262. }
  12263. public void get_mark_number()
  12264. {
  12265. string eid = GetPostString("ctid");
  12266. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12267. if (entity != null)
  12268. {
  12269. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12270. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12271. int current = 1;
  12272. if (ceErpDeliverMark == null)
  12273. {
  12274. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12275. List<string> ids = new List<string>();
  12276. if (dt != null && dt.Rows.Count > 1)
  12277. {
  12278. foreach (DataRow dr in dt.Rows)
  12279. {
  12280. ids.Add("'" + dr["ctid"] + "'");
  12281. }
  12282. //查询已有的编号
  12283. StringBuilder sql = new StringBuilder();
  12284. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12285. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12286. if (dt1 == null || dt1.Rows.Count == 0)
  12287. {
  12288. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12289. List<int> list_number = new List<int>();
  12290. foreach (DataRow row in numbers.Rows)
  12291. {
  12292. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12293. }
  12294. //查询空余编号
  12295. for (int i = 0; i < list_number.Count + 2; i++)
  12296. {
  12297. if (!list_number.Contains(current))
  12298. {
  12299. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12300. //防止查询过程中有新数据生成
  12301. if (ceErpDeliverMark1 == null)
  12302. {
  12303. break;
  12304. }
  12305. }
  12306. current++;
  12307. }
  12308. }
  12309. else
  12310. {
  12311. foreach (DataRow row in dt1.Rows)
  12312. {
  12313. current = Convert.ToInt32(row["markNumber"]);
  12314. }
  12315. }
  12316. ceErpDeliverMark = new CeErpDeliverMark();
  12317. ceErpDeliverMark.ctid = eid;
  12318. ceErpDeliverMark.createtime = DateTime.Now;
  12319. if (ceErpTrade != null)
  12320. {
  12321. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12322. }
  12323. ceErpDeliverMark.markNumber = current;
  12324. ceErpDeliverMark.Create();
  12325. }
  12326. }
  12327. else
  12328. {
  12329. current = ceErpDeliverMark.markNumber;
  12330. }
  12331. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12332. return;
  12333. }
  12334. }
  12335. public void aftersaleCytSend()
  12336. {
  12337. string ctid = GetPostString("ctid");
  12338. if (!string.IsNullOrEmpty(ctid))
  12339. {
  12340. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12341. if (ceErpTradeCell != null)
  12342. {
  12343. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12344. }
  12345. returnSuccessMsg("推送成功");
  12346. return;
  12347. }
  12348. returnErrorMsg("缺少必要的参数");
  12349. }
  12350. public void packOrderInfo()
  12351. {
  12352. string ctids = GetPostString("ctids");
  12353. if (!string.IsNullOrEmpty(ctids))
  12354. {
  12355. string[] ctid_list = ctids.Split(',');
  12356. if (ctid_list.Length > 20)
  12357. {
  12358. returnErrorMsg("单次下载次数不能超过20个");
  12359. return;
  12360. }
  12361. string textCtids = "'" + ctids.Replace(",", "','") + "'";
  12362. StringBuilder sql = new StringBuilder();
  12363. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", textCtids);
  12364. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12365. int supplierId = 0;
  12366. StringBuilder insterSql = new StringBuilder();
  12367. for (int i = 0; i < dt.Rows.Count; i++)
  12368. {
  12369. DataRow row = dt.Rows[i];
  12370. if (i == 0)
  12371. {
  12372. supplierId = Convert.ToInt32(row["SupplierId"]);
  12373. }
  12374. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12375. {
  12376. returnErrorMsg("同车间的订单才能一起打包");
  12377. return;
  12378. }
  12379. int orderState = Convert.ToInt32(row["OrderState"]);
  12380. if (orderState != 5)
  12381. {
  12382. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12383. return;
  12384. }
  12385. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12386. }
  12387. CeErpPackData ceErpPackData = new CeErpPackData();
  12388. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + CurrentUser.UserID + ".zip";
  12389. ceErpPackData.supplierId = supplierId;
  12390. ceErpPackData.createtime = DateTime.Now;
  12391. ceErpPackData.createBy = CurrentUser.UserID;
  12392. ceErpPackData.createName = CurrentUser.UserName;
  12393. ceErpPackData.Create();
  12394. if (ceErpPackData.ID > 0)
  12395. {
  12396. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12397. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12398. }
  12399. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=6,IsVerifyToSupplier=0 where ctid in ({0}) and OrderState=5 and IsVerifyToSupplier=1", textCtids));
  12400. returnSuccessMsg("打包成功");
  12401. return;
  12402. }
  12403. returnErrorMsg("缺少必要的参数");
  12404. }
  12405. public void rePackOrderInfo()
  12406. {
  12407. string id = GetPostString("id");
  12408. if (!string.IsNullOrEmpty(id))
  12409. {
  12410. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12411. if (ceErpPackData == null)
  12412. {
  12413. returnSuccessMsg("查无数据");
  12414. return;
  12415. }
  12416. ceErpPackData.upStatus = 0;
  12417. ceErpPackData.message = "";
  12418. ceErpPackData.Update();
  12419. returnSuccessMsg("打包成功");
  12420. return;
  12421. }
  12422. returnErrorMsg("缺少必要的参数");
  12423. }
  12424. public void backPackOrderInfo()
  12425. {
  12426. string id = GetPostString("id");
  12427. if (!string.IsNullOrEmpty(id))
  12428. {
  12429. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12430. if (ceErpPackData == null)
  12431. {
  12432. returnSuccessMsg("查无数据");
  12433. return;
  12434. }
  12435. ceErpPackData.upStatus = 4;
  12436. ceErpPackData.Update();
  12437. List<string> list = new List<string>();
  12438. StringBuilder sql = new StringBuilder();
  12439. sql.AppendFormat("select * from CE_ErpPackDataItem where packId = {0}", ceErpPackData.ID);
  12440. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12441. for (int i = 0; i < dt.Rows.Count; i++)
  12442. {
  12443. DataRow row = dt.Rows[i];
  12444. list.Add("'" + row["ctid"].ToString() + "'");
  12445. }
  12446. string textCtids = string.Join(",", list);
  12447. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=5,IsVerifyToSupplier=0,IsReturn=1,ReturnTime=GETDATE(),ReturnReason='无法打包' where ctid in ({0}) and OrderState=6", textCtids));
  12448. DbHelper.DbConn.ExecuteNonQuery(string.Format("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", textCtids, (int)OrderState.下单完成, 0, "无法打包退回"));
  12449. returnSuccessMsg("退回成功");
  12450. return;
  12451. }
  12452. returnErrorMsg("缺少必要的参数");
  12453. }
  12454. public void addPackDownNum()
  12455. {
  12456. string id = GetPostString("id");
  12457. if (!string.IsNullOrEmpty(id))
  12458. {
  12459. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpPackData set downNum+=1 where id= {0}", id));
  12460. returnSuccessMsg("下载成功");
  12461. return;
  12462. }
  12463. returnErrorMsg("缺少必要的参数");
  12464. }
  12465. public void get_pack_list()
  12466. {
  12467. DataStruct dStruct = GetPostStruct();
  12468. List<string> lw = new List<string>();
  12469. string supplier = GetPostString("supplier");
  12470. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12471. string posTag = CurrentUser.UserPost.Post.Code;
  12472. if (posTag == "Supplier")
  12473. {
  12474. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12475. }
  12476. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12477. dStruct.Order = "createtime desc";
  12478. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12479. writeGridDataTableJson(dStruct.TotalCount, dt);
  12480. }
  12481. public void get_pack_order_list()
  12482. {
  12483. string packId = GetPostString("packId");
  12484. if (string.IsNullOrEmpty(packId))
  12485. {
  12486. returnErrorMsg("缺少必要的参数");
  12487. return;
  12488. }
  12489. StringBuilder sql = new StringBuilder();
  12490. sql.AppendFormat("select c.ctid,c.seller_memo,i.message from CE_ErpPackDataItem i left join CE_ErpTradeCell c on i.ctid=c.ctid where i.packId = {0}", packId);
  12491. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12492. if (dt == null || dt.Rows.Count == 0)
  12493. {
  12494. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12495. return;
  12496. }
  12497. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12498. return;
  12499. }
  12500. public void get_supplier_product_time_list()
  12501. {
  12502. DataStruct dStruct = GetPostStruct();
  12503. List<string> lw = new List<string>();
  12504. string supplier = GetPostString("supplier");
  12505. if (supplier.Length > 0) lw.Add(string.Format("supplierName = '{0}'", supplier));
  12506. string posTag = CurrentUser.UserPost.Post.Code;
  12507. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12508. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12509. writeGridDataTableJson(dStruct.TotalCount, dt);
  12510. }
  12511. public void saveSupplierProductTime()
  12512. {
  12513. string productId = GetPostString("productId");
  12514. if (string.IsNullOrEmpty(productId))
  12515. {
  12516. returnErrorMsg("缺少必要的参数");
  12517. return;
  12518. }
  12519. string productName = GetPostString("productName");
  12520. int supplierId = GetPostInt("supplierId");
  12521. if (supplierId == 0)
  12522. {
  12523. returnErrorMsg("缺少必要的参数");
  12524. return;
  12525. }
  12526. int quantity = GetPostInt("quantity");
  12527. int sendDay = GetPostInt("sendTime");
  12528. string supplierName = GetPostString("supplierName");
  12529. string craft = GetPostString("craft");
  12530. string deadLine = GetPostString("deadLine");
  12531. string dayDeadLine = GetPostString("dayDeadLine");
  12532. try
  12533. {
  12534. int eid = GetPostInt("eid");
  12535. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12536. if (ceErpSupplierProductTime == null)
  12537. {
  12538. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12539. }
  12540. ceErpSupplierProductTime.productId = productId;
  12541. ceErpSupplierProductTime.productName = productName;
  12542. ceErpSupplierProductTime.supplierId = supplierId;
  12543. ceErpSupplierProductTime.supplierName = supplierName;
  12544. ceErpSupplierProductTime.craft = craft;
  12545. ceErpSupplierProductTime.sendDay = sendDay;
  12546. ceErpSupplierProductTime.quantity = quantity;
  12547. if (!string.IsNullOrEmpty(deadLine))
  12548. {
  12549. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  12550. }
  12551. if (!string.IsNullOrEmpty(dayDeadLine))
  12552. {
  12553. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  12554. }
  12555. if (ceErpSupplierProductTime.ID == 0)
  12556. {
  12557. ceErpSupplierProductTime.Save();
  12558. }
  12559. else
  12560. {
  12561. ceErpSupplierProductTime.Update();
  12562. }
  12563. }
  12564. catch (Exception e)
  12565. {
  12566. }
  12567. returnSuccessMsg("保存成功");
  12568. return;
  12569. }
  12570. public void delSupplierProductTime()
  12571. {
  12572. int eid = GetPostInt("eid");
  12573. if (eid > 0)
  12574. {
  12575. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12576. if (ceErpSupplierProductTime == null)
  12577. {
  12578. returnErrorMsg("查无数据");
  12579. return;
  12580. }
  12581. ceErpSupplierProductTime.Delete();
  12582. returnSuccessMsg("保存成功");
  12583. return;
  12584. }
  12585. returnErrorMsg("缺少必要的参数");
  12586. }
  12587. public void getExpressInfo()
  12588. {
  12589. string ctid = GetPostString("ctid");
  12590. if (!string.IsNullOrEmpty(ctid))
  12591. {
  12592. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12593. if (ceErpTradeCell != null)
  12594. {
  12595. string outSid = ceErpTradeCell.OutSid;
  12596. if (outSid.Length > 0)
  12597. {
  12598. string sql = string.Format("SELECT out_sid FROM [dbo].[CE_ErpExpressInfo] WHERE (out_sid in ({0}) or tid = '{1}') and ISNULL(DATALENGTH(postData), 0)>0;", "'" + outSid.Replace(",", "','") + "'", ceErpTradeCell.tid);
  12599. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12600. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12601. return;
  12602. }
  12603. }
  12604. returnErrorMsg("查无记录");
  12605. return;
  12606. }
  12607. returnErrorMsg("缺少必要的参数");
  12608. }
  12609. public void getExpressPostData()
  12610. {
  12611. string express = GetPostString("express");
  12612. if (!string.IsNullOrEmpty(express))
  12613. {
  12614. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  12615. if (ceErpExpressInfo != null)
  12616. {
  12617. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  12618. return;
  12619. }
  12620. }
  12621. returnErrorMsg("缺少必要的参数");
  12622. }
  12623. public void checkSupplierOrder()
  12624. {
  12625. string ctids = GetPostString("ctids");
  12626. if (ctids != null)
  12627. {
  12628. List<string> list = new List<string>();
  12629. string sql = string.Format("SELECT ctid,seller_memo,OrderState,IsVerifyToSupplier FROM [dbo].[CE_ErpTradeCell] WHERE ctid in ({0});", "'" + ctids.Replace(",", "','") + "'");
  12630. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12631. for (int i = 0; i < dt.Rows.Count; i++)
  12632. {
  12633. DataRow row = dt.Rows[i];
  12634. if (Convert.ToInt16(row["OrderState"]) == 6 && Convert.ToInt16(row["IsVerifyToSupplier"]) == 1)
  12635. {
  12636. continue;
  12637. }
  12638. list.Add(row["seller_memo"].ToString());
  12639. }
  12640. if (list.Count > 0)
  12641. {
  12642. DbHelper.DbConn.ExecuteNonQuery(string.Format("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", "'" + ctids.Replace(",", "','") + "'", (int)OrderState.下单完成, CurrentUser.UserID, "点击下载按钮"));
  12643. ReturnSuccess("{" + string.Format("\"data\":{0}", JsonConvert.SerializeObject(list)) + "}");
  12644. return;
  12645. }
  12646. }
  12647. ReturnSuccess("{" + string.Format("\"data\":{0}", "[]") + "}");
  12648. return;
  12649. }
  12650. public void addPersonId()
  12651. {
  12652. string tid = GetPostString("tid");
  12653. string personId = GetPostString("personId");
  12654. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12655. if (ceErpTrade != null)
  12656. {
  12657. ceErpTrade.receiver_zip = personId;
  12658. ceErpTrade.Update();
  12659. LogHelper.addLog(tid, CurrentUser.UserID, "身份证号:" + personId, 6);
  12660. returnSuccessMsg("保存成功");
  12661. return;
  12662. }
  12663. returnErrorMsg("缺少必要的参数");
  12664. }
  12665. public void addDeliveryPaymant()
  12666. {
  12667. string tid = GetPostString("tid");
  12668. string paymant = GetPostString("paymant");
  12669. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12670. if (ceErpTrade != null)
  12671. {
  12672. if (!string.IsNullOrEmpty(paymant))
  12673. {
  12674. ceErpTrade.delivery_paymant = Convert.ToDouble(paymant);
  12675. }
  12676. ceErpTrade.Update();
  12677. LogHelper.addLog(tid, CurrentUser.UserID, "偏远物流费:" + paymant, 6);
  12678. returnSuccessMsg("保存成功");
  12679. return;
  12680. }
  12681. returnErrorMsg("缺少必要的参数");
  12682. }
  12683. public void saveCellFile()
  12684. {
  12685. string tid = GetPostString("tid");
  12686. string ctid = GetPostString("ctid");
  12687. string urls = GetPostString("urls");
  12688. string type = GetPostString("type");
  12689. string del = GetPostString("del");
  12690. if (Enum.TryParse(type, out TradeCellFile tradeCellFile))
  12691. {
  12692. if ("1".Equals(del))
  12693. {
  12694. CeErpTradeCellFile.delByCtid(tid, ctid, tradeCellFile.ToString());
  12695. }
  12696. string[] list = urls.Split(',');
  12697. if (!string.IsNullOrEmpty(urls) && list.Length > 0)
  12698. {
  12699. foreach (string item in list)
  12700. {
  12701. CeErpTradeCellFile ceErpTradeCellFile = new CeErpTradeCellFile(tid, ctid, item, tradeCellFile.ToString());
  12702. ceErpTradeCellFile.Create();
  12703. LogHelper.addLog(ctid, CurrentUser.UserID, "上传客户文件:" + item, 6);
  12704. }
  12705. }
  12706. returnSuccessMsg("保存成功");
  12707. return;
  12708. }
  12709. returnErrorMsg("缺少必要的参数");
  12710. }
  12711. public void getCellFile()
  12712. {
  12713. string tid = GetPostString("tid");
  12714. string ctid = GetPostString("ctid");
  12715. string type = GetPostString("type");
  12716. if (Enum.TryParse(type, out TradeCellFile tradeCellFile))
  12717. {
  12718. string sql = string.Format("SELECT * FROM [dbo].[CE_ErpTradeCellFile] WHERE isDel=0 and tid='{0}' and ctid='{1}' and type='{2}';", tid, ctid, tradeCellFile);
  12719. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12720. ReturnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  12721. return;
  12722. }
  12723. returnErrorMsg("缺少必要的参数");
  12724. }
  12725. public void delCellFile()
  12726. {
  12727. string id = GetPostString("id");
  12728. if (string.IsNullOrEmpty(id))
  12729. {
  12730. returnErrorMsg("缺少必要的参数");
  12731. return;
  12732. }
  12733. CeErpTradeCellFile ceErpTradeCellFile = CeErpTradeCellFile.Get(id);
  12734. CeErpTradeCellFile.delByID(id);
  12735. LogHelper.addLog(ceErpTradeCellFile.ctid, CurrentUser.UserID, "删除客户文件", 6);
  12736. returnSuccessMsg("保存成功");
  12737. }
  12738. }
  12739. }