Нет описания

WxLoginController.cs 352KB

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