No Description

WxLoginController.cs 303KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563
  1. using CallCenter.Utility;
  2. using CallCenterApi.DB;
  3. using CallCenterApi.Interface.App_Start;
  4. using CallCenterApi.Interface.Controllers.Base;
  5. using CallCenterApi.Interface.Controllers.workorder;
  6. using CallCenterApi.Interface.Models.Enum;
  7. using CallCenterApi.Interface.Models.Input;
  8. using CallCenterAPI.WechatSDK;
  9. using CallCenterAPI.WechatSDK.Models;
  10. using qcloudsms_csharp;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Data;
  14. using System.IO;
  15. using System.Linq;
  16. using System.Text.RegularExpressions;
  17. using System.Web;
  18. using System.Web.Mvc;
  19. namespace CallCenterApi.Interface.Controllers.weixin
  20. {
  21. public class WxLoginController : BaseController
  22. {
  23. private readonly BLL.T_Sys_UserAccount userAccountBLL = new BLL.T_Sys_UserAccount();
  24. private readonly BLL.T_Sys_RoleInfo roleBLL = new BLL.T_Sys_RoleInfo();
  25. private readonly BLL.T_Cus_CustomerBaseNew customerBaseBLL = new BLL.T_Cus_CustomerBaseNew();
  26. private readonly BLL.T_Cus_CustomerFinance finbll = new BLL.T_Cus_CustomerFinance();
  27. private readonly BLL.T_Wo_WorkOrder woBLL = new BLL.T_Wo_WorkOrder();
  28. private readonly BLL.T_Sys_Department departmentBLL = new BLL.T_Sys_Department();
  29. private readonly BLL.T_Wo_WorkOrderItem_New itembll = new BLL.T_Wo_WorkOrderItem_New();
  30. private readonly BLL.T_Wo_WorkOrder_Logs blllogs = new BLL.T_Wo_WorkOrder_Logs();
  31. private readonly BLL.T_Sys_RoleInfo rolebll = new BLL.T_Sys_RoleInfo();
  32. private readonly BLL.T_Sys_DictionaryValue dicvalueBll = new BLL.T_Sys_DictionaryValue();
  33. private readonly BLL.T_Wo_MaterialManage mmBLL = new BLL.T_Wo_MaterialManage();
  34. BLL.T_Wo_QuestionManage quesBLL = new BLL.T_Wo_QuestionManage();
  35. ///// <summary>
  36. ///// 绑定微信号
  37. ///// </summary>
  38. ///// <param name="wxLoginDto"></param>
  39. ///// <returns></returns>
  40. //public ActionResult Login(WxLoginDto wxLoginDto)
  41. //{
  42. // var res = Redirect("获取微信openId", wxLoginDto.RedirectUrl);
  43. // var temp = WxHelper.GetOpenId(wxLoginDto);
  44. // if (string.IsNullOrWhiteSpace(temp.OpenId))
  45. // return res;
  46. // //openId => 用户
  47. // //如果不存在,跳转至登录页面
  48. // res = Redirect("绑定微信号", "");
  49. // return res;
  50. //}
  51. /// <summary>
  52. /// 绑定微信号 - 员工和业主分开登陆
  53. /// </summary>
  54. /// <param name="login"></param>
  55. /// <returns></returns>
  56. public ActionResult Login(WxLoginDto login)
  57. {
  58. #region 把其他OpenId更新为空
  59. var userAccount = userAccountBLL.GetModelByOpenid(login.OpenId);
  60. if (userAccount != null)
  61. {
  62. userAccount.F_WxOpenId = "";
  63. userAccountBLL.Update(userAccount);
  64. }
  65. var modelcustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + login.OpenId + "'").FirstOrDefault(); //customerBaseBLL.GetModelByOpenid(login.OpenId);
  66. if (modelcustomer != null)
  67. {
  68. modelcustomer.F_WxOpenId = "";
  69. customerBaseBLL.Update(modelcustomer);
  70. }
  71. #endregion
  72. if (string.IsNullOrEmpty(login.UserCode))
  73. return Error("账号不能为空!");
  74. if (string.IsNullOrEmpty(login.Password))
  75. return Error("密码不能为空!");
  76. Model.T_Sys_UserAccount loginCode = new BLL.T_Sys_UserAccount().LoginGetModel(login.UserCode, login.Password);
  77. Model.T_Sys_UserAccount loginwork = new BLL.T_Sys_UserAccount().LogworkGetModel(login.UserCode, login.Password);
  78. if (loginCode != null || loginwork != null)
  79. {
  80. Model.T_Sys_UserAccount loginUser = null;
  81. string deptcode = "";
  82. if (loginCode != null)
  83. loginUser = loginCode;
  84. else
  85. loginUser = loginwork;
  86. loginUser.F_WxOpenId = login.OpenId;
  87. int UserType = 0; string rolecode = ""; string UserName = ""; string rolename = "";
  88. UserName = loginUser.F_UserName;
  89. //部门
  90. Model.T_Sys_Department modelDep = new BLL.T_Sys_Department().GetModel(loginUser.F_DeptId);
  91. if (modelDep == null)
  92. return Error("获取失败!");
  93. #region 读取角色code
  94. var rolemodel = roleBLL.GetModel(loginUser.F_RoleId);
  95. if (rolemodel != null)
  96. rolecode = rolemodel.F_RoleCode;
  97. #endregion
  98. #region 部门角色
  99. //部门角色(-1管理员,1接待部,2案场经理、项目负责人,3销售部总经理、物业部总经理、工程总经理、设计总经理,4区域客服,5业主(客户档案))
  100. if (loginUser.F_RoleId == 17)
  101. {
  102. //-1管理员
  103. return Error("无操作权限");
  104. }
  105. else
  106. {
  107. if (loginUser.F_RoleId == 60)
  108. {
  109. UserType = 0;
  110. rolename = "分公司经理";
  111. }
  112. else if (loginUser.F_RoleId == 62)
  113. {
  114. UserType = 0;
  115. rolename = "大区经理";
  116. }
  117. else if (loginUser.F_RoleId == 61)
  118. {
  119. UserType = 2;
  120. rolename = "高层";
  121. }
  122. else if (loginUser.F_RoleId == 58)
  123. {
  124. UserType = 4;
  125. rolename = "业务员";
  126. }
  127. else if (loginUser.F_RoleId == 59)
  128. {
  129. UserType = 3;
  130. rolename = "办理人员";
  131. }
  132. else
  133. {
  134. return Error("无操作权限");
  135. }
  136. #region
  137. ////部门操作权限:1接待部,2办理人员,3区域客服,4监管
  138. //IF (MODELDEP.F_TYPE == 1)
  139. //{
  140. // //1--接待部
  141. // USERTYPE = 1;
  142. //}
  143. //ELSE IF (MODELDEP.F_TYPE == 2)
  144. //{
  145. // //2--办理人员
  146. // USERTYPE = 2;
  147. //}
  148. //ELSE IF (MODELDEP.F_TYPE == 3)
  149. //{
  150. // //3--区域客服
  151. // USERTYPE = 3;
  152. //}
  153. //ELSE IF (MODELDEP.F_TYPE == 4)
  154. //{
  155. // //4--监管
  156. // USERTYPE = 4;
  157. //}
  158. //ELSE
  159. //{
  160. // USERTYPE = 0;
  161. //}
  162. #endregion
  163. }
  164. #endregion
  165. var obj = new
  166. {
  167. openid = login.OpenId,
  168. usercode = login.UserCode,
  169. usertype = UserType,
  170. UserName = UserName,
  171. rolename = rolename,
  172. rolecode = rolecode,
  173. };
  174. if (userAccountBLL.Update(loginUser))
  175. return Success("绑定成功", obj);
  176. else
  177. return Error("绑定失败");
  178. }
  179. return Error("账号或密码错误,请重新登录");
  180. //else if (login.UserType == 5)
  181. //{
  182. // //客户档案登录 - 用戶信息不存在时,登录客户档案业主账号
  183. // Dictionary<string, string> paras_Customer = new Dictionary<string, string>();
  184. // // F_RelationShipClassID IN (1,2) 用户类型:0来电用户; 1准业主; 2不是准业主或是亲戚朋友
  185. // //首次密码默认为身份证后6位信息
  186. // //F_CustomerClassID >= 0 为业主或租户,且F_RelationShipClassID = 0为会员账号 2、登录最早的信息
  187. // string sql_Customer = " select * from dbo.T_Cus_CustomerBaseNew (NOLOCK) where F_CustomerCode=@F_UserCode and F_WxPassword=@F_PassWord and F_DeleteFlag = 0 ORDER BY F_CreatedOn ASC ";
  188. // paras_Customer.Add("@F_UserCode", login.UserCode);
  189. // paras_Customer.Add("@F_PassWord", login.Password);
  190. // var dt_Customer = DbHelperSQL.Query(sql_Customer, paras_Customer).Tables[0];
  191. // if (dt_Customer != null && dt_Customer.Rows.Count > 0)
  192. // {
  193. // //var customer = customerBaseBLL.GetModel(login.UserCode); //20180926 次方法查询有漏洞
  194. // var customer = customerBaseBLL.DataTableToList(dt_Customer).ToList().FirstOrDefault();
  195. // customer.F_WxOpenId = login.OpenId;
  196. // #region 新加 - 登录后同时获取用户账号,openid,和角色
  197. // //5--业主(客户档案会员)
  198. // //int UserType = 5;
  199. // var obj = new
  200. // {
  201. // openid = login.OpenId,
  202. // usercode = login.UserCode,
  203. // companyname = customer.F_CompanyName,
  204. // //companyaddress=customer.F_CompanyAddress,
  205. // };
  206. // #endregion
  207. // if (customerBaseBLL.Update(customer))
  208. // return Success("绑定成功!", obj);
  209. // else
  210. // return Error("绑定失败!");
  211. // }
  212. // return Error("账号或密码错误或者没有注册,请重新登录");
  213. //}
  214. return Error("绑定失败");
  215. }
  216. /// <summary>
  217. /// 绑定微信号 - 员工和业主统一登陆 - 不用
  218. /// </summary>
  219. /// <param name="login"></param>
  220. /// <returns></returns>
  221. [WechatActionFilter]
  222. public ActionResult Login2(WxLoginDto login)
  223. {
  224. Dictionary<string, string> paras = new Dictionary<string, string>();
  225. string sql = " select * from T_Sys_UserAccount (NOLOCK) where F_UserCode=@F_UserCode and F_PassWord=@F_PassWord and F_DeleteFlag = 0 ";
  226. paras.Add("@F_UserCode", login.UserCode);
  227. paras.Add("@F_PassWord", login.Password);
  228. var dt = DbHelperSQL.Query(sql, paras).Tables[0];
  229. #region 把其他OpenId更新为空
  230. var userAccount = userAccountBLL.GetModelByOpenid(login.OpenId);
  231. if (userAccount != null)
  232. {
  233. userAccount.F_WxOpenId = "";
  234. userAccountBLL.Update(userAccount);
  235. }
  236. var modelcustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + login.OpenId + "'").FirstOrDefault();//.GetModelByOpenid(login.OpenId);
  237. if (modelcustomer != null)
  238. {
  239. modelcustomer.F_WxOpenId = "";
  240. customerBaseBLL.Update(modelcustomer);
  241. }
  242. #endregion
  243. if (dt != null && dt.Rows.Count > 0)
  244. {
  245. var user = userAccountBLL.GetModel(login.UserCode);
  246. user.F_WxOpenId = login.OpenId;
  247. //int UserType = 0;
  248. //部门
  249. Model.T_Sys_Department modelDep = new BLL.T_Sys_Department().GetModel(user.F_DeptId);
  250. if (modelDep == null)
  251. return Error("获取失败!");
  252. #region 部门角色
  253. ////部门角色(-1管理员,1接待部,2案场经理、项目负责人,3销售部总经理、物业部总经理、工程总经理、设计总经理,4区域客服,5业主(客户档案))
  254. //if (user.F_RoleId == 17)
  255. //{
  256. // //-1管理员
  257. // UserType = -1;
  258. //}
  259. //else
  260. //{
  261. // //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  262. // if (modelDep.F_Type == 1)
  263. // {
  264. // //1--接待部
  265. // UserType = 1;
  266. // }
  267. // else if (modelDep.F_Type == 2)
  268. // {
  269. // //2--办理人员
  270. // UserType = 2;
  271. // }
  272. // else if (modelDep.F_Type == 3)
  273. // {
  274. // //3--区域客服
  275. // UserType = 3;
  276. // }
  277. // else if (modelDep.F_Type == 4)
  278. // {
  279. // //4--监管
  280. // UserType = 4;
  281. // }
  282. // else
  283. // {
  284. // UserType = 0;
  285. // }
  286. //}
  287. #endregion
  288. var obj = new
  289. {
  290. openid = login.OpenId,
  291. usercode = login.UserCode,
  292. //usertype = UserType
  293. };
  294. if (userAccountBLL.Update(user))
  295. {
  296. return Success("绑定成功", obj);
  297. }
  298. else
  299. {
  300. return Error("绑定失败");
  301. }
  302. }
  303. else
  304. {
  305. //客户档案登录 - 用戶信息不存在时,登录客户档案业主账号
  306. Dictionary<string, string> paras_Customer = new Dictionary<string, string>();
  307. // F_RelationShipClassID IN (1,2) 用户类型:0来电用户; 1准业主; 2不是准业主或是亲戚朋友
  308. //首次密码默认为身份证后6位信息
  309. //F_CustomerClassID >= 0 为业主或租户,且F_RelationShipClassID = 0为会员账号 2、登录最早的信息
  310. string sql_Customer = " select * from dbo.T_Cus_CustomerBaseNew (NOLOCK) where F_CustomerCode=@F_UserCode and F_PassWord=@F_PassWord and F_DeleteFlag = 0 ";
  311. paras_Customer.Add("@F_UserCode", login.UserCode);
  312. paras_Customer.Add("@F_PassWord", login.Password);
  313. var dt_Customer = DbHelperSQL.Query(sql_Customer, paras_Customer).Tables[0];
  314. if (dt_Customer != null && dt_Customer.Rows.Count > 0)
  315. {
  316. var customer = customerBaseBLL.GetModelList(" F_CustomerCode='" + login.UserCode + "'").FirstOrDefault(); //customerBaseBLL.GetModel(login.UserCode);
  317. customer.F_WxOpenId = login.OpenId;
  318. #region 新加 - 登录后同时获取用户账号,openid,和角色
  319. //5--业主(客户档案会员)
  320. //int UserType = 5;
  321. var obj = new
  322. {
  323. openid = login.OpenId,
  324. usercode = login.UserCode,
  325. //usertype = UserType
  326. };
  327. #endregion
  328. if (customerBaseBLL.Update(customer))
  329. {
  330. return Success("绑定成功!", obj);
  331. }
  332. else
  333. {
  334. return Error("绑定失败!");
  335. }
  336. }
  337. else
  338. {
  339. return Error("账号或密码错误,请重新登录");
  340. }
  341. //return Error("账号或密码错误,请重新登录");
  342. }
  343. }
  344. /// <summary>
  345. /// 获取微信openid
  346. /// </summary>
  347. /// <param name="login"></param>
  348. /// <returns></returns>
  349. public ActionResult GetOpenId(WxLoginDto wld)
  350. {
  351. wld.RedirectUrl = RequestString.GetUrlReferrer();
  352. if (string.IsNullOrEmpty(wld.OpenId))
  353. {
  354. var temp = WxHelper.GetOpenId(wld);
  355. if (string.IsNullOrWhiteSpace(temp.OpenId))
  356. {
  357. //Request.QueryString[ ] == null
  358. return Redirect("请求", temp.RedirectUrl);
  359. }
  360. wld.OpenId = temp.OpenId;
  361. #region 获取是否绑定用户表
  362. //获取是否绑定用户表
  363. var usertemp = new BLL.T_Sys_UserAccount().GetModelByOpenid(wld.OpenId);
  364. if (usertemp != null)
  365. {
  366. //部门
  367. Model.T_Sys_Department modelDep = new BLL.T_Sys_Department().GetModel(usertemp.F_DeptId);
  368. if (modelDep == null)
  369. return Error("获取失败!");
  370. wld.UserCode = usertemp.F_UserCode;
  371. #region 读取角色code
  372. var rolemodel = roleBLL.GetModel(usertemp.F_RoleId);
  373. if (rolemodel != null)
  374. wld.RoleCode = rolemodel.F_RoleCode;
  375. #endregion
  376. #region 部门角色
  377. if (usertemp.F_RoleId == 17)
  378. {
  379. //-1管理员
  380. wld.UserType = -1;
  381. }
  382. else
  383. {
  384. if (usertemp.F_RoleId == 60 || usertemp.F_RoleId == 62)
  385. {
  386. wld.UserType = 0;
  387. }
  388. else if (usertemp.F_RoleId == 61)
  389. {
  390. wld.UserType = 2;
  391. }
  392. else if (usertemp.F_RoleId == 58)
  393. {
  394. wld.UserType = 4;
  395. }
  396. else if (usertemp.F_RoleId == 59)
  397. {
  398. wld.UserType = 3;
  399. }
  400. else
  401. {
  402. wld.UserType = 1;
  403. }
  404. #region
  405. ////部门操作权限:1接待部,2办理人员,3区域客服,4监管
  406. //IF (MODELDEP.F_TYPE == 1)
  407. //{
  408. // //1--接待部
  409. // USERTYPE = 1;
  410. //}
  411. //ELSE IF (MODELDEP.F_TYPE == 2)
  412. //{
  413. // //2--办理人员
  414. // USERTYPE = 2;
  415. //}
  416. //ELSE IF (MODELDEP.F_TYPE == 3)
  417. //{
  418. // //3--区域客服
  419. // USERTYPE = 3;
  420. //}
  421. //ELSE IF (MODELDEP.F_TYPE == 4)
  422. //{
  423. // //4--监管
  424. // USERTYPE = 4;
  425. //}
  426. //ELSE
  427. //{
  428. // USERTYPE = 0;
  429. //}
  430. #endregion
  431. #region
  432. ////部门操作权限:1接待部,2办理人员,3区域客服,4监管
  433. //if (modelDep.F_Type == 1)
  434. //{
  435. // //1--接待部
  436. // wld.UserType = 1;
  437. //}
  438. //else if (modelDep.F_Type == 2)
  439. //{
  440. // //2--办理人员
  441. // wld.UserType = 2;
  442. //}
  443. //else if (modelDep.F_Type == 3)
  444. //{
  445. // //3--区域客服
  446. // wld.UserType = 3;
  447. //}
  448. //else if (modelDep.F_Type == 4)
  449. //{
  450. // //4--监管
  451. // wld.UserType = 4;
  452. //}
  453. //else
  454. //{
  455. // wld.UserType = 0;
  456. //}
  457. #endregion
  458. }
  459. #endregion
  460. }
  461. else
  462. {
  463. var customertemp = customerBaseBLL.GetModelByOpenid(wld.OpenId);
  464. if (customertemp != null)
  465. {
  466. wld.UserCode = customertemp.F_CustomerCode;
  467. //5--业主(客户档案会员)
  468. wld.UserType = 5;
  469. }
  470. else
  471. {
  472. wld.UserCode = "";
  473. }
  474. //wld.UserCode = "";
  475. }
  476. #endregion
  477. }
  478. var model = new BLL.T_Sys_Users().GetModel(wld.OpenId);
  479. if (model == null)
  480. {
  481. model = new Model.T_Sys_Users();
  482. model.F_OpenId = wld.OpenId;
  483. model.F_Type = 1;
  484. model.F_CreateTime = DateTime.Now;
  485. new BLL.T_Sys_Users().Add(model);
  486. }
  487. var newobj = new
  488. {
  489. openid = wld.OpenId,
  490. usercode = wld.UserCode,
  491. usertype = wld.UserType,
  492. rolecode = wld.RoleCode,
  493. };
  494. return Success("成功", newobj);
  495. }
  496. /// <summary>
  497. ///退回工单列表
  498. /// </summary>
  499. public string GetBackid(Model.T_Sys_UserAccount ua)
  500. {
  501. string str = string.Empty;
  502. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_ItemType in(" + (int)EnumItemType.deal + "," + (int)EnumItemType.audit + ")"
  503. + " and "
  504. + "F_OptType in(" + (int)EnumItemOpt.abreback + "," + (int)EnumItemOpt.reback + ") and F_NextUser='" + ua.F_UserCode + "'"
  505. + ""
  506. + " and isnull(F_IsUsed,'0')='0' ";
  507. return str;
  508. }
  509. /// <summary>
  510. ///工单列表
  511. /// </summary>
  512. public ActionResult GetList(string OpenId, string code, string cusname, string keywords, string cusphone, string companyname, string province, string city,
  513. string country, string township, string category, string salebase, string touser, int source = 0, int state = -1, int status = -1, int type = 0, int pageindex = 1, int pagesize = 10)
  514. {
  515. // int userId = CurrentUser.UserData.F_UserId;
  516. if (!string.IsNullOrEmpty(OpenId))
  517. {
  518. // Model.T_Sys_UserAccount ua = userAccountBLL.GetModel(userId);
  519. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  520. // if (source != 3)
  521. // {
  522. // if (ua == null)
  523. // {
  524. // return Error("你的账号已在别处登录,你确定要再次登录吗?");
  525. // }
  526. // }
  527. // Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  528. string sql = $" and F_IsDelete=0";
  529. DataTable dt = new DataTable();
  530. #region 筛选条件
  531. if (type > 0 && type < 5)//工单类型
  532. sql += $" and F_Type=" + type;
  533. if (source > 0)//工单来源
  534. sql += $" and F_Source=" + source;
  535. if (!string.IsNullOrWhiteSpace(touser))//参与人
  536. sql += $" and F_DealBy like '%" + touser.Trim() + "%'";
  537. if (!string.IsNullOrWhiteSpace(code))//工单编号
  538. sql += $" and F_WorkOrderCode like '%" + code.Trim() + "%'";
  539. if (!string.IsNullOrWhiteSpace(keywords))//关键字搜索
  540. sql += $" and (F_QuestionType like '%" + keywords.Trim()
  541. + "%' or F_ZX_Area like '%" + keywords.Trim() + "%' or F_ZX_Branch like '%" + keywords.Trim()
  542. + "%' or F_CusName like '%" + keywords.Trim() + "%'or F_CusPhone like '%" + keywords.Trim() + "%' ) ";
  543. if (!string.IsNullOrWhiteSpace(cusname))//客户姓名
  544. sql += $" and F_CusName like '%" + cusname.Trim() + "%'";
  545. if (!string.IsNullOrWhiteSpace(cusphone))//客户电话
  546. sql += $" and F_CusPhone like '%" + cusphone.Trim() + "%'";
  547. if (!string.IsNullOrWhiteSpace(companyname))//公司名称
  548. sql += $" and F_CompanyName like '%" + companyname.Trim() + "%'";
  549. if (!string.IsNullOrWhiteSpace(category))//产品名称
  550. sql += $" and F_TS_Category like '%" + category.Trim() + "%'";
  551. if (!string.IsNullOrWhiteSpace(salebase))//销售基地
  552. sql += $" and F_SalesBase like '%" + salebase.Trim() + "%'";
  553. if (!string.IsNullOrWhiteSpace(province))//省
  554. sql += $" and F_IncidentProvince like '%" + province.Trim() + "%'";
  555. if (!string.IsNullOrWhiteSpace(province))//市
  556. sql += $" and F_IncidentCity like '%" + city.Trim() + "%'";
  557. if (!string.IsNullOrWhiteSpace(province))//县
  558. sql += $" and F_IncidentCountry like '%" + country.Trim() + "%'";
  559. if (!string.IsNullOrWhiteSpace(province))//乡
  560. sql += $" and F_IncidentTownship like '%" + township.Trim() + "%'";
  561. // sql += " and (F_CreateBy= '" + ua.F_UserCode + "' or T_Wo_WorkOrder.F_ID in ( " + GetCYWorkOrderID(ua.F_UserCode) + ")) ";
  562. if (ua != null)
  563. {
  564. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  565. if (source == 3)
  566. {
  567. sql += $" and F_WxOpenId ='" + OpenId + "'";
  568. }
  569. switch (state)
  570. {
  571. case 0://待审批
  572. string uwhere = "";
  573. if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL")
  574. {
  575. if (GetApprovalOrderID(ua, OpenId, ro.F_RoleCode) != "")
  576. {
  577. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetApprovalOrderID(ua, OpenId, ro.F_RoleCode) + ") ";
  578. }
  579. else
  580. {
  581. return Success("暂无工单");
  582. }
  583. }
  584. else
  585. {
  586. return Success("无操作权限");
  587. }
  588. break;
  589. case 11://已创单
  590. sql += $" and F_CreateBy ='" + ua.F_UserCode + "'";
  591. break;
  592. case 12://退单
  593. if (GetBackid(ua) != "")
  594. {
  595. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetBackid(ua) + ") ";
  596. }
  597. else
  598. {
  599. return Success("暂无工单");
  600. }
  601. break;
  602. case 1://已审核
  603. if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "GC")
  604. {
  605. if (GetApprovedOrderID(ua.F_UserCode) != "")
  606. {
  607. sql += $" and F_ID in ( " + GetApprovedOrderID(ua.F_UserCode) + ") "; ;
  608. }
  609. else
  610. {
  611. return Error("暂无工单");
  612. }
  613. }
  614. else
  615. {
  616. return Success("暂无工单");
  617. }
  618. break;
  619. case 2://待完成的(待接单)
  620. if (GetDeptWorkOrderID(ua.F_DeptId, ua.F_UserCode) != "")
  621. {
  622. sql += $" and F_State in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.reassign + "," + (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.assign + ") and T_Wo_WorkOrder.F_ID in ( " +
  623. GetDeptWorkOrderID(ua.F_DeptId, ua.F_UserCode) + ") "; ;
  624. }
  625. else
  626. {
  627. return Success("暂无工单"); ;
  628. }
  629. break;
  630. case 5://待审批
  631. if (ro.F_RoleCode == "GC")
  632. {
  633. if (GetHApproval(ua.F_UserCode) != "")
  634. {
  635. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetHApproval(ua.F_UserCode) + ") "; ;
  636. }
  637. }
  638. else
  639. {
  640. return Success("暂无工单"); ;
  641. }
  642. break;
  643. case 4://待完成的(待处理)
  644. if (GetDWCWorkOrderID(ua.F_UserCode) != null)
  645. {
  646. sql += " and F_State in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + ") and T_Wo_WorkOrder.F_ID in ( " + GetDWCWorkOrderID(ua.F_UserCode) + ") ";
  647. }
  648. else
  649. {
  650. return Success("暂无工单"); ;
  651. }
  652. break;
  653. case 10://已完成的
  654. sql += " and F_State =" + (int)EnumWorkOrderState.finish + " and F_DealBy = '" + ua.F_UserCode + "' ";
  655. break;
  656. case 3://我参与的
  657. if (GetParticipateID(ua.F_UserCode) != "")
  658. {
  659. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetParticipateID(ua.F_UserCode) + ") ";
  660. }
  661. else
  662. {
  663. return Error("暂无工单");
  664. }
  665. break;
  666. case 6://待回访
  667. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "JDYBZZX")
  668. {
  669. uwhere = "";
  670. }
  671. else
  672. {
  673. return Success("无操作权限"); ;
  674. }
  675. sql += $" and F_State=" + (int)EnumWorkOrderState.finish + " and F_IsVisit = '" + "1" + "' " + uwhere; ;
  676. break;
  677. case 7://已回访
  678. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "JDYBZZX")
  679. {
  680. if (GetCYWorkOrderID(ua.F_UserCode) != "")
  681. {
  682. sql += " and (F_CreateBy= '" + ua.F_UserCode + "' or T_Wo_WorkOrder.F_ID in ( " + GetCYWorkOrderID(ua.F_UserCode) + ")) ";
  683. }
  684. else
  685. {
  686. return Success("暂无工单"); ;
  687. }
  688. sql += $" and F_State=" + (int)EnumWorkOrderState.evaluate;
  689. }
  690. else if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "ZG")
  691. {
  692. string detpid = "";
  693. var deparmentlist = new List<Model.T_Sys_Department>();
  694. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  695. if (dModel != null)
  696. {
  697. if (dModel.F_Layer == 1)
  698. {
  699. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  700. if (deparmentlist.Count > 0)
  701. {
  702. foreach (var it in deparmentlist)
  703. {
  704. if (detpid != "")
  705. {
  706. detpid += "," + it.F_DeptId;
  707. }
  708. else
  709. {
  710. detpid = "" + it.F_DeptId; ;
  711. }
  712. }
  713. }
  714. }
  715. else
  716. {
  717. detpid = ua.F_DeptId.ToString();
  718. }
  719. if (GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.evaluate + "") != "")
  720. {
  721. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.evaluate + "") + ") "; ;
  722. }
  723. else
  724. {
  725. return Success("暂无工单"); ;
  726. }
  727. }
  728. else
  729. {
  730. return Error("加载失败");
  731. }
  732. }
  733. else
  734. {
  735. return Success("无操作权限"); ;
  736. }
  737. sql += $" and F_State=" + (int)EnumWorkOrderState.evaluate;
  738. break;
  739. case 8://待完结
  740. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "JDYBZZX")
  741. {
  742. uwhere = ""; ;
  743. }
  744. else
  745. {
  746. return Success("无操作权限"); ;
  747. }
  748. sql += $" and F_State=" + (int)EnumWorkOrderState.finish + " and F_IsVisit = '" + "0" + "' "; ;
  749. break;
  750. case 9://待接单
  751. if (GetDeptWorkOrderID(ua.F_DeptId, ua.F_UserCode) != "")
  752. {
  753. sql += $" and F_State in(" + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.assign + ") and T_Wo_WorkOrder.F_ID in ( " +
  754. GetDeptWorkOrderID(ua.F_DeptId, ua.F_UserCode) + ") "; ;
  755. }
  756. else
  757. {
  758. return Success("暂无工单"); ;
  759. }
  760. break;
  761. }
  762. }
  763. else
  764. {
  765. sql += $" and F_WxOpenId ='" + OpenId + "'";
  766. }
  767. #endregion
  768. int recordCount = 0;
  769. if (!string.IsNullOrWhiteSpace(sql))
  770. {
  771. dt = BLL.PagerBLL.GetListPager(
  772. "T_Wo_WorkOrder",
  773. "F_ID",
  774. "*",
  775. sql,
  776. "ORDER BY T_Wo_WorkOrder.F_ID desc",
  777. pagesize,
  778. pageindex,
  779. true,
  780. out recordCount);
  781. }
  782. List<Model.T_Wo_WorkOrder> modlelist = new BLL.T_Wo_WorkOrder().DataTableToList(dt);
  783. if (modlelist.Count > 0)
  784. {
  785. List<WorkOrderNewInput> Input = modeltooip(modlelist, ua);
  786. var obj = new
  787. {
  788. state = "success",
  789. message = "成功",
  790. rows = Input,
  791. total = recordCount
  792. };
  793. return Content(obj.ToJson()); ;
  794. }
  795. else
  796. {
  797. return Success("暂无工单"); ;
  798. }
  799. }
  800. else
  801. {
  802. return Error("无操作权限!");
  803. }
  804. }
  805. /// <summary>
  806. ///综合查询列表
  807. /// </summary>
  808. public ActionResult GetComprehensive(string OpenId, string code, string createby, string cusname, string keywords, string cusphone, string companyname, string province, string city,
  809. string country, string township, string category, string salebase, string touser, int source = 0, int state = -1, int type = 0, int pageindex = 1, int pagesize = 10)
  810. {
  811. if (!string.IsNullOrEmpty(OpenId))
  812. {
  813. // Model.T_Sys_UserAccount ua = userAccountBLL.GetModel(userId);
  814. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  815. // if (ua == null)
  816. // {
  817. // return Error("你的账号已在别处登录,你确定要再次登录吗?");
  818. // }
  819. string sql = $" and F_IsDelete=0";
  820. DataTable dt = new DataTable();
  821. #region 筛选条件
  822. if (type > 0 && type < 5)//工单类型
  823. sql += $" and F_Type=" + type;
  824. if (state >= 0)//
  825. sql += $" and F_State=" + state;
  826. if (source > 0)//工单来源
  827. sql += $" and F_Source=" + source;
  828. if (!string.IsNullOrWhiteSpace(createby))//创建人
  829. sql += $" and F_CreateBy like '%" + createby.Trim() + "%'";
  830. if (!string.IsNullOrWhiteSpace(touser))//参与人
  831. sql += $" and F_DealBy like '%" + touser.Trim() + "%'";
  832. if (!string.IsNullOrWhiteSpace(code))//工单编号
  833. sql += $" and F_WorkOrderCode like '%" + code.Trim() + "%'";
  834. if (!string.IsNullOrWhiteSpace(keywords))//关键字搜索
  835. sql += $" and ( F_QuestionType like '%" + keywords.Trim()
  836. + "%' or F_ZX_Area like '%" + keywords.Trim() + "%' or F_ZX_Branch like '%" + keywords.Trim()
  837. + "%' or F_CusName like '%" + keywords.Trim() + "%'or F_CusPhone like '%" + keywords.Trim() + "%') ";
  838. if (!string.IsNullOrWhiteSpace(cusname))//客户姓名
  839. sql += $" and F_CusName like '%" + cusname.Trim() + "%'";
  840. if (!string.IsNullOrWhiteSpace(cusphone))//客户电话
  841. sql += $" and F_CusPhone like '%" + cusphone.Trim() + "%'";
  842. if (!string.IsNullOrWhiteSpace(companyname))//公司名称
  843. sql += $" and F_CompanyName like '%" + companyname.Trim() + "%'";
  844. if (!string.IsNullOrWhiteSpace(category))//产品名称
  845. sql += $" and F_TS_Category like '%" + category.Trim() + "%'";
  846. if (!string.IsNullOrWhiteSpace(salebase))//销售基地
  847. sql += $" and F_SalesBase like '%" + salebase.Trim() + "%'";
  848. if (!string.IsNullOrWhiteSpace(province))//省
  849. sql += $" and F_IncidentProvince like '%" + province.Trim() + "%'";
  850. if (!string.IsNullOrWhiteSpace(province))//市
  851. sql += $" and F_IncidentCity like '%" + city.Trim() + "%'";
  852. if (!string.IsNullOrWhiteSpace(province))//县
  853. sql += $" and F_IncidentCountry like '%" + country.Trim() + "%'";
  854. if (!string.IsNullOrWhiteSpace(province))//乡
  855. sql += $" and F_IncidentTownship like '%" + township.Trim() + "%'";
  856. if (ua != null)
  857. {
  858. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  859. if (ro.F_RoleCode == "QTJS" || ro.F_RoleCode == "YWY")
  860. {
  861. sql += $" and F_CreateBy like '%" + ua.F_UserCode.Trim() + "%'";
  862. }
  863. else if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "BLRY" || ro.F_RoleCode == "ZG")
  864. {
  865. string detpid = "";
  866. var deparmentlist = new List<Model.T_Sys_Department>();
  867. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  868. if (dModel != null)
  869. {
  870. if (dModel.F_Layer == 1)
  871. {
  872. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  873. if (deparmentlist.Count > 0)
  874. {
  875. foreach (var it in deparmentlist)
  876. {
  877. if (detpid != "")
  878. {
  879. detpid += "," + it.F_DeptId;
  880. }
  881. else
  882. {
  883. detpid = "" + it.F_DeptId;
  884. }
  885. }
  886. }
  887. }
  888. else
  889. {
  890. detpid = ua.F_DeptId.ToString();
  891. }
  892. if (state >= 0)
  893. {
  894. if (GetDeptWorkOrderID(detpid, "" + state + "") != "")
  895. {
  896. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid, "" + state + "") + ") ";
  897. }
  898. else
  899. {
  900. return Success("暂无工单"); ;
  901. }
  902. }
  903. else
  904. {
  905. if (GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.neworder + ", " + (int)EnumWorkOrderState.assign + "," +
  906. (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.finish
  907. + "," + (int)EnumWorkOrderState.evaluate + "") != "")
  908. {
  909. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.neworder + ", " + (int)EnumWorkOrderState.assign + "," +
  910. (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.finish
  911. + "," + (int)EnumWorkOrderState.evaluate + "") + ") ";
  912. }
  913. else
  914. {
  915. return Success("暂无工单"); ;
  916. }
  917. }
  918. }
  919. else
  920. {
  921. return Error("加载失败");
  922. }
  923. }
  924. }
  925. else
  926. {
  927. return Error("无操作权限");
  928. }
  929. #endregion
  930. int recordCount = 0;
  931. if (!string.IsNullOrWhiteSpace(sql))
  932. {
  933. dt = BLL.PagerBLL.GetListPager(
  934. "T_Wo_WorkOrder",
  935. "F_ID",
  936. "*",
  937. sql,
  938. "ORDER BY T_Wo_WorkOrder.F_ID desc",
  939. pagesize,
  940. pageindex,
  941. true,
  942. out recordCount);
  943. }
  944. List<Model.T_Wo_WorkOrder> modlelist = new BLL.T_Wo_WorkOrder().DataTableToList(dt);
  945. if (modlelist.Count > 0)
  946. {
  947. List<WorkOrderNewInput> Input = modeltooip(modlelist, ua);
  948. var obj = new
  949. {
  950. state = "success",
  951. message = "成功",
  952. rows = Input,
  953. total = recordCount
  954. };
  955. return Content(obj.ToJson()); ;
  956. }
  957. else
  958. {
  959. return Success("暂无工单"); ;
  960. }
  961. }
  962. else
  963. {
  964. return Error("无操作权限!");
  965. }
  966. }
  967. /// <summary>
  968. /// 根据部门获取工单号
  969. /// </summary>
  970. /// <returns></returns>
  971. public string GetDeptWorkOrderID(string user)
  972. {
  973. string sql = " ";
  974. string ua = "";
  975. DataTable dt = new DataTable();
  976. if (user != "")
  977. {
  978. sql += " and F_DeptId in ( " + user + ") ";
  979. }
  980. int recordCount;
  981. dt = BLL.PagerBLL.GetListPager(
  982. "T_Sys_UserAccount",
  983. "F_UserId",
  984. "*",
  985. sql,
  986. "ORDER BY F_UserId desc",
  987. 10000,
  988. 1,
  989. true,
  990. out recordCount);
  991. List<Model.UserAccount> modelList = new BLL.UserAccount().DataTableToList(dt);
  992. if (modelList != null)
  993. {
  994. foreach (var it in modelList)
  995. {
  996. if (ua != "")
  997. ua += "," + it.F_UserCode;
  998. else
  999. ua += it.F_UserCode;
  1000. }
  1001. }
  1002. string str = string.Empty;
  1003. str = "select F_WoID from T_Wo_WorkOrderItem_New where "
  1004. + "F_CreateUser in(" + ua + ") "
  1005. ;
  1006. return str;
  1007. }
  1008. /// <summary>
  1009. /// 根据部门获取工单号
  1010. /// </summary>
  1011. /// <returns></returns>
  1012. public string GetDeptWorkOrderID(string user, string F_ItemType)
  1013. {
  1014. string sql = " ";
  1015. string ua = "";
  1016. DataTable dt = new DataTable();
  1017. if (user != "")
  1018. {
  1019. sql += " and F_DeptId in ( " + user + ") ";
  1020. }
  1021. int recordCount;
  1022. dt = BLL.PagerBLL.GetListPager(
  1023. "T_Sys_UserAccount",
  1024. "F_UserId",
  1025. "*",
  1026. sql,
  1027. "ORDER BY F_UserId desc",
  1028. 10000,
  1029. 1,
  1030. true,
  1031. out recordCount);
  1032. List<Model.UserAccount> modelList = new BLL.UserAccount().DataTableToList(dt);
  1033. if (modelList != null)
  1034. {
  1035. foreach (var it in modelList)
  1036. {
  1037. if (ua != "")
  1038. ua += "," + it.F_UserCode;
  1039. else
  1040. ua += it.F_UserCode;
  1041. }
  1042. }
  1043. string str = string.Empty;
  1044. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_OptType in(" + F_ItemType + ")"
  1045. + " and "
  1046. + "F_CreateUser in(" + ua + ")"
  1047. ;
  1048. return str;
  1049. }
  1050. /// <summary>
  1051. /// 获取待完成的工单编号
  1052. /// </summary>
  1053. /// <returns></returns>
  1054. public string GetDWCWorkOrderID(string user)
  1055. {
  1056. string str = string.Empty;
  1057. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_ItemType=" + (int)EnumItemType.deal
  1058. + " and ("
  1059. + "(F_WoState in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + ") and F_CreateUser='" + user + "') "//办理中和接单状态的操作人
  1060. + " or (F_WoState in(" + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.receive + ") and F_NextUser='" + user + "')"//退回下一步操作人
  1061. + ")"
  1062. + " and isnull(F_IsUsed,'0')='0' ";
  1063. return str;
  1064. }
  1065. public string GetHApproval(string user)
  1066. {
  1067. string str = string.Empty;
  1068. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_ItemType=" + (int)EnumItemType.audit + " and F_OptType=" + (int)EnumItemOpt.audit + "and F_NextUser= '" + user + "'" + "and F_IsUsed=2";
  1069. return str;
  1070. }
  1071. /// <summary>
  1072. /// 获取部门待完成的工单编号
  1073. /// </summary>
  1074. /// <returns></returns>
  1075. public string GetDeptWorkOrderID(int deptid, string user)
  1076. {
  1077. string str = string.Empty;
  1078. string deptuser = string.Empty;
  1079. var dept = userAccountBLL.GetModelList("F_DeptId=" + deptid);
  1080. if (dept != null)
  1081. {
  1082. foreach (var it in dept)
  1083. {
  1084. if (it.F_UserCode != user)
  1085. {
  1086. if (deptuser != "")
  1087. deptuser += "','" + it.F_UserCode;
  1088. else
  1089. deptuser += it.F_UserCode;
  1090. }
  1091. }
  1092. }
  1093. if (!string.IsNullOrEmpty(deptuser))
  1094. {
  1095. // string deptuser = "select F_WoID from T_Sys_UserAccount where F_DeptId=" + deptid;
  1096. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_ItemType=" + (int)EnumItemType.deal
  1097. + " and isnull(F_IsUsed,'0')='0' " + " and "
  1098. + "(F_WoState in(" + (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.abreback + ") and F_NextDept =" + deptid + ") "//办理中和接单状态的操作人
  1099. + " or (F_WoState =" + (int)EnumWorkOrderState.assign + " and F_NextUser in('" + deptuser + "'))";//退回下一步操作人
  1100. }
  1101. else
  1102. {
  1103. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_ItemType=" + (int)EnumItemType.deal
  1104. + " and "
  1105. + "F_WoState in(" + (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.abreback + ") and F_NextDept =" + deptid + " "//办理中和接单状态的操作人
  1106. + " and isnull(F_IsUsed,'0')='0' ";
  1107. }
  1108. return str;
  1109. }
  1110. /// <summary>
  1111. /// 获取工单数量
  1112. /// </summary>
  1113. /// <returns></returns>
  1114. public ActionResult GetWorkCount(string OpenId)
  1115. {
  1116. if (string .IsNullOrEmpty (OpenId) )
  1117. return Success ("你的账号已在别处登录,你确定要再次登录吗?");
  1118. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  1119. if (ua == null)
  1120. {
  1121. return Success("你的账号已在别处登录,你确定要再次登录吗?");
  1122. }
  1123. DataTable dt = new DataTable();
  1124. #region 筛选条件
  1125. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  1126. string uwhere = " ";
  1127. string sql = "";
  1128. if (!Refresh())
  1129. {
  1130. return Error("查询失败");
  1131. }
  1132. int YCD = 0, DJD = 0, DCL = 0, DSP = 0, YCL = 0, GCDBL = 0, YBL = 0, CQGD = 0, TD = 0,YFP=0;
  1133. for (int i = 0; i <= 9; i++)
  1134. {
  1135. switch (i)
  1136. {
  1137. case 0://待接单的
  1138. sql = "";
  1139. sql += $" F_IsDelete=0";
  1140. if (GetDeptWorkOrderID(ua.F_DeptId, ua.F_UserCode) != "")
  1141. {
  1142. sql += $" and F_State in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.reassign + "," + (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.assign + ") and T_Wo_WorkOrder.F_ID in ( " +
  1143. GetDeptWorkOrderID(ua.F_DeptId, ua.F_UserCode) + ") "; ;
  1144. }
  1145. else
  1146. {
  1147. DJD = 0;
  1148. break;
  1149. }
  1150. DJD = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//接单
  1151. break;
  1152. case 1://待完成的(待处理)
  1153. sql = "";
  1154. sql += $" F_IsDelete=0";
  1155. if (GetDWCWorkOrderID(ua.F_UserCode) != null)
  1156. {
  1157. sql += " and F_State in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.reassign + "," + (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + ") and T_Wo_WorkOrder.F_ID in ( " + GetDWCWorkOrderID(ua.F_UserCode) + ") ";
  1158. }
  1159. else
  1160. {
  1161. DCL = 0;
  1162. break;
  1163. }
  1164. DCL = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//已接单
  1165. break;
  1166. case 2://已完成的
  1167. sql = "";
  1168. sql += $" F_IsDelete=0";
  1169. sql += " and F_State =" + (int)EnumWorkOrderState.finish + " and F_DealBy = '" + ua.F_UserCode + "' ";
  1170. YCL = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//已完成的
  1171. break;
  1172. case 3://待审批
  1173. sql = "";
  1174. sql += $" F_IsDelete=0";
  1175. if (ro.F_RoleCode == "GC")
  1176. {
  1177. if (GetHApproval(ua.F_UserCode) != "")
  1178. {
  1179. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetHApproval(ua.F_UserCode) + ") "; ;
  1180. }
  1181. }
  1182. else
  1183. {
  1184. GCDBL = 0;
  1185. break; ;
  1186. }
  1187. GCDBL = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//高层待审批
  1188. break;
  1189. case 4://已审批
  1190. sql = "";
  1191. sql += $" F_IsDelete=0";
  1192. if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "GC")
  1193. {
  1194. if (GetApprovedOrderID(ua.F_UserCode) != "")
  1195. {
  1196. sql += $" and F_ID in ( " + GetApprovedOrderID(ua.F_UserCode) + ") "; ;
  1197. }
  1198. else
  1199. {
  1200. YBL = 0;
  1201. break; ;
  1202. }
  1203. }
  1204. else
  1205. {
  1206. YBL = 0;
  1207. break; ;
  1208. }
  1209. YBL = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//已审批
  1210. break;
  1211. case 5://待审批
  1212. sql = "";
  1213. sql += $" F_IsDelete=0";
  1214. if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL")
  1215. {
  1216. if (GetApprovalOrderID(ua, OpenId, ro.F_RoleCode) != "")
  1217. {
  1218. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetApprovalOrderID(ua, OpenId, ro.F_RoleCode) + ") ";
  1219. }
  1220. else
  1221. {
  1222. DSP = 0;
  1223. break; ;
  1224. }
  1225. }
  1226. else
  1227. {
  1228. DSP = 0;
  1229. break; ;
  1230. }
  1231. DSP = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//待审批
  1232. break;
  1233. case 6:
  1234. sql = "";
  1235. sql += $" F_IsDelete=0";
  1236. sql += $" and F_CreateBy ='" + ua.F_UserCode + "'";
  1237. YCD = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//业务员已创单
  1238. break;
  1239. case 7://超期
  1240. sql = "";
  1241. sql += $" F_IsDelete=0";
  1242. sql += $" and F_IsOver=" + 1;
  1243. sql += $" and F_State !=" + 11;
  1244. if (ro.F_RoleCode == "YWY" || ro.F_RoleCode == "BLRY")
  1245. {
  1246. sql += $" and F_DealBy like '%" + ua.F_UserCode.Trim() + "%'";
  1247. }
  1248. else if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "ZG")
  1249. {
  1250. string detpid = "";
  1251. var deparmentlist = new List<Model.T_Sys_Department>();
  1252. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  1253. if (dModel != null)
  1254. {
  1255. if (dModel.F_Layer == 1)
  1256. {
  1257. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  1258. if (deparmentlist.Count > 0)
  1259. {
  1260. foreach (var it in deparmentlist)
  1261. {
  1262. if (detpid != "")
  1263. {
  1264. detpid += "," + it.F_DeptId;
  1265. }
  1266. else
  1267. {
  1268. detpid = "" + it.F_DeptId; ;
  1269. }
  1270. }
  1271. }
  1272. }
  1273. else
  1274. {
  1275. detpid = ua.F_DeptId.ToString();
  1276. }
  1277. if (GetDeptWorkOrderID(detpid) != "")
  1278. {
  1279. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid) + ") "; ;
  1280. }
  1281. else
  1282. {
  1283. CQGD = 0;
  1284. break; ;
  1285. }
  1286. }
  1287. else
  1288. {
  1289. CQGD = 0;
  1290. break; ;
  1291. }
  1292. }
  1293. else if (ro.F_RoleCode == "QTJS")
  1294. {
  1295. CQGD = 0;
  1296. break; ;
  1297. }
  1298. CQGD = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//超期
  1299. break;
  1300. case 8://退单
  1301. sql = "";
  1302. sql += $" F_IsDelete=0";
  1303. if (GetBackid(ua) != "")
  1304. {
  1305. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetBackid(ua) + ") ";
  1306. }
  1307. else
  1308. {
  1309. TD = 0;
  1310. break;
  1311. }
  1312. TD = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//
  1313. break;
  1314. case 9://我参与的
  1315. sql = "";
  1316. sql += $" F_IsDelete=0";
  1317. if (GetParticipateID(ua.F_UserCode) != "")
  1318. {
  1319. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetParticipateID(ua.F_UserCode) + ") ";
  1320. }
  1321. else
  1322. {
  1323. YFP = 0;
  1324. break;
  1325. }
  1326. YFP = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//
  1327. break;
  1328. }
  1329. }
  1330. #endregion
  1331. var obj = new
  1332. {
  1333. state = "success",
  1334. message = "成功",
  1335. DJD = DJD,//待接单
  1336. DCL = DCL,//已接单(待处理)
  1337. YCL = YCL,//已完成的
  1338. GCDBL = GCDBL,//高层待审批
  1339. YBL = YBL,//已审批
  1340. DSP = DSP,//待审批
  1341. YCD = YCD,//业务员已创单
  1342. TD = TD,//退单
  1343. CQGD = CQGD,//超期
  1344. YFP= YFP
  1345. };
  1346. return Content(obj.ToJson()); ;
  1347. }
  1348. /// <summary>
  1349. /// 审核工单
  1350. /// </summary>
  1351. public ActionResult GetApproval(string OpenId, long orderid, string AuditCont, int IsAudit = 0, int AuditState = 0, float overtime = 0, int sms = 0)
  1352. {
  1353. if (!string.IsNullOrEmpty(OpenId))
  1354. {
  1355. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  1356. if (ua != null)
  1357. {
  1358. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  1359. if (model != null)
  1360. {
  1361. var res = Approval(OpenId, orderid, AuditCont, ua, model, overtime, sms, IsAudit, AuditState);
  1362. if (res)
  1363. return Success("审核成功");
  1364. else
  1365. return Error("审核失败");
  1366. }
  1367. else
  1368. return Error("工单不存在");
  1369. }
  1370. }
  1371. return Error("OpenId不能为空");
  1372. }
  1373. /// <summary>
  1374. /// 填写超时原因
  1375. /// </summary>
  1376. /// <param name="input"></param>
  1377. /// <returns></returns>
  1378. [WechatActionFilter]
  1379. public ActionResult Reasontimeout(string OpenId, long orderid, string cont)
  1380. {
  1381. if (!string.IsNullOrEmpty(OpenId))
  1382. {
  1383. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  1384. if (ua != null)
  1385. {
  1386. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  1387. //验证信息
  1388. if (model != null)
  1389. {
  1390. model.F_Reasontimeout = cont;
  1391. bool n = woBLL.Update(model);
  1392. if (n)
  1393. return Success("填写成功");
  1394. else
  1395. return Error("填写失败!");
  1396. }
  1397. return Error("工单不存在");
  1398. }
  1399. }
  1400. return Error("无操作权限");
  1401. }
  1402. /// <summary>
  1403. /// 审核工单
  1404. /// </summary>
  1405. [WechatActionFilter]
  1406. public bool Approval(string OpenId, long orderid, string AuditCont, Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, float overtime = 0, int sms = 0, int IsAudit = 0, int AuditState = 0)
  1407. {
  1408. bool res = true;
  1409. string touser = ""; string tousername = "";
  1410. string opt = "审核";
  1411. #region 获取接收人
  1412. string deptname = "";
  1413. string deptmodelsname = "";
  1414. int wostate = 0;
  1415. var toussers = "";
  1416. #region 上报
  1417. if (IsAudit != 0)
  1418. {
  1419. if (GetUser(OpenId) != null)
  1420. {
  1421. var user = GetUser(OpenId);
  1422. var deptmodel = departmentBLL.GetModel(user.F_DeptId);
  1423. var deptmodels = departmentBLL.GetModel(nowUser.F_DeptId);
  1424. if (deptmodel != null)
  1425. {
  1426. deptname = deptmodel.F_DeptName + "-";
  1427. }
  1428. if (deptmodels != null)
  1429. {
  1430. deptmodelsname = deptmodels.F_DeptName + "-";
  1431. }
  1432. var itemlast = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.audit + " and F_CreateUser!=" + user.F_UserCode + " and F_OptType=" + (int)EnumItemOpt.audit + " and F_WoID='" + model.F_ID + "' and F_NextUser='" + nowUser.F_UserCode + "' order by F_ID desc").FirstOrDefault();
  1433. if (itemlast != null)
  1434. toussers = itemlast.F_CreateUser;
  1435. wostate = 16;
  1436. if (AuditState == 0)
  1437. {
  1438. opt = "同意上报";
  1439. var userid = AddLog(model.F_ID, model.F_State.Value, deptmodelsname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + "工单审批:同意上报" + AuditCont, (int)EnumItemType.audit, (int)EnumItemOpt.reaudit, user.F_UserCode, user.F_DeptId, nowUser, overtime, sms);
  1440. var uaid = AddLog(model.F_ID, model.F_State.Value, deptname + user.F_UserName + "(" + user.F_WorkNumber + ")" + "待审批", (int)EnumItemType.audit, (int)EnumItemOpt.audit, user.F_UserCode, user.F_DeptId, nowUser, overtime, sms);
  1441. if (userid <= 0 || uaid <= 0)
  1442. res = false;
  1443. }
  1444. else if (AuditState == 1)
  1445. {
  1446. opt = "驳回修订";
  1447. var userid = AddLog(model.F_ID, model.F_State.Value, deptmodelsname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + "工单审批:驳回修订" + AuditCont, (int)EnumItemType.audit, (int)EnumItemOpt.reback, toussers, 0, nowUser, overtime, sms);
  1448. if (userid <= 0)
  1449. res = false;
  1450. }
  1451. else
  1452. {
  1453. opt = "强制结案";
  1454. wostate = 11;
  1455. var userid = AddLog(model.F_ID, model.F_State.Value, deptmodelsname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + "工单审批:强制结案" + AuditCont, (int)EnumItemType.audit, (int)EnumItemOpt.visit, "", 0, nowUser, overtime, sms);
  1456. if (userid <= 0)
  1457. res = false;
  1458. }
  1459. }
  1460. else
  1461. {
  1462. Model.T_Sys_RoleInfo ro = rolebll.GetModel(nowUser.F_RoleId);
  1463. if (ro.F_RoleCode == "DQJL")
  1464. {
  1465. var itemlast = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.audit + " and F_OptType=" + (int)EnumItemOpt.audit + " and F_WoID='" + model.F_ID + "' and F_NextUser='" + nowUser.F_UserCode + "' order by F_ID desc").FirstOrDefault();
  1466. if (itemlast != null)
  1467. toussers = itemlast.F_CreateUser;
  1468. if (AuditState == 0)
  1469. {
  1470. opt = "同意上报";
  1471. var userid = AddLog(model.F_ID, model.F_State.Value, deptmodelsname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + "工单审批:同意上报" + AuditCont, (int)EnumItemType.audit, (int)EnumItemOpt.reaudit, "", 0, nowUser, overtime, sms);
  1472. res = GetDaQucirCulation(AuditCont, nowUser, DateTime.Now.ToString(), model.F_ID, true);
  1473. if (userid <= 0 || !res)
  1474. res = false;
  1475. wostate = 1;
  1476. }
  1477. else if (AuditState == 1)
  1478. {
  1479. opt = "驳回修订";
  1480. var userid = AddLog(model.F_ID, model.F_State.Value, deptmodelsname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + "工单审批:驳回修订" + AuditCont, (int)EnumItemType.audit, (int)EnumItemOpt.reback, toussers, 0, nowUser, overtime, sms);
  1481. if (userid <= 0)
  1482. res = false;
  1483. wostate = 16;
  1484. }
  1485. else
  1486. {
  1487. opt = "强制结案";
  1488. var userid = AddLog(model.F_ID, model.F_State.Value, deptmodelsname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + "工单审批:强制结案" + AuditCont, (int)EnumItemType.audit, (int)EnumItemOpt.visit, "", 0, nowUser, overtime, sms);
  1489. if (userid <= 0)
  1490. res = false;
  1491. wostate = 11;
  1492. }
  1493. }
  1494. else
  1495. {
  1496. res = false;
  1497. }
  1498. }
  1499. }
  1500. #endregion
  1501. #endregion
  1502. if (res)
  1503. {
  1504. model.F_State = wostate;
  1505. //处理内容
  1506. if (!string.IsNullOrEmpty(AuditCont))
  1507. model.F_AuditCont += AuditCont + ";";
  1508. model.F_IsAudit = IsAudit;
  1509. model.F_AuditState = AuditState;
  1510. model.F_AuditBy = nowUser.F_UserCode;
  1511. model.F_AuditOn = DateTime.Now;
  1512. woBLL.Update(model);
  1513. if (nowUser.F_UserCode != model.F_CreateBy)
  1514. {
  1515. sendsysmsg(model, nowUser, model.F_CreateBy, (int)model.F_ID, opt);//
  1516. var createmodel = userAccountBLL.GetModel(model.F_CreateBy); //
  1517. if (createmodel != null)
  1518. {
  1519. if (!string.IsNullOrEmpty(createmodel.F_WxOpenId))
  1520. {
  1521. sendwxmsg(model, createmodel.F_WxOpenId, nowUser, opt);
  1522. }
  1523. }
  1524. }
  1525. #region 向下一级操作人员推送消息
  1526. if (!string.IsNullOrWhiteSpace(touser))
  1527. {
  1528. sendsysmsg(model, nowUser, touser, (int)model.F_ID, opt);//
  1529. var modelUser2 = userAccountBLL.GetModel(touser); //
  1530. if (modelUser2 != null)
  1531. {
  1532. if (!string.IsNullOrEmpty(modelUser2.F_WxOpenId))
  1533. {
  1534. sendwxmsg(model, modelUser2.F_WxOpenId, nowUser, opt);
  1535. }
  1536. }
  1537. }
  1538. #endregion 向下一级操作人员推送消息
  1539. }
  1540. else
  1541. return false;
  1542. return true;
  1543. }
  1544. /// <summary>
  1545. /// 大区经理未审批流转市场管理科
  1546. /// </summary>
  1547. /// <param name="ua"></param>
  1548. /// <param name="time"></param>
  1549. /// <param name="id"></param>
  1550. public bool GetDaQucirCulation(string AuditCont, Model.T_Sys_UserAccount ua, string time, long id, bool istrue)
  1551. {
  1552. DateTime times = DateTime.Parse(time).AddHours(24);
  1553. Model.T_Wo_WorkOrder model = woBLL.GetModel(id);
  1554. List<Model.T_Wo_WorkOrder> modeLlist = new List<Model.T_Wo_WorkOrder>();
  1555. modeLlist.Add(model);
  1556. List<WorkOrderNewInput> Input = modeltooip(modeLlist, ua);
  1557. string cont = "";
  1558. int dapt = 0, nextda = 0; string opt = "";
  1559. var deptmodel1 = departmentBLL.GetModel(ua.F_DeptId);
  1560. if (deptmodel1 != null)
  1561. {
  1562. dapt = deptmodel1.F_ParentId;
  1563. }
  1564. if (dapt != 0)
  1565. {
  1566. if (dapt == 11)
  1567. {
  1568. nextda = 37;
  1569. opt = "流转市场管理科";
  1570. }
  1571. else if (dapt == 14)
  1572. {
  1573. nextda = 57;
  1574. opt = "流转营销管理处";
  1575. }
  1576. else if (dapt == 15)
  1577. {
  1578. nextda = 74;
  1579. opt = "流转策划推广";
  1580. }
  1581. else if (dapt == 16)
  1582. {
  1583. nextda = 88;
  1584. opt = "流转销售部";
  1585. }
  1586. }
  1587. if (istrue)
  1588. {
  1589. cont = "大区经理已审批:" + AuditCont + "," + opt;
  1590. }
  1591. else
  1592. {
  1593. cont = "大区经理未审批" + opt;
  1594. }
  1595. if (nextda != 0)
  1596. {
  1597. var res = AssignWO(ua, model, Input[0], cont, "", nextda, 0, 0, 0, 0, 0, 0, time.ToString());
  1598. return res;
  1599. }
  1600. else
  1601. {
  1602. return false;
  1603. }
  1604. }
  1605. /// <summary>
  1606. /// 查询工单详情
  1607. /// </summary>
  1608. [WechatActionFilter]
  1609. public ActionResult GetDetails(string OpenId, int id)
  1610. {
  1611. if (!string.IsNullOrEmpty(OpenId))
  1612. {
  1613. if (id <= 0)
  1614. {
  1615. return Error("请输入正确的id");
  1616. }
  1617. DataTable FileUrl = new DataTable();
  1618. var list = new List<Model.T_Wo_WorkOrder>();
  1619. var model = woBLL.GetModel(id);
  1620. if (model != null)
  1621. list.Add(model);
  1622. var itemlasts = itembll.GetModelList(" F_WoID=" + +id + " ");
  1623. ; var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  1624. if (!string.IsNullOrEmpty(model.F_Files))
  1625. {
  1626. FileUrl = GetFileData(model.F_Files, configfj.F_ParamValue);
  1627. }
  1628. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  1629. if (model.F_Source != "3")
  1630. {
  1631. if (ua == null)
  1632. {
  1633. return Success("你的账号已在别处登录,你确定要再次登录吗?");
  1634. }
  1635. }
  1636. if (list.Count > 0)
  1637. {
  1638. List<WorkOrderNewInput> Input = modeltooip(list, ua);
  1639. if (Input != null)
  1640. {
  1641. var obj = new
  1642. {
  1643. state = "success",
  1644. message = "成功",
  1645. rows = Input,
  1646. FileUrl,
  1647. total = itemlasts,
  1648. };
  1649. return Content(obj.ToJson());
  1650. }
  1651. else
  1652. {
  1653. return Error("没有查询到此工单");
  1654. }
  1655. }
  1656. else
  1657. return Error("没有查询到此工单");
  1658. }
  1659. else
  1660. {
  1661. return Error("无操作权限!");
  1662. }
  1663. }
  1664. public string GetID(string str, long id)
  1665. {
  1666. if (str != "")
  1667. {
  1668. str += "," + id;
  1669. }
  1670. else
  1671. {
  1672. str += id;
  1673. }
  1674. return str;
  1675. }
  1676. public string GetDeptment(Model.T_Sys_UserAccount ua)
  1677. {
  1678. string detpid = string.Empty;
  1679. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  1680. var deparmentlist = new List<Model.T_Sys_Department>();
  1681. if (dModel != null)
  1682. {
  1683. if (dModel.F_Layer == 1)
  1684. {
  1685. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  1686. if (deparmentlist.Count > 0)
  1687. {
  1688. foreach (var it in deparmentlist)
  1689. {
  1690. if (detpid != "")
  1691. {
  1692. detpid += "," + it.F_DeptId;
  1693. }
  1694. else
  1695. {
  1696. detpid = "" + it.F_DeptId;
  1697. }
  1698. }
  1699. }
  1700. }
  1701. else
  1702. {
  1703. detpid = ua.F_DeptId.ToString();
  1704. }
  1705. }
  1706. return detpid;
  1707. }
  1708. /// <summary>
  1709. /// 获取待审批的工单
  1710. /// </summary>
  1711. /// <param name="user"></param>
  1712. /// <returns></returns>
  1713. public string GetApprovalOrderID(Model.T_Sys_UserAccount ua, string OpenId, string F_RoleCode)
  1714. {
  1715. string str = string.Empty;
  1716. #region 查询自己名下未审批的工单列表
  1717. var itemlast = itembll.GetModelList(" isnull(F_IsUsed,'0')='0' and F_OptType in(" + (int)EnumItemOpt.audit + ")" + " and "
  1718. + "F_WoState in(" + (int)EnumWorkOrderState.audit + ") and F_NextUser='" + ua.F_UserCode + "' "
  1719. + "" + " ");
  1720. foreach (var it in itemlast)
  1721. {
  1722. float hours = (DateTime.Now - DateTime.Parse(it.F_CreateTime.ToString())).Hours;
  1723. int overtime = 0;
  1724. if (!string .IsNullOrEmpty (it.F_LimitTime))
  1725. {
  1726. overtime = int.Parse(it.F_LimitTime);
  1727. }
  1728. int sms = int.Parse (it.F_IsSMS.ToString ());
  1729. if (F_RoleCode == "DQJL")
  1730. {
  1731. if (hours >= 24)
  1732. {
  1733. GetDaQucirCulation("", ua, it.F_CreateTime.ToString(), it.F_WoID, false);
  1734. }
  1735. else
  1736. {
  1737. str = GetID(str, it.F_WoID);
  1738. }
  1739. }
  1740. else
  1741. {
  1742. var user = GetUser(OpenId);
  1743. string deptname = "";
  1744. string deptmodelsname = "";
  1745. var deptmodel = departmentBLL.GetModel(user.F_DeptId);
  1746. var deptmodels = departmentBLL.GetModel(ua.F_DeptId);
  1747. if (deptmodel != null)
  1748. {
  1749. deptname = deptmodel.F_DeptName + "-";
  1750. }
  1751. if (deptmodels != null)
  1752. {
  1753. deptmodelsname = deptmodels.F_DeptName + "-";
  1754. }
  1755. if (hours >= 24)
  1756. {
  1757. DateTime time = DateTime.Parse(it.F_CreateTime.ToString()).AddHours(24);
  1758. Model.T_Wo_WorkOrder model = woBLL.GetModel(it.F_WoID);
  1759. AddLog(model.F_ID, model.F_State.Value, deptmodelsname + ua.F_UserName + "(" + ua.F_WorkNumber + ")" + "未审批流转大区经理", (int)EnumItemType.audit, (int)EnumItemOpt.audit, user.F_UserCode, user.F_DeptId, ua, overtime, sms );
  1760. AddLog(model.F_ID, model.F_State.Value, deptname + user.F_UserName + "(" + user.F_WorkNumber + ")" + "待审批", (int)EnumItemType.audit, (int)EnumItemOpt.audit, user.F_UserCode, user.F_DeptId, user, overtime, sms);
  1761. }
  1762. else if (hours >= 48)
  1763. {
  1764. GetDaQucirCulation("", user, it.F_CreateTime.ToString(), it.F_WoID, false);
  1765. }
  1766. else
  1767. {
  1768. str = GetID(str, it.F_WoID);
  1769. }
  1770. }
  1771. }
  1772. #endregion
  1773. if (F_RoleCode == "DQJL")
  1774. {
  1775. if (!string.IsNullOrEmpty(GetDeptment(ua)))
  1776. {
  1777. var itemlasts = itembll.GetModelList(" isnull(F_IsUsed,'0')='0' and F_OptType in(" + (int)EnumItemOpt.audit + ")" + " and "
  1778. + "F_WoState in(" + (int)EnumWorkOrderState.audit + ") and F_NextUser in ( " + GetDeptment(ua) + ") ");
  1779. foreach (var it in itemlasts)
  1780. {
  1781. int overtime = 0;
  1782. if (!string.IsNullOrEmpty(it.F_LimitTime))
  1783. {
  1784. overtime = int.Parse(it.F_LimitTime);
  1785. }
  1786. int sms = int.Parse(it.F_IsSMS.ToString());
  1787. float hours = (DateTime.Now - DateTime.Parse(it.F_CreateTime.ToString())).Hours;
  1788. if (F_RoleCode == "DQJL")
  1789. {
  1790. if (hours >= 24)
  1791. {
  1792. Model.T_Sys_UserAccount user = userAccountBLL.GetModel(it.F_CreateUser);
  1793. DateTime time = DateTime.Parse(it.F_CreateTime.ToString()).AddHours(24);
  1794. Model.T_Wo_WorkOrder model = woBLL.GetModel(it.F_WoID);
  1795. string deptname = "";
  1796. string deptmodelsname = "";
  1797. var deptmodel = departmentBLL.GetModel(user.F_DeptId);
  1798. var deptmodels = departmentBLL.GetModel(ua.F_DeptId);
  1799. if (deptmodel != null)
  1800. {
  1801. deptname = deptmodel.F_DeptName + "-";
  1802. }
  1803. if (deptmodels != null)
  1804. {
  1805. deptmodelsname = deptmodels.F_DeptName + "-";
  1806. }
  1807. AddLog(model.F_ID, model.F_State.Value, deptmodelsname + user.F_UserName + "(" + user.F_WorkNumber + ")" + "未审批流转大区经理", (int)EnumItemType.audit, (int)EnumItemOpt.audit, ua.F_UserCode, ua.F_DeptId, user, overtime, sms);
  1808. AddLog(model.F_ID, model.F_State.Value, deptname + ua.F_UserName + "(" + ua.F_WorkNumber + ")" + "待审批", (int)EnumItemType.audit, (int)EnumItemOpt.audit, ua.F_UserCode, ua.F_DeptId, ua, overtime, sms );
  1809. if (hours < 48)
  1810. {
  1811. str = GetID(str, it.F_WoID);
  1812. }
  1813. else
  1814. {
  1815. GetDaQucirCulation("", ua, time.ToString(), it.F_WoID, false);
  1816. }
  1817. }
  1818. }
  1819. }
  1820. }
  1821. }
  1822. return str;
  1823. }
  1824. /// <summary>
  1825. /// 获取已审批的工单列表
  1826. /// </summary>
  1827. /// <param name="user"></param>
  1828. /// <returns></returns>
  1829. public string GetApprovedOrderID(string user)
  1830. {
  1831. string str = string.Empty;
  1832. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_OptType=" + (int)EnumItemOpt.reaudit
  1833. + " and F_CreateUser=" + user + " "//
  1834. ;
  1835. return str;
  1836. }
  1837. /// <summary>
  1838. /// 获取已审批的工单列表
  1839. /// </summary>
  1840. /// <param name="user"></param>
  1841. /// <returns></returns>
  1842. public string GetApprovedOrderID()
  1843. {
  1844. string str = string.Empty;
  1845. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_OptType=" + (int)EnumItemOpt.reaudit
  1846. //
  1847. ;
  1848. return str;
  1849. }
  1850. /// <summary>
  1851. /// 根据model返回CustomerBaseNewInput对象
  1852. /// </summary>
  1853. private List<WorkOrderNewInput> modeltooip(List<Model.T_Wo_WorkOrder> model1, Model.T_Sys_UserAccount ua)
  1854. {
  1855. if (model1 != null && model1.Count > 0)
  1856. {
  1857. List<WorkOrderNewInput> Input = new List<WorkOrderNewInput>(model1.Count);
  1858. for (int i = 0; i < model1.Count; i++)
  1859. {
  1860. WorkOrderNewInput model = new WorkOrderNewInput();
  1861. Model.T_Cus_CustomerBaseNew cuModel = new Model.T_Cus_CustomerBaseNew();
  1862. if (!string.IsNullOrEmpty(model1[i].F_CustomerID))
  1863. {
  1864. cuModel = customerBaseBLL.GetModel(model1[i].F_CustomerID.ToString());//通过客户编号获取客户资料
  1865. }
  1866. else
  1867. {
  1868. var sql = $" and F_LegalPhone ='" + model1[i].F_CusPhone.Trim() + "'";
  1869. cuModel = new BLL.T_Cus_CustomerBaseNew().GetModelList(" F_IsDelete = 0 " + sql).FirstOrDefault();
  1870. }
  1871. if (cuModel != null)
  1872. {
  1873. if (!string.IsNullOrEmpty(cuModel.F_AreaID))
  1874. {
  1875. Model.T_Sys_Department pdModel = departmentBLL.GetModel(int.Parse(cuModel.F_AreaID));//通过公司id获取部门
  1876. if (pdModel != null)
  1877. {
  1878. model.F_AreaName = pdModel.F_DeptName;
  1879. }
  1880. }
  1881. if (!string.IsNullOrEmpty(cuModel.F_BranchID))
  1882. {
  1883. Model.T_Sys_Department pdModel1 = departmentBLL.GetModel(int.Parse(cuModel.F_BranchID));
  1884. if (pdModel1 != null)
  1885. {
  1886. model.F_BranchName = pdModel1.F_DeptName;
  1887. }
  1888. }
  1889. model.F_CompanyName = cuModel.F_CompanyName;//公司名称
  1890. model.F_CustomerID = cuModel.F_CustomerCode;//客户编码
  1891. model.F_Salesman = cuModel.F_Salesman;
  1892. model.F_SalesPhone = cuModel.F_SalesPhone;
  1893. model.F_Legal = cuModel.F_Legal;
  1894. model.F_LegalPhone = cuModel.F_LegalPhone;
  1895. model.F_AddressProvince = cuModel.F_AddressProvince;
  1896. model.F_AddressCity = cuModel.F_AddressCity;
  1897. model.F_AddressCountry = cuModel.F_AddressCountry;
  1898. model.F_AddressTownship = cuModel.F_AddressTownship;
  1899. model.F_AddressFull = cuModel.F_AddressFull;
  1900. model.F_Brands = cuModel.F_Brands;
  1901. model.F_Channel = cuModel.F_Channel;
  1902. model.F_IsRunXLX = cuModel.F_IsRunXLX;
  1903. model.F_AnnualSales = cuModel.F_AnnualSales;
  1904. model.F_Formula = cuModel.F_Formula;
  1905. model.F_RaiseCrops = cuModel.F_RaiseCrops;
  1906. model.F_PlantingArea = cuModel.F_PlantingArea;
  1907. model.F_FertilizerBrand = cuModel.F_FertilizerBrand;
  1908. }
  1909. if (valcode(model1[i].F_MaterialID.ToString(), 11))
  1910. {
  1911. model.F_MaterialID = model1[i].F_MaterialID;//验证物料编码为11位纯数字
  1912. Model.T_Wo_MaterialManage maModel = mmBLL.GetModel(model1[i].F_MaterialID.ToString());//通过物料编码获取物料信息
  1913. if (maModel != null)
  1914. {
  1915. model.F_MaterialName = maModel.F_MaterialName;
  1916. model.F_Model = maModel.F_Model;
  1917. model.F_Specs = maModel.F_Specs;
  1918. model.F_Level1 = maModel.F_Level1;
  1919. model.F_Level2 = maModel.F_Level2;
  1920. model.F_Level3 = maModel.F_Level3;
  1921. model.F_Brand = maModel.F_Brand;
  1922. model.F_MaterialEffect = maModel.F_MaterialEffect;
  1923. model.F_Pipeline = maModel.F_Pipeline;
  1924. model.F_Craft = maModel.F_Craft;
  1925. }
  1926. }
  1927. #region 基本字段
  1928. model.F_ID = model1[i].F_ID;//
  1929. model.F_WorkOrderCode = model1[i].F_WorkOrderCode;//工单编号
  1930. #region
  1931. if (!string.IsNullOrEmpty(model1[i].F_Source))
  1932. {
  1933. model.F_Source = int.Parse(model1[i].F_Source);//工单来源
  1934. }
  1935. if (model1[i].F_Source == "1")
  1936. {
  1937. model.F_SourceName = "电话";
  1938. }
  1939. else if (model1[i].F_Source == "2")
  1940. {
  1941. model.F_SourceName = "微信业务员";
  1942. }
  1943. else if (model1[i].F_Source == "3")
  1944. {
  1945. model.F_SourceName = "微信客户";
  1946. }
  1947. else
  1948. {
  1949. model.F_SourceName = "官网";
  1950. }
  1951. model.F_Type = int.Parse(model1[i].F_Type);//工单来源
  1952. if (model1[i].F_Type == "1")
  1953. {
  1954. model.F_TypeName = "咨询";//工单类型:咨询及需求、投诉、抽检、其他(其它手动输入别的点选)
  1955. }
  1956. else if (model1[i].F_Type == "2")
  1957. {
  1958. model.F_TypeName = "投诉";//工单类型:咨询及需求、投诉、抽检、其他(其它手动输入别的点选)
  1959. }
  1960. else if (model1[i].F_Type == "3")
  1961. {
  1962. model.F_TypeName = "抽检";//工单类型:咨询及需求、投诉、抽检、其他(其它手动输入别的点选)
  1963. }
  1964. else
  1965. {
  1966. model.F_TypeName = "建议及其他";//工单类型:咨询及需求、投诉、抽检、其他(其它手动输入别的点选)
  1967. }
  1968. model.F_State = model1[i].F_State;
  1969. if (model1[i].F_State == 0)//工单状态
  1970. {
  1971. model.F_StateName = "待指派";
  1972. }
  1973. else if (model1[i].F_State == 1)
  1974. {
  1975. model.F_StateName = "待接单";
  1976. }
  1977. else if (model1[i].F_State == 2)
  1978. {
  1979. model.F_StateName = "待处理";
  1980. }
  1981. else if (model1[i].F_State == 3)
  1982. {
  1983. model.F_StateName = "已退回";
  1984. }
  1985. else if (model1[i].F_State == 4)
  1986. {
  1987. model.F_StateName = "异常退回";
  1988. }
  1989. else if (model1[i].F_State == 5)
  1990. {
  1991. model.F_StateName = "处理中";
  1992. }
  1993. else if (model1[i].F_State == 6)
  1994. {
  1995. model.F_StateName = "待回访";
  1996. }
  1997. else if (model1[i].F_State == 7)
  1998. {
  1999. model.F_StateName = "待完结";
  2000. }
  2001. else if (model1[i].F_State == 10)
  2002. {
  2003. model.F_StateName = "已处理";
  2004. }
  2005. else if (model1[i].F_State == 11)
  2006. {
  2007. model.F_StateName = "已评价";
  2008. }
  2009. else if (model1[i].F_State == 12)
  2010. {
  2011. model.F_StateName = "已退回";
  2012. }
  2013. else if (model1[i].F_State == 14)
  2014. {
  2015. model.F_StateName = "待办理";
  2016. }
  2017. else if (model1[i].F_State == 15)
  2018. {
  2019. model.F_StateName = "微信未通过";
  2020. }
  2021. else if (model1[i].F_State == 16)
  2022. {
  2023. model.F_StateName = "待办理";
  2024. }
  2025. #endregion
  2026. model.F_CusName = model1[i].F_CusName;//客户姓名
  2027. model.F_CusPhone = model1[i].F_CusPhone;//客户电话
  2028. model.F_Canal = model1[i].F_Canal;//
  2029. model.F_IncidentProvince = model1[i].F_IncidentProvince;//事发地-省
  2030. model.F_IncidentCity = model1[i].F_IncidentCity;//事发地-市
  2031. model.F_IncidentCountry = model1[i].F_IncidentCountry;//事发地-县
  2032. model.F_IncidentTownship = model1[i].F_IncidentTownship;//事发地-乡
  2033. model.F_IncidentDetailed = model1[i].F_IncidentDetailed;//事发地-详细
  2034. model.F_SalesBase = model1[i].F_SalesBase;//销售基地:新乡、新疆、九江、东北、其他(其它手动输入别的点选)
  2035. model.F_Description = model1[i].F_Description;//问题描述
  2036. model.F_Files = "0";//附件上传ids
  2037. model.F_DealType = model1[i].F_DealType;//处理方式:当即办理、电话转接、网络转办(点选)
  2038. #endregion
  2039. if (!string.IsNullOrEmpty(model1[i].F_QuestionType))
  2040. {
  2041. try
  2042. {
  2043. int b = int.Parse(model1[i].F_QuestionType.Trim());
  2044. Model.T_Wo_QuestionManage manage = quesBLL.GetModel(b);
  2045. if (manage != null)
  2046. {
  2047. model.F_QuestionType = manage.F_QuestionName;
  2048. if (manage.F_Label == "3")
  2049. {
  2050. Model.T_Wo_QuestionManage Manage1 = quesBLL.GetModel(int.Parse(manage.F_ParentId.ToString()));//获取问题类别
  2051. Model.T_Wo_QuestionManage Manage2 = quesBLL.GetModel(int.Parse(Manage1.F_ParentId.ToString()));//获取问题类别
  2052. model.F_QuestionTypeone = Manage2.F_QuestionName;//问题类别1
  2053. model.F_QuestionTypetwo = Manage1.F_QuestionName;//问题类别2
  2054. }
  2055. }
  2056. }
  2057. catch (Exception)
  2058. {
  2059. model.F_QuestionType = model1[i].F_QuestionType; //问题类别(投诉抽捡和咨询类别不一样)
  2060. }
  2061. }
  2062. #region 投诉类
  2063. model.F_BatchNumber = model1[i].F_BatchNumber;//生产批次号
  2064. model.F_TS_Formula = model1[i].F_TS_Formula;// 投诉-配方
  2065. model.F_TS_Category = model1[i].F_TS_Category;//投诉-产品种类:化肥、化工、其他
  2066. model.F_TS_Quantity = model1[i].F_TS_Quantity;//投诉-问题数量(吨)
  2067. model.F_TS_Level = model1[i].F_TS_Level;//投诉-重要级别:轻微、一般、较大、重大
  2068. #endregion
  2069. #region 咨询类
  2070. // model.F_ZX_ProName = model1[i].F_ZX_ProName;//咨询-产品名称:三聚氰胺、甲醇、液氨、二甲醚、糠醇、其他
  2071. model.F_ZX_Quantity = model1[i].F_ZX_Quantity;// 咨询-问题数量(吨)
  2072. model.F_ZX_Area = model1[i].F_ZX_Area;// 咨询-大区
  2073. model.F_ZX_Branch = model1[i].F_ZX_Branch;// 咨询-分公司
  2074. #endregion
  2075. #region 抽检类
  2076. model.F_CJ_Time = model1[i].F_CJ_Time;// 抽检-抽检时间
  2077. model.F_CJ_Level = model1[i].F_CJ_Level;// 抽检-抽检级别:乡镇级、县级、市级、省级及以上、个人送检
  2078. model.F_CJ_Unit = model1[i].F_CJ_Unit;// 抽检-抽检单位:市场监督、农业部、土肥站、工商、联合执法、其他
  2079. model.F_CJ_TestUnit = model1[i].F_CJ_TestUnit;//抽检-化验单位
  2080. model.F_CJ_Tonnage = model1[i].F_CJ_Tonnage;//抽检-抽检吨数
  2081. model.F_CJ_BagNo = model1[i].F_CJ_BagNo;//抽检-抽检袋数
  2082. model.F_CJ_Outlay = model1[i].F_CJ_Outlay;//抽检-公关费用金额:单位元
  2083. model.F_WorkerBrand = model1[i].F_Brand;//工单品牌
  2084. model.F_DealBy = model1[i].F_DealBy;//处理人
  2085. model.F_DealTime = model1[i].F_DealTime;//处理时间
  2086. model.F_DealContent = model1[i].F_DealContent;//处理内容
  2087. model.F_DealResult = model1[i].F_DealResult;//处理结果
  2088. model.F_DealReasons = model1[i].F_DealReasons;//未处理原因
  2089. model.F_SC_ProductBase = model1[i].F_SC_ProductBase;//市场管理科-生产基地(新乡、新疆、九江、东北、贴牌、无法确定)
  2090. model.F_SC_PreliminaryOpinion = model1[i].F_SC_PreliminaryOpinion;// 市场管理科-初审意见:退货、换货、补偿、自行处理
  2091. model.F_SC_QualityMonth = model1[i].F_SC_QualityMonth;//市场管理科-超出质保期限(算法:工单创建日期-生产日期,生产日期根据生产批次号获取,单位:月)
  2092. model.F_SC_CJ_SpotResult = model1[i].F_SC_CJ_SpotResult;/// 市场管理科-抽检-抽检结果(视同合格、合格、不合格、复检后合格、未送检)
  2093. model.F_SC_CJ_SelfResult = model1[i].F_SC_CJ_SelfResult;//市场管理科-抽检-自检结果
  2094. model.F_SC_CJ_ApprovalNo = model1[i].F_SC_CJ_ApprovalNo;// 市场管理科-抽检-对应审批工作流单号
  2095. model.F_SC_CJ_ReturnAccount = model1[i].F_SC_CJ_ReturnAccount;//市场管理科-抽检-确认返账金额(元)
  2096. model.F_ZL_QualityEventLevel = model1[i].F_ZL_QualityEventLevel;// 质量管理科-质量事件等级(未遂、一般、较大、重大)
  2097. model.F_ZL_ClaimAmount = model1[i].F_ZL_ClaimAmount;//质量管理科-索赔金额(单位元,对应责任单位)
  2098. model.F_ZL_ResponsibleUnit = model1[i].F_ZL_ResponsibleUnit;//质量管理科-责任单位(需列出,可选多个)
  2099. model.F_ZL_ApprovalOpinions = model1[i].F_ZL_ApprovalOpinions;// 质量管理科-审批意见(同意、不同意,若选择不同意,增加输入框输入补充内容)
  2100. model.F_ZL_ApprovalDisagree = model1[i].F_ZL_ApprovalDisagree;// 质量管理科-审批不同意意见
  2101. model.F_ZL_CompensationMethod = model1[i].F_ZL_CompensationMethod;//质量管理科-补偿方式(实物、钱款【单位元】,若选择钱款,增加输入框输入补充内容)
  2102. model.F_ZL_CompensationMoney = model1[i].F_ZL_CompensationMoney;// 质量管理科-补偿钱款
  2103. model.F_ZL_CResponsibleUnits = model1[i].F_ZL_CResponsibleUnits;//质量管理科-对应责任单位(生产、研发、农化、物流、质量管理科,销售内勤)
  2104. model.F_ZL_Fquantity = model1[i].F_ZL_Fquantity;// 质量管理科-确认实收数量(吨)
  2105. model.F_ZL_ImprovementRequirements = model1[i].F_ZL_ImprovementRequirements;//质量管理科-改进要求
  2106. model.F_ZL_CApprovalNo = model1[i].F_ZL_CApprovalNo;//质量管理科-对应审批工作流单号
  2107. model.F_ZL_CJ_IsRecord = model1[i].F_ZL_CJ_IsRecord;//质量管理科-抽检-未备案、已备案
  2108. model.F_VisitRemarks = model1[i].F_VisitRemarks;//回访备注
  2109. model.SuperiorOpinion = AssCont(model1[i].F_ID);//上级处理意见
  2110. if (model1[i].F_SMSReply == 1)
  2111. {
  2112. model.F_SMSReply = "满意";//短信回访结果
  2113. }
  2114. else if (model1[i].F_SMSReply == 2)
  2115. {
  2116. model.F_SMSReply = "一般";//短信回访结果
  2117. }
  2118. else if (model1[i].F_SMSReply == 3)
  2119. {
  2120. model.F_SMSReply = "不满意";//短信回访结果
  2121. }
  2122. else
  2123. {
  2124. model.F_SMSReply = "";//短信回访结果
  2125. }
  2126. if (model1[i].F_IsVisit != 0)
  2127. {
  2128. model.F_IsVisit = "是";//是否回访
  2129. }
  2130. else
  2131. {
  2132. model.F_IsVisit = "否";//是否回访
  2133. }
  2134. model.F_IsAudit = model1[i].F_IsAudit;//是否审核
  2135. model.F_Highopinions = model1[i].F_Highopinions;//高层处理意见
  2136. model.F_CreateOn = model1[i].F_CreateOn; ;//添加时间
  2137. // model.F_CreateBy = model1[i].F_CreateBy; ;//添加人
  2138. if (!string.IsNullOrEmpty(model1[i].F_CreateBy))
  2139. {
  2140. Model.T_Sys_UserAccount creatname = userAccountBLL.GetModel(model1[i].F_CreateBy);
  2141. if (creatname != null)
  2142. {
  2143. model.F_CreateBy = creatname.F_WorkNumber; ;//添加人
  2144. model.F_CreateName = creatname.F_UserName; ;//添加人
  2145. model.CreateName = creatname.F_UserName + "(" + creatname.F_WorkNumber + ")";
  2146. }
  2147. }
  2148. model.F_UpdateBy = model1[i].F_UpdateBy;//修改人工号
  2149. model.F_UpdateOn = model1[i].F_UpdateOn; ;//修改人工号
  2150. if (model1[i].F_IsAudit != 0 && model1[i].F_IsAudit != null)
  2151. {
  2152. if (model1[i].F_AuditState == 0)
  2153. {
  2154. model.F_AuditState = "同意上报";
  2155. }
  2156. else if (model1[i].F_AuditState == 1)
  2157. {
  2158. model.F_AuditState = "驳回修订";
  2159. }
  2160. else
  2161. {
  2162. model.F_AuditState = "强制结案";
  2163. }
  2164. }
  2165. else
  2166. {
  2167. model.F_AuditState = "";
  2168. }
  2169. model.F_AuditBy = model1[i].F_AuditBy;//审核人
  2170. model.F_AuditOn = model1[i].F_AuditOn;//审核时间
  2171. model.F_AuditCont = model1[i].F_AuditCont;//审核内容
  2172. model.RemainingTime = float.Parse(string.Format("{0:f2}", TimeToOver(model1[i].F_ID, model1[i].F_limit)));
  2173. if (ua != null)
  2174. {
  2175. var itemlast = itembll.GetModelList(" F_WoID='" + model.F_ID + "' order by F_ID desc").FirstOrDefault();
  2176. if (itemlast != null)
  2177. model.F_UserCode = itemlast.F_CreateUser;
  2178. if (!string.IsNullOrEmpty(model.F_UserCode))
  2179. {
  2180. Model.T_Sys_UserAccount user = userAccountBLL.GetModel(model.F_UserCode);
  2181. model.F_UserName = user.F_UserName;
  2182. Model.T_Sys_Department dept = departmentBLL.GetModel(user.F_DeptId);
  2183. if (dept != null)
  2184. {
  2185. model.F_NextDeptName = dept.F_DeptName;
  2186. }
  2187. }
  2188. }
  2189. if (TimeToOver(model1[i].F_ID, model1[i].F_limit) < 0)
  2190. {
  2191. model.F_IsOver = 1;
  2192. }
  2193. else
  2194. {
  2195. model.F_IsOver = model1[i].F_IsOver;
  2196. }
  2197. if (ua != null)
  2198. {
  2199. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  2200. if (deptmodel != null)
  2201. {
  2202. model.F_Deptid = deptmodel.F_DeptId;
  2203. model.F_DeptName = deptmodel.F_DeptName;
  2204. }
  2205. }
  2206. #endregion
  2207. Input.Add(model);
  2208. }
  2209. return Input;
  2210. }
  2211. else
  2212. {
  2213. return null;
  2214. }
  2215. }
  2216. /// <summary>
  2217. /// 是否超时
  2218. /// </summary>
  2219. /// <param name="id"></param>
  2220. /// <returns></returns>
  2221. private float TimeToOver(int id, int limit)
  2222. {
  2223. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID=" + id + "order by F_ID desc ");
  2224. string time1 = "", time2 = ""; int x = 0, y = 0;
  2225. if (itemlasts.Count > 0)
  2226. {
  2227. for (int z = 0; z < itemlasts.Count; z++)
  2228. {
  2229. if (itemlasts[z].F_WoState >= 1)
  2230. {
  2231. if (itemlasts[z].F_WoState == 1)
  2232. {
  2233. x = z;
  2234. time1 = itemlasts[z].F_CreateTime.ToString();
  2235. break;
  2236. }
  2237. }
  2238. }
  2239. for (int i = 0; i < itemlasts.Count; i++)
  2240. {
  2241. if (itemlasts[i].F_WoState >= 1)
  2242. {
  2243. if (itemlasts[i].F_WoState == 11)
  2244. {
  2245. y = i;
  2246. time2 = itemlasts[i].F_CreateTime.ToString();
  2247. }
  2248. }
  2249. }
  2250. if (time2 != "")
  2251. {
  2252. if (time1 != "")
  2253. {
  2254. if (x > y)
  2255. {
  2256. System.TimeSpan a = DateTime.Parse(time2) - DateTime.Parse(time1);
  2257. float b = limit - (float)a.TotalHours;
  2258. return b;
  2259. }
  2260. else
  2261. {
  2262. System.TimeSpan a = DateTime.Now - DateTime.Parse(time1);
  2263. float b = limit - (float)a.TotalHours;
  2264. return b;
  2265. }
  2266. }
  2267. else
  2268. {
  2269. return 0;
  2270. }
  2271. }
  2272. else if (time1 != "")
  2273. {
  2274. System.TimeSpan a = DateTime.Now - DateTime.Parse(time1);
  2275. float b = limit - (float)a.TotalHours;
  2276. return b;
  2277. }
  2278. else
  2279. {
  2280. return 0;
  2281. }
  2282. }
  2283. else
  2284. {
  2285. return 0;
  2286. }
  2287. }
  2288. private string AssCont(int id)
  2289. {
  2290. string cont = "";
  2291. var itemlist = itembll.GetModelList("F_WoID=" + id + "and F_IsUsed=0" + "order by F_ID desc");
  2292. if (itemlist.Count > 0)
  2293. {
  2294. cont = itemlist[0].F_OptContent;
  2295. }
  2296. return cont;
  2297. }
  2298. /// <summary>
  2299. /// 获取当前用户上一级的用户
  2300. /// </summary>
  2301. /// <param name="OpenId"></param>
  2302. /// <returns></returns>
  2303. public Model.T_Sys_UserAccount GetUser(string OpenId)
  2304. {
  2305. if (!string.IsNullOrEmpty(OpenId))
  2306. {
  2307. // int userId = CurrentUser.UserData.F_UserId;
  2308. // Model.T_Sys_UserAccount ua = userAccountBLL.GetModel(userId);
  2309. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  2310. if (ua != null)
  2311. {
  2312. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  2313. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  2314. // var dept = departmentBLL.GetModel(deptmodel.F_ParentId);
  2315. #region 业务员
  2316. if (ro.F_RoleCode == "YWY")
  2317. {
  2318. if (deptmodel != null)
  2319. {
  2320. if (deptmodel.F_Layer == 2)
  2321. {
  2322. Model.T_Sys_UserAccount userModel = userAccountBLL.GetModelList(" F_DeptId=" + deptmodel.F_DeptId + " and F_RoleId=60 ").FirstOrDefault();
  2323. if (userModel!=null )
  2324. return userModel;
  2325. else
  2326. {
  2327. var dept = departmentBLL.GetModel(deptmodel.F_ParentId);
  2328. if (dept != null)
  2329. {
  2330. Model.T_Sys_UserAccount userModel1 = userAccountBLL.GetModelList(" F_DeptId=" + dept.F_DeptId + " and F_RoleId=62 ").FirstOrDefault();
  2331. return userModel1;
  2332. }
  2333. }
  2334. }
  2335. if (deptmodel.F_Layer == 1)
  2336. {
  2337. Model.T_Sys_UserAccount userModel = userAccountBLL.GetModelList(" F_DeptId=" + deptmodel.F_DeptId + " and F_RoleId=62 ").FirstOrDefault();
  2338. return userModel;
  2339. }
  2340. }
  2341. else
  2342. {
  2343. return null;
  2344. }
  2345. }
  2346. #endregion
  2347. #region 大区经理
  2348. else if (ro.F_RoleCode == "DQJL")
  2349. {
  2350. return null;
  2351. }
  2352. #endregion
  2353. #region 分公司经理
  2354. else if (ro.F_RoleCode == "FGSJL")
  2355. {
  2356. if (deptmodel != null)
  2357. {
  2358. var dept = departmentBLL.GetModel(deptmodel.F_ParentId);
  2359. if (dept != null)
  2360. {
  2361. Model.T_Sys_UserAccount userModel = userAccountBLL.GetModelList(" F_DeptId=" + dept.F_DeptId + " and F_RoleId=62 ").FirstOrDefault();
  2362. if (userModel!=null )
  2363. return userModel;
  2364. }
  2365. else
  2366. {
  2367. return null;
  2368. }
  2369. }
  2370. else
  2371. {
  2372. return null;
  2373. }
  2374. }
  2375. #endregion
  2376. }
  2377. return null;
  2378. }
  2379. else
  2380. {
  2381. return null;
  2382. }
  2383. }
  2384. /// <summary>
  2385. /// 获取上一级管理员
  2386. /// </summary>
  2387. /// <param name="OpenId"></param>
  2388. /// <returns></returns>
  2389. [WechatActionFilter]
  2390. public ActionResult GetDpment(string OpenId)
  2391. {
  2392. if (!string.IsNullOrEmpty(OpenId))
  2393. {
  2394. if (GetUser(OpenId) != null)
  2395. {
  2396. return Success("获取成功!", GetUser(OpenId));
  2397. }
  2398. else
  2399. {
  2400. return Success("获取失败!", null);
  2401. }
  2402. }
  2403. else
  2404. {
  2405. return Error("OpenId不能为空!");
  2406. }
  2407. }
  2408. /// <summary>
  2409. /// 修改密码
  2410. /// </summary>
  2411. /// <returns></returns>
  2412. [WechatActionFilter]
  2413. public ActionResult UpdatePassWord()
  2414. {
  2415. string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  2416. //5--业主(客户档案会员)
  2417. int usertype = RequestString.GetInt("usertype", 0);
  2418. //原密码
  2419. string oldpwd = RequestString.GetFormString("oldpwd").Trim();
  2420. string pwd = RequestString.GetFormString("pwd").Trim();
  2421. string repeatpwd = RequestString.GetFormString("repeatpwd").Trim();
  2422. if (usertype == 0)
  2423. return Error("无权修改密码");
  2424. if (string.IsNullOrWhiteSpace(oldpwd))
  2425. return Error("请输入原密码");
  2426. if (string.IsNullOrWhiteSpace(pwd))
  2427. return Error("请输入新密码");
  2428. if (string.IsNullOrWhiteSpace(repeatpwd))
  2429. return Error("请再次输入新密码");
  2430. if (!pwd.Equals(repeatpwd))
  2431. return Error("两个新密码不同,请重新输入");
  2432. var model = new Model.T_Sys_UserAccount();
  2433. var modelCus = new Model.T_Cus_CustomerBaseNew();
  2434. //坐席表
  2435. if (usertype < 5)
  2436. {
  2437. model = userAccountBLL.GetModelByOpenid(stropenid);
  2438. if (model != null)
  2439. {
  2440. if (!model.F_Password.Equals(oldpwd)) return Error("原密码不正确");
  2441. model.F_Password = pwd;
  2442. if (userAccountBLL.Update(model))
  2443. return Success("重置密码成功");
  2444. }
  2445. return Error("重置密码失败");
  2446. }
  2447. //客户档案表
  2448. modelCus = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();//customerBaseBLL.GetModelByOpenid(stropenid);
  2449. if (modelCus != null)
  2450. {
  2451. if (!modelCus.F_WxPassword.Equals(oldpwd)) return Error("原密码不正确");
  2452. modelCus.F_WxPassword = pwd;
  2453. if (customerBaseBLL.Update(modelCus))
  2454. return Success("重置密码成功");
  2455. }
  2456. return Error("重置密码失败");
  2457. }
  2458. /// <summary>
  2459. /// 验证生产批次号为15位
  2460. /// </summary>
  2461. private bool vaBatchNumber(string code)
  2462. {
  2463. var res = false;
  2464. if (code.Length == 15)
  2465. {
  2466. char chr = code[12];
  2467. if (chr > 'A' && chr < 'Z')
  2468. {
  2469. string code1 = code.Substring(0, 12);
  2470. string code2 = code.Substring(15 - 2, 2);
  2471. if (Regex.IsMatch(code1, @"^\d{12}$") && Regex.IsMatch(code2, @"^\d{2}$"))
  2472. res = true;
  2473. }
  2474. else
  2475. {
  2476. res = false;
  2477. }
  2478. }
  2479. return res;
  2480. }
  2481. /// <summary>
  2482. /// 验证物料编码为10位纯数字
  2483. /// </summary>
  2484. private bool valcode(string code, int number)
  2485. {
  2486. var res = false;
  2487. //11位数字
  2488. if (code.Length == number && Regex.IsMatch(code, @"^\d{" + number + "}$"))
  2489. res = true;
  2490. return res;
  2491. }
  2492. /// <summary>
  2493. /// 验证物料编号是否唯一
  2494. /// </summary>
  2495. private bool gematerque(int id, string code)
  2496. {
  2497. var sql = " F_IsDelete=0 ";
  2498. sql += "and (F_MaterialCode='" + code + "')";
  2499. if (id > 0)
  2500. sql += " and F_Id<>" + id;
  2501. var count = mmBLL.GetModelList(sql).Count();
  2502. return count > 0;
  2503. }
  2504. /// <summary>
  2505. /// 验证客户编号是否唯一
  2506. /// </summary>
  2507. private bool getunique(int id, string code)
  2508. {
  2509. var sql = " F_IsDelete=0 ";
  2510. sql += "and (F_CustomerCode='" + code + "')";
  2511. if (id > 0)
  2512. sql += " and F_CustomerId<>" + id;
  2513. var count = customerBaseBLL.GetModelList(sql).Count();
  2514. return count > 0;
  2515. }
  2516. /// <summary>
  2517. /// 获取我参与的工单编号
  2518. /// </summary>
  2519. /// <param name="user"></param>
  2520. /// <returns></returns>
  2521. public string GetParticipateID(string user)
  2522. {
  2523. string str = string.Empty;
  2524. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_CreateUser in(" + user + ") and F_OptType in( 1,7 )";
  2525. ;
  2526. return str;
  2527. }
  2528. /// <summary>
  2529. /// 添加客户
  2530. /// </summary>
  2531. private Model.T_Cus_CustomerBaseNew inputtooCustomer(Model.T_Cus_CustomerBaseNew model, WorkOrderNewInput input)
  2532. {
  2533. var newmodel = model;
  2534. if (!string.IsNullOrWhiteSpace(input.F_CustomerID.ToString()))
  2535. model.F_CustomerCode = input.F_CustomerID.ToString();
  2536. else
  2537. model.F_CustomerCode = model.F_CustomerCode;
  2538. if (!string.IsNullOrWhiteSpace(input.F_CompanyName))
  2539. model.F_CompanyName = input.F_CompanyName;
  2540. #region 基本字段
  2541. Model.T_Sys_Department dept = departmentBLL.GetModel(input.F_AreaName);
  2542. if (dept != null)
  2543. {
  2544. model.F_AreaID = dept.F_DeptId.ToString();//大区ID
  2545. }
  2546. Model.T_Sys_Department deptBranch = departmentBLL.GetModel(input.F_BranchName);
  2547. if (dept != null)
  2548. {
  2549. model.F_BranchID = deptBranch.F_DeptId.ToString();//大区ID
  2550. }
  2551. model.F_Salesman = input.F_Salesman;//业务员
  2552. model.F_SalesPhone = input.F_SalesPhone;//业务员电话
  2553. model.F_Channel = input.F_Channel;// 渠道类型:总经销、二级商、种田大户、农户、化工客户、公司员工
  2554. model.F_Legal = input.F_Legal;//法人
  2555. model.F_LegalPhone = input.F_LegalPhone;//法人电话
  2556. model.F_AddressProvince = input.F_AddressProvince;//省
  2557. model.F_AddressCity = input.F_AddressCity;//市
  2558. model.F_AddressCountry = input.F_AddressCountry;//县
  2559. model.F_AddressTownship = input.F_AddressTownship;//乡
  2560. model.F_AddressFull = input.F_AddressFull;//详细地址
  2561. model.F_Brands = input.F_Brands;// 经营品牌:心连心、手拉手、沃利沃、双心、空
  2562. model.F_IsRunXLX = input.F_IsRunXLX;// 是否经营心连心:是、否
  2563. model.F_AnnualSales = input.F_AnnualSales;//年销量
  2564. model.F_Formula = input.F_Formula;//配方
  2565. model.F_RaiseCrops = input.F_RaiseCrops;//种植作物
  2566. model.F_PlantingArea = input.F_PlantingArea;//种植面积
  2567. model.F_FertilizerBrand = input.F_FertilizerBrand;//用肥品牌
  2568. model.F_FileId = 0;
  2569. #endregion
  2570. return model;
  2571. }
  2572. private string GetCusCode(int i)
  2573. {
  2574. DateTime times = DateTime.Now.AddMinutes(i);
  2575. string time = times.ToString("yyMMddhhmm");
  2576. return time;
  2577. }
  2578. private string GetIntCode()
  2579. {
  2580. string time = DateTime.Now.ToString("hhmmss");
  2581. Random ran = new Random();
  2582. int RandKey = ran.Next(1000, 9999);
  2583. string timecode = 3 + "" + RandKey + "" + time;
  2584. return timecode;
  2585. }
  2586. private bool IsMaterial(WorkOrderNewInput input)
  2587. {
  2588. bool n = false;
  2589. if (!string.IsNullOrEmpty(input.F_MaterialID) || !string.IsNullOrEmpty(input.F_MaterialName)
  2590. || !string.IsNullOrEmpty(input.F_Model) || !string.IsNullOrEmpty(input.F_Specs)
  2591. || !string.IsNullOrEmpty(input.F_Level1) || !string.IsNullOrEmpty(input.F_Level2)
  2592. || !string.IsNullOrEmpty(input.F_Level3) || !string.IsNullOrEmpty(input.F_Brand)
  2593. || !string.IsNullOrEmpty(input.F_MaterialEffect) || !string.IsNullOrEmpty(input.F_Craft)
  2594. || !string.IsNullOrEmpty(input.F_Pipeline))
  2595. {
  2596. n = true;
  2597. }
  2598. return n;
  2599. }
  2600. private void AddMait(WorkOrderNewInput input, string usercode)
  2601. {
  2602. Model.T_Wo_MaterialManage dModel = new Model.T_Wo_MaterialManage();
  2603. dModel.F_MaterialCode = input.F_MaterialID.ToString();//物料编号
  2604. dModel.F_MaterialName = input.F_MaterialName;//物料名称
  2605. dModel.F_Model = input.F_Model;//型号
  2606. dModel.F_Specs = input.F_Specs;//规格
  2607. dModel.F_Level1 = input.F_Level1;//一级分类
  2608. dModel.F_Level2 = input.F_Level2;//二级分类
  2609. dModel.F_Level3 = input.F_Level3;//三级分类
  2610. dModel.F_Brand = input.F_Brand;//品牌
  2611. dModel.F_MaterialEffect = input.F_MaterialEffect;//复合肥肥效
  2612. dModel.F_Craft = input.F_Craft;//工艺
  2613. dModel.F_Pipeline = input.F_Pipeline;//产品线
  2614. dModel.F_IsDelete = 0;
  2615. dModel.F_CreateOn = DateTime.Now;
  2616. dModel.F_CreateBy = usercode;
  2617. int f = mmBLL.Add(dModel);
  2618. }
  2619. /// <summary>
  2620. /// 根据传入的对象和input的内容返回对象(添加修改使用)
  2621. /// </summary>
  2622. private Model.T_Wo_WorkOrder inputtoobj(Model.T_Sys_UserAccount ua, Model.T_Wo_WorkOrder model, WorkOrderNewInput input, int type)
  2623. {
  2624. string usercode = "";
  2625. if (ua != null)
  2626. {
  2627. usercode = ua.F_UserCode;
  2628. }
  2629. var newmodel = model;
  2630. if (input.F_ID != 0)
  2631. {
  2632. model.F_ID = input.F_ID;
  2633. }
  2634. else
  2635. {
  2636. model.F_ID = model.F_ID;//工单ID
  2637. }
  2638. if (type == 2)
  2639. {
  2640. model.F_WorkOrderCode = DateTime.Now.ToString("yyyyMMddHHmmssfff"); //工单编号
  2641. model.F_Source = model.F_Source;
  2642. }
  2643. else
  2644. {
  2645. model.F_WorkOrderCode = model.F_WorkOrderCode;//工单编号
  2646. model.F_Source = model.F_Source.ToString();//工单来源
  2647. }
  2648. if (input.F_Type == 2 || input.F_Type == 3)
  2649. {
  2650. if (string.IsNullOrEmpty(input.F_CustomerID))
  2651. {
  2652. var sql = $" and F_LegalPhone = '" + input.F_CusPhone.Trim() + "'";
  2653. var Customer = new BLL.T_Cus_CustomerBaseNew().GetModelList(" F_IsDelete = 0 " + sql).FirstOrDefault(); ;
  2654. if (Customer != null)
  2655. {
  2656. model.F_CustomerID = Customer.F_CustomerCode;
  2657. if (!string.IsNullOrEmpty(input.F_Salesman))
  2658. Customer.F_Salesman = input.F_Salesman;
  2659. if (!string.IsNullOrEmpty(input.F_SalesPhone))
  2660. Customer.F_SalesPhone = input.F_SalesPhone;
  2661. if (!string.IsNullOrEmpty(input.F_Brands))
  2662. Customer.F_Brands = input.F_Brands;
  2663. if (!string.IsNullOrEmpty(input.F_AreaName))
  2664. Customer.F_AreaID = input.F_AreaName.Trim();
  2665. if (!string.IsNullOrEmpty(input.F_BranchName))
  2666. Customer.F_BranchID = input.F_BranchName.Trim();
  2667. customerBaseBLL.Update(Customer);
  2668. }
  2669. }
  2670. else
  2671. {
  2672. var Customer = customerBaseBLL.GetModel(input.F_CustomerID.Trim());
  2673. if (Customer != null)
  2674. {
  2675. if (!string.IsNullOrEmpty(input.F_Salesman))
  2676. Customer.F_Salesman = input.F_Salesman;
  2677. if (!string.IsNullOrEmpty(input.F_SalesPhone))
  2678. Customer.F_SalesPhone = input.F_SalesPhone;
  2679. if (!string.IsNullOrEmpty(input.F_Brands))
  2680. Customer.F_Brands = input.F_Brands;
  2681. if (!string.IsNullOrEmpty(input.F_AreaName))
  2682. Customer.F_AreaID = input.F_AreaName.Trim();
  2683. if (!string.IsNullOrEmpty(input.F_BranchName))
  2684. Customer.F_BranchID = input.F_BranchName.Trim();
  2685. customerBaseBLL.Update(Customer);
  2686. }
  2687. }
  2688. if (IsMaterial(input))
  2689. {
  2690. if (string.IsNullOrEmpty(input.F_MaterialID))
  2691. {
  2692. while (true)
  2693. {
  2694. if (!gematerque(0, GetIntCode()))
  2695. {
  2696. input.F_MaterialID = GetIntCode();
  2697. AddMait(input, usercode);
  2698. break;
  2699. }
  2700. }
  2701. }
  2702. else
  2703. {
  2704. if (!gematerque(0, input.F_MaterialID))
  2705. {
  2706. AddMait(input, usercode);
  2707. }
  2708. }
  2709. }
  2710. }
  2711. #region 基本字段
  2712. model.F_Source = input.F_Source.ToString();//工单来源
  2713. model.F_WxOpenId = input.F_WxOpenId;
  2714. model.F_Type = input.F_Type.ToString();//工单类型:咨询及需求、投诉、抽检、其他(其它手动输入别的点选)
  2715. model.F_CusName = input.F_CusName;//客户姓名
  2716. model.F_CusPhone = input.F_CusPhone;//客户电话
  2717. model.F_CompanyName = input.F_CompanyName;//公司名称
  2718. model.F_IncidentProvince = input.F_IncidentProvince;//事发地-省
  2719. model.F_IncidentCity = input.F_IncidentCity;//事发地-市
  2720. model.F_IncidentCountry = input.F_IncidentCountry;//事发地-县
  2721. model.F_IncidentTownship = input.F_IncidentTownship;//事发地-乡
  2722. model.F_IncidentDetailed = input.F_IncidentDetailed;//事发地-详细
  2723. model.F_SalesBase = input.F_SalesBase;//销售基地:新乡、新疆、九江、东北、其他(其它手动输入别的点选)
  2724. model.F_Description = input.F_Description;//问题描述
  2725. model.F_ZX_Area = input.F_ZX_Area;// 大区
  2726. model.F_ZX_Branch = input.F_ZX_Branch;//分公司
  2727. if (!string.IsNullOrEmpty(input.F_Files))
  2728. model.F_Files = input.F_Files;//附件上传ids
  2729. else
  2730. model.F_Files = model.F_Files;//附件上传ids
  2731. model.F_Brand = input.F_WorkerBrand;//分公司
  2732. model.F_DealType = model.F_DealType;//处理方式:当即办理、电话转接、网络转办(点选)
  2733. model.F_Canal = input.F_Canal;//处理方式:当即办理、电话转接、网络转办(点选)
  2734. #endregion
  2735. model.F_QuestionType = input.F_QuestionType;//问题类别(投诉抽捡和咨询类别不一样)
  2736. model.F_CustomerID = input.F_CustomerID;//客户编号为10为纯数字
  2737. model.F_MaterialID = input.F_MaterialID;//物料编码为11为纯数字
  2738. #region 投诉类
  2739. model.F_BatchNumber = input.F_BatchNumber;//生产批次号
  2740. model.F_TS_Formula = input.F_TS_Formula;// 投诉-配方
  2741. model.F_TS_Category = input.F_TS_Category;//投诉-产品种类:化肥、化工、其他
  2742. model.F_TS_Quantity = input.F_TS_Quantity;//投诉-问题数量(吨)
  2743. model.F_TS_Level = input.F_TS_Level;//投诉-重要级别:轻微、一般、较大、重大
  2744. #endregion
  2745. #region 咨询类
  2746. // model.F_ZX_ProName = input.F_ZX_ProName;//咨询-产品名称:三聚氰胺、甲醇、液氨、二甲醚、糠醇、其他
  2747. model.F_ZX_Quantity = input.F_ZX_Quantity;// 咨询-问题数量(吨)
  2748. #endregion
  2749. #region 抽检类
  2750. model.F_CJ_Time = input.F_CJ_Time;// 抽检-抽检时间
  2751. model.F_CJ_Level = input.F_CJ_Level;// 抽检-抽检级别:乡镇级、县级、市级、省级及以上、个人送检
  2752. model.F_CJ_Unit = input.F_CJ_Unit;// 抽检-抽检单位:市场监督、农业部、土肥站、工商、联合执法、其他
  2753. model.F_CJ_TestUnit = input.F_CJ_TestUnit;//抽检-化验单位
  2754. model.F_CJ_Tonnage = input.F_CJ_Tonnage;//抽检-抽检吨数
  2755. model.F_CJ_BagNo = input.F_CJ_BagNo;//抽检-抽检袋数
  2756. model.F_CJ_Outlay = input.F_CJ_Outlay;//抽检-公关费用金额:单位元】
  2757. // model.F_VisitRemarks = input.F_VisitRemarks;//回访备注
  2758. if (!string.IsNullOrEmpty(input.F_BatchNumber))
  2759. {
  2760. if (type == 1)
  2761. {
  2762. model.F_SC_QualityMonth = new WorkOrderController().GetProTime(input.F_BatchNumber, DateTime.Parse(model.F_CreateOn.ToString())).ToString();
  2763. }
  2764. else
  2765. {
  2766. model.F_SC_QualityMonth = new WorkOrderController().GetProTime(input.F_BatchNumber, DateTime.Now).ToString();
  2767. }
  2768. }
  2769. if (type == 1)
  2770. {
  2771. model.F_State = model.F_State;//工单状态
  2772. model.F_CreateOn = model.F_CreateOn;//添加时间
  2773. model.F_CreateBy = model.F_CreateBy;//添加人
  2774. model.F_UpdateBy = usercode;//修改人工号
  2775. model.F_UpdateOn = DateTime.Now;//修改人工号
  2776. if (input.F_UpdateCount != null)
  2777. {
  2778. model.F_UpdateCount = model.F_UpdateCount + 1;//修改次数
  2779. }
  2780. else
  2781. {
  2782. model.F_UpdateCount = 1;//修改次数
  2783. }
  2784. model.F_limit = model.F_limit;
  2785. }
  2786. else
  2787. {
  2788. model.F_limit = 0;
  2789. model.F_State = (int)EnumWorkOrderState.neworder;
  2790. model.F_CreateBy = usercode;
  2791. model.F_CreateOn = DateTime.Now;
  2792. }
  2793. model.F_IsVisit = 1;
  2794. model.F_IsDelete = 0;
  2795. model.F_IsOver = 0;
  2796. #endregion
  2797. return model;
  2798. }
  2799. /// <summary>
  2800. /// 获取我参与的工单编号
  2801. /// </summary>
  2802. /// <param name="user"></param>
  2803. /// <returns></returns>
  2804. public string GetCYWorkOrderID(string user)
  2805. {
  2806. string str = string.Empty;
  2807. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_CreateUser in(" + user + ") and F_OptType in( 1,3,13 )";
  2808. return str;
  2809. }
  2810. /// <summary>
  2811. /// 获取高层
  2812. /// </summary>
  2813. /// <param name="deptId"></param>
  2814. /// <returns></returns>
  2815. public ActionResult GetHighlevel()
  2816. {
  2817. var user = userAccountBLL.GetModelList(" F_RoleId=61");
  2818. if (user != null)
  2819. return Success("获取高层信息成功", new
  2820. {
  2821. user
  2822. });
  2823. return Error("获取高层信息失败");
  2824. }
  2825. /// <summary>
  2826. /// 验证客户电话是否唯一
  2827. /// </summary>
  2828. private bool getunphone(int id, string phone)
  2829. {
  2830. var sql = " F_IsDelete=0 ";
  2831. sql += "and (F_LegalPhone='" + phone + "')";
  2832. if (id > 0)
  2833. sql += " and F_CustomerId<>" + id;
  2834. var count = customerBaseBLL.GetModelList(sql).Count();
  2835. return count > 0;
  2836. }
  2837. /// <summary>
  2838. /// 添加工单
  2839. /// </summary>
  2840. /// <returns></returns>
  2841. public ActionResult Add(WorkOrderNewInput input, int overtime = 0, int sms = 0)
  2842. {
  2843. if (!string.IsNullOrEmpty(input.F_WxOpenId))
  2844. {
  2845. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + input.F_WxOpenId + "'").FirstOrDefault();
  2846. // string usercode = CurrentUser.UserData.F_UserCode;
  2847. // Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModel(userId);
  2848. if (ua == null && input.F_Source != 3)
  2849. {
  2850. return Error("无操作权限!");
  2851. }
  2852. if (!string.IsNullOrEmpty(input.F_BatchNumber) && !vaBatchNumber(input.F_BatchNumber))
  2853. {
  2854. return Error("请输入正确的生产批次号!");
  2855. }
  2856. else
  2857. {
  2858. if (!string.IsNullOrEmpty(input.F_BatchNumber))
  2859. {
  2860. var prono = input.F_BatchNumber.Substring(0, 6);
  2861. try
  2862. {
  2863. var pronos = DateTime.ParseExact(prono, "yyMMdd", null).ToString("yyyy-MM-dd");
  2864. var protime = Convert.ToDateTime(pronos);
  2865. if (DateTime.Parse(pronos) > DateTime.Now)
  2866. {
  2867. return Error("生产批次号错误,生产日期不能大于当前时间!");
  2868. }
  2869. }
  2870. catch
  2871. {
  2872. return Error("生产批次号错误,日期格式错误!");
  2873. }
  2874. }
  2875. }
  2876. if (!string.IsNullOrEmpty(input.F_CustomerID) && !valcode(input.F_CustomerID.ToString(), 10))
  2877. return Error("客户编号为10为纯数字!");
  2878. if (!string.IsNullOrEmpty(input.F_MaterialID) && !valcode(input.F_MaterialID.ToString(), 11))
  2879. return Error("物料编码为11为纯数字!");
  2880. if (string.IsNullOrEmpty(input.F_CusName))
  2881. return Error("请输入客户姓名!");
  2882. if (string.IsNullOrEmpty(input.F_CusPhone))
  2883. return Error("请输入客户电话!");
  2884. //if (input.F_Type == 2 || input.F_Type == 3)
  2885. //{
  2886. // if (string.IsNullOrEmpty(input.F_CustomerID))
  2887. // {
  2888. // if (string.IsNullOrEmpty(input.F_LegalPhone))
  2889. // return Error("请输入客户电话");
  2890. // if (getunphone(0, input.F_LegalPhone))
  2891. // return Error("已存在该客户请勿重复添加");
  2892. // }
  2893. //}
  2894. var model = new Model.T_Wo_WorkOrder();
  2895. #region 保存客户基本信息
  2896. model = inputtoobj(ua, model, input, 2);
  2897. if (model.F_Source == "3")
  2898. {
  2899. model.F_State = (int)EnumWorkOrderState.customers;
  2900. }
  2901. else
  2902. {
  2903. model.F_State = (int)EnumWorkOrderState.audit;
  2904. }
  2905. model.F_limit = overtime;
  2906. #endregion
  2907. long n = woBLL.Add(model);
  2908. if (n > 0)
  2909. {
  2910. #region 流转上一级领导审批
  2911. Model.T_Wo_WorkOrder modlelist = new BLL.T_Wo_WorkOrder().GetModel(n);
  2912. if (modlelist != null)
  2913. {
  2914. if (ua != null && model.F_Source != "3")
  2915. {
  2916. if (GetUser(input.F_WxOpenId) != null)
  2917. {
  2918. var user = GetUser(input.F_WxOpenId);
  2919. string deptname = "", deptname1 = "";
  2920. var deptmodel = departmentBLL.GetModel(user.F_DeptId);
  2921. if (deptmodel != null)
  2922. {
  2923. deptname = deptmodel.F_DeptName + "-";
  2924. }
  2925. var deptmodel1 = departmentBLL.GetModel(ua.F_DeptId);
  2926. if (deptmodel1 != null)
  2927. {
  2928. deptname1 = deptmodel1.F_DeptName + "-";
  2929. }
  2930. AddLog(modlelist.F_ID, 0, deptname1 + ua.F_UserName + "(" + ua.F_WorkNumber + ")" + "创建工单", (int)EnumWorkOrderState.neworder, (int)EnumItemOpt.create, user.F_UserCode, user.F_DeptId, ua, overtime, sms );
  2931. AddLog(modlelist.F_ID, modlelist.F_State.Value, deptname + user.F_UserName + "(" + user.F_WorkNumber + ")" + "待审批", (int)EnumItemType.audit, (int)EnumItemOpt.audit, user.F_UserCode, user.F_DeptId, ua, overtime, sms);
  2932. }
  2933. else
  2934. {
  2935. string deptname1 = "";
  2936. int dapt = 0, nextda = 0;
  2937. var deptmodel1 = departmentBLL.GetModel(ua.F_DeptId);
  2938. if (deptmodel1 != null)
  2939. {
  2940. deptname1 = deptmodel1.F_DeptName + "-";
  2941. dapt = deptmodel1.F_ParentId;
  2942. }
  2943. AddLog(modlelist.F_ID, 0, deptname1 + ua.F_UserName + "(" + ua.F_WorkNumber + ")" + "创建工单", (int)EnumWorkOrderState.neworder, (int)EnumItemOpt.create, "", 0, ua, overtime, sms);
  2944. string opt = "";
  2945. if (dapt != 0)
  2946. {
  2947. if (dapt == 11)
  2948. {
  2949. nextda = 37;
  2950. opt = "流转市场管理科";
  2951. }
  2952. else if (dapt == 14)
  2953. {
  2954. nextda = 57;
  2955. opt = "流转营销管理处";
  2956. }
  2957. else if (dapt == 15)
  2958. {
  2959. nextda = 74;
  2960. opt = "流转策划推广";
  2961. }
  2962. else if (dapt == 16)
  2963. {
  2964. nextda = 88;
  2965. opt = "流转销售部";
  2966. }
  2967. }
  2968. if (nextda != 0)
  2969. {
  2970. var res = AssignWO(ua, modlelist, input, opt, "", nextda, 0, overtime, sms);
  2971. if (res)
  2972. return Success("添加成功");
  2973. else
  2974. return Error("流转失败!");
  2975. }
  2976. else
  2977. {
  2978. return Error("流转失败!");
  2979. }
  2980. }
  2981. }
  2982. else
  2983. {
  2984. AddLog(modlelist.F_ID, 0, "客户" + "创建工单", (int)EnumItemType.deal, (int)EnumItemOpt.create, "", 0, null, overtime, sms);
  2985. return Success("添加成功");
  2986. }
  2987. }
  2988. #endregion
  2989. return Success("添加成功!");
  2990. }
  2991. else
  2992. return Error("添加失败!");
  2993. }
  2994. else
  2995. {
  2996. return Error("OpenId不能为空!");
  2997. }
  2998. }
  2999. /// <summary>
  3000. /// 更新市场管理科,质量管理科
  3001. /// </summary>
  3002. /// <param name="model"></param>
  3003. /// <param name="input"></param>
  3004. /// <returns></returns>
  3005. private Model.T_Wo_WorkOrder InToworkModel(Model.T_Wo_WorkOrder model, WorkOrderNewInput input)
  3006. {
  3007. if (!string.IsNullOrEmpty(input.F_SC_ProductBase))
  3008. model.F_SC_ProductBase = input.F_SC_ProductBase;//市场管理科-生产基地(新乡、新疆、九江、东北、贴牌、无法确定)
  3009. if (!string.IsNullOrEmpty(input.F_SC_PreliminaryOpinion))
  3010. model.F_SC_PreliminaryOpinion = input.F_SC_PreliminaryOpinion;// 市场管理科-初审意见:退货、换货、补偿、自行处理
  3011. if (!string.IsNullOrEmpty(input.F_SC_QualityMonth))
  3012. model.F_SC_QualityMonth = input.F_SC_QualityMonth;//市场管理科-超出质保期限(算法:工单创建日期-生产日期,生产日期根据生产批次号获取,单位:月)
  3013. if (!string.IsNullOrEmpty(input.F_SC_CJ_SpotResult))
  3014. model.F_SC_CJ_SpotResult = input.F_SC_CJ_SpotResult;/// 市场管理科-抽检-抽检结果(视同合格、合格、不合格、复检后合格、未送检)
  3015. if (!string.IsNullOrEmpty(input.F_SC_CJ_SelfResult))
  3016. model.F_SC_CJ_SelfResult = input.F_SC_CJ_SelfResult;//市场管理科-抽检-自检结果
  3017. if (!string.IsNullOrEmpty(input.F_SC_CJ_ApprovalNo))
  3018. model.F_SC_CJ_ApprovalNo = input.F_SC_CJ_ApprovalNo;// 市场管理科-抽检-对应审批工作流单号
  3019. if (!string.IsNullOrEmpty(input.F_SC_CJ_ReturnAccount))
  3020. model.F_SC_CJ_ReturnAccount = input.F_SC_CJ_ReturnAccount;//市场管理科-抽检-确认返账金额(元)
  3021. if (!string.IsNullOrEmpty(input.F_ZL_QualityEventLevel))
  3022. model.F_ZL_QualityEventLevel = input.F_ZL_QualityEventLevel;// 质量管理科-质量事件等级(未遂、一般、较大、重大)
  3023. if (!string.IsNullOrEmpty(input.F_ZL_ClaimAmount))
  3024. model.F_ZL_ClaimAmount = input.F_ZL_ClaimAmount;//质量管理科-索赔金额(单位元,对应责任单位)
  3025. if (!string.IsNullOrEmpty(input.F_ZL_ResponsibleUnit))
  3026. model.F_ZL_ResponsibleUnit = input.F_ZL_ResponsibleUnit;//质量管理科-责任单位(需列出,可选多个)
  3027. if (!string.IsNullOrEmpty(input.F_ZL_ApprovalOpinions))
  3028. model.F_ZL_ApprovalOpinions = input.F_ZL_ApprovalOpinions;// 质量管理科-审批意见(同意、不同意,若选择不同意,增加输入框输入补充内容)
  3029. if (!string.IsNullOrEmpty(input.F_ZL_ApprovalDisagree))
  3030. model.F_ZL_ApprovalDisagree = input.F_ZL_ApprovalDisagree;// 质量管理科-审批不同意意见
  3031. if (!string.IsNullOrEmpty(input.F_ZL_CompensationMethod))
  3032. model.F_ZL_CompensationMethod = input.F_ZL_CompensationMethod;//质量管理科-补偿方式(实物、钱款【单位元】,若选择钱款,增加输入框输入补充内容)
  3033. if (!string.IsNullOrEmpty(input.F_ZL_CompensationMoney))
  3034. model.F_ZL_CompensationMoney = input.F_ZL_CompensationMoney;// 质量管理科-补偿钱款
  3035. if (!string.IsNullOrEmpty(input.F_ZL_CResponsibleUnits))
  3036. model.F_ZL_CResponsibleUnits = input.F_ZL_CResponsibleUnits;//质量管理科-对应责任单位(生产、研发、农化、物流、质量管理科,销售内勤)
  3037. if (!string.IsNullOrEmpty(input.F_ZL_Fquantity))
  3038. model.F_ZL_Fquantity = input.F_ZL_Fquantity;// 质量管理科-确认实收数量(吨)
  3039. if (!string.IsNullOrEmpty(input.F_ZL_ImprovementRequirements))
  3040. model.F_ZL_ImprovementRequirements = input.F_ZL_ImprovementRequirements;//质量管理科-改进要求
  3041. if (!string.IsNullOrEmpty(input.F_ZL_CApprovalNo))
  3042. model.F_ZL_CApprovalNo = input.F_ZL_CApprovalNo;//质量管理科-对应审批工作流单号
  3043. if (!string.IsNullOrEmpty(input.F_ZL_CJ_IsRecord))
  3044. model.F_ZL_CJ_IsRecord = input.F_ZL_CJ_IsRecord;//质量管理科-抽检-未备案、已备案
  3045. if (input.F_IsVisit != null)
  3046. {
  3047. try
  3048. {
  3049. model.F_IsVisit = int.Parse(input.F_IsVisit);
  3050. }
  3051. catch
  3052. {
  3053. model.F_IsVisit = 1;
  3054. }
  3055. }
  3056. return model;
  3057. }
  3058. /// <summary>
  3059. /// 指派/转派工单
  3060. /// <param name="orderid">工单id</param>
  3061. /// <param name="cont">指派说明</param>
  3062. /// <param name="clbm">指派部门</param>
  3063. /// <param name="clid">指派人</param>
  3064. /// </summary>
  3065. /// <returns></returns>
  3066. [WechatActionFilter]
  3067. public ActionResult AssignWorkOrder(string OpenId, long orderid, string cont, WorkOrdeDeptment deptment, string F_Files, int isvisit = 1,
  3068. int overtime = 0, int sms = 0, int clbm = 0, int clid = 0, int isApprovalp = 0, int hclbm = 0, int hclid = 0)
  3069. {
  3070. if (!string.IsNullOrEmpty(OpenId))
  3071. {
  3072. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  3073. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  3074. WorkOrderNewInput input = new WorkOrderNewInput();
  3075. if (ua != null)
  3076. {
  3077. if (hclid == 0 && hclbm == 0 && isApprovalp != 0)
  3078. {
  3079. return Error("请选择接收部门");
  3080. }
  3081. if (clbm == 0 && clid == 0)
  3082. {
  3083. return Error("请选择接收部门");
  3084. }
  3085. else
  3086. {
  3087. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  3088. if (deptmodel != null)
  3089. {
  3090. if (model != null)
  3091. {
  3092. if (model.F_Type == "2")
  3093. {
  3094. if (deptmodel.F_DeptId == 37)
  3095. {
  3096. // input. F_SC_QualityMonth = QualityMonth;//市场管理科-超出质保期限
  3097. input.F_SC_PreliminaryOpinion = deptment.PreliminaryOpinion;//市场管理科-初审意见:退货、换货、补偿、自行处理
  3098. }
  3099. else if (deptmodel.F_DeptId == 12)
  3100. {
  3101. input.F_IsVisit = isvisit.ToString();
  3102. input.F_ZL_QualityEventLevel = deptment.QualityEventLevel;//质量管理科-质量事件等级(未遂、一般、较大、重大)
  3103. input.F_ZL_ClaimAmount = deptment.ClaimAmount;// 质量管理科-索赔金额(单位元,对应责任单位)
  3104. input.F_ZL_ResponsibleUnit = deptment.ResponsibleUnit;// 质量管理科-责任单位(需列出,可选多个)
  3105. input.F_ZL_ApprovalOpinions = deptment.ApprovalOpinions;// 质量管理科-审批意见(同意、不同意,若选择不同意,增加输入框输入补充内容)
  3106. input.F_ZL_ApprovalDisagree = deptment.ApprovalDisagree;// 质量管理科-审批不同意意见
  3107. input.F_ZL_CompensationMethod = deptment.CompensationMethod;// 质量管理科-补偿方式(实物、钱款【单位元】,若选择钱款,增加输入框输入补充内容)
  3108. input.F_ZL_CompensationMoney = deptment.CompensationMoney;// 质量管理科-补偿钱款
  3109. input.F_ZL_CResponsibleUnits = deptment.CResponsibleUnits;//质量管理科-对应责任单位(生产、研发、农化、物流、质量管理科,销售内勤)
  3110. input.F_ZL_Fquantity = deptment.Fquantity;//质量管理科-确认实收数量(吨)
  3111. input.F_ZL_ImprovementRequirements = deptment.ImprovementRequirements;// 质量管理科-改进要求
  3112. input.F_ZL_CApprovalNo = deptment.CApprovalNo;// 质量管理科-对应审批工作流单号
  3113. }
  3114. }
  3115. else if (model.F_Type == "3")
  3116. {
  3117. if (deptmodel.F_DeptId == 37)
  3118. {
  3119. input.F_SC_CJ_SpotResult = deptment.SpotResult;//市场管理科-抽检-抽检结果(视同合格、合格、不合格、复检后合格、未送检)
  3120. input.F_SC_CJ_SelfResult = deptment.SelfResult;//市场管理科-抽检-自检结果
  3121. input.F_SC_CJ_ApprovalNo = deptment.ApprovalNo;//市场管理科-抽检-对应审批工作流单号
  3122. input.F_SC_CJ_ReturnAccount = deptment.ReturnAccount;//市场管理科-抽检-确认返账金额
  3123. }
  3124. else if (deptmodel.F_DeptId == 12)
  3125. {
  3126. input.F_IsVisit = isvisit.ToString();
  3127. input.F_ZL_CJ_IsRecord = deptment.IsRecord;//质量管理科-抽检-未备案、已备案
  3128. input.F_ZL_ClaimAmount = deptment.ClaimAmount;// 质量管理科-索赔金额(单位元,对应责任单位)
  3129. }
  3130. }
  3131. if (deptmodel.F_DeptId == 25)
  3132. {
  3133. input.F_SC_CJ_ReturnAccount = deptment.ReturnAccount;//销售内勤-确认返账金额
  3134. }
  3135. else if (deptmodel.F_DeptId == 36)
  3136. {
  3137. input.F_ZL_Fquantity = deptment.Fquantity;//质量管理科-确认实收数量(吨)
  3138. }
  3139. }
  3140. else
  3141. return Error("工单不存在!");
  3142. }
  3143. else
  3144. {
  3145. return Error("请选择接收部门");
  3146. }
  3147. }
  3148. if (model != null)
  3149. {
  3150. if (model.F_State == 1)
  3151. {
  3152. return Error("工单已转派请勿重复操作!");
  3153. }
  3154. else
  3155. {
  3156. var res = AssignWO(ua, model, input, cont, F_Files, clbm, clid, overtime, sms, isApprovalp, hclbm, hclid);
  3157. if (res)
  3158. return Success("转派成功");
  3159. else
  3160. return Error("转派失败!");
  3161. }
  3162. }
  3163. else
  3164. return Error("工单不存在!");
  3165. }
  3166. }
  3167. return Error("无操作权限!");
  3168. }
  3169. /// <summary>
  3170. /// 转派工单
  3171. /// </summary>
  3172. public bool AssignWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, WorkOrderNewInput input, string cont, string F_Files, int clbm = 0, int clid = 0, int overtime = 0, int sms = 0, int isApprovalp = 0, int hclbm = 0, int hclid = 0, string creat = "")
  3173. {
  3174. string smscont = "";
  3175. if (model.F_Type == "1")
  3176. {
  3177. smscont = "咨询";
  3178. }
  3179. else if (model.F_Type == "2")
  3180. {
  3181. smscont = "投诉";
  3182. }
  3183. else if (model.F_Type == "3")
  3184. {
  3185. smscont = "抽检";
  3186. }
  3187. else
  3188. {
  3189. smscont = "建议";
  3190. }
  3191. string[] mag = { smscont };
  3192. string smsmsg = "您好,您有一条新的" + smscont + "工单,请及时接单处理!";
  3193. string touser = ""; string tousername = "";
  3194. #region 获取接收人
  3195. int deptid = 0;
  3196. if (clid != 0)
  3197. {
  3198. Model.T_Sys_UserAccount clus = userAccountBLL.GetModel(clid);
  3199. deptid = clus.F_DeptId;
  3200. clbm = clus.F_DeptId;
  3201. if (clus != null)
  3202. {
  3203. touser = clus.F_UserCode;
  3204. tousername = clus.F_UserName + "(" + clus.F_WorkNumber + ")";
  3205. }
  3206. if (sms != 0)
  3207. {
  3208. if (!string.IsNullOrEmpty(clus.F_Mobile))
  3209. {
  3210. SmsSingleSenderResult result = new SMSController().SMSSingleshot(395191, mag, clus.F_Mobile);
  3211. bool n = new SMSController().AddSmS(clus.F_Mobile, smsmsg, nowUser.F_UserId);
  3212. }
  3213. }
  3214. }
  3215. else
  3216. {
  3217. string users = string.Empty;
  3218. deptid = clbm;
  3219. var list = userAccountBLL.GetModelList(" F_DeptId='" + clbm + "'");
  3220. foreach (var l in list)
  3221. {
  3222. if (string.IsNullOrEmpty(users))
  3223. {
  3224. users = l.F_UserCode;
  3225. tousername = l.F_UserName + "(" + l.F_WorkNumber + ")";
  3226. }
  3227. else
  3228. {
  3229. users = users + "," + l.F_UserCode;
  3230. tousername = tousername + "," + l.F_UserName + "(" + l.F_WorkNumber + ")";
  3231. }
  3232. if (sms != 0)
  3233. {
  3234. if (!string.IsNullOrEmpty(l.F_Mobile))
  3235. {
  3236. SmsSingleSenderResult result = new SMSController().SMSSingleshot(395191, mag, l.F_Mobile);
  3237. bool n = new SMSController().AddSmS(l.F_Mobile, smsmsg, nowUser.F_UserId);
  3238. }
  3239. }
  3240. }
  3241. touser = users;
  3242. }
  3243. string htouser = "", htousername = "";
  3244. if (isApprovalp != 0 && nowUser.F_DeptId == 37)
  3245. {
  3246. if (hclid != 0)
  3247. {
  3248. Model.T_Sys_UserAccount clus = userAccountBLL.GetModel(hclid);
  3249. if (clus != null)
  3250. {
  3251. if (string.IsNullOrEmpty(htouser))
  3252. {
  3253. htouser = clus.F_UserCode;
  3254. htousername = clus.F_UserName + "(" + clus.F_WorkNumber + ")";
  3255. }
  3256. }
  3257. }
  3258. else
  3259. {
  3260. var list = userAccountBLL.GetModelList(" F_DeptId='" + hclbm + "'");
  3261. foreach (var l in list)
  3262. {
  3263. if (string.IsNullOrEmpty(htouser))
  3264. {
  3265. htouser = l.F_UserCode;
  3266. htousername = l.F_UserName + "(" + l.F_UserCode + ")";
  3267. }
  3268. else
  3269. {
  3270. htouser = htouser + "," + l.F_UserCode;
  3271. htousername = htousername + "," + l.F_UserName + "(" + l.F_WorkNumber + ")";
  3272. }
  3273. }
  3274. }
  3275. AddLog(model.F_ID, (int)EnumWorkOrderState.assign, htousername + "高层待审批", (int)EnumItemType.audit, (int)EnumItemOpt.audit, htouser, hclbm, nowUser, overtime, sms, creat, 2);
  3276. }
  3277. #endregion
  3278. #region 工单处理
  3279. var opt = "指派";
  3280. int optbut = (int)EnumItemOpt.assign;
  3281. int wostate = (int)EnumWorkOrderState.assign;//已指派待接单
  3282. #region 读取当前登录人部门
  3283. string deptname = "";
  3284. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  3285. if (deptmodel != null)
  3286. {
  3287. deptname = deptmodel.F_DeptName + "-";
  3288. }
  3289. #endregion
  3290. var optcont = "";
  3291. if (!string.IsNullOrEmpty(cont))
  3292. optcont = ",说明:" + cont;
  3293. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + opt + "工单给 " + tousername + optcont;
  3294. var itemid = AddLog(model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, touser, clbm, nowUser, overtime, sms, creat);
  3295. if (itemid > 0)
  3296. {
  3297. #region 处理工单
  3298. //工单完结要更新工单的状态
  3299. // model.F_DealBy = touser;
  3300. model.F_State = wostate;
  3301. model.F_limit = overtime;
  3302. if (!string.IsNullOrEmpty(F_Files))
  3303. {
  3304. if (!string .IsNullOrEmpty(model.F_Files))
  3305. model.F_Files = model.F_Files+ ","+F_Files;
  3306. else
  3307. model.F_Files = F_Files;
  3308. }
  3309. //处理内容
  3310. if (!string.IsNullOrEmpty(cont))
  3311. model.F_DealContent += cont + ";";
  3312. InToworkModel(model, input);
  3313. woBLL.Update(model);
  3314. #endregion
  3315. #region 推送消息
  3316. #region 推送消息给添加的坐席 -转派和处理
  3317. if (nowUser.F_UserCode != model.F_CreateBy)
  3318. {
  3319. sendsysmsg(model, nowUser, model.F_CreateBy, (int)model.F_ID, opt);//推送系统消息
  3320. var createmodel = userAccountBLL.GetModel(model.F_CreateBy); //被指派人
  3321. if (createmodel != null)
  3322. {
  3323. if (!string.IsNullOrEmpty(createmodel.F_WxOpenId))
  3324. {
  3325. sendwxmsg(model, createmodel.F_WxOpenId, nowUser, opt);
  3326. }
  3327. }
  3328. }
  3329. #endregion
  3330. #region 向下一级操作人员推送消息
  3331. if (!string.IsNullOrWhiteSpace(touser))
  3332. {
  3333. sendsysmsg(model, nowUser, touser, (int)model.F_ID, opt);//推送系统消息
  3334. var modelUser2 = userAccountBLL.GetModel(touser); //被指派人
  3335. if (modelUser2 != null)
  3336. {
  3337. if (!string.IsNullOrEmpty(modelUser2.F_WxOpenId))
  3338. {
  3339. sendwxmsg(model, modelUser2.F_WxOpenId, nowUser, "指派");
  3340. }
  3341. }
  3342. }
  3343. #endregion
  3344. #endregion
  3345. return true;
  3346. }
  3347. else
  3348. return false;
  3349. #endregion
  3350. }
  3351. /// <summary>
  3352. /// 查询超时工单列表
  3353. /// </summary>
  3354. [WechatActionFilter]
  3355. public ActionResult GetOvertime(string OpenId, string code, string keywords, string cusname, string cusphone, string companyname, string province, string city,
  3356. string country, string township, string touser, int source = 0, int type = 0, int pageindex = 1, int pagesize = 10)
  3357. {
  3358. if (!string.IsNullOrEmpty(OpenId))
  3359. {
  3360. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  3361. if (ua == null)
  3362. {
  3363. return Success("你的账号已在别处登录,你确定要再次登录吗?");
  3364. }
  3365. if (!Refresh())
  3366. {
  3367. return Error("查询失败");
  3368. }
  3369. string sql = $" and F_IsDelete=0";
  3370. DataTable dt = new DataTable();
  3371. #region 筛选条件
  3372. if (type > 0 && type < 5)//工单类型
  3373. sql += $" and F_Type=" + type;
  3374. if (source > 0)//工单来源
  3375. sql += $" and F_Source=" + source;
  3376. if (!string.IsNullOrWhiteSpace(touser))//参与人
  3377. sql += $" and F_DealBy like '%" + touser.Trim() + "%'";
  3378. if (!string.IsNullOrWhiteSpace(code))//工单编号
  3379. sql += $" and F_WorkOrderCode like '%" + code.Trim() + "%'";
  3380. if (!string.IsNullOrWhiteSpace(keywords))//关键字搜索
  3381. sql += $" and (F_WorkOrderCode like '%" + keywords.Trim() + "%' or F_CusName like '%" + keywords.Trim() + "%'or F_CusPhone like '%" + keywords.Trim() + "%' )";
  3382. if (!string.IsNullOrWhiteSpace(cusname))//客户姓名
  3383. sql += $" and F_CusName like '%" + cusname.Trim() + "%'";
  3384. if (!string.IsNullOrWhiteSpace(cusphone))//客户电话
  3385. sql += $" and F_CusPhone like '%" + cusphone.Trim() + "%'";
  3386. if (!string.IsNullOrWhiteSpace(companyname))//公司名称
  3387. sql += $" and F_CompanyName like '%" + companyname.Trim() + "%'";
  3388. if (!string.IsNullOrWhiteSpace(province))//省
  3389. sql += $" and F_IncidentProvince like '%" + province.Trim() + "%'";
  3390. if (!string.IsNullOrWhiteSpace(province))//市
  3391. sql += $" and F_IncidentCity like '%" + city.Trim() + "%'";
  3392. if (!string.IsNullOrWhiteSpace(province))//县
  3393. sql += $" and F_IncidentCountry like '%" + country.Trim() + "%'";
  3394. if (!string.IsNullOrWhiteSpace(province))//乡
  3395. sql += $" and F_IncidentTownship like '%" + township.Trim() + "%'";
  3396. sql += $" and F_State in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," +
  3397. (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + ")";
  3398. sql += $" and F_IsOver=" + 1;
  3399. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  3400. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "YWY" || ro.F_RoleCode == "BLRY")
  3401. {
  3402. sql += $" and F_DealBy like '%" + ua.F_UserCode.Trim() + "%'";
  3403. }
  3404. else if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "ZG")
  3405. {
  3406. string detpid = "";
  3407. var deparmentlist = new List<Model.T_Sys_Department>();
  3408. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  3409. if (dModel != null)
  3410. {
  3411. if (dModel.F_Layer == 1)
  3412. {
  3413. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  3414. if (deparmentlist.Count > 0)
  3415. {
  3416. foreach (var it in deparmentlist)
  3417. {
  3418. if (detpid != "")
  3419. {
  3420. detpid += "," + it.F_DeptId;
  3421. }
  3422. else
  3423. {
  3424. detpid = "" + it.F_DeptId; ;
  3425. }
  3426. }
  3427. }
  3428. }
  3429. else
  3430. {
  3431. detpid = ua.F_DeptId.ToString();
  3432. }
  3433. if (GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.dealing + ", " + (int)EnumWorkOrderState.receive + "," +
  3434. (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "") != "")
  3435. {
  3436. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," +
  3437. (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "") + ") "; ;
  3438. }
  3439. else
  3440. {
  3441. return Success("暂无工单"); ;
  3442. }
  3443. }
  3444. else
  3445. {
  3446. return Error("加载失败");
  3447. }
  3448. }
  3449. else if (ro.F_RoleCode == "JDYBZZX")
  3450. {
  3451. sql += $" and F_CreateBy like '%" + ua.F_UserCode.Trim() + "%'";
  3452. }
  3453. else if (ro.F_RoleCode == "QTJS")
  3454. {
  3455. return Error("无操作权限!");
  3456. }
  3457. #endregion
  3458. int recordCount = 0;
  3459. if (!string.IsNullOrWhiteSpace(sql))
  3460. {
  3461. dt = BLL.PagerBLL.GetListPager(
  3462. "T_Wo_WorkOrder",
  3463. "F_ID",
  3464. "*",
  3465. sql,
  3466. "ORDER BY T_Wo_WorkOrder.F_ID desc",
  3467. pagesize,
  3468. pageindex,
  3469. true,
  3470. out recordCount);
  3471. }
  3472. List<long> woid = new List<long>();
  3473. List<Model.T_Wo_WorkOrder> modlelist = new BLL.T_Wo_WorkOrder().DataTableToList(dt);
  3474. List<WorkOrderNewInput> Input = modeltooip(modlelist, ua);
  3475. var obj = new
  3476. {
  3477. state = "success",
  3478. message = "成功",
  3479. rows = Input,
  3480. total = recordCount
  3481. };
  3482. return Content(obj.ToJson()); ;
  3483. }
  3484. else
  3485. {
  3486. return Error("无操作权限!");
  3487. }
  3488. }
  3489. /// 是否超时
  3490. /// </summary>
  3491. /// <param name="id"></param>
  3492. /// <returns></returns>
  3493. private bool TimeforOver(int id)
  3494. {
  3495. var itemlasts = itembll.GetModelList(" F_WoID=" + id + " order by F_ID desc");
  3496. string time1 = "", time2 = ""; int x = 0, y = 0;
  3497. float time = 0;
  3498. if (itemlasts.Count > 0)
  3499. {
  3500. for (int z = 0; z < itemlasts.Count; z++)
  3501. {
  3502. if (itemlasts[z].F_WoState >= 1)
  3503. {
  3504. if (itemlasts[z].F_WoState == 1)
  3505. {
  3506. x = z;
  3507. time1 = itemlasts[z].F_CreateTime.ToString();
  3508. time = float.Parse(itemlasts[z].F_LimitTime);
  3509. break; ;
  3510. }
  3511. }
  3512. }
  3513. for (int i = 0; i < itemlasts.Count; i++)
  3514. {
  3515. if (itemlasts[i].F_WoState >= 1)
  3516. {
  3517. if (itemlasts[i].F_WoState == 11)
  3518. {
  3519. y = i;
  3520. time2 = itemlasts[i].F_CreateTime.ToString();
  3521. }
  3522. }
  3523. }
  3524. if (time2 != "")
  3525. {
  3526. if (time1 != "")
  3527. {
  3528. if (x > y)
  3529. {
  3530. System.TimeSpan a = DateTime.Parse(time2) - DateTime.Parse(time1);
  3531. if ((float)a.TotalHours > time)
  3532. {
  3533. return false;
  3534. }
  3535. }
  3536. else
  3537. {
  3538. System.TimeSpan a = DateTime.Now - DateTime.Parse(time1);
  3539. if ((float)a.TotalHours > time)
  3540. {
  3541. return false;
  3542. }
  3543. }
  3544. }
  3545. else
  3546. {
  3547. return true;
  3548. }
  3549. }
  3550. else if (time1 != "")
  3551. {
  3552. System.TimeSpan a = DateTime.Now - DateTime.Parse(time1);
  3553. if ((float)a.TotalHours > time)
  3554. {
  3555. return false;
  3556. }
  3557. }
  3558. else
  3559. {
  3560. return true;
  3561. }
  3562. }
  3563. else
  3564. {
  3565. return true;
  3566. }
  3567. return true;
  3568. }
  3569. /// <summary>
  3570. /// 接单 - 确认工单
  3571. /// </summary>
  3572. /// <returns></returns>
  3573. [WechatActionFilter]
  3574. public ActionResult SureWorkOrder(long orderid, string OpenId)
  3575. {
  3576. if (!string.IsNullOrEmpty(OpenId))
  3577. {
  3578. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  3579. if (ua != null)
  3580. {
  3581. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  3582. if (model != null)
  3583. {
  3584. if (model.F_State == 2)
  3585. {
  3586. return Error("工单已接单无需重新接单");
  3587. }
  3588. else
  3589. {
  3590. var res = SureWO(ua, model);
  3591. if (res)
  3592. return Success("接单成功");
  3593. else
  3594. return Error("接单失败");
  3595. }
  3596. }
  3597. else
  3598. return Error("工单不存在");
  3599. }
  3600. return Error("OpenId不能为空");
  3601. }
  3602. return Error("无操作权限");
  3603. }
  3604. /// <summary>
  3605. /// 高层审批
  3606. /// </summary>
  3607. /// <param name="input"></param>
  3608. /// <returns></returns>
  3609. [WechatActionFilter]
  3610. public ActionResult HigApprovalOrder(string OpenId, long orderid, string cont)
  3611. {
  3612. if (!string.IsNullOrEmpty(OpenId))
  3613. {
  3614. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  3615. if (ua != null)
  3616. {
  3617. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  3618. //验证信息
  3619. if (model != null)
  3620. {
  3621. var itemlast = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.audit + " and F_OptType=" + (int)EnumItemOpt.audit + "and F_NextUser= '" + ua.F_UserCode + "'" + "and F_IsUsed=2 and F_WoID = " + orderid);
  3622. int overtime = 0, sms = 0;
  3623. if (itemlast.Count > 0)
  3624. {
  3625. foreach (var it in itemlast)
  3626. {
  3627. if (!string .IsNullOrEmpty (it.F_LimitTime))
  3628. overtime = int.Parse(it.F_LimitTime);
  3629. sms = int .Parse (it.F_IsSMS.ToString ());
  3630. it.F_IsUsed = 1;
  3631. itembll.Update(it);
  3632. }
  3633. }
  3634. model.F_Highopinions = cont;
  3635. string deptname = "";
  3636. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  3637. if (deptmodel != null)
  3638. {
  3639. deptname = deptmodel.F_DeptName + "-";
  3640. }
  3641. AddLog(model.F_ID, model.F_State.Value, deptname + ua.F_UserName + "(" + ua.F_WorkNumber + ")" + "高层已审批", (int)EnumItemType.audit, (int)EnumItemOpt.reaudit, "", 0, ua, overtime, sms, "", 1);
  3642. bool n = woBLL.Update(model);
  3643. if (n)
  3644. return Success("审批成功");
  3645. else
  3646. return Error("审批失败!");
  3647. }
  3648. return Error("工单不存在");
  3649. }
  3650. }
  3651. return Error("无操作权限");
  3652. }
  3653. /// <summary>
  3654. /// 接单
  3655. /// </summary>
  3656. public bool SureWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model)
  3657. {
  3658. int overtime = 0, sms = 0;
  3659. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID=" + model.F_ID + " ");
  3660. if (itemlasts.Count > 0)
  3661. {
  3662. foreach (var it in itemlasts)
  3663. {
  3664. if (it.F_WoState == 1)
  3665. {
  3666. overtime = int.Parse(it.F_LimitTime);
  3667. sms = int.Parse(it.F_IsSMS.ToString());
  3668. }
  3669. }
  3670. }
  3671. #region 工单处理
  3672. var opt = "处理接单";
  3673. int optbut = (int)EnumItemOpt.receive;
  3674. int wostate = (int)EnumWorkOrderState.receive;
  3675. #region 读取当前登录人部门
  3676. string deptname = "";
  3677. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  3678. if (deptmodel != null)
  3679. {
  3680. deptname = deptmodel.F_DeptName + "-";
  3681. }
  3682. #endregion
  3683. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + opt;
  3684. var itemid = AddLog((int)model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, nowUser.F_UserCode, nowUser.F_DeptId, nowUser, overtime, sms);
  3685. if (itemid > 0)
  3686. {
  3687. #region 处理工单
  3688. model.F_State = wostate;//已接单待处理
  3689. model.F_DealBy = nowUser.F_UserCode;//已接单待处理
  3690. woBLL.Update(model);
  3691. #endregion
  3692. #region 推送消息
  3693. //读取上一级指派人员以及添加坐席并推送系统消息和微信消息
  3694. #region 给添加坐席推送系统消息和微信消息
  3695. sendsysmsg(model, nowUser, model.F_CreateBy, (int)itemid, "处理接单");
  3696. var createUser = userAccountBLL.GetModel(model.F_CreateBy);
  3697. if (createUser != null && !string.IsNullOrEmpty(createUser.F_WxOpenId))
  3698. sendwxmsg(model, createUser.F_WxOpenId, nowUser, "接单");
  3699. #endregion
  3700. #region 读取上一级指派人员推送系统消息和微信消息
  3701. var itemlast = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID='" + model.F_ID + "' and F_NextUser='" + nowUser.F_UserCode + "' order by F_ID desc").FirstOrDefault();
  3702. if (itemlast != null)
  3703. {
  3704. if (itemlast.F_CreateUser != model.F_CreateBy)
  3705. {
  3706. sendsysmsg(model, nowUser, itemlast.F_CreateUser, (int)itemid, "处理接单");
  3707. var lastUser = userAccountBLL.GetModel(itemlast.F_CreateUser);
  3708. if (lastUser != null && !string.IsNullOrEmpty(lastUser.F_WxOpenId))
  3709. sendwxmsg(model, lastUser.F_WxOpenId, nowUser, "接单");
  3710. }
  3711. }
  3712. #endregion
  3713. #endregion
  3714. return true;
  3715. }
  3716. else
  3717. return false;
  3718. #endregion
  3719. }
  3720. /// <summary>
  3721. /// 工单处理
  3722. /// </summary>
  3723. /// <returns></returns>
  3724. [WechatActionFilter]
  3725. public ActionResult DealWorkOrder(string OpenId, long orderid, string F_Files, string cont, WorkOrdeDeptment deptment,
  3726. string uncont = "",
  3727. int isvisit = 1, int isover = 0)
  3728. {
  3729. if (!string.IsNullOrEmpty(OpenId))
  3730. {
  3731. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  3732. WorkOrderNewInput input = new WorkOrderNewInput();
  3733. if (ua != null)
  3734. {
  3735. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  3736. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  3737. if (deptmodel != null)
  3738. {
  3739. if (model != null)
  3740. {
  3741. if (model.F_Type == "2")
  3742. {
  3743. if (deptmodel.F_DeptId == 37)
  3744. {
  3745. input.F_SC_ProductBase = deptment.ProductBase;//
  3746. }
  3747. else if (deptmodel.F_DeptId == 12)
  3748. {
  3749. input.F_IsVisit = isvisit.ToString();
  3750. input.F_ZL_QualityEventLevel = deptment.QualityEventLevel;//质量管理科-质量事件等级(未遂、一般、较大、重大)
  3751. input.F_ZL_ClaimAmount = deptment.ClaimAmount;// 质量管理科-索赔金额(单位元,对应责任单位)
  3752. input.F_ZL_ResponsibleUnit = deptment.ResponsibleUnit;// 质量管理科-责任单位(需列出,可选多个)
  3753. input.F_ZL_ApprovalOpinions = deptment.ApprovalOpinions;// 质量管理科-审批意见(同意、不同意,若选择不同意,增加输入框输入补充内容)
  3754. input.F_ZL_ApprovalDisagree = deptment.ApprovalDisagree;// 质量管理科-审批不同意意见
  3755. input.F_ZL_CompensationMethod = deptment.CompensationMethod;// 质量管理科-补偿方式(实物、钱款【单位元】,若选择钱款,增加输入框输入补充内容)
  3756. input.F_ZL_CompensationMoney = deptment.CompensationMoney;// 质量管理科-补偿钱款
  3757. input.F_ZL_CResponsibleUnits = deptment.CResponsibleUnits;//质量管理科-对应责任单位(生产、研发、农化、物流、质量管理科,销售内勤)
  3758. input.F_ZL_Fquantity = deptment.Fquantity;//质量管理科-确认实收数量(吨)
  3759. input.F_ZL_ImprovementRequirements = deptment.ImprovementRequirements;// 质量管理科-改进要求
  3760. input.F_ZL_CApprovalNo = deptment.CApprovalNo;// 质量管理科-对应审批工作流单号
  3761. }
  3762. }
  3763. else if (model.F_Type == "3")
  3764. {
  3765. if (deptmodel.F_DeptId == 37)
  3766. {
  3767. input.F_SC_ProductBase = deptment.ProductBase;//
  3768. }
  3769. else if (deptmodel.F_DeptId == 12)
  3770. {
  3771. input.F_IsVisit = isvisit.ToString();
  3772. input.F_ZL_CJ_IsRecord = deptment.IsRecord;//质量管理科-抽检-未备案、已备案
  3773. }
  3774. }
  3775. if (deptmodel.F_DeptId == 25)
  3776. {
  3777. input.F_SC_CJ_ReturnAccount = deptment.ReturnAccount;//销售内勤-确认返账金额
  3778. }
  3779. else if (deptmodel.F_DeptId == 36)
  3780. {
  3781. input.F_ZL_Fquantity = deptment.Fquantity;//质量管理科-确认实收数量(吨)
  3782. }
  3783. }
  3784. else
  3785. return Error("工单不存在!");
  3786. }
  3787. else
  3788. {
  3789. return Error("请选择接收部门");
  3790. }
  3791. if (model != null)
  3792. {
  3793. if (model.F_State == 10)
  3794. return Error("工单已处理请勿重复操作!");
  3795. else
  3796. {
  3797. var res = DealWO(ua, model, F_Files, input, cont, isover, uncont);
  3798. if (res)
  3799. return Success("处理成功");
  3800. else
  3801. return Error("处理失败!");
  3802. }
  3803. }
  3804. else
  3805. return Error("工单不存在!");
  3806. }
  3807. }
  3808. return Error("无操作权限!");
  3809. }
  3810. /// <summary>
  3811. /// 更新工单
  3812. /// </summary>
  3813. private bool Refresh()
  3814. {
  3815. int type = 0;
  3816. var modlelist = woBLL.GetModelList(" F_IsDelete=0" + "and F_IsOver=0" + " and F_State in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," +
  3817. (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.finish + ")");
  3818. if (modlelist.Count > 0)
  3819. {
  3820. foreach (var it in modlelist)
  3821. {
  3822. if (TimeforOver(it.F_ID))
  3823. {
  3824. type = 0;
  3825. }
  3826. else
  3827. {
  3828. type = 1;
  3829. }
  3830. if (type != it.F_IsOver)
  3831. {
  3832. it.F_IsOver = type;
  3833. bool n = woBLL.Update(it);
  3834. if (!n)
  3835. {
  3836. return false;
  3837. }
  3838. }
  3839. }
  3840. }
  3841. return true;
  3842. }
  3843. /// <summary>
  3844. /// 退回工单
  3845. /// </summary>
  3846. /// <param name="input"></param>
  3847. /// <returns></returns>
  3848. [WechatActionFilter]
  3849. public ActionResult BackWorkOrder(string OpenId, long orderid, string cont, int type = 0)
  3850. {//办理人员和监管可以退回工单
  3851. if (!string.IsNullOrEmpty(OpenId))
  3852. {
  3853. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  3854. //河南心连心化学工业集团股份有限公司-系统维护管理员(8000)指派工单给 李波(80324),张绍申(80325),杜爱国(80326),说明:无
  3855. if (ua != null)
  3856. {
  3857. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  3858. //验证信息
  3859. if (model != null)
  3860. {
  3861. var res = BackWO(ua, model, cont, type);
  3862. if (res)
  3863. return Success("退回成功");
  3864. else
  3865. return Error("退回失败!");
  3866. }
  3867. return Error("工单不存在");
  3868. }
  3869. }
  3870. return Error("无操作权限");
  3871. }
  3872. /// <summary>
  3873. ///申请延期
  3874. /// </summary>
  3875. /// <returns></returns>
  3876. [WechatActionFilter]
  3877. public ActionResult DelayWorkOrder(string OpenId, long orderid, string cont, float limit = 0)
  3878. {
  3879. if (!string.IsNullOrEmpty(OpenId))
  3880. {
  3881. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  3882. if (ua != null)
  3883. {
  3884. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  3885. //验证信息
  3886. if (model != null)
  3887. {
  3888. var res = DeWO(ua, model, cont, limit);
  3889. if (res)
  3890. return Success("延期成功");
  3891. else
  3892. return Error("延期失败!");
  3893. }
  3894. return Error("工单不存在");
  3895. }
  3896. }
  3897. return Error("无操作权限");
  3898. }
  3899. /// <summary>
  3900. /// 申请延期
  3901. /// </summary>
  3902. public bool DeWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, string cont, float limit)
  3903. {
  3904. #region 工单处理
  3905. int sms = 0; int wostate = 0;
  3906. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID=" + model.F_ID + " ");
  3907. if (itemlasts.Count > 0)
  3908. {
  3909. foreach (var it in itemlasts)
  3910. {
  3911. if (it.F_WoState == 1)
  3912. {
  3913. sms = int.Parse(it.F_IsSMS.ToString());
  3914. }
  3915. itembll.Update(it);
  3916. wostate = int.Parse(it.F_WoState.ToString());
  3917. }
  3918. }
  3919. int optbut = (int)EnumItemOpt.Delay;
  3920. #region 读取当前登录人部门
  3921. string deptname = "";
  3922. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  3923. if (deptmodel != null)
  3924. {
  3925. deptname = deptmodel.F_DeptName + "-";
  3926. }
  3927. #endregion
  3928. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + "延期工单,延期说明:" + cont;
  3929. //获取上一级处理人员
  3930. var touser = "";
  3931. var itemlast = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID='" + model.F_ID + "' and F_NextUser='" + nowUser.F_UserCode + "' order by order F_ID desc").FirstOrDefault();
  3932. if (itemlast != null)
  3933. touser = itemlast.F_CreateUser;
  3934. var itemid = AddLog((int)model.F_ID, wostate, content, (int)EnumItemType.Delay, optbut, touser, 0, nowUser, limit + model.F_limit, sms, "", 1);
  3935. #endregion
  3936. return true;
  3937. }
  3938. /// <summary>
  3939. /// 退回工单
  3940. /// </summary>
  3941. public bool BackWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, string cont, int type)
  3942. {
  3943. #region 工单处理
  3944. int sms = 0;
  3945. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID=" + model.F_ID + " ");
  3946. if (itemlasts.Count > 0)
  3947. {
  3948. foreach (var it in itemlasts)
  3949. {
  3950. if (it.F_WoState == 1)
  3951. {
  3952. sms = int.Parse(it.F_IsSMS.ToString());
  3953. }
  3954. }
  3955. }
  3956. var opt = "退回";
  3957. int F_OptType = 1;
  3958. int optbut = (int)EnumItemOpt.reback;
  3959. int wostate = (int)EnumWorkOrderState.reback;
  3960. if (type == 1)
  3961. {
  3962. opt = "异常退回";
  3963. optbut = (int)EnumItemOpt.abreback;
  3964. wostate = (int)EnumWorkOrderState.abreback;
  3965. F_OptType = 2;
  3966. }
  3967. #region 读取当前登录人部门
  3968. string deptname = "";
  3969. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  3970. if (deptmodel != null)
  3971. {
  3972. deptname = deptmodel.F_DeptName + "-";
  3973. }
  3974. #endregion
  3975. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + opt + "工单,退回说明:" + cont;
  3976. //获取上一级处理人员
  3977. var touser = ""; var deptid = 0;
  3978. var itemlast = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_NextDept =" + nowUser.F_DeptId + " and F_WoState =" + F_OptType + " and F_WoID='" + model.F_ID + "' order by F_ID desc").FirstOrDefault();
  3979. if (itemlast != null)
  3980. {
  3981. touser = itemlast.F_CreateUser;
  3982. if (!string.IsNullOrEmpty(touser))
  3983. {
  3984. var ua = userAccountBLL.GetModel(touser);
  3985. if (ua != null)
  3986. {
  3987. deptid = ua.F_DeptId;
  3988. }
  3989. }
  3990. }
  3991. var itemid = AddLog((int)model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, touser, deptid, nowUser, model.F_limit, sms);
  3992. if (itemid > 0)
  3993. {
  3994. #region 处理工单
  3995. if (model.F_State == (int)EnumWorkOrderState.assign || model.F_State == (int)EnumWorkOrderState.abreback)
  3996. {
  3997. model.F_State = (int)EnumWorkOrderState.reassign;
  3998. }
  3999. else
  4000. {
  4001. model.F_State = wostate;
  4002. }
  4003. woBLL.Update(model);
  4004. #endregion
  4005. #region 推送消息
  4006. #region 向上一级操作人员推送消息
  4007. if (!string.IsNullOrWhiteSpace(touser) && touser != nowUser.F_UserCode)
  4008. {//排除上一级指派人是自己
  4009. sendsysmsg(model, nowUser, touser, (int)itemid, opt);
  4010. var lastUser = userAccountBLL.GetModel(touser);
  4011. if (lastUser != null && !string.IsNullOrEmpty(lastUser.F_WxOpenId))
  4012. sendwxmsg(model, lastUser.F_WxOpenId, nowUser, opt);
  4013. }
  4014. #endregion
  4015. #endregion
  4016. return true;
  4017. }
  4018. else
  4019. return false;
  4020. #endregion
  4021. }
  4022. /// <summary>
  4023. /// 处理工单
  4024. /// </summary>
  4025. public bool DealWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, string F_Files, WorkOrderNewInput input, string cont, int isover = 0, string uncont = "")
  4026. {
  4027. #region 工单处理
  4028. int sms = 0;
  4029. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID=" + model.F_ID + " ");
  4030. if (itemlasts.Count > 0)
  4031. {
  4032. foreach (var it in itemlasts)
  4033. {
  4034. if (it.F_WoState == 1)
  4035. {
  4036. sms = int.Parse(it.F_IsSMS.ToString());
  4037. }
  4038. }
  4039. }
  4040. var opt = "处理";
  4041. int optbut = (int)EnumItemOpt.deal;
  4042. int wostate = (int)EnumWorkOrderState.receive;
  4043. if (isover == 1)
  4044. {
  4045. model.F_DealResult = "已处理";//处理结果
  4046. opt = "处理完结";
  4047. optbut = (int)EnumItemOpt.end;
  4048. wostate = (int)EnumWorkOrderState.finish;
  4049. model.F_DealBy = nowUser.F_UserCode;
  4050. model.F_DealTime = DateTime.Now;
  4051. }
  4052. else
  4053. {
  4054. model.F_DealResult = "未处理";//处理结果
  4055. model.F_DealReasons = uncont;//未处理原因
  4056. }
  4057. #region 读取当前登录人部门
  4058. string deptname = "";
  4059. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  4060. if (deptmodel != null)
  4061. {
  4062. deptname = deptmodel.F_DeptName + "-";
  4063. }
  4064. #endregion
  4065. var optcont = "";
  4066. if (!string.IsNullOrEmpty(cont))
  4067. optcont = ",处理内容:" + cont;
  4068. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + opt + "工单" + optcont;
  4069. var itemid = AddLog(model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, "", 0, nowUser, model.F_limit, sms);
  4070. if (itemid > 0)
  4071. {
  4072. #region 处理工单
  4073. model.F_State = wostate;
  4074. if (!string.IsNullOrEmpty(F_Files))
  4075. model.F_Files = F_Files;
  4076. //处理内容
  4077. if (!string.IsNullOrEmpty(cont))
  4078. model.F_DealContent += cont + ";";
  4079. model.F_DealTime = DateTime.Now;
  4080. InToworkModel(model, input);
  4081. woBLL.Update(model);
  4082. #endregion
  4083. #region 推送消息
  4084. #region 推送消息给添加的坐席 -处理情况
  4085. if (nowUser.F_UserCode != model.F_CreateBy)
  4086. {
  4087. sendsysmsg(model, nowUser, model.F_CreateBy, (int)model.F_ID, opt);//推送系统消息
  4088. var createmodel = userAccountBLL.GetModel(model.F_CreateBy); //被指派人
  4089. if (createmodel != null)
  4090. {
  4091. if (!string.IsNullOrEmpty(createmodel.F_WxOpenId))
  4092. {
  4093. sendwxmsg(model, createmodel.F_WxOpenId, nowUser, opt);
  4094. }
  4095. }
  4096. }
  4097. #endregion
  4098. #region 向上一级操作人员推送消息
  4099. var itemlast = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID='" + model.F_ID + "' and F_NextUser='" + nowUser.F_UserCode + "' order by F_ID desc").FirstOrDefault();
  4100. if (itemlast != null)
  4101. {
  4102. if (itemlast.F_CreateUser != model.F_CreateBy)
  4103. {
  4104. sendsysmsg(model, nowUser, itemlast.F_CreateUser, (int)itemid, opt);
  4105. var lastUser = userAccountBLL.GetModel(itemlast.F_CreateUser);
  4106. if (lastUser != null && !string.IsNullOrEmpty(lastUser.F_WxOpenId))
  4107. sendwxmsg(model, lastUser.F_WxOpenId, nowUser, opt);
  4108. }
  4109. }
  4110. #endregion
  4111. #region 办理完结向客户发送消息
  4112. if (model.F_State == (int)EnumWorkOrderState.finish)
  4113. {
  4114. if (!string.IsNullOrEmpty(model.F_CustomerID))
  4115. {
  4116. var cusmodel = customerBaseBLL.GetModel(model.F_CustomerID.Trim());
  4117. if (cusmodel != null && !string.IsNullOrEmpty(cusmodel.F_WxOpenId))
  4118. {
  4119. sendwxmsg(model, cusmodel.F_WxOpenId, nowUser, opt);
  4120. }
  4121. }
  4122. }
  4123. #endregion
  4124. #endregion
  4125. return true;
  4126. }
  4127. else
  4128. return false;
  4129. #endregion
  4130. }
  4131. //推送系统提醒
  4132. public void sendsysmsg(Model.T_Wo_WorkOrder womodel, Model.T_Sys_UserAccount nowUser, string touser, int toid, string opt)
  4133. {
  4134. #region 消息提醒
  4135. string strmsg = string.Empty;
  4136. strmsg = nowUser.F_UserName + "(" + nowUser.F_UserCode + ")" + "操作" + opt + "工单";
  4137. Model.T_Msg_List msg = new Model.T_Msg_List();
  4138. msg.Type = (int)Model.MSGType.workorder;//处理
  4139. msg.ToUser = touser;
  4140. msg.ToID = toid;
  4141. msg.Detail = strmsg;
  4142. msg.State = 0;
  4143. msg.IsDel = 0;
  4144. msg.CreateUser = nowUser.F_UserCode;
  4145. msg.CreateDate = DateTime.Now;
  4146. new BLL.T_Msg_List().Add(msg);
  4147. #endregion
  4148. }
  4149. //推送微信消息
  4150. public void sendwxmsg(Model.T_Wo_WorkOrder womodel, string openid, Model.T_Sys_UserAccount nowUser, string opt)
  4151. {
  4152. #region 推送微信
  4153. try
  4154. {
  4155. if (!string.IsNullOrEmpty(openid))
  4156. {
  4157. var dicv = dicvalueBll.GetModel(int.Parse(womodel.F_Type));
  4158. string content = string.Empty;
  4159. var wotype = "";
  4160. if (dicv != null)
  4161. {
  4162. wotype = dicv.F_Name;
  4163. }
  4164. content = "编号" + womodel.F_WorkOrderCode + "的工单已" + opt + ",操作人:" + nowUser.F_UserName + "(" + nowUser.F_UserCode + ")";
  4165. var msg = WxHelper.SendWechatMsg1(womodel.F_WorkOrderCode, "你有工单已" + opt, wotype, womodel.F_State.ToString(), content, womodel.F_ID.ToString(), openid, "");
  4166. Error("推送微信::::::" + msg.ToString());
  4167. }
  4168. }
  4169. catch { }
  4170. #endregion
  4171. }
  4172. /// <summary>
  4173. /// 修改工单
  4174. /// </summary>
  4175. /// <returns></returns>
  4176. [WechatActionFilter]
  4177. public ActionResult Update(WorkOrderNewInput input )
  4178. {
  4179. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + input.F_WxOpenId + "'").FirstOrDefault();
  4180. if (ua != null)
  4181. {
  4182. #region 添加验证判断
  4183. if (input.F_ID <= 0)
  4184. return Error("参数错误!");
  4185. if (!(input.F_Type > 0 && input.F_Type < 5))
  4186. return Error("工单类型错误!");
  4187. if (string.IsNullOrEmpty(input.F_CusName))
  4188. return Error("请输入客户姓名!");
  4189. if (string.IsNullOrEmpty(input.F_CusPhone))
  4190. return Error("请输入客户电话!");
  4191. if (!string.IsNullOrEmpty(input.F_BatchNumber) && !vaBatchNumber(input.F_BatchNumber))
  4192. {
  4193. return Error("请输入正确的生产批次号!");
  4194. }
  4195. else
  4196. {
  4197. if (!string.IsNullOrEmpty(input.F_BatchNumber))
  4198. {
  4199. var prono = input.F_BatchNumber.Substring(0, 6);
  4200. try
  4201. {
  4202. var pronos = DateTime.ParseExact(prono, "yyMMdd", null).ToString("yyyy-MM-dd");
  4203. var protime = Convert.ToDateTime(pronos);
  4204. if (DateTime.Parse(pronos) > DateTime.Now)
  4205. {
  4206. return Error("生产批次号错误,生产日期不能大于当前时间!");
  4207. }
  4208. }
  4209. catch
  4210. {
  4211. return Error("生产批次号错误,日期格式错误!");
  4212. }
  4213. }
  4214. }
  4215. if (!string.IsNullOrEmpty(input.F_CustomerID) && !valcode(input.F_CustomerID.ToString(), 10))
  4216. return Error("客户编号为10为纯数字!");
  4217. if (!string.IsNullOrEmpty(input.F_MaterialID) && !valcode(input.F_MaterialID.ToString(), 11))
  4218. return Error("物料编码为11为纯数字!");
  4219. #endregion
  4220. var model = woBLL.GetModel(input.F_ID);
  4221. if (model == null)
  4222. return Error("查询不到此工单!");
  4223. if (model.F_State == 2)
  4224. {
  4225. return Error("此工单已接单不能修改!");
  4226. }
  4227. else if (model.F_State == 11 || model.F_State == 10)
  4228. {
  4229. return Error("此工单已处理不能修改!");
  4230. }
  4231. var itemlasts = itembll.GetModelList(" F_WoID=" + model.F_ID + "order by F_ID desc ").FirstOrDefault ();
  4232. int overtime = 0, sms = 0;
  4233. if (itemlasts!=null )
  4234. {
  4235. if (itemlasts.F_LimitTime != "")
  4236. overtime = int.Parse(itemlasts.F_LimitTime);
  4237. sms = int.Parse(itemlasts.F_IsSMS.ToString());
  4238. }
  4239. #region 保存客户基本信息
  4240. model = inputtoobj(ua, model, input, 1);
  4241. #endregion
  4242. bool n = woBLL.Update(model);
  4243. if (n)
  4244. {
  4245. WriteWorkOrderLog(model.F_WorkOrderCode, ua.F_UserCode, 0, "", 1, "修改工单");
  4246. #region 读取当前登录人的部门
  4247. string deptname = "";
  4248. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  4249. if (deptmodel != null)
  4250. {
  4251. deptname = deptmodel.F_DeptName + "-";
  4252. }
  4253. #endregion
  4254. AddLog(input.F_ID, model.F_State.Value, deptname + ua.F_UserName + "(" + ua.F_WorkNumber + ")" + "修改工单", (int)EnumItemType.update, (int)EnumItemOpt.update, "", 0, ua, overtime, sms);
  4255. if (GetUser(input.F_WxOpenId) != null)
  4256. {
  4257. var user = GetUser(input.F_WxOpenId);
  4258. string deptname1 = "";
  4259. var deptmode = departmentBLL.GetModel(user.F_DeptId);
  4260. if (deptmode != null)
  4261. {
  4262. deptname1 = deptmode.F_DeptName + "-";
  4263. }
  4264. var deptmodel1 = departmentBLL.GetModel(ua.F_DeptId);
  4265. AddLog(input.F_ID, model.F_State.Value, deptname1 + user.F_UserName + "(" + user.F_WorkNumber + ")" + "待审批", (int)EnumItemType.audit, (int)EnumItemOpt.audit, user.F_UserCode, user.F_DeptId, ua, overtime, sms);
  4266. }
  4267. else
  4268. {
  4269. string deptname1 = "";
  4270. int dapt = 0, nextda = 0; string opt = "";
  4271. var deptmodel1 = departmentBLL.GetModel(ua.F_DeptId);
  4272. if (deptmodel1 != null)
  4273. {
  4274. deptname1 = deptmodel1.F_DeptName + "-";
  4275. dapt = deptmodel1.F_ParentId;
  4276. }
  4277. if (dapt != 0)
  4278. {
  4279. if (dapt == 11)
  4280. {
  4281. nextda = 37;
  4282. opt = "流转市场管理科";
  4283. }
  4284. else if (dapt == 14)
  4285. {
  4286. nextda = 57;
  4287. opt = "流转营销管理处";
  4288. }
  4289. else if (dapt == 15)
  4290. {
  4291. nextda = 74;
  4292. opt = "流转策划推广";
  4293. }
  4294. else if (dapt == 16)
  4295. {
  4296. nextda = 88;
  4297. opt = "流转销售部";
  4298. }
  4299. }
  4300. if (nextda != 0)
  4301. {
  4302. var res = AssignWO(ua, model, input, opt, "", nextda, 0, model.F_limit, sms );
  4303. if (res)
  4304. return Success("保存成功");
  4305. else
  4306. return Error("流转失败!");
  4307. }
  4308. else
  4309. {
  4310. return Error("流转失败!");
  4311. }
  4312. }
  4313. return Success("保存成功!");
  4314. }
  4315. else
  4316. return Error("保存失败!");
  4317. }
  4318. else
  4319. {
  4320. return Error("OpenId不能为空!!");
  4321. }
  4322. }
  4323. public void WriteWorkOrderLog(string WorkOrderID, string UserCode, int IsDelete, string DelUserCode, int TypeId, string Remark)
  4324. {
  4325. var model = new Model.T_Wo_WorkOrder_Logs();
  4326. model.WorkOrderID = WorkOrderID; //工单编号
  4327. model.UserCode = UserCode; //修改人code
  4328. model.AddTime = DateTime.Now; //添加时间
  4329. model.IsDelete = IsDelete; //是否删除(0正常1删除)
  4330. model.DelUserCode = DelUserCode; //删除人code
  4331. model.TypeId = TypeId; //类型(0添加,1修改)
  4332. model.Remark = Remark; //备注
  4333. blllogs.Add(model);
  4334. }
  4335. /// <summary>
  4336. /// 添加工单记录
  4337. /// </summary>
  4338. public long AddLog(long woid, int wostate, string content, int itemtype, int opttype, string nextuser, int nextdept, Model.T_Sys_UserAccount nowUser, float overtime, int sms, string create = "", int F_IsUsed = 0)
  4339. {
  4340. Model.T_Wo_WorkOrderItem_New itemModel = new Model.T_Wo_WorkOrderItem_New();
  4341. #region
  4342. //处理当前工单的记录之前的记录过期
  4343. var itemlast = itembll.GetModelList(" isnull(F_IsUsed,'0')='0' and F_ItemType=" + itemtype + " and F_WoID=" + woid + " ");
  4344. if (F_IsUsed == 0)
  4345. {
  4346. if (itemlast.Count > 0)
  4347. {
  4348. foreach (var it in itemlast)
  4349. {
  4350. it.F_IsUsed = 1;
  4351. it.F_LimitTime = overtime.ToString();
  4352. itembll.Update(it);
  4353. }
  4354. }
  4355. }
  4356. #endregion
  4357. itemModel.F_WoID = woid;
  4358. itemModel.F_IsSMS = sms;
  4359. itemModel.F_WoState = wostate;
  4360. itemModel.F_ItemType = itemtype;
  4361. itemModel.F_OptType = opttype;
  4362. itemModel.F_OptContent = content;
  4363. itemModel.F_NextUser = nextuser;
  4364. itemModel.F_NextDept = nextdept;
  4365. itemModel.F_IsUsed = F_IsUsed;
  4366. itemModel.F_LimitTime = overtime.ToString();
  4367. if (nowUser != null)
  4368. {
  4369. itemModel.F_CreateUser = nowUser.F_UserCode;
  4370. }
  4371. else
  4372. {
  4373. itemModel.F_CreateUser = "";
  4374. }
  4375. if (create != "")
  4376. {
  4377. itemModel.F_CreateTime = DateTime.Parse(create);
  4378. }
  4379. else
  4380. {
  4381. itemModel.F_CreateTime = DateTime.Now;
  4382. }
  4383. var res = itembll.Add(itemModel);
  4384. return res;
  4385. }
  4386. #region
  4387. //workorder.WoBillController blcon = new WoBillController();
  4388. ///// <summary>
  4389. ///// 获取所有业务
  4390. ///// </summary>
  4391. ///// <returns></returns>
  4392. //[WechatActionFilter]
  4393. //public ActionResult GetBusList()
  4394. //{
  4395. // var list = blcon.GetBusAllList();
  4396. // return Success("获取信息列表成功", list);
  4397. //}
  4398. ///// <summary>
  4399. ///// 获取业务内容
  4400. ///// </summary>
  4401. ///// <returns></returns>
  4402. //[WechatActionFilter]
  4403. //public ActionResult GetBusInfo()
  4404. //{
  4405. // string strbusid = HttpUtility.UrlDecode(RequestString.GetQueryString("busid"));
  4406. // if (string.IsNullOrEmpty(strbusid))
  4407. // return Error("参数错误");
  4408. // var model = blcon.GetBusInfo(strbusid);
  4409. // if (model != null)
  4410. // return Success("获取信息成功", model);
  4411. // else
  4412. // return Error("获取信息失败");
  4413. //}
  4414. ///// <summary>
  4415. ///// 获取开票列表
  4416. ///// </summary>
  4417. ///// <returns></returns>
  4418. //[WechatActionFilter]
  4419. //public ActionResult GetBillList()
  4420. //{
  4421. // DataTable dt = new DataTable();
  4422. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  4423. // string strbtime = HttpUtility.UrlDecode(RequestString.GetQueryString("btime"));
  4424. // string stretime = HttpUtility.UrlDecode(RequestString.GetQueryString("etime"));
  4425. // string strpageindex = RequestString.GetQueryString("pageindex");
  4426. // int pageindex = 1;
  4427. // string strpagesize = RequestString.GetQueryString("pagesize");
  4428. // int pagesize = 10;
  4429. // if (strpageindex.Trim() != "")
  4430. // {
  4431. // pageindex = Convert.ToInt32(strpageindex);
  4432. // }
  4433. // if (strpagesize.Trim() != "")
  4434. // {
  4435. // pagesize = Convert.ToInt32(strpagesize);
  4436. // }
  4437. // var obj=blcon.GetLists(stropenid, strbtime, stretime, pageindex, pagesize);
  4438. // return Content(obj.ToJson());
  4439. //}
  4440. ///// <summary>
  4441. ///// 获取开票详情
  4442. ///// </summary>
  4443. ///// <returns></returns>
  4444. //[WechatActionFilter]
  4445. //public ActionResult GetBillInfo()
  4446. //{
  4447. // string strbillid = HttpUtility.UrlDecode(RequestString.GetQueryString("billid"));
  4448. // if (string.IsNullOrEmpty(strbillid))
  4449. // return Error("参数错误");
  4450. // var model = blcon.GetBillInfo(strbillid);
  4451. // if (model != null)
  4452. // return Success("获取信息成功", model);
  4453. // else
  4454. // return Error("获取信息失败");
  4455. //}
  4456. ///// <summary>
  4457. ///// 开票
  4458. ///// </summary>
  4459. ///// <returns></returns>
  4460. //[WechatActionFilter]
  4461. //public ActionResult AddBill()
  4462. //{
  4463. // string billtype = RequestString.GetFormString("billtype");//发票类型
  4464. // string cusname = RequestString.GetFormString("cusname");//客户名称
  4465. // string taxidnum = RequestString.GetFormString("taxidnum");//纳税人识别号
  4466. // string address = RequestString.GetFormString("address");//地址
  4467. // string phone = RequestString.GetFormString("phone");//电话
  4468. // string bank = RequestString.GetFormString("bank");//开户行
  4469. // string bankaccount = RequestString.GetFormString("bankaccount");//开户行账号
  4470. // string proname = RequestString.GetFormString("proname");//项目名称
  4471. // string models = RequestString.GetFormString("models");//型号
  4472. // string unit = RequestString.GetFormString("unit");//单位
  4473. // string amount = RequestString.GetFormString("amount");//数量
  4474. // string unitprice = RequestString.GetFormString("unitprice");//单价
  4475. // string sumprice = RequestString.GetFormString("sumprice");//金额
  4476. // string taxrate = RequestString.GetFormString("taxrate");//税率
  4477. // string taxamount = RequestString.GetFormString("taxamount");//税额
  4478. // string billingMethod = RequestString.GetFormString("billingmethod");//开票方式:快递/自取
  4479. // string billingTime = RequestString.GetFormString("billingtime");//开票时间
  4480. // string remark = RequestString.GetFormString("remark");//备注
  4481. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  4482. // Model.T_Wo_Bill dModel = new Model.T_Wo_Bill();
  4483. // #region 保存基本信息
  4484. // dModel.F_BillType = billtype;
  4485. // dModel.F_CusName = cusname;
  4486. // dModel.F_TaxIDNum = taxidnum;
  4487. // dModel.F_Address = address;
  4488. // dModel.F_Phone = phone;
  4489. // dModel.F_Bank = bank;
  4490. // dModel.F_BankAccount = bankaccount;
  4491. // dModel.F_ProName = proname;
  4492. // dModel.F_Models = models;
  4493. // dModel.F_Unit = unit;
  4494. // dModel.F_Amount = amount;
  4495. // dModel.F_UnitPrice = unitprice;
  4496. // dModel.F_SumPrice = sumprice;
  4497. // dModel.F_TaxRate = taxrate;
  4498. // dModel.F_TaxAmount = taxamount;
  4499. // dModel.F_BillingMethod = billingMethod;
  4500. // dModel.F_BillingTime = billingTime;
  4501. // dModel.F_Remark = remark;
  4502. // dModel.F_Openid = stropenid;
  4503. // dModel.F_CreateOn = DateTime.Now;
  4504. // dModel.F_State = 0;
  4505. // #endregion
  4506. // var res=blcon.addbills(dModel);
  4507. // if (res)
  4508. // return Success("保存成功");
  4509. // else
  4510. // return Error("保存失败");
  4511. //}
  4512. #endregion
  4513. #region 获取公司详情
  4514. ////获取公司信息
  4515. //[WechatActionFilter]
  4516. //public ActionResult GetInfo()
  4517. //{
  4518. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  4519. // if (string.IsNullOrEmpty(stropenid))
  4520. // return Error("参数错误!");
  4521. // var model=customerBaseBLL.GetModelByOpenid(stropenid);
  4522. // if (model != null)
  4523. // {
  4524. // var sqlwo = " IsDel=0 and State <>2 "; var sqlno = " F_isDel=0 ";
  4525. // var nowUser = userAccountBLL.GetModelByOpenid(stropenid);
  4526. // var nowCus = customerBaseBLL.GetModelByOpenid(stropenid);
  4527. // if (nowUser != null)
  4528. // {
  4529. // workorder.WorkOrderController wo = new workorder.WorkOrderController();
  4530. // sqlwo += " and State =1 and WorkOrderID in ( '" + wo.GetDWCWorkOrderID(nowUser.F_UserCode) + "') ";
  4531. // sqlno += " and (ISNULL(F_UserId,'') = '' or ISNULL(F_UserId,'') like '%," + nowUser.F_UserId + ",%')";
  4532. // }
  4533. // else if (nowCus != null)
  4534. // {
  4535. // sqlwo += " and ( CustomerID=" + model.F_CustomerId + " or County like '%" + model.F_CompanyName + "%' )";
  4536. // sqlno += " and F_isCus=1 and F_NoticeId not in (select toid from T_Msg_List where Type=6 and ToUser='"+nowCus.F_CustomerCode+ "' and state=1 and IsDel=0)";
  4537. // }
  4538. // var ordercount = woBLL.GetRecordCount(sqlwo);
  4539. // var noticecount = new BLL.T_Msg_NoticeInfo().GetRecordCount(sqlno);
  4540. // var obj = new
  4541. // {
  4542. // model.F_CompanyName,//公司名称
  4543. // model.F_CompanyLogo,//logo
  4544. // model.F_CustomerCode,//编号
  4545. // model.F_CycleStart,//服务周期-开始时间
  4546. // model.F_CycleEnd,//服务周期-结束时间
  4547. // model.F_ChargeType,//收费类型:1月度,2季度,3年度
  4548. // model.F_Charges,//收费
  4549. // model.F_TaxNumber,//公司税号
  4550. // model.F_CompanyAddress,//公司地址
  4551. // ordercount,//待处理工单数量
  4552. // noticecount,//未读公告数量
  4553. // };
  4554. // return Success("获取成功", obj);
  4555. // }
  4556. // return Error("获取失败");
  4557. //}
  4558. ////获取财税信息
  4559. ////[WechatActionFilter]
  4560. //public ActionResult GetFinc()
  4561. //{
  4562. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  4563. // var model = customerBaseBLL.GetModelByOpenid(stropenid);
  4564. // if (model != null)
  4565. // {
  4566. // var finmodel = finbll.GetModelList(" F_CustomerId=" + model.F_CustomerId).FirstOrDefault();
  4567. // if (finmodel != null)
  4568. // {
  4569. // var obj = new
  4570. // {
  4571. // model.F_CompanyName,//公司名称
  4572. // model.F_CompanyLogo,//logo
  4573. // model.F_CustomerCode,//编号
  4574. // finmodel.F_CusFinId,
  4575. // finmodel.F_CustomerId,
  4576. // finmodel.F_MonthState,
  4577. // finmodel.F_AnnualIncome,
  4578. // finmodel.F_AnnualProfit,
  4579. // finmodel.F_AnnualCost,
  4580. // finmodel.F_AnnualPersonCount,
  4581. // finmodel.F_AnnualWages,
  4582. // finmodel.F_QuarterlyCost,
  4583. // finmodel.F_QuarterlyPersonCount,
  4584. // finmodel.F_QuarterlyWages,
  4585. // finmodel.F_QuarterlyIncome,
  4586. // finmodel.F_QPVAT,
  4587. // finmodel.F_QPSurtax,
  4588. // finmodel.F_QPTaxes,
  4589. // finmodel.F_QPConTax,
  4590. // finmodel.F_QPPerinTax,
  4591. // finmodel.F_QPStampTax,
  4592. // finmodel.F_QPOtherTax
  4593. // };
  4594. // return Success("获取成功", obj);
  4595. // }
  4596. // }
  4597. // return Error("获取失败");
  4598. //}
  4599. #endregion
  4600. #region 工单
  4601. /// <summary>
  4602. /// 工单列表
  4603. /// </summary>
  4604. [WechatActionFilter]
  4605. public ActionResult GetWoList()
  4606. {
  4607. workorder.WorkOrderController wo = new workorder.WorkOrderController();
  4608. var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='TimeLimitDays' ").FirstOrDefault();
  4609. int days = config != null ? Convert.ToInt32(config.F_ParamValue) : 60; //默认60天
  4610. DataTable dt = new DataTable();
  4611. int recordCount = 0;
  4612. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  4613. //客户姓名,电话,工单号
  4614. string keyword = HttpUtility.UrlDecode(RequestString.GetQueryString("keyword"));
  4615. //工单状态
  4616. int states = RequestString.GetInt("states", -1);
  4617. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  4618. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  4619. string strpageindex = RequestString.GetQueryString("page");
  4620. int pageindex = 1;
  4621. string strpagesize = RequestString.GetQueryString("pagesize");
  4622. int pagesize = 10;
  4623. //#region sql 语句相关处理
  4624. string sql = " ";
  4625. //获取坐席表信息
  4626. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  4627. //获取客户档案(业主)表信息
  4628. var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  4629. if (!string.IsNullOrEmpty(sql))
  4630. {
  4631. //sql += " and IsDel=0 ";
  4632. ////客户姓名,电话,房间号,工单号,接待描述
  4633. //if (!string.IsNullOrEmpty(keyword))
  4634. //{
  4635. // sql += " and (CustomerTel like '%" + keyword + "%' or Customer like '%" + keyword + "%' or WorkOrderID like '%" + keyword + "%' or Detail like '%" + keyword + "%' or County like '%" + keyword + "%' ) ";
  4636. //}
  4637. //if (states >= 0)
  4638. //{
  4639. // #region 权限限制
  4640. // if (ua != null)
  4641. // {
  4642. // string uwhere = " ";
  4643. // switch (states)
  4644. // {
  4645. // case 0://待指派的
  4646. // //sql += " and State ='0' and CreateUser= '" + ua.F_UserCode + "' ";
  4647. // //3区域客服可以看到区域待指派工单
  4648. // if (ua.F_RoleId != 17)
  4649. // {
  4650. // uwhere += " and CreateUser='" + ua.F_UserCode + "' ";
  4651. // }
  4652. // sql += " and State =0 " + uwhere;
  4653. // break;
  4654. // case 1://待接单的
  4655. // sql += " and State =" + (int)EnumWorkOrderState.assign + " and T_Wo_WorkOrder.ID in ( " + wo.GetDJDWorkOrderID(ua.F_UserCode) + ") ";
  4656. // break;
  4657. // case 2://待完成的(待处理)
  4658. // sql += " and State in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + ") and T_Wo_WorkOrder.ID in ( " + wo.GetDWCWorkOrderID(ua.F_UserCode) + ") ";
  4659. // break;
  4660. // case 3://已完成的
  4661. // sql += " and State =" + (int)EnumWorkOrderState.finish + " and LastDealUser = '" + ua.F_UserCode + "' ";
  4662. // break;
  4663. // case 4://我参与的
  4664. // sql += " and (CreateUser= '" + ua.F_UserCode + "' or T_Wo_WorkOrder.ID in ( " + wo.GetCYWorkOrderID(ua.F_UserCode) + ")) ";
  4665. // break;
  4666. // case 5://超期工单 - 设置两个月的处理时效,两个月内未解决的工单都直接汇总到这里
  4667. // sql += $" and DATEADD(DAY,{days},CreateTime) < GETDATE() AND State < " + (int)EnumWorkOrderState.finish + " ";
  4668. // break;
  4669. // }
  4670. // }
  4671. // else if (modelCustomer != null)
  4672. // {
  4673. // sql += " and ( CustomerID=" + modelCustomer.F_CustomerId + " or County like '%"+modelCustomer.F_CompanyName+"%' )";
  4674. // }
  4675. // else
  4676. // {
  4677. // sql = "";
  4678. // }
  4679. // #endregion
  4680. //}
  4681. //if (strstarttime.Trim() != "" && strstarttime != "undefined")
  4682. //{
  4683. // sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
  4684. //}
  4685. //if (strendtime.Trim() != "" && strendtime != "undefined")
  4686. //{
  4687. // sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0 ";
  4688. //}
  4689. //#endregion
  4690. //if (strpageindex.Trim() != "")
  4691. //{
  4692. // pageindex = Convert.ToInt32(strpageindex);
  4693. //}
  4694. //if (strpagesize.Trim() != "")
  4695. //{
  4696. // pagesize = Convert.ToInt32(strpagesize);
  4697. //}
  4698. //string cols = "*,dbo.GetDictionaryName(Source) as GDLYName,dbo.GetDictionaryName(Type) as GDLXName,dbo.GetDictionaryName(TypeClass) as TypeClassName,dbo.GetUserName(CreateUser) as CreateUserNameRel,dbo.GetUserName(LastDealUser) as LastDealUserNameRel,dbo.GetUserName(AuditUser) as AuditUserNameRel,dbo.GetDeptName(ResponDept) as ResponDeptName";
  4699. //dt = BLL.PagerBLL.GetListPager(
  4700. // "T_Wo_WorkOrder (NOLOCK)",
  4701. // "WorkOrderID",
  4702. // cols,
  4703. // sql,
  4704. // "ORDER BY CreateTime DESC,State asc",
  4705. // pagesize,
  4706. // pageindex,
  4707. // true,
  4708. // out recordCount);
  4709. }
  4710. var obj = new
  4711. {
  4712. state = "success",
  4713. message = "成功",
  4714. rows = dt,
  4715. total = recordCount
  4716. };
  4717. return Content(obj.ToJson());
  4718. }
  4719. /// <summary>
  4720. /// 工单详情
  4721. /// </summary>
  4722. [WechatActionFilter]
  4723. public ActionResult GetWoInfo()
  4724. {
  4725. string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
  4726. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  4727. if (string.IsNullOrEmpty(strworkorderid))
  4728. return Error("参数错误");
  4729. if (string.IsNullOrEmpty(stropenid))
  4730. return Error("参数错误!");
  4731. //string sql = "select *,dbo.GetDictionaryName(Type) as GDLXName,dbo.GetDictionaryName(TypeClass) as YWLXName,dbo.GetDictionaryName(Source) as GDLYName,dbo.GetUserName(CreateUser) as CreateUserName,dbo.GetUserName(LastDealUser) as LastDealUserNameRel,dbo.GetUserName(AuditUser) as AuditUserNameRel,dbo.GetUserName(ResponUser) as ResponUserName,dbo.GetDeptName(ResponDept) AS ComplaintDepartment "
  4732. // + " from T_Wo_WorkOrder where T_Wo_WorkOrder.ID ='" + strworkorderid + "' ";
  4733. //var dt = DbHelperSQL.Query(sql).Tables[0];
  4734. //if (dt.Rows.Count > 0)
  4735. //{
  4736. // var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
  4737. // var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  4738. // if (configfj != null)
  4739. // {
  4740. // dt = BindFileData(dt, configfj.F_ParamValue);
  4741. // }
  4742. // string gcsql = "select *,dbo.GetUserName(F_NextUser) as F_NextUserName, dbo.GetDeptName(F_NextDept) as F_NextDeptName,dbo.GetUserName(F_CreateUser) as F_CreateUserName "
  4743. // + "from T_Wo_WorkOrderItem_New where F_WoID ='" + strworkorderid + "'";
  4744. // var gcdt = DbHelperSQL.Query(gcsql).Tables[0];
  4745. // dt.Columns.Add("FilePath", typeof(string));
  4746. // if (configfj != null || config != null)
  4747. // {
  4748. // foreach (DataRow bldr in dt.Rows)
  4749. // {
  4750. // if (bldr["CallID"] != null && config != null)
  4751. // {
  4752. // bldr["FilePath"] = GetCallPath(bldr["CallID"].ToString(), config.F_ParamValue);
  4753. // }
  4754. // }
  4755. // }
  4756. // var obj = new
  4757. // {
  4758. // data = dt,
  4759. // item = gcdt
  4760. // };
  4761. // return Success("查询成功", obj);
  4762. //}
  4763. return Error("查询失败");
  4764. }
  4765. #region 在用工单操作
  4766. ///// <summary>
  4767. ///// 处理工单
  4768. ///// </summary>
  4769. ///// <returns></returns>
  4770. //[WechatActionFilter]
  4771. //public ActionResult DealWorkOrder(long orderid, string cont, int isover = 0)
  4772. //{
  4773. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  4774. // if (!string.IsNullOrEmpty(stropenid))
  4775. // {
  4776. // Model.T_Sys_UserAccount ua = userAccountBLL.GetModelByOpenid(stropenid);
  4777. // if (ua != null)
  4778. // {
  4779. // Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  4780. // if (model != null)
  4781. // {
  4782. // bool res = new workorder.WorkOrderController().DealWO(ua, model, cont, isover);
  4783. // if (res)
  4784. // return Success("处理成功");
  4785. // else
  4786. // return Error("操作失败");
  4787. // }
  4788. // else
  4789. // return Error("工单不存在");
  4790. // }
  4791. // else
  4792. // return Error("无操作权限");
  4793. // }
  4794. // else
  4795. // return Error("参数错误");
  4796. //}
  4797. ///// <summary>
  4798. ///// 接单 - 确认工单
  4799. ///// </summary>
  4800. ///// <returns></returns>
  4801. //[WechatActionFilter]
  4802. //public ActionResult SureWorkOrder(long orderid)
  4803. //{
  4804. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  4805. // if (!string.IsNullOrEmpty(stropenid))
  4806. // {
  4807. // var ua = userAccountBLL.GetModelByOpenid(stropenid);
  4808. // if (ua != null)
  4809. // {
  4810. // Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  4811. // if (model != null)
  4812. // {
  4813. // bool res = new workorder.WorkOrderController().SureWO(ua, model);
  4814. // if (res)
  4815. // return Success("接单成功");
  4816. // else
  4817. // return Error("操作失败");
  4818. // }
  4819. // else
  4820. // return Error("工单不存在");
  4821. // }
  4822. // else
  4823. // return Error("无操作权限");
  4824. // }
  4825. // else
  4826. // return Error("参数错误");
  4827. //}
  4828. ///// <summary>
  4829. ///// 指派/转派工单
  4830. ///// </summary>
  4831. ///// <returns></returns>
  4832. //[WechatActionFilter]
  4833. //public ActionResult AssignWorkOrder(long orderid, string cont, int clbm = 0, int clid = 0)
  4834. //{
  4835. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  4836. // if (!string.IsNullOrEmpty(stropenid))
  4837. // {
  4838. // var ua = userAccountBLL.GetModelByOpenid(stropenid);
  4839. // if (ua != null)
  4840. // {
  4841. // if (clbm != 0 && clid == 0)
  4842. // return Error("请选择接收人");
  4843. // Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  4844. // if (model != null)
  4845. // {
  4846. // var res = new workorder.WorkOrderController().AssignWO(ua, model, cont, clbm, clid);
  4847. // if (res)
  4848. // return Success("转派成功");
  4849. // else
  4850. // return Error("转派失败!");
  4851. // }
  4852. // else
  4853. // return Error("工单不存在!");
  4854. // }
  4855. // }
  4856. // return Error("无操作权限!");
  4857. //}
  4858. ///// <summary>
  4859. ///// 退回工单
  4860. ///// </summary>
  4861. ///// <param name="input"></param>
  4862. ///// <returns></returns>
  4863. //[WechatActionFilter]
  4864. //public ActionResult BackWorkOrder(long orderid, string cont,int type=0)
  4865. //{//办理人员和监管可以退回工单
  4866. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  4867. // if (!string.IsNullOrEmpty(stropenid))
  4868. // {
  4869. // var ua = userAccountBLL.GetModelByOpenid(stropenid);
  4870. // if (ua != null)
  4871. // {
  4872. // Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  4873. // //验证信息
  4874. // if (model != null)
  4875. // {
  4876. // var res = new workorder.WorkOrderController().BackWO(ua, model, cont, type);
  4877. // if (res)
  4878. // return Success("处理成功");
  4879. // else
  4880. // return Error("处理失败!");
  4881. // }
  4882. // return Error("工单不存在");
  4883. // }
  4884. // }
  4885. // return Error("无操作权限");
  4886. //}
  4887. ///// <summary>
  4888. ///// 催办工单
  4889. ///// </summary>
  4890. ///// <returns></returns>
  4891. //[WechatActionFilter]
  4892. //public ActionResult AddWorkOrderRemind(long orderid, string cont)
  4893. //{
  4894. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  4895. // if (!string.IsNullOrEmpty(stropenid))
  4896. // {
  4897. // var ua = userAccountBLL.GetModelByOpenid(stropenid);
  4898. // if (ua != null)
  4899. // {
  4900. // Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  4901. // if (model != null)
  4902. // {
  4903. // var res = new workorder.WorkOrderController().RemindWO(ua, model, cont);
  4904. // if (res)
  4905. // Success("催办成功!");
  4906. // else
  4907. // Success("操作失败!");
  4908. // }
  4909. // return Error("工单不存在!");
  4910. // }
  4911. // }
  4912. // return Error("无操作权限!");
  4913. //}
  4914. #endregion
  4915. #endregion
  4916. #region 公告通知
  4917. /// <summary>
  4918. /// 获取公告列表
  4919. /// </summary>
  4920. /// <returns></returns>
  4921. //[WechatActionFilter]
  4922. public ActionResult GetNoticeList()
  4923. {
  4924. DataTable dt = new DataTable(); int recordCount = 0;
  4925. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  4926. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  4927. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  4928. string strpageindex = RequestString.GetQueryString("page");
  4929. int pageindex = 1;
  4930. string strpagesize = RequestString.GetQueryString("pagesize");
  4931. int pagesize = 10;
  4932. #region sql 语句相关处理
  4933. string sql = " and F_isDel=0 ";
  4934. //获取坐席表信息
  4935. var ua = userAccountBLL.GetModelByOpenid(stropenid);
  4936. //获取客户档案(业主)表信息
  4937. var modelCustomer = customerBaseBLL.GetModelByOpenid(stropenid);
  4938. if (ua != null)
  4939. {
  4940. sql += " and (ISNULL(F_UserId,'') = '' or ISNULL(F_UserId,'') like '%," + ua.F_UserId + ",%')";
  4941. }
  4942. else if (modelCustomer != null) {
  4943. sql += " and F_isCus=1";
  4944. }
  4945. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  4946. {
  4947. sql += " and datediff(day,F_CreateOn,'" + strstarttime + "')<=0 ";
  4948. }
  4949. if (strendtime.Trim() != "" && strendtime != "undefined")
  4950. {
  4951. sql += " and datediff(day,F_CreateOn,'" + strendtime + "')>=0 ";
  4952. }
  4953. #endregion
  4954. if (strpageindex.Trim() != "")
  4955. {
  4956. pageindex = Convert.ToInt32(strpageindex);
  4957. }
  4958. if (strpagesize.Trim() != "")
  4959. {
  4960. pagesize = Convert.ToInt32(strpagesize);
  4961. }
  4962. dt = BLL.PagerBLL.GetListPager(
  4963. "T_Msg_NoticeInfo",
  4964. "F_NoticeId",
  4965. "*",
  4966. sql,
  4967. "ORDER BY F_NoticeId desc",
  4968. pagesize,
  4969. pageindex,
  4970. true,
  4971. out recordCount);
  4972. List<Model.T_Msg_NoticeInfo> msgList = new BLL.T_Msg_NoticeInfo().DataTableToList(dt);
  4973. List<Model.T_Sys_UserAccount> userList = new BLL.T_Sys_UserAccount().GetModelList("");
  4974. var obj = new
  4975. {
  4976. rows = msgList.Select(m =>
  4977. {
  4978. Model.T_Sys_UserAccount usermodel = userList.Where(u => u.F_UserId == m.F_CreateBy.Value).FirstOrDefault();
  4979. var uname = "";
  4980. if (usermodel != null)
  4981. uname = usermodel.F_UserName;
  4982. return new
  4983. {
  4984. F_NoticeId = m.F_NoticeId,
  4985. F_Title = m.F_Title,
  4986. F_Content = m.F_Content,
  4987. F_isCus = m.F_isCus,
  4988. F_CreateOn = m.F_CreateOn,
  4989. F_CreateBy = m.F_CreateBy,
  4990. F_CreateByName = uname
  4991. };
  4992. }),
  4993. total = recordCount
  4994. };
  4995. return Content(obj.ToJson());
  4996. }
  4997. /// <summary>
  4998. /// 获取公告详情
  4999. /// </summary>
  5000. /// <returns></returns>
  5001. //[WechatActionFilter]
  5002. public ActionResult GetNoticeInfo()
  5003. {
  5004. string strnoticeid = HttpUtility.UrlDecode(RequestString.GetQueryString("noticeid"));
  5005. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  5006. if (string.IsNullOrEmpty(strnoticeid))
  5007. return Error("参数错误");
  5008. if (string.IsNullOrEmpty(stropenid))
  5009. return Error("参数错误!");
  5010. var dModel = new BLL.T_Msg_NoticeInfo().GetModel(int.Parse(strnoticeid.Trim()));
  5011. Model.T_Sys_UserAccount userModel = new Model.T_Sys_UserAccount();
  5012. if (dModel != null)
  5013. {
  5014. if (dModel.F_CreateBy != null)
  5015. userModel = userAccountBLL.GetModel(dModel.F_CreateBy.Value);
  5016. var uname = "";
  5017. if (userModel != null)
  5018. uname = userModel.F_UserName;
  5019. #region 标记为已读
  5020. var nowUser = userAccountBLL.GetModelByOpenid(stropenid);
  5021. var nowCus = customerBaseBLL.GetModelByOpenid(stropenid);
  5022. var usercode = "";
  5023. if (nowUser != null)
  5024. {
  5025. usercode = nowUser.F_UserCode;
  5026. var msglist = new BLL.T_Msg_List().GetModelList(" State=0 and ToUser='" + usercode + "' and Type=5 and ToID=" + dModel.F_NoticeId);
  5027. foreach (var item in msglist)
  5028. {
  5029. item.State = 1;
  5030. item.ReadDate = DateTime.Now;
  5031. new BLL.T_Msg_List().Update(item);
  5032. }
  5033. }
  5034. else if (nowCus != null)
  5035. {
  5036. usercode = nowCus.F_CustomerCode;
  5037. Model.T_Msg_List msg = new Model.T_Msg_List();
  5038. msg.Type = (int)Model.MSGType.cusnotice;
  5039. msg.ToUser = usercode;
  5040. msg.ToID = dModel.F_NoticeId;
  5041. msg.Detail = "客户" + usercode + "查看了公告《" + dModel.F_Title + "》";
  5042. msg.State = 1;
  5043. msg.IsDel = 0;
  5044. msg.CreateDate = DateTime.Now;
  5045. msg.ReadDate = DateTime.Now;
  5046. new BLL.T_Msg_List().Add(msg);
  5047. }
  5048. #endregion
  5049. var obj = new
  5050. {
  5051. F_NoticeId = dModel.F_NoticeId,
  5052. F_Title = dModel.F_Title,
  5053. F_Content = dModel.F_Content,
  5054. F_isCus = dModel.F_isCus,
  5055. F_CreateOn = dModel.F_CreateOn,
  5056. F_CreateBy = dModel.F_CreateBy,
  5057. F_CreateByName = uname,
  5058. F_UserId = dModel.F_UserId,
  5059. F_RoleId = dModel.F_RoleId,
  5060. };
  5061. return Success("获取公告详情成功", dModel);
  5062. }
  5063. else
  5064. return Error("获取公告详情失败");
  5065. }
  5066. #endregion
  5067. #region 微信工单
  5068. ///// <summary>
  5069. ///// 获取工单列表
  5070. ///// </summary>
  5071. ///// <returns></returns>
  5072. //[WechatActionFilter]
  5073. //public ActionResult GetList()
  5074. //{
  5075. // workorder.WorkOrderController wo = new workorder.WorkOrderController();
  5076. // var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='TimeLimitDays' ").FirstOrDefault();
  5077. // int days = config != null ? Convert.ToInt32(config.F_ParamValue) : 60; //默认60天
  5078. // DataTable dt = new DataTable();
  5079. // int recordCount = 0;
  5080. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  5081. // //客户姓名,电话,房间号,工单号
  5082. // string keyword = HttpUtility.UrlDecode(RequestString.GetQueryString("keyword"));
  5083. // //工单状态(ltype:)
  5084. // string strltype = HttpUtility.UrlDecode(RequestString.GetQueryString("ltype"));
  5085. // //工单状态
  5086. // int states = RequestString.GetInt("states", -1);
  5087. // //工单来源
  5088. // int strtype = RequestString.GetInt("type", 0);
  5089. // //工单类型
  5090. // int strtypeclass = RequestString.GetInt("typeclass", 0);
  5091. // //工单起止时间
  5092. // string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  5093. // string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  5094. // //来电单位
  5095. // string lddep = HttpUtility.UrlDecode(RequestString.GetQueryString("lddep"));
  5096. // //20180329 来电弹屏工单记录根据反馈单位获取列表 可以看到同一坐席组的所有人的工单记录
  5097. // string fkdep = HttpUtility.UrlDecode(RequestString.GetQueryString("fkdep"));
  5098. // int isldtp = RequestString.GetQueryInt("isldtp", 0);
  5099. // //微信列表(0未审核微信列表,1已审核微信列表)
  5100. // int isaudit = RequestString.GetInt("isaudit", -1);
  5101. // string strpageindex = RequestString.GetQueryString("page");
  5102. // int pageindex = 1;
  5103. // string strpagesize = RequestString.GetQueryString("pagesize");
  5104. // int pagesize = 10;
  5105. // #region sql 语句相关处理
  5106. // string sql = " ";
  5107. // //获取坐席表信息
  5108. // var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  5109. // //获取客户档案(业主)表信息
  5110. // var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  5111. // #region 权限限制
  5112. // string mobile = "", roomno = "";
  5113. // int customerid = 0, areaid = 0, proid = 0, buildingid = 0;
  5114. // if (ua != null)
  5115. // {
  5116. // int deptid = ua.F_DeptId; //部门id
  5117. // string deptCode = ua.F_DeptCode; //部门code
  5118. // int userRegionId = ua.RegionId; //项目id
  5119. // //部门信息
  5120. // var modelDep = new BLL.T_Sys_Department().GetModel(deptid);
  5121. // int depType = 0, depRegion = 0;
  5122. // if (modelDep != null)
  5123. // {
  5124. // depType = modelDep.F_Type ?? 0; //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  5125. // depRegion = modelDep.F_Header ?? 0; //部门权限范围:9全部,1区域,2项目,3期
  5126. // }
  5127. // if (ua.F_RoleId != 17)
  5128. // {
  5129. // if (depType == 2)
  5130. // {
  5131. // if (depRegion == 1)
  5132. // {
  5133. // // 查看该区域工单
  5134. // //sql += $" and IsUserSend = (SELECT TOP 1 F_ParentId FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = {userRegionId}) ";
  5135. // sql += $" and IsUserSend = {userRegionId} ";
  5136. // }
  5137. // else if (depRegion == 2)
  5138. // {
  5139. // // 查看该项目工单
  5140. // sql += $" and IsAdminSend = {userRegionId} ";
  5141. // }
  5142. // }
  5143. // else if (depType == 3)
  5144. // {
  5145. // if (depRegion == 1)
  5146. // {
  5147. // // 查看该区域工单
  5148. // //sql += $" and IsUserSend = (SELECT TOP 1 F_ParentId FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = {userRegionId}) ";
  5149. // sql += $" and IsUserSend = {userRegionId} ";
  5150. // }
  5151. // }
  5152. // else if (depType == 4)
  5153. // {
  5154. // if (depRegion == 2)
  5155. // {
  5156. // // 查看该项目工单
  5157. // sql += $" and IsAdminSend = {userRegionId} ";
  5158. // }
  5159. // else if (depRegion == 9)
  5160. // {
  5161. // // 查看该部门工单(包括一级,二级)
  5162. // string deptCodeNew = String.Empty;
  5163. // int deptCodeIndex = 0; //变量声明
  5164. // string deptCodeN = deptCode.TrimEnd('|'); //去掉最后一个|
  5165. // deptCodeIndex = deptCodeN.LastIndexOf("|"); //获得|的索引
  5166. // deptCodeNew = deptCodeN.Substring(0, deptCodeIndex + 1); //获得目标字符串(//去掉最后一个|后面的字符串)
  5167. // //============== 部门权限条件 - 部门 ================
  5168. // string arrUser = " select F_UserCode from T_Sys_UserAccount where F_DeptCode LIKE '" + deptCodeNew + "%' ";
  5169. // sql += $" and WorkOrderID in (SELECT DISTINCT WorkOrderID FROM dbo.T_Wo_WorkOrderItem WHERE ToUser IN ({arrUser})) ";
  5170. // }
  5171. // }
  5172. // }
  5173. // string uwhere = " ";
  5174. // switch (strltype)
  5175. // {
  5176. // case "0"://待指派的
  5177. // //sql += " and State ='0' and CreateUser= '" + ua.F_UserCode + "' ";
  5178. // if (ua.F_RoleId != 17 && depType != 1 && depType != 3)
  5179. // {
  5180. // uwhere += " and CreateUser='" + ua.F_UserCode + "' ";
  5181. // }
  5182. // sql += " and State ='0' " + uwhere;
  5183. // break;
  5184. // case "1"://待接单的
  5185. // sql += " and State ='1' and WorkOrderID in ( '" + wo.GetDJDWorkOrderID(ua.F_UserCode) + "') ";
  5186. // break;
  5187. // case "2"://待完成的
  5188. // sql += " and State ='1' and WorkOrderID in ( '" + wo.GetDWCWorkOrderID(ua.F_UserCode) + "') ";
  5189. // break;
  5190. // case "3"://已完成的
  5191. // sql += " and State ='2' and LastDealUser = '" + ua.F_UserCode + "' ";
  5192. // break;
  5193. // case "4"://我参与的
  5194. // sql += " and (CreateUser= '" + ua.F_UserCode + "' or WorkOrderID in ( '" + wo.GetCYWorkOrderID(ua.F_UserCode) + "')) ";
  5195. // break;
  5196. // case "5"://超期工单 - 设置两个月的处理时效,两个月内未解决的工单都直接汇总到这里
  5197. // sql += $" and DATEADD(DAY,{days},CreateTime) < GETDATE() AND State < 2 ";
  5198. // break;
  5199. // }
  5200. // }
  5201. // else if (modelCustomer != null)
  5202. // {
  5203. // #region 根据openid获取所有工单号
  5204. // //var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  5205. // //if (wxuser != null)
  5206. // //{
  5207. // // sql += " and id in (select distinct F_WorkOrderID from T_WO_UserWorkOrder where F_UserId='" + wxuser.F_Id + "') ";
  5208. // //}
  5209. // #endregion
  5210. // // ============== 项目权限 - 项目 ============== 不通过项目查询,因为客户可能有多个项目的房产
  5211. // // ============== 电话,区域,项目,楼号,房间号权限条件 - 电话 ================
  5212. // //通过相关电话,区域,项目,楼号,房间号(CustomerTel,IsUserSend,IsAdminSend,IsTimeOut,Address)查询该用户查看的工单
  5213. // //mobile = modelCustomer.F_LegalTel;
  5214. // customerid = modelCustomer.F_CustomerId;
  5215. // //int CustomerClassID = modelCustomer.F_CustomerClassID ?? 0;
  5216. // ////F_Layer区域id F_CategoryId所购项目id F_CustomerType楼号 F_BusinessLicenseID房间号
  5217. // //areaid = modelCustomer.F_Layer ?? 0;
  5218. // //proid = modelCustomer.F_CategoryId ?? 0;
  5219. // //buildingid = modelCustomer.F_CustomerType ?? 0;
  5220. // //roomno = modelCustomer.F_BusinessLicenseID;
  5221. // ////查询业主和相关的亲属租户名下工单
  5222. // //sql += $" and CustomerTel IN (SELECT DISTINCT F_Mobile FROM dbo.T_Cus_CustomerBase WHERE F_CustomerClassID = {customerid} OR F_CustomerId = {customerid}) ";
  5223. // //if (CustomerClassID == 0)
  5224. // //{
  5225. // // //业主查看房屋所有工单
  5226. // // sql += $" and CustomerID IN (SELECT DISTINCT F_CustomerId FROM dbo.T_Cus_CustomerBase WHERE F_CustomerClassID = {customerid} OR F_CustomerId = {customerid}) ";
  5227. // //}
  5228. // //else
  5229. // //{
  5230. // // //租户只可查看自己工单
  5231. // // sql += $" and CustomerID = {customerid} ";
  5232. // //}
  5233. // ////查询相关房间号下工单
  5234. // //if (areaid > 0 && proid > 0 && buildingid > 0 && !string.IsNullOrEmpty(roomno))
  5235. // //{
  5236. // // sql += $" and F_Layer = {areaid} and F_CategoryId = {proid} and F_CustomerType = {buildingid} and F_BusinessLicenseID = '{roomno}' ";
  5237. // //}
  5238. // }
  5239. // else
  5240. // {
  5241. // sql = "";
  5242. // }
  5243. // #endregion
  5244. // if (!string.IsNullOrEmpty(sql))
  5245. // {
  5246. // sql += " and IsDel=0 ";
  5247. // //客户姓名,电话,房间号,工单号,接待描述
  5248. // if (!string.IsNullOrEmpty(keyword))
  5249. // {
  5250. // sql += " and (CustomerTel like '%" + keyword + "%' or Customer like '%" + keyword + "%' or Address like '%" + keyword + "%' or WorkOrderID like '%" + keyword + "%' or Detail like '%" + keyword + "%' ) ";
  5251. // }
  5252. // if (isaudit >= 0)
  5253. // {
  5254. // sql += " and IsAudit = " + isaudit + " "; // ANd Type = (SELECT F_DictionaryValueId FROM dbo.T_Sys_DictionaryValue (NOLOCK) WHERE F_DictionaryFlag = 'GDLY' AND F_Name = '微信')
  5255. // }
  5256. // if (states >= 0)
  5257. // sql += " and State = " + states + " ";
  5258. // if (strtype > 0)
  5259. // {
  5260. // sql += " and Type = " + strtype + " ";
  5261. // }
  5262. // if (strtypeclass > 0)
  5263. // {
  5264. // sql += " and TypeClass = " + strtypeclass + " ";
  5265. // }
  5266. // if (lddep.Trim() != "" && lddep != "undefined")
  5267. // {
  5268. // sql += " and Address = '" + lddep.Trim() + "' ";
  5269. // }
  5270. // if (fkdep.Trim() != "" && fkdep != "undefined")
  5271. // {
  5272. // sql += " and Source = '" + fkdep.Trim() + "' ";
  5273. // }
  5274. // if (strstarttime.Trim() != "" && strstarttime != "undefined")
  5275. // {
  5276. // sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
  5277. // }
  5278. // if (strendtime.Trim() != "" && strendtime != "undefined")
  5279. // {
  5280. // sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0 ";
  5281. // }
  5282. // #endregion
  5283. // if (strpageindex.Trim() != "")
  5284. // {
  5285. // pageindex = Convert.ToInt32(strpageindex);
  5286. // }
  5287. // if (strpagesize.Trim() != "")
  5288. // {
  5289. // pagesize = Convert.ToInt32(strpagesize);
  5290. // }
  5291. // string cols = "*,dbo.GetDictionaryName(Source) as GDLYName,dbo.GetDictionaryName(Type) as GDLXName,dbo.GetDictionaryName(TypeClass) as TypeClassName,dbo.GetUserName(CreateUser) as CreateUserNameRel,dbo.GetUserName(LastDealUser) as LastDealUserNameRel,dbo.GetUserName(AuditUser) as AuditUserNameRel,dbo.GetDeptName(ResponDept) as ResponDeptName";
  5292. // dt = BLL.PagerBLL.GetListPager(
  5293. // "T_Wo_WorkOrder (NOLOCK)",
  5294. // "WorkOrderID",
  5295. // cols,
  5296. // sql,
  5297. // "ORDER BY CreateTime DESC",
  5298. // pagesize,
  5299. // pageindex,
  5300. // true,
  5301. // out recordCount);
  5302. // }
  5303. // var obj = new
  5304. // {
  5305. // state = "success",
  5306. // message = "成功",
  5307. // rows = dt,
  5308. // total = recordCount
  5309. // };
  5310. // return Content(obj.ToJson());
  5311. //}
  5312. ///// <summary>
  5313. ///// 获取可催办工单列表
  5314. ///// </summary>
  5315. ///// <returns></returns>
  5316. //[WechatActionFilter]
  5317. //public ActionResult GetNotDoneWorkList()
  5318. //{
  5319. // workorder.WorkOrderController wo = new workorder.WorkOrderController();
  5320. // DataTable dt = new DataTable();
  5321. // int recordCount = 0;
  5322. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  5323. // //客户姓名,电话,房间号,工单号
  5324. // string keyword = HttpUtility.UrlDecode(RequestString.GetQueryString("keyword"));
  5325. // //工单状态
  5326. // string strltype = HttpUtility.UrlDecode(RequestString.GetQueryString("ltype"));
  5327. // //工单状态
  5328. // int states = RequestString.GetInt("states", -1);
  5329. // //工单来源
  5330. // int strtype = RequestString.GetInt("type", 0);
  5331. // //工单类型
  5332. // int strtypeclass = RequestString.GetInt("typeclass", 0);
  5333. // //工单起止时间
  5334. // string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  5335. // string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  5336. // //区域id
  5337. // int areaid = RequestString.GetInt("areaid", 0);
  5338. // //项目id
  5339. // int regionid = RequestString.GetInt("regionid", 0);
  5340. // //期id
  5341. // int buldingid = RequestString.GetInt("buldingid", 0);
  5342. // string uid = HttpUtility.UrlDecode(RequestString.GetQueryString("userid") == "" ? "0" : HttpUtility.UrlDecode(RequestString.GetQueryString("userid")));
  5343. // string strpageindex = RequestString.GetQueryString("page");
  5344. // int pageindex = 1;
  5345. // string strpagesize = RequestString.GetQueryString("pagesize");
  5346. // int pagesize = 10;
  5347. // string sql = " and isdel=0 and State != 2 ";
  5348. // //获取坐席表信息
  5349. // var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  5350. // //获取客户档案(业主)表信息
  5351. // var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  5352. // if (ua != null)
  5353. // {
  5354. // #region 权限限制
  5355. // int deptid = ua.F_DeptId; //部门id
  5356. // string deptCode = ua.F_DeptCode; //部门code
  5357. // int userRegionId = ua.RegionId; //项目id
  5358. // //部门信息
  5359. // var modelDep = new BLL.T_Sys_Department().GetModel(deptid);
  5360. // int depType = 0, depRegion = 0;
  5361. // if (modelDep != null)
  5362. // {
  5363. // depType = modelDep.F_Type ?? 0; //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  5364. // depRegion = modelDep.F_Header ?? 0; //部门权限范围:9全部,1区域,2项目,3期
  5365. // }
  5366. // if (ua.F_RoleId != 17)
  5367. // {
  5368. // if (depType == 2)
  5369. // {
  5370. // if (depRegion == 1)
  5371. // {
  5372. // // 查看该区域工单
  5373. // //sql += $" and IsUserSend = (SELECT TOP 1 F_ParentId FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = {userRegionId}) ";
  5374. // sql += $" and IsUserSend = {userRegionId} ";
  5375. // }
  5376. // else if (depRegion == 2)
  5377. // {
  5378. // // 查看该项目工单
  5379. // sql += $" and IsAdminSend = {userRegionId} ";
  5380. // }
  5381. // }
  5382. // else if (depType == 3)
  5383. // {
  5384. // if (depRegion == 1)
  5385. // {
  5386. // // 查看该区域工单
  5387. // //sql += $" and IsUserSend = (SELECT TOP 1 F_ParentId FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = {userRegionId}) ";
  5388. // sql += $" and IsUserSend = {userRegionId} ";
  5389. // }
  5390. // }
  5391. // else if (depType == 4)
  5392. // {
  5393. // if (depRegion == 2)
  5394. // {
  5395. // // 查看该项目工单
  5396. // sql += $" and IsAdminSend = {userRegionId} ";
  5397. // }
  5398. // else if (depRegion == 9)
  5399. // {
  5400. // // 查看该部门工单(包括一级,二级)
  5401. // string deptCodeNew = String.Empty;
  5402. // int deptCodeIndex = 0; //变量声明
  5403. // string deptCodeN = deptCode.TrimEnd('|'); //去掉最后一个|
  5404. // deptCodeIndex = deptCodeN.LastIndexOf("|"); //获得|的索引
  5405. // deptCodeNew = deptCodeN.Substring(0, deptCodeIndex + 1); //获得目标字符串(//去掉最后一个|后面的字符串)
  5406. // //============== 部门权限条件 - 部门 ================
  5407. // string arrUser = " select F_UserCode from T_Sys_UserAccount where F_DeptCode LIKE '" + deptCodeNew + "%' ";
  5408. // sql += $" and WorkOrderID in (SELECT DISTINCT WorkOrderID FROM dbo.T_Wo_WorkOrderItem WHERE ToUser IN ({arrUser})) ";
  5409. // }
  5410. // }
  5411. // }
  5412. // #endregion
  5413. // //客户姓名,电话,房间号,工单号
  5414. // if (!string.IsNullOrEmpty(keyword))
  5415. // {
  5416. // sql += " and (CustomerTel like '%" + keyword + "%' or Customer like '%" + keyword + "%' or Address like '%" + keyword + "%' or WorkOrderID like '%" + keyword + "%' ) ";
  5417. // }
  5418. // if (states >= 0)
  5419. // sql += " and State = " + states + " ";
  5420. // if (areaid > 0)
  5421. // sql += " and IsUserSend = " + areaid + " ";
  5422. // if (regionid > 0)
  5423. // sql += " and IsAdminSend = " + regionid + " ";
  5424. // if (buldingid > 0)
  5425. // sql += " and IsTimeOut = " + buldingid + " ";
  5426. // //坐席工号
  5427. // if (uid.Trim() != "" && uid != "0")
  5428. // {
  5429. // sql += " and CreateUser = '" + uid + "' ";
  5430. // }
  5431. // if (strtype > 0)
  5432. // {
  5433. // sql += " and Type = " + strtype + " ";
  5434. // }
  5435. // if (strtypeclass > 0)
  5436. // {
  5437. // sql += " and TypeClass = " + strtype + " ";
  5438. // }
  5439. // if (strstarttime.Trim() != "" && strstarttime != "undefined")
  5440. // {
  5441. // sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
  5442. // }
  5443. // if (strendtime.Trim() != "" && strendtime != "undefined")
  5444. // {
  5445. // sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0 ";
  5446. // }
  5447. // if (strpageindex.Trim() != "")
  5448. // {
  5449. // pageindex = Convert.ToInt32(strpageindex);
  5450. // }
  5451. // if (strpagesize.Trim() != "")
  5452. // {
  5453. // pagesize = Convert.ToInt32(strpagesize);
  5454. // }
  5455. // dt = BLL.PagerBLL.GetListPager(
  5456. // "T_Wo_WorkOrder",
  5457. // "T_Wo_WorkOrder.ID",
  5458. // "*,(SELECT F_RegionName FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = dbo.T_Wo_WorkOrder.IsUserSend) AS areaname,(SELECT F_RegionName FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = dbo.T_Wo_WorkOrder.IsAdminSend) AS proname,(SELECT F_RegionName FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = dbo.T_Wo_WorkOrder.IsTimeOut) AS buildingname,dbo.GetDictionaryName(Type) as GDLYName,dbo.GetDictionaryName(Ownerrelationsid) as OwnerrelationsName,dbo.GetDictionaryName(TypeClass) as TypeClassName,dbo.GetUserName(CreateUser) as CreateUserNameRel,dbo.GetUserName(LastDealUser) as LastDealUserNameRel,dbo.GetUserName(AuditUser) as AuditUserNameRel,(SELECT TOP 1 F_DeptName FROM dbo.T_Sys_Department WHERE F_DeptId = Source) AS complaintTypeName",
  5459. // sql,
  5460. // "ORDER BY T_Wo_WorkOrder.ID desc",
  5461. // pagesize,
  5462. // pageindex,
  5463. // true,
  5464. // out recordCount);
  5465. // dt.Columns.Add("CBCount", typeof(int));
  5466. // foreach (DataRow dr in dt.Rows)
  5467. // {
  5468. // var list = new BLL.T_Wo_WorkOrderItem().GetList(" WorkOrderID='" + dr["WorkOrderID"].ToString() + "' and IsDel=0 and Type=2 and ','+ToUser+',' like ',%" + ua.F_UserCode + "%,' ").Tables[0];
  5469. // dr["CBCount"] = list.Rows.Count;
  5470. // }
  5471. // }
  5472. // var obj = new
  5473. // {
  5474. // state = "success",
  5475. // message = "成功",
  5476. // rows = dt,
  5477. // total = recordCount
  5478. // };
  5479. // return Content(obj.ToJson());
  5480. //}
  5481. ///// <summary>
  5482. ///// 新增工单
  5483. ///// </summary>
  5484. ///// <returns></returns>
  5485. //[WechatActionFilter]
  5486. //public ActionResult AddWorkOrder()
  5487. //{
  5488. // DataTable dt = new DataTable();
  5489. // //工单来源
  5490. // int gdly = RequestString.GetFormInt("gdly", 0);
  5491. // //工单类型
  5492. // int gdlx = RequestString.GetFormInt("gdlx", 0);
  5493. // //客户id
  5494. // int customerid = RequestString.GetFormInt("customerid", 0);
  5495. // //客户姓名
  5496. // string callCustomer = RequestString.GetFormString("callCustomer");
  5497. // //联系电话
  5498. // string tel = RequestString.GetFormString("tel");
  5499. // //处理部门
  5500. // string fkdep = RequestString.GetFormString("fkdep");
  5501. // //客服类类型
  5502. // string kfdepid = RequestString.GetFormString("kfdepid");
  5503. // //受理人 - 审核人工号
  5504. // string auditusercode = RequestString.GetFormString("auditusercode");
  5505. // //工单状态
  5506. // int gdzt = RequestString.GetFormInt("gdzt", 0);
  5507. // //接待描述 - 反馈内容
  5508. // string fkcont = RequestString.GetFormString("fkcont");
  5509. // string callid = HttpUtility.UrlDecode(RequestString.GetFormString("callid"));
  5510. // string files = RequestString.GetFormString("files");
  5511. // //咨询类工单指派部门
  5512. // int clbm = RequestString.GetFormInt("clbm", 0);
  5513. // //备注
  5514. // string note = RequestString.GetFormString("note");
  5515. // #region 添加验证判断
  5516. // if (string.IsNullOrEmpty(callCustomer))
  5517. // return Error("姓名不能为空!");
  5518. // if (string.IsNullOrEmpty(tel))
  5519. // return Error("电话不能为空!");
  5520. // #endregion
  5521. // string workOrder = DateTime.Now.ToString("yyyyMMddHHmmssfff"); //工单编号
  5522. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  5523. // var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  5524. // var model = userAccountBLL.GetModelByOpenid(stropenid);
  5525. // var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault(); //customerBaseBLL.GetModelByOpenid(stropenid);
  5526. // string usercode = "";
  5527. // if (model != null)
  5528. // {
  5529. // usercode = model.F_UserCode;
  5530. // }
  5531. // else if (modelCustomer != null)
  5532. // {
  5533. // usercode = modelCustomer.F_CustomerCode;
  5534. // customerid = modelCustomer.F_CustomerId;
  5535. // }
  5536. // workorder.WorkOrderController wo = new workorder.WorkOrderController();
  5537. // string workorderid = wo.AddWXWorkOrder(workOrder, gdly, gdlx, customerid, callCustomer, tel, fkdep, kfdepid, auditusercode, fkcont, files, gdzt, note, usercode,-1);
  5538. // if (string.IsNullOrEmpty(workorderid))
  5539. // {
  5540. // return Error("新增失败");
  5541. // }
  5542. // else
  5543. // {
  5544. // #region 咨询类工单指派至部门
  5545. // //工单类型(107咨询,108投诉)
  5546. // if (gdlx == 107)
  5547. // {
  5548. // //需要审核后,再处理
  5549. // //bool b = wo.DealWXWorkOrder(workOrder, 0, 0, clbm, 0, "", fkcont, stropenid);
  5550. // }
  5551. // #endregion
  5552. // //暂时排除客户档案用户(F_UserId无法区分是住户添加 还是管理员添加) - 后期完善
  5553. // if (wxuser != null)
  5554. // {
  5555. // Model.T_WO_UserWorkOrder tbu = new Model.T_WO_UserWorkOrder();
  5556. // tbu.F_UserId = wxuser.F_Id;
  5557. // tbu.F_WorkOrderId = workorderid;
  5558. // new BLL.T_WO_UserWorkOrder().Add(tbu);
  5559. // }
  5560. // return Success("新增成功", workorderid);
  5561. // }
  5562. //}
  5563. ///// <summary>
  5564. ///// 修改工单
  5565. ///// </summary>
  5566. ///// <returns></returns>
  5567. //[WechatActionFilter]
  5568. //public ActionResult UpdateWorkOrder()
  5569. //{
  5570. // DataTable dt = new DataTable();
  5571. // //工单id
  5572. // string workorderid = RequestString.GetFormString("orderid");
  5573. // //工单来源
  5574. // int gdly = RequestString.GetFormInt("gdly", 0);
  5575. // //工单类型
  5576. // int gdlx = RequestString.GetFormInt("gdlx", 0);
  5577. // //客户id
  5578. // int customerid = RequestString.GetFormInt("customerid", 0);
  5579. // //客户姓名
  5580. // string callCustomer = RequestString.GetFormString("callCustomer");
  5581. // //联系电话
  5582. // string tel = RequestString.GetFormString("tel");
  5583. // //处理部门
  5584. // string fkdep = RequestString.GetFormString("fkdep");
  5585. // //客服类类型
  5586. // string kfdepid = RequestString.GetFormString("kfdepid");
  5587. // //受理人 - 审核人工号
  5588. // string auditusercode = RequestString.GetFormString("auditusercode");
  5589. // //接待描述 - 反馈内容
  5590. // string fkcont = RequestString.GetFormString("fkcont");
  5591. // string files = RequestString.GetFormString("files");
  5592. // //备注
  5593. // string note = RequestString.GetFormString("note");
  5594. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  5595. // //var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  5596. // if (!string.IsNullOrEmpty(stropenid))
  5597. // {
  5598. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  5599. // if (ua != null)
  5600. // {
  5601. // WorkOrderController wo = new WorkOrderController();
  5602. // if (!string.IsNullOrEmpty(workorderid))
  5603. // {
  5604. // var models = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + workorderid + "'");
  5605. // if (models.Count > 0)
  5606. // {
  5607. // var model = models.FirstOrDefault();
  5608. // string detail = model.Detail;
  5609. // model.Type = gdly; //工单来源
  5610. // model.TypeClass = gdlx; //投诉类型 -工单类型
  5611. // model.Customer = callCustomer; //客户姓名
  5612. // model.CustomerTel = tel; //联系电话
  5613. // //model.CustomerID = customerid; //用户档案Id
  5614. // model.Source = fkdep; //处理部门 反馈单位
  5615. // model.CreateUserID = kfdepid; //客服类类型
  5616. // model.AuditUser = auditusercode; //受理人 - 审核人工号
  5617. // //model.CreateUser = ua.F_UserCode; //接待人(工号)
  5618. // //model.State = 0; //工单状态
  5619. // //反馈内容
  5620. // var detailutf8 = System.Web.HttpUtility.UrlDecode(fkcont, System.Text.Encoding.UTF8);
  5621. // model.Detail = detailutf8;
  5622. // if (new BLL.T_Wo_WorkOrder().Update(model))
  5623. // {
  5624. // //添加工单修改操作日志
  5625. // wo.WriteWorkOrderLog(workorderid, detail, detailutf8, ua.F_UserCode, 0, "", 1, "修改工单(微信端)");
  5626. // return Success("修改成功!");
  5627. // }
  5628. // }
  5629. // }
  5630. // }
  5631. // }
  5632. // return Error("修改失败!");
  5633. //}
  5634. ///// <summary>
  5635. ///// 处理工单
  5636. ///// </summary>
  5637. ///// <returns></returns>
  5638. //[WechatActionFilter]
  5639. //public ActionResult DealWorkOrder()
  5640. //{
  5641. // DataTable dt = new DataTable();
  5642. // string orderid = RequestString.GetFormString("orderid");
  5643. // int isend = RequestString.GetInt("isend", 0); //0转派
  5644. // int ltype = RequestString.GetInt("ltype", 0); //处理方式 1结束 0转派
  5645. // int clbm = RequestString.GetInt("clbm", 0); //部门id
  5646. // int clid = RequestString.GetInt("clid", 0); //用户接收人id
  5647. // string cont = RequestString.GetFormString("cont"); //处理内容
  5648. // string detail = RequestString.GetFormString("detail");
  5649. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  5650. // workorder.WorkOrderController wo = new workorder.WorkOrderController();
  5651. // bool res = wo.DealWXWorkOrder(orderid, isend, ltype, clbm, clid, cont, detail, stropenid);
  5652. // if (res)
  5653. // {
  5654. // return Success("操作成功");
  5655. // }
  5656. // else
  5657. // {
  5658. // return Error("操作失败");
  5659. // }
  5660. //}
  5661. ///// <summary>
  5662. ///// 接单 - 确认工单
  5663. ///// </summary>
  5664. ///// <returns></returns>
  5665. //[WechatActionFilter]
  5666. //public ActionResult SureWorkOrder()
  5667. //{
  5668. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  5669. // string orderid = RequestString.GetFormString("orderid");
  5670. // if (!string.IsNullOrEmpty(stropenid))
  5671. // {
  5672. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  5673. // if (ua != null)
  5674. // {
  5675. // Model.T_Wo_WorkOrder model = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + orderid + "'").FirstOrDefault();
  5676. // if (model != null)
  5677. // {
  5678. // Model.T_Wo_WorkOrderItem item = new BLL.T_Wo_WorkOrderItem().GetModelList(" WorkOrderID='" + orderid + "' and isdel=0 and Type=1 ").OrderByDescending(p => p.CreateTime).FirstOrDefault();
  5679. // if (item != null && item.State == 0 && ("," + item.ToUser + ",").Contains("," + ua.F_UserCode + ","))
  5680. // {
  5681. // item.SureUser = ua.F_UserCode;
  5682. // item.State = 1;
  5683. // item.SureTime = DateTime.Now;
  5684. // if (new BLL.T_Wo_WorkOrderItem().Update(item))
  5685. // {
  5686. // return Success("接单成功!");
  5687. // }
  5688. // }
  5689. // return Error("操作失败,工单还没有派单!");
  5690. // }
  5691. // }
  5692. // return Error("操作失败");
  5693. // }
  5694. // return Error("参数错误");
  5695. //}
  5696. ///// <summary>
  5697. ///// 催办工单(管理员,业主)
  5698. ///// </summary>
  5699. ///// <returns></returns>
  5700. //[WechatActionFilter]
  5701. //public ActionResult RemindWorkOrder()
  5702. //{
  5703. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  5704. // if (!string.IsNullOrEmpty(stropenid))
  5705. // {
  5706. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  5707. // string usercode = string.Empty;
  5708. // string username = string.Empty;
  5709. // if (ua != null)
  5710. // {
  5711. // usercode = ua.F_UserCode;
  5712. // username = ua.F_UserName;
  5713. // }
  5714. // else
  5715. // {
  5716. // //获取客户档案(业主)表信息
  5717. // var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  5718. // if (modelCustomer != null)
  5719. // {
  5720. // usercode = modelCustomer.F_CustomerCode;
  5721. // username = modelCustomer.F_CompanyName;
  5722. // }
  5723. // }
  5724. // if (string.IsNullOrEmpty(usercode))
  5725. // return Error("参数错误!");
  5726. // string orderid = RequestString.GetFormString("orderid");
  5727. // string cont = RequestString.GetFormString("cont");
  5728. // string callid = RequestString.GetFormString("callid");
  5729. // Model.T_Wo_WorkOrder model = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + orderid + "'").FirstOrDefault();
  5730. // if (model != null)
  5731. // {
  5732. // Model.T_Wo_WorkOrderItem itemlast = new BLL.T_Wo_WorkOrderItem().GetModelList(" WorkOrderID='" + orderid + "' and IsDel=0 and Type=1 and (State=0 or State=1) ").FirstOrDefault();
  5733. // Model.T_Wo_WorkOrderItem item = new Model.T_Wo_WorkOrderItem();
  5734. // if (itemlast != null)
  5735. // {
  5736. // item.ToDept = itemlast.ToDept;
  5737. // item.ToUser = itemlast.ToUser;
  5738. // }
  5739. // else
  5740. // {
  5741. // var cu = new BLL.T_Sys_UserAccount().GetModel(model.CreateUser);
  5742. // if (cu != null)
  5743. // {
  5744. // item.ToDept = cu.F_DeptId;
  5745. // item.ToUser = cu.F_UserCode;
  5746. // }
  5747. // else {
  5748. // var modelCus = customerBaseBLL.GetModelList(" F_CustomerCode='" + model.CreateUser + "'").FirstOrDefault(); //customerBaseBLL.GetModel(model.CreateUser);
  5749. // if (modelCus != null)
  5750. // {
  5751. // item.ToDept = 0;
  5752. // item.ToUser = modelCus.F_LegalTel;
  5753. // }
  5754. // }
  5755. // }
  5756. // item.WorkOrderID = orderid;
  5757. // item.Type = 2;
  5758. // item.Detail = cont;
  5759. // item.CallID = callid;
  5760. // item.State = 0;
  5761. // item.IsDel = 0;
  5762. // item.IsLast = 0;
  5763. // item.IsStart = 0;
  5764. // item.IsTimeOut = 0;
  5765. // item.CreateUser = usercode; // ua.F_UserCode;
  5766. // item.CreateTime = DateTime.Now;
  5767. // long itemid = new BLL.T_Wo_WorkOrderItem().Add(item);
  5768. // if (itemid > 0 && !string.IsNullOrEmpty(item.ToUser))
  5769. // {
  5770. // foreach (string ur in item.ToUser.Split(','))
  5771. // {
  5772. // Model.T_Msg_List msg = new Model.T_Msg_List();
  5773. // msg.Type = 1;
  5774. // msg.ToUser = ur;
  5775. // msg.ToID = Int32.Parse(itemid.ToString());
  5776. // msg.Detail = username + "向你催办了工单,单号:" + model.WorkOrderID;
  5777. // msg.State = 0;
  5778. // msg.IsDel = 0;
  5779. // msg.CreateUser = usercode;
  5780. // msg.CreateDate = DateTime.Now;
  5781. // new BLL.T_Msg_List().Add(msg);
  5782. // }
  5783. // return Success("催办成功!");
  5784. // }
  5785. // }
  5786. // }
  5787. // return Error("参数错误");
  5788. //}
  5789. ///// <summary>
  5790. ///// 退回工单
  5791. ///// </summary>
  5792. ///// <param name="input"></param>
  5793. ///// <returns></returns>
  5794. //[WechatActionFilter]
  5795. //public ActionResult BackWorkOrder()
  5796. //{
  5797. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  5798. // if (!string.IsNullOrEmpty(stropenid))
  5799. // {
  5800. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  5801. // if (ua != null)
  5802. // {
  5803. // string orderid = RequestString.GetFormString("orderid");
  5804. // var model = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + orderid + "'").FirstOrDefault();
  5805. // //验证信息
  5806. // if (model == null)
  5807. // {
  5808. // return Error("工单不存在");
  5809. // }
  5810. // model.State = 0;
  5811. // if (new BLL.T_Wo_WorkOrder().Update(model))
  5812. // {
  5813. // var modelItem = new BLL.T_Wo_WorkOrderItem().GetModelList(" IsDel=0 and Type=1 and (state='0' and ','+ToUser+',' like '%," + ua.F_UserCode + ",%') and WorkOrderID = '" + orderid + "' ").FirstOrDefault();
  5814. // if (modelItem != null)
  5815. // {
  5816. // modelItem.State = 6;
  5817. // new BLL.T_Wo_WorkOrderItem().Update(modelItem);
  5818. // }
  5819. // return Success("操作成功");
  5820. // }
  5821. // return Error("操作失败");
  5822. // }
  5823. // }
  5824. // return Error("操作失败");
  5825. //}
  5826. ///// <summary>
  5827. ///// 评论工单(管理人员,业主)
  5828. ///// </summary>
  5829. ///// <returns></returns>
  5830. //[WechatActionFilter]
  5831. //public ActionResult CommentWorkOrder()
  5832. //{
  5833. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  5834. // if (!string.IsNullOrEmpty(stropenid))
  5835. // {
  5836. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  5837. // string usercode = string.Empty;
  5838. // string username = string.Empty;
  5839. // if (ua != null)
  5840. // {
  5841. // usercode = ua.F_UserCode;
  5842. // username = ua.F_UserName;
  5843. // }
  5844. // else
  5845. // {
  5846. // //获取客户档案(业主)表信息
  5847. // var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  5848. // if (modelCustomer != null)
  5849. // {
  5850. // usercode = modelCustomer.F_CustomerCode;
  5851. // username = modelCustomer.F_CompanyName;
  5852. // }
  5853. // }
  5854. // if (string.IsNullOrEmpty(usercode))
  5855. // return Error("参数错误!");
  5856. // string orderid = RequestString.GetFormString("orderid");
  5857. // string cont = RequestString.GetFormString("cont");
  5858. // string file = RequestString.GetFormString("file");
  5859. // Model.T_Wo_WorkOrder model = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + orderid + "'").FirstOrDefault();
  5860. // if (model != null)
  5861. // {
  5862. // Model.T_Wo_WorkOrderItem item = new Model.T_Wo_WorkOrderItem();
  5863. // item.WorkOrderID = orderid;
  5864. // item.Type = 3; //评论
  5865. // item.Detail = cont;
  5866. // item.Files = file;
  5867. // item.State = 0;
  5868. // item.IsDel = 0;
  5869. // item.IsStart = 0;
  5870. // item.IsTimeOut = 0;
  5871. // item.IsLast = 0;
  5872. // item.CreateUser = usercode;
  5873. // item.CreateTime = DateTime.Now;
  5874. // if (new BLL.T_Wo_WorkOrderItem().Add(item) > 0)
  5875. // {
  5876. // return Success("评论成功!");
  5877. // }
  5878. // }
  5879. // }
  5880. // return Error("操作失败");
  5881. //}
  5882. ///// <summary>
  5883. ///// 刪除工单
  5884. ///// </summary>
  5885. ///// <returns></returns>
  5886. //[WechatActionFilter]
  5887. //public ActionResult DelWorkOrder(string[] ids)
  5888. //{
  5889. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  5890. // if (!string.IsNullOrEmpty(stropenid))
  5891. // {
  5892. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  5893. // if (ua != null)
  5894. // {
  5895. // if (ids != null && ids.Length > 0)
  5896. // {
  5897. // string idd = " ";
  5898. // foreach (string str in ids)
  5899. // {
  5900. // idd += str + ",";
  5901. // }
  5902. // string sql = "update T_Wo_WorkOrder set IsDel=1,DelUser='" + ua.F_UserCode + "',DelTime=getdate() where ID in (" + idd.TrimEnd(',') + ")";
  5903. // if (!string.IsNullOrEmpty(idd.Trim()))
  5904. // {
  5905. // if (DbHelperSQL.ExecuteSql(sql) > 0)
  5906. // {
  5907. // return Success("删除成功");
  5908. // }
  5909. // }
  5910. // else
  5911. // {
  5912. // return Error("请选择记录");
  5913. // }
  5914. // }
  5915. // else
  5916. // {
  5917. // return Error("获取参数失败");
  5918. // }
  5919. // }
  5920. // }
  5921. // return Error("操作失败");
  5922. //}
  5923. ///// <summary>
  5924. ///// 获取工单详情
  5925. ///// </summary>
  5926. ///// <returns></returns>
  5927. //[WechatActionFilter]
  5928. //public ActionResult GetWorkOrder()
  5929. //{
  5930. // string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
  5931. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  5932. // if (string.IsNullOrEmpty(strworkorderid))
  5933. // return Error("参数错误");
  5934. // if (string.IsNullOrEmpty(stropenid))
  5935. // return Error("参数错误!");
  5936. // #region pc端工单也可以查看,所以注释(注释功能只能查看自己创建的工单)
  5937. // //var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  5938. // //if (wxuser != null)
  5939. // //{
  5940. // // var tbu = new BLL.T_WO_UserWorkOrder().GetList(" F_UserId='" + wxuser.F_Id + "' and F_WorkOrderId=" + strworkorderid + " ").Tables[0];
  5941. // // if (tbu.Rows.Count > 0)
  5942. // // {
  5943. // // }
  5944. // //}
  5945. // #endregion
  5946. // string sql = "select *,dbo.GetDictionaryName(Type) as GDLXName,dbo.GetDictionaryName(TypeClass) as YWLXName,dbo.GetDictionaryName(Source) as GDLYName,dbo.GetUserName(CreateUser) as CreateUserName,dbo.GetUserName(LastDealUser) as LastDealUserNameRel,dbo.GetUserName(AuditUser) as AuditUserNameRel,dbo.GetUserName(ResponUser) as ResponUserName,dbo.GetDeptName(ResponDept) AS ComplaintDepartment "
  5947. // + " from T_Wo_WorkOrder where WorkOrderID ='" + strworkorderid + "' ";
  5948. // var dt = DbHelperSQL.Query(sql).Tables[0];
  5949. // if (dt.Rows.Count > 0)
  5950. // {
  5951. // var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
  5952. // var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  5953. // if (configfj != null)
  5954. // {
  5955. // dt = BindFileData(dt, configfj.F_ParamValue);
  5956. // }
  5957. // string gcsql = "select *,dbo.GetUserName(CreateUser) as UserName "
  5958. // + "from T_Wo_WorkOrderItem where IsDel=0 and WorkOrderID ='" + dt.Rows[0]["WorkOrderId"] + "'";
  5959. // var gcdt = DbHelperSQL.Query(gcsql).Tables[0];
  5960. // dt.Columns.Add("FilePath", typeof(string));
  5961. // if (configfj != null || config != null)
  5962. // {
  5963. // foreach (DataRow bldr in dt.Rows)
  5964. // {
  5965. // if (bldr["CallID"] != null && config != null)
  5966. // {
  5967. // bldr["FilePath"] = GetCallPath(bldr["CallID"].ToString(), config.F_ParamValue);
  5968. // }
  5969. // }
  5970. // }
  5971. // var obj = new
  5972. // {
  5973. // data = dt,
  5974. // item = gcdt
  5975. // };
  5976. // return Success("查询成功", obj);
  5977. // }
  5978. // return Error("查询失败");
  5979. //}
  5980. ///// <summary>
  5981. ///// 获取工单明细列表
  5982. ///// </summary>
  5983. ///// <returns></returns>
  5984. //[WechatActionFilter]
  5985. //public ActionResult GetItemList()
  5986. //{
  5987. // string sql = " and IsDel=0 ";
  5988. // DataTable dt = new DataTable();
  5989. // string strid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
  5990. // string strtype = HttpUtility.UrlDecode(RequestString.GetQueryString("type"));
  5991. // string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  5992. // string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  5993. // string strpageindex = RequestString.GetQueryString("page");
  5994. // int pageindex = 1;
  5995. // string strpagesize = RequestString.GetQueryString("pagesize");
  5996. // int pagesize = 10;
  5997. // if (strid.Trim() != "" && strid != "undefined")
  5998. // {
  5999. // sql += " and WorkOrderID = '" + strid.Trim() + "' ";
  6000. // }
  6001. // if (strtype.Trim() != "" && strtype != "undefined")
  6002. // {
  6003. // sql += " and Type = '" + strtype.Trim() + "' ";
  6004. // }
  6005. // if (strstarttime.Trim() != "" && strstarttime != "undefined")
  6006. // {
  6007. // sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
  6008. // }
  6009. // if (strendtime.Trim() != "" && strendtime != "undefined")
  6010. // {
  6011. // sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0 ";
  6012. // }
  6013. // if (strpageindex.Trim() != "")
  6014. // {
  6015. // pageindex = Convert.ToInt32(strpageindex);
  6016. // }
  6017. // if (strpagesize.Trim() != "")
  6018. // {
  6019. // pagesize = Convert.ToInt32(strpagesize);
  6020. // }
  6021. // int recordCount = 0;
  6022. // dt = BLL.PagerBLL.GetListPager(
  6023. // "T_Wo_WorkOrderItem",
  6024. // "T_Wo_WorkOrderItem.ID",
  6025. // "*,dbo.GetUserName(ToUser) as ToUserName, dbo.GetDeptName(ToDept) as ToDeptName,dbo.GetUserName(SureUser) as SureUserName,dbo.GetUserName(DealUser) as DealUserName,dbo.GetUserName(CreateUser) as CreateUserName,case Type when 1 then convert(decimal(18,2),DATEDIFF(minute, CreateTime, ISNULL(DealTime, GETDATE()))/60.00) else 0 end as totalhour",
  6026. // sql,
  6027. // "ORDER BY T_Wo_WorkOrderItem.ID desc",
  6028. // pagesize,
  6029. // pageindex,
  6030. // true,
  6031. // out recordCount);
  6032. // var obj = new
  6033. // {
  6034. // state = "success",
  6035. // message = "成功",
  6036. // rows = dt,
  6037. // total = recordCount
  6038. // };
  6039. // return Content(obj.ToJson());
  6040. //}
  6041. ///// <summary>
  6042. ///// 获取工作动态列表 - 工单明细动态列表 - 管理员功能
  6043. ///// </summary>
  6044. ///// <returns></returns>
  6045. //[WechatActionFilter]
  6046. //public ActionResult GetWorkOrderItemList()
  6047. //{
  6048. // DataTable dt = new DataTable();
  6049. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  6050. // //string stropenid = "oXF5e1mWpX5DajW5_yjNLPKb8ThE";
  6051. // //获取客户档案(业主)表信息
  6052. // var model = userAccountBLL.GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  6053. // string sql = " and IsDel=0 ";
  6054. // string daytype = HttpUtility.UrlDecode(RequestString.GetQueryString("daytype"));
  6055. // string strpageindex = RequestString.GetQueryString("page");
  6056. // int pageindex = 1;
  6057. // string strpagesize = RequestString.GetQueryString("pagesize");
  6058. // int pagesize = 10;
  6059. // #region 权限限制
  6060. // //if (model != null) {
  6061. // // var sqlUser = "";
  6062. // // //部门信息
  6063. // // var modelDep = new BLL.T_Sys_Department().GetModel(model.F_DeptId);
  6064. // // int depType = 0, depRegion = 0;
  6065. // // if (modelDep != null)
  6066. // // {
  6067. // // depType = modelDep.F_Type ?? 0; //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  6068. // // depRegion = modelDep.F_Header ?? 0; //部门权限范围:9全部,1区域,2项目,3期
  6069. // // }
  6070. // // //根据部门查询工单(可查看当前部门工单)
  6071. // // string deptCode = model.F_DeptCode; //部门code
  6072. // // int userRegionId = model.RegionId; //项目id
  6073. // // ////接待部(坐席)可以看到所有的工单
  6074. // // //if (model.F_RoleId != 17 && depType != 1)
  6075. // // //{
  6076. // // // //if (depType == 2 || depType == 3)
  6077. // // // //{
  6078. // // // // // ============== 项目权限 - 项目 ==============
  6079. // // // // sqlUser += $" and IsAdminSend = {userRegionId} ";
  6080. // // // //}
  6081. // // // //else if (depType == 4)
  6082. // // // //{
  6083. // // // // // 查看该部门工单(包括一级,二级)
  6084. // // // // string deptCodeNew = String.Empty;
  6085. // // // // int deptCodeIndex = 0; //变量声明
  6086. // // // // string deptCodeN = deptCode.TrimEnd('|'); //去掉最后一个|
  6087. // // // // deptCodeIndex = deptCodeN.LastIndexOf("|"); //获得|的索引
  6088. // // // // deptCodeNew = deptCodeN.Substring(0, deptCodeIndex + 1); //获得目标字符串(//去掉最后一个|后面的字符串)
  6089. // // // // // ============== 部门权限条件 - 部门 ================
  6090. // // // // string arrUser = " select F_UserCode from T_Sys_UserAccount where F_DeptCode LIKE '" + deptCodeNew + "%' ";
  6091. // // // // sql += $" and ToUser IN ({arrUser}) and WorkOrderID IN (SELECT WorkOrderID FROM dbo.T_Wo_WorkOrder WHERE 1=1 {sqlUser} ) ";
  6092. // // // //}
  6093. // // //}
  6094. // //}
  6095. // #endregion
  6096. // switch (daytype)
  6097. // {
  6098. // case "today":
  6099. // sql += " and DateDiff(dd,CreateTime,getdate())=0 ";
  6100. // break;
  6101. // case "yesterday":
  6102. // sql += " and DateDiff(dd,CreateTime,getdate())=1 ";
  6103. // break;
  6104. // case "month":
  6105. // sql += " and DateDiff(mm,CreateTime,getdate())=0 ";
  6106. // break;
  6107. // default:
  6108. // break;
  6109. // }
  6110. // if (strpageindex.Trim() != "")
  6111. // {
  6112. // pageindex = Convert.ToInt32(strpageindex);
  6113. // }
  6114. // if (strpagesize.Trim() != "")
  6115. // {
  6116. // pagesize = Convert.ToInt32(strpagesize);
  6117. // }
  6118. // int recordCount = 0;
  6119. // dt = BLL.PagerBLL.GetListPager(
  6120. // "T_Wo_WorkOrderItem",
  6121. // "T_Wo_WorkOrderItem.ID",
  6122. // "*,dbo.GetUserName(ToUser) as ToUserName, dbo.GetDeptName(ToDept) as ToDeptName,dbo.GetUserName(SureUser) as SureUserName,dbo.GetUserName(DealUser) as DealUserName,dbo.GetUserName(CreateUser) as CreateUserName,case Type when 1 then convert(decimal(18,2),DATEDIFF(minute, CreateTime, ISNULL(DealTime, GETDATE()))/60.00) else 0 end as totalhour",
  6123. // sql,
  6124. // "ORDER BY T_Wo_WorkOrderItem.ID desc",
  6125. // pagesize,
  6126. // pageindex,
  6127. // true,
  6128. // out recordCount);
  6129. // var obj = new
  6130. // {
  6131. // state = "success",
  6132. // message = "成功",
  6133. // rows = dt,
  6134. // total = recordCount
  6135. // };
  6136. // return Content(obj.ToJson());
  6137. //}
  6138. #endregion
  6139. #region 附件和语音文件
  6140. /// <summary>
  6141. /// 获取留言路径
  6142. /// </summary>
  6143. /// <param name="lid">留言id</param>
  6144. /// <param name="prefix">前缀</param>
  6145. /// <returns></returns>
  6146. public string GetLeavePath(string lid, string prefix)
  6147. {
  6148. string path = string.Empty;
  6149. var liuyan = new BLL.T_Call_LeaveRecord().GetModelList(" F_Id='" + lid + "' ").FirstOrDefault();
  6150. if (liuyan != null)
  6151. {
  6152. if (!string.IsNullOrEmpty(liuyan.F_RecFileUrl))
  6153. {
  6154. path = prefix + liuyan.F_RecFileUrl;
  6155. }
  6156. }
  6157. return path;
  6158. }
  6159. /// <summary>
  6160. /// 获取通话录音路径
  6161. /// </summary>
  6162. /// <param name="cid">通话id</param>
  6163. /// <param name="prefix">前缀</param>
  6164. /// <returns></returns>
  6165. public string GetCallPath(string cid, string prefix)
  6166. {
  6167. string path = string.Empty;
  6168. var luyin = new BLL.T_Call_CallRecords().GetModelList(" callid='" + cid + "' ").FirstOrDefault();
  6169. if (luyin != null)
  6170. {
  6171. if (!string.IsNullOrEmpty(luyin.FilePath))
  6172. {
  6173. var ym = prefix;
  6174. ym = ym.Substring(0, ym.Length - 1);
  6175. path = ym + luyin.FilePath.Substring(luyin.FilePath.IndexOf(':') + 1).Replace('\\', '/');
  6176. }
  6177. }
  6178. return path;
  6179. }
  6180. /// <summary>
  6181. /// 获取附件数据
  6182. /// </summary>
  6183. /// <param name="ids">附件id,多个用英文逗号,隔开</param>
  6184. /// <param name="prefix">前缀</param>
  6185. /// <returns></returns>
  6186. public DataTable GetFileData(string ids, string prefix)
  6187. {
  6188. DataTable dt = DbHelperSQL.Query("select * from T_Sys_Accessories where F_FileId in (" + ids + ")").Tables[0];
  6189. foreach (DataRow dr in dt.Rows)
  6190. {
  6191. dr["F_FileUrl"] = prefix + dr["F_FileUrl"].ToString();
  6192. }
  6193. return dt;
  6194. }
  6195. /// <summary>
  6196. /// 绑定附件信息
  6197. /// </summary>
  6198. /// <param name="dt"></param>
  6199. /// <param name="prefix"></param>
  6200. /// <returns></returns>
  6201. public DataTable BindFileData(DataTable dt, string prefix)
  6202. {
  6203. dt.Columns.Add("File", typeof(object));
  6204. foreach (DataRow dr in dt.Rows)
  6205. {
  6206. if (dr["Files"] != null && dr["Files"].ToString() != "")
  6207. {
  6208. dr["File"] = GetFileData(dr["Files"].ToString(), prefix);
  6209. }
  6210. }
  6211. return dt;
  6212. }
  6213. #endregion
  6214. #region 上传附件
  6215. /// <summary>
  6216. /// 上传附件
  6217. /// </summary>
  6218. /// <returns></returns>
  6219. public ActionResult UpLoadProcess(string id, string name, string type, string lastModifiedDate, int size, HttpPostedFileBase file)
  6220. {
  6221. try
  6222. {
  6223. string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  6224. string filePathName = string.Empty;
  6225. string path = "/Upload/Files/" + DateTime.Now.ToString("yyyy/MM/dd") + "/";
  6226. string localPath = Server.MapPath(Path.Combine(HttpRuntime.AppDomainAppPath, path));
  6227. if (Request.Files.Count == 0)
  6228. {
  6229. return Error("保存失败");
  6230. }
  6231. string ex = Path.GetExtension(file.FileName);
  6232. filePathName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + Guid.NewGuid().ToString("N") + ex;
  6233. if (!System.IO.Directory.Exists(localPath))
  6234. {
  6235. System.IO.Directory.CreateDirectory(localPath);
  6236. }
  6237. file.SaveAs(Path.Combine(localPath, filePathName));
  6238. #region 添加日志
  6239. Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
  6240. model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
  6241. model_T_Sys_Accessories.F_FileName = filePathName;//附件名称
  6242. model_T_Sys_Accessories.F_FileType = type;//附件类型
  6243. model_T_Sys_Accessories.F_FileUrl = path + filePathName;//附件地址
  6244. model_T_Sys_Accessories.F_Size = size;
  6245. model_T_Sys_Accessories.F_UserCode = stropenid;//上传人
  6246. int fid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
  6247. #endregion
  6248. if (fid > 0)
  6249. {//返回附件的ID
  6250. model_T_Sys_Accessories.F_FileId = fid;//修改为返回对象以便查看图片
  6251. return Success("文件日志都成功", model_T_Sys_Accessories);
  6252. }
  6253. else
  6254. return Success("文件成功");
  6255. }
  6256. catch (Exception ex)
  6257. {
  6258. return Error(ex.Message);
  6259. }
  6260. }
  6261. }
  6262. #endregion
  6263. }