Нет описания

WxLoginController.cs 453KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765
  1. using CallCenter.Utility;
  2. using CallCenterApi.DB;
  3. using CallCenterApi.Interface.App_Start;
  4. using CallCenterApi.Interface.Controllers.Base;
  5. using CallCenterApi.Interface.Controllers.workorder;
  6. using CallCenterApi.Interface.Models.Enum;
  7. using CallCenterApi.Interface.Models.Input;
  8. using CallCenterApi.Model;
  9. using CallCenterAPI.WechatSDK;
  10. using CallCenterAPI.WechatSDK.Models;
  11. using Newtonsoft.Json;
  12. using Newtonsoft.Json.Linq;
  13. using qcloudsms_csharp;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Data;
  17. using System.IO;
  18. using System.Linq;
  19. using System.Net;
  20. using System.Security.Cryptography;
  21. using System.Text;
  22. using System.Text.RegularExpressions;
  23. using System.Threading.Tasks;
  24. using System.Web;
  25. using System.Web.Mvc;
  26. using System.Web.Script.Serialization;
  27. using System.Xml;
  28. namespace CallCenterApi.Interface.Controllers.weixin
  29. {
  30. public class WxLoginController : BaseController
  31. {
  32. private readonly BLL.T_Sys_UserAccount userAccountBLL = new BLL.T_Sys_UserAccount();
  33. private readonly BLL.T_Sys_RoleInfo roleBLL = new BLL.T_Sys_RoleInfo();
  34. private readonly BLL.T_Cus_CustomerBaseNew customerBaseBLL = new BLL.T_Cus_CustomerBaseNew();
  35. private readonly BLL.T_Cus_CustomerFinance finbll = new BLL.T_Cus_CustomerFinance();
  36. private readonly BLL.T_Wo_WorkOrder woBLL = new BLL.T_Wo_WorkOrder();
  37. private readonly BLL.T_Sys_Department departmentBLL = new BLL.T_Sys_Department();
  38. private readonly BLL.T_Wo_WorkOrderItem_New itembll = new BLL.T_Wo_WorkOrderItem_New();
  39. private readonly BLL.T_Wo_WorkOrder_Logs blllogs = new BLL.T_Wo_WorkOrder_Logs();
  40. private readonly BLL.T_Sys_RoleInfo rolebll = new BLL.T_Sys_RoleInfo();
  41. private readonly BLL.T_Sys_DictionaryValue dicvalueBll = new BLL.T_Sys_DictionaryValue();
  42. private readonly BLL.T_Wo_MaterialManage mmBLL = new BLL.T_Wo_MaterialManage();
  43. BLL.T_Wo_QuestionManage quesBLL = new BLL.T_Wo_QuestionManage();
  44. ///// <summary>
  45. ///// 绑定微信号
  46. ///// </summary>
  47. ///// <param name="wxLoginDto"></param>
  48. ///// <returns></returns>
  49. //public ActionResult Login(WxLoginDto wxLoginDto)
  50. //{
  51. // var res = Redirect("获取微信openId", wxLoginDto.RedirectUrl);
  52. // var temp = WxHelper.GetOpenId(wxLoginDto);
  53. // if (string.IsNullOrWhiteSpace(temp.OpenId))
  54. // return res;
  55. // //openId => 用户
  56. // //如果不存在,跳转至登录页面
  57. // res = Redirect("绑定微信号", "");
  58. // return res;
  59. //}
  60. /// <summary>
  61. /// 绑定微信号 - 员工和业主分开登陆
  62. /// </summary>
  63. /// <param name="login"></param>
  64. /// <returns></returns>
  65. public ActionResult Login(WxLoginDto login)
  66. {
  67. #region 把其他OpenId更新为空
  68. var userAccount = userAccountBLL.GetModelByOpenid(login.OpenId);
  69. if (userAccount != null)
  70. {
  71. userAccount.F_WxOpenId = "";
  72. //userAccountBLL.Update(userAccount);
  73. string sql = $"update T_Sys_UserAccount set F_WxOpenId='' where F_UserId=" + userAccount.F_UserId;
  74. DbHelperSQL.ExecuteSql(sql);
  75. }
  76. var modelcustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + login.OpenId + "'").FirstOrDefault(); //customerBaseBLL.GetModelByOpenid(login.OpenId);
  77. if (modelcustomer != null)
  78. {
  79. modelcustomer.F_WxOpenId = "";
  80. //customerBaseBLL.Update(modelcustomer);
  81. string strsql = $"update T_Cus_CustomerBaseNew set F_WxOpenId='' where F_CustomerId=" + modelcustomer.F_CustomerId;
  82. DbHelperSQL.ExecuteSql(strsql);
  83. }
  84. #endregion
  85. if (string.IsNullOrEmpty(login.UserCode))
  86. return Error("账号不能为空!");
  87. if (string.IsNullOrEmpty(login.Password))
  88. return Error("密码不能为空!");
  89. Model.T_Sys_UserAccount loginCode = new BLL.T_Sys_UserAccount().LoginGetModel(login.UserCode, login.Password);
  90. Model.T_Sys_UserAccount loginwork = new BLL.T_Sys_UserAccount().LogworkGetModel(login.UserCode, login.Password);
  91. if (loginCode != null || loginwork != null)
  92. {
  93. Model.T_Sys_UserAccount loginUser = null;
  94. string deptcode = "";
  95. if (loginCode != null)
  96. loginUser = loginCode;
  97. else
  98. loginUser = loginwork;
  99. loginUser.F_WxOpenId = login.OpenId;
  100. int UserType = 0; string rolecode = ""; string UserName = ""; string rolename = "";
  101. UserName = loginUser.F_UserName;
  102. //部门
  103. Model.T_Sys_Department modelDep = new BLL.T_Sys_Department().GetModel(loginUser.F_DeptId);
  104. if (modelDep == null)
  105. return Error("获取失败!");
  106. #region 读取角色code
  107. var rolemodel = roleBLL.GetModel(loginUser.F_RoleId);
  108. if (rolemodel != null)
  109. rolecode = rolemodel.F_RoleCode;
  110. string area="", offic = "", region = "";
  111. region = loginUser.F_Remark;
  112. if (rolemodel.F_RoleCode == "DQJL")
  113. {
  114. area = modelDep.F_DeptName;
  115. }
  116. else if (rolemodel.F_RoleCode == "FGSJL")
  117. {
  118. var dept = departmentBLL.GetModel(modelDep.F_ParentId);
  119. if (dept != null)
  120. {
  121. area = dept.F_DeptName;
  122. offic = modelDep.F_DeptName;
  123. }
  124. }
  125. else if (rolemodel.F_RoleCode == "YWY")
  126. {
  127. if (modelDep != null)
  128. {
  129. if (modelDep.F_Layer == 2)
  130. {
  131. var dept = departmentBLL.GetModel(modelDep.F_ParentId);
  132. if (dept != null)
  133. {
  134. area = dept.F_DeptName;
  135. offic = modelDep.F_DeptName;
  136. }
  137. }
  138. if (modelDep.F_Layer == 1)
  139. {
  140. area = modelDep.F_DeptName;
  141. }
  142. }
  143. }
  144. #endregion
  145. #region 部门角色
  146. //部门角色(-1管理员,1接待部,2案场经理、项目负责人,3销售部总经理、物业部总经理、工程总经理、设计总经理,4区域客服,5业主(客户档案))
  147. if (loginUser.F_RoleId == 17)
  148. {
  149. //-1管理员
  150. return Error("无操作权限");
  151. }
  152. else
  153. {
  154. if (loginUser.F_RoleId == 60)
  155. {
  156. UserType = 0;
  157. rolename = "分公司经理";
  158. }
  159. else if (loginUser.F_RoleId == 62)
  160. {
  161. UserType = 0;
  162. rolename = "大区经理";
  163. }
  164. else if (loginUser.F_RoleId == 61)
  165. {
  166. UserType = 2;
  167. rolename = "高层";
  168. }
  169. else if (loginUser.F_RoleId == 58)
  170. {
  171. UserType = 4;
  172. rolename = "业务员";
  173. }
  174. else if (rolemodel.F_RoleCode== "BLRY")
  175. {
  176. UserType = 3;
  177. rolename = "办理人员";
  178. }
  179. //else if (loginUser.F_RoleId == 59)
  180. //{
  181. // UserType = 3;
  182. // rolename = "办理人员";
  183. //}
  184. else
  185. {
  186. return Error("无操作权限");
  187. }
  188. #region
  189. ////部门操作权限:1接待部,2办理人员,3区域客服,4监管
  190. //IF (MODELDEP.F_TYPE == 1)
  191. //{
  192. // //1--接待部
  193. // USERTYPE = 1;
  194. //}
  195. //ELSE IF (MODELDEP.F_TYPE == 2)
  196. //{
  197. // //2--办理人员
  198. // USERTYPE = 2;
  199. //}
  200. //ELSE IF (MODELDEP.F_TYPE == 3)
  201. //{
  202. // //3--区域客服
  203. // USERTYPE = 3;
  204. //}
  205. //ELSE IF (MODELDEP.F_TYPE == 4)
  206. //{
  207. // //4--监管
  208. // USERTYPE = 4;
  209. //}
  210. //ELSE
  211. //{
  212. // USERTYPE = 0;
  213. //}
  214. #endregion
  215. }
  216. #endregion
  217. var obj = new
  218. {
  219. openid = login.OpenId,
  220. usercode = login.UserCode,
  221. usertype = UserType,
  222. UserName = UserName,
  223. rolename = rolename,
  224. rolecode = rolecode,
  225. area = area ,
  226. offic =offic ,
  227. region =region ,
  228. flag= loginUser.F_Flag
  229. };
  230. if (userAccountBLL.Update(loginUser))
  231. return Success("绑定成功", obj);
  232. else
  233. return Error("绑定失败");
  234. }
  235. return Error("账号或密码错误,请重新登录");
  236. //else if (login.UserType == 5)
  237. //{
  238. // //客户档案登录 - 用戶信息不存在时,登录客户档案业主账号
  239. // Dictionary<string, string> paras_Customer = new Dictionary<string, string>();
  240. // // F_RelationShipClassID IN (1,2) 用户类型:0来电用户; 1准业主; 2不是准业主或是亲戚朋友
  241. // //首次密码默认为身份证后6位信息
  242. // //F_CustomerClassID >= 0 为业主或租户,且F_RelationShipClassID = 0为会员账号 2、登录最早的信息
  243. // 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 ";
  244. // paras_Customer.Add("@F_UserCode", login.UserCode);
  245. // paras_Customer.Add("@F_PassWord", login.Password);
  246. // var dt_Customer = DbHelperSQL.Query(sql_Customer, paras_Customer).Tables[0];
  247. // if (dt_Customer != null && dt_Customer.Rows.Count > 0)
  248. // {
  249. // //var customer = customerBaseBLL.GetModel(login.UserCode); //20180926 次方法查询有漏洞
  250. // var customer = customerBaseBLL.DataTableToList(dt_Customer).ToList().FirstOrDefault();
  251. // customer.F_WxOpenId = login.OpenId;
  252. // #region 新加 - 登录后同时获取用户账号,openid,和角色
  253. // //5--业主(客户档案会员)
  254. // //int UserType = 5;
  255. // var obj = new
  256. // {
  257. // openid = login.OpenId,
  258. // usercode = login.UserCode,
  259. // companyname = customer.F_CompanyName,
  260. // //companyaddress=customer.F_CompanyAddress,
  261. // };
  262. // #endregion
  263. // if (customerBaseBLL.Update(customer))
  264. // return Success("绑定成功!", obj);
  265. // else
  266. // return Error("绑定失败!");
  267. // }
  268. // return Error("账号或密码错误或者没有注册,请重新登录");
  269. //}
  270. return Error("绑定失败");
  271. }
  272. /// <summary>
  273. /// 绑定微信号 - 员工和业主统一登陆 - 不用
  274. /// </summary>
  275. /// <param name="login"></param>
  276. /// <returns></returns>
  277. [WechatActionFilter]
  278. public ActionResult Login2(WxLoginDto login)
  279. {
  280. Dictionary<string, string> paras = new Dictionary<string, string>();
  281. string sql = " select * from T_Sys_UserAccount (NOLOCK) where F_UserCode=@F_UserCode and F_PassWord=@F_PassWord and F_DeleteFlag = 0 ";
  282. paras.Add("@F_UserCode", login.UserCode);
  283. paras.Add("@F_PassWord", login.Password);
  284. var dt = DbHelperSQL.Query(sql, paras).Tables[0];
  285. #region 把其他OpenId更新为空
  286. var userAccount = userAccountBLL.GetModelByOpenid(login.OpenId);
  287. if (userAccount != null)
  288. {
  289. userAccount.F_WxOpenId = "";
  290. userAccountBLL.Update(userAccount);
  291. }
  292. var modelcustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + login.OpenId + "'").FirstOrDefault();//.GetModelByOpenid(login.OpenId);
  293. if (modelcustomer != null)
  294. {
  295. modelcustomer.F_WxOpenId = "";
  296. customerBaseBLL.Update(modelcustomer);
  297. }
  298. #endregion
  299. if (dt != null && dt.Rows.Count > 0)
  300. {
  301. var user = userAccountBLL.GetModel(login.UserCode);
  302. user.F_WxOpenId = login.OpenId;
  303. //int UserType = 0;
  304. //部门
  305. Model.T_Sys_Department modelDep = new BLL.T_Sys_Department().GetModel(user.F_DeptId);
  306. if (modelDep == null)
  307. return Error("获取失败!");
  308. #region 部门角色
  309. ////部门角色(-1管理员,1接待部,2案场经理、项目负责人,3销售部总经理、物业部总经理、工程总经理、设计总经理,4区域客服,5业主(客户档案))
  310. //if (user.F_RoleId == 17)
  311. //{
  312. // //-1管理员
  313. // UserType = -1;
  314. //}
  315. //else
  316. //{
  317. // //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  318. // if (modelDep.F_Type == 1)
  319. // {
  320. // //1--接待部
  321. // UserType = 1;
  322. // }
  323. // else if (modelDep.F_Type == 2)
  324. // {
  325. // //2--办理人员
  326. // UserType = 2;
  327. // }
  328. // else if (modelDep.F_Type == 3)
  329. // {
  330. // //3--区域客服
  331. // UserType = 3;
  332. // }
  333. // else if (modelDep.F_Type == 4)
  334. // {
  335. // //4--监管
  336. // UserType = 4;
  337. // }
  338. // else
  339. // {
  340. // UserType = 0;
  341. // }
  342. //}
  343. #endregion
  344. var obj = new
  345. {
  346. openid = login.OpenId,
  347. usercode = login.UserCode,
  348. //usertype = UserType
  349. };
  350. if (userAccountBLL.Update(user))
  351. {
  352. return Success("绑定成功", obj);
  353. }
  354. else
  355. {
  356. return Error("绑定失败");
  357. }
  358. }
  359. else
  360. {
  361. //客户档案登录 - 用戶信息不存在时,登录客户档案业主账号
  362. Dictionary<string, string> paras_Customer = new Dictionary<string, string>();
  363. // F_RelationShipClassID IN (1,2) 用户类型:0来电用户; 1准业主; 2不是准业主或是亲戚朋友
  364. //首次密码默认为身份证后6位信息
  365. //F_CustomerClassID >= 0 为业主或租户,且F_RelationShipClassID = 0为会员账号 2、登录最早的信息
  366. string sql_Customer = " select * from dbo.T_Cus_CustomerBaseNew (NOLOCK) where F_CustomerCode=@F_UserCode and F_PassWord=@F_PassWord and F_DeleteFlag = 0 ";
  367. paras_Customer.Add("@F_UserCode", login.UserCode);
  368. paras_Customer.Add("@F_PassWord", login.Password);
  369. var dt_Customer = DbHelperSQL.Query(sql_Customer, paras_Customer).Tables[0];
  370. if (dt_Customer != null && dt_Customer.Rows.Count > 0)
  371. {
  372. var customer = customerBaseBLL.GetModelList(" F_CustomerCode='" + login.UserCode + "'").FirstOrDefault(); //customerBaseBLL.GetModel(login.UserCode);
  373. customer.F_WxOpenId = login.OpenId;
  374. #region 新加 - 登录后同时获取用户账号,openid,和角色
  375. //5--业主(客户档案会员)
  376. //int UserType = 5;
  377. var obj = new
  378. {
  379. openid = login.OpenId,
  380. usercode = login.UserCode,
  381. //usertype = UserType
  382. };
  383. #endregion
  384. if (customerBaseBLL.Update(customer))
  385. {
  386. return Success("绑定成功!", obj);
  387. }
  388. else
  389. {
  390. return Error("绑定失败!");
  391. }
  392. }
  393. else
  394. {
  395. return Error("账号或密码错误,请重新登录");
  396. }
  397. //return Error("账号或密码错误,请重新登录");
  398. }
  399. }
  400. /// <summary>
  401. /// 随机字符串数组集合
  402. /// </summary>
  403. private static readonly string[] NonceStrings = new string[]
  404. {
  405. "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",
  406. "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"
  407. };
  408. /// <summary>
  409. /// 生成签名的随机串
  410. /// </summary>
  411. /// <returns></returns>
  412. public static string CreateNonceStr()
  413. {
  414. Random random = new Random();
  415. var sb = new StringBuilder();
  416. var length = NonceStrings.Length;
  417. //生成15位数的随机字符串,当然也可以通过控制对应字符串大小生成,但是至多不超过32位
  418. for (int i = 0; i < 16; i++)
  419. {
  420. sb.Append(NonceStrings[random.Next(length - 1)]);//通过random获得的随机索引到,NonceStrings数组中获取对应数组值
  421. }
  422. return sb.ToString();
  423. }
  424. /// <summary>
  425. /// 获取签名
  426. /// </summary>
  427. /// <param name="url"></param>
  428. /// <returns></returns>
  429. public ActionResult GetJsSdk(string url)
  430. {
  431. var timestamp = GetCurrentUinxTime();
  432. var nonceStr = CreateNonceStr();
  433. var obj = new
  434. {
  435. state = "success",
  436. message = "成功",
  437. appId = AppId,
  438. timestamp = timestamp,
  439. nonceStr = nonceStr,
  440. token = GetToken(),
  441. ticket= Getticket(GetToken()),
  442. url,
  443. signature = GetSignature(Getticket(GetToken()), nonceStr, timestamp, url)
  444. };
  445. return Content(obj.ToJson()); ;
  446. }
  447. string AppId = Configs.GetValue("WechatAppid");
  448. string AppSecret = Configs.GetValue("WechatAppsecret");
  449. public class Token
  450. {
  451. public string token;
  452. public DateTime time;
  453. }
  454. public class AssedToken
  455. {
  456. public string access_token { get; set; }
  457. public int expires_in { get; set; }
  458. }
  459. public string GetToken()
  460. {
  461. WebClient web = new WebClient();
  462. web.Encoding = Encoding.UTF8;
  463. string msg = "";
  464. var model = new BLL.T_Sys_AssToken().GetModelList("F_IsDelete=0 order by F_ID desc").FirstOrDefault();
  465. if (model!=null )
  466. {
  467. System.TimeSpan id = DateTime.Now - DateTime.Parse(model.F_CreatTime .ToString());
  468. if (id.TotalMinutes>=120)
  469. {
  470. string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + AppId + "&secret=" + AppSecret;
  471. string Dataaa = web.DownloadString(url);//这一句话就能请求到数据了
  472. JObject jo = (JObject)JsonConvert.DeserializeObject(Dataaa);
  473. string access_token = jo["access_token"].ToString();
  474. var asser = new Model.T_Sys_AssToken();
  475. asser.F_CreatTime = DateTime.Now;
  476. asser.F_IsDelete = 0;
  477. asser.F_Token = access_token;
  478. int a = new BLL.T_Sys_AssToken().Add(asser);
  479. if (a >0)
  480. {
  481. msg = access_token;
  482. }
  483. }
  484. else
  485. {
  486. msg = model.F_Token ;
  487. }
  488. }
  489. else
  490. {
  491. string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + AppId + "&secret=" + AppSecret;
  492. string Dataaa = web.DownloadString(url);//这一句话就能请求到数据了
  493. JObject jo = (JObject)JsonConvert.DeserializeObject(Dataaa);
  494. string access_token = jo["access_token"].ToString();
  495. var asser = new Model.T_Sys_AssToken();
  496. asser.F_CreatTime = DateTime.Now;
  497. asser.F_IsDelete = 0;
  498. asser.F_Token = access_token;
  499. int a = new BLL.T_Sys_AssToken().Add(asser);
  500. if (a > 0)
  501. {
  502. msg = access_token;
  503. }
  504. }
  505. return msg;
  506. }
  507. public string Getticket(string token)
  508. {
  509. WebClient web = new WebClient();
  510. web.Encoding = Encoding.UTF8;
  511. string msg = "";
  512. string urltoken = " https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + token + "&type=jsapi";
  513. string Dataaasig = web.DownloadString(urltoken);//这一句话就能请求到数据了
  514. JObject jo = (JObject)JsonConvert.DeserializeObject(Dataaasig);
  515. string ticket = jo["ticket"].ToString();
  516. string errmsg = jo["errmsg"].ToString();
  517. return ticket;
  518. }
  519. public class Accesstoken
  520. {
  521. public string access_token;
  522. public int expires_in;
  523. }
  524. /// <summary>
  525. /// 获取jsapi_ticket
  526. /// </summary>
  527. /// <param name="jsapi_ticket">微信公众号调用微信JS临时票据</param>
  528. /// <param name="nonceStr">随机串</param>
  529. /// <param name="timestamp">时间戳</param>
  530. /// <param name="url">当前网页URL</param>
  531. /// <returns></returns>
  532. public static string GetSignature(string jsapi_ticket, string nonceStr, long timestamp, string url)
  533. {
  534. var string1Builder = new StringBuilder();
  535. //注意这里参数名必须全部小写,且必须有序
  536. string1Builder.Append("jsapi_ticket=").Append(jsapi_ticket).Append("&")
  537. .Append("noncestr=").Append(nonceStr).Append("&")
  538. .Append("timestamp=").Append(timestamp).Append("&")
  539. .Append("url=").Append(url.IndexOf("#") >= 0 ? url.Substring(0, url.IndexOf("#")) : url);
  540. return Sha1Sign(string1Builder.ToString());
  541. }
  542. public static string Sha1Sign(string data)
  543. {
  544. byte[] temp1 = Encoding.UTF8.GetBytes(data);
  545. SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();
  546. byte[] temp2 = sha.ComputeHash(temp1);
  547. sha.Clear();
  548. // 注意, 不能用这个
  549. // string output = Convert.ToBase64String(temp2);// 不能直接转换成base64string
  550. var output = BitConverter.ToString(temp2);
  551. output = output.Replace("-", "");
  552. output = output.ToLower();
  553. return output;
  554. }
  555. /// <summary>
  556. /// 获取当前时间戳
  557. /// </summary>
  558. /// <returns></returns>
  559. public static long GetCurrentUinxTime()
  560. {
  561. DateTime currentDate = DateTime.Now;//当前时间
  562. //转化为时间戳
  563. DateTime localTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  564. return long.Parse((currentDate - localTime).TotalSeconds.ToString().Split('.')[0]);
  565. // var ticks = currentDate.ToUniversalTime().Ticks - new DateTime(1970, 1, 1, 0, 0, 0, //DateTimeKind.Utc).Ticks;
  566. // var timeSpan = ticks / TimeSpan.TicksPerSecond;
  567. //return timeSpan;
  568. }
  569. /// <summary>
  570. /// 获取微信openid
  571. /// </summary>
  572. /// <param name="login"></param>
  573. /// <returns></returns>
  574. public ActionResult GetOpenId(WxLoginDto wld)
  575. {
  576. //wld.RedirectUrl = RequestString.GetUrlReferrer();
  577. if (string.IsNullOrEmpty(wld.OpenId))
  578. {
  579. var temp = WxHelper.GetOpenId(wld);
  580. if (string.IsNullOrWhiteSpace(temp.OpenId))
  581. {
  582. //Request.QueryString[ ] == null
  583. return Redirect("请求", temp.RedirectUrl);
  584. }
  585. wld.OpenId = temp.OpenId;
  586. #region 获取是否绑定用户表
  587. //获取是否绑定用户表
  588. var usertemp = new BLL.T_Sys_UserAccount().GetModelByOpenid(wld.OpenId);
  589. if (usertemp != null)
  590. {
  591. //部门
  592. Model.T_Sys_Department modelDep = new BLL.T_Sys_Department().GetModel(usertemp.F_DeptId);
  593. if (modelDep == null)
  594. return Error("获取失败!");
  595. wld.UserCode = usertemp.F_UserCode;
  596. wld.Flag = usertemp.F_Flag;
  597. #region 读取角色code
  598. var rolemodel = roleBLL.GetModel(usertemp.F_RoleId);
  599. if (rolemodel != null)
  600. wld.RoleCode = rolemodel.F_RoleCode;
  601. #endregion
  602. #region 部门角色
  603. if (usertemp.F_RoleId == 17)
  604. {
  605. //-1管理员
  606. wld.UserType = -1;
  607. }
  608. else
  609. {
  610. if (usertemp.F_RoleId == 60 || usertemp.F_RoleId == 62)
  611. {
  612. wld.UserType = 0;
  613. }
  614. else if (usertemp.F_RoleId == 61)
  615. {
  616. wld.UserType = 2;
  617. }
  618. else if (usertemp.F_RoleId == 58)
  619. {
  620. wld.UserType = 4;
  621. }
  622. else if (rolemodel.F_RoleCode== "BLRY")
  623. {
  624. wld.UserType = 3;
  625. }
  626. else
  627. {
  628. wld.UserType = 1;
  629. }
  630. #region
  631. ////部门操作权限:1接待部,2办理人员,3区域客服,4监管
  632. //IF (MODELDEP.F_TYPE == 1)
  633. //{
  634. // //1--接待部
  635. // USERTYPE = 1;
  636. //}
  637. //ELSE IF (MODELDEP.F_TYPE == 2)
  638. //{
  639. // //2--办理人员
  640. // USERTYPE = 2;
  641. //}
  642. //ELSE IF (MODELDEP.F_TYPE == 3)
  643. //{
  644. // //3--区域客服
  645. // USERTYPE = 3;
  646. //}
  647. //ELSE IF (MODELDEP.F_TYPE == 4)
  648. //{
  649. // //4--监管
  650. // USERTYPE = 4;
  651. //}
  652. //ELSE
  653. //{
  654. // USERTYPE = 0;
  655. //}
  656. #endregion
  657. #region
  658. ////部门操作权限:1接待部,2办理人员,3区域客服,4监管
  659. //if (modelDep.F_Type == 1)
  660. //{
  661. // //1--接待部
  662. // wld.UserType = 1;
  663. //}
  664. //else if (modelDep.F_Type == 2)
  665. //{
  666. // //2--办理人员
  667. // wld.UserType = 2;
  668. //}
  669. //else if (modelDep.F_Type == 3)
  670. //{
  671. // //3--区域客服
  672. // wld.UserType = 3;
  673. //}
  674. //else if (modelDep.F_Type == 4)
  675. //{
  676. // //4--监管
  677. // wld.UserType = 4;
  678. //}
  679. //else
  680. //{
  681. // wld.UserType = 0;
  682. //}
  683. #endregion
  684. }
  685. #endregion
  686. }
  687. else
  688. {
  689. var customertemp = customerBaseBLL.GetModelByOpenid(wld.OpenId);
  690. if (customertemp != null)
  691. {
  692. wld.UserCode = customertemp.F_CustomerCode;
  693. //5--业主(客户档案会员)
  694. wld.UserType = 5;
  695. }
  696. else
  697. {
  698. wld.UserCode = "";
  699. }
  700. //wld.UserCode = "";
  701. }
  702. #endregion
  703. }
  704. var model = new BLL.T_Sys_Users().GetModel(wld.OpenId);
  705. if (model == null)
  706. {
  707. model = new Model.T_Sys_Users();
  708. model.F_OpenId = wld.OpenId;
  709. model.F_Type = 1;
  710. model.F_CreateTime = DateTime.Now;
  711. new BLL.T_Sys_Users().Add(model);
  712. }
  713. var newobj = new
  714. {
  715. openid = wld.OpenId,
  716. usercode = wld.UserCode,
  717. usertype = wld.UserType,
  718. rolecode = wld.RoleCode,
  719. flag=wld.Flag
  720. };
  721. return Success("成功", newobj);
  722. }
  723. /// <summary>
  724. ///退回工单列表
  725. /// </summary>
  726. public string GetBackid(Model.T_Sys_UserAccount ua)
  727. {
  728. string str = string.Empty;
  729. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_ItemType in(" + (int)EnumItemType.deal + "," + (int)EnumItemType.audit + ")"
  730. + " and "
  731. + "F_OptType in(" + (int)EnumItemOpt.abreback + "," + (int)EnumItemOpt.reback + ") and F_NextUser='" + ua.F_UserCode + "'"
  732. + ""
  733. + " and isnull(F_IsUsed,'0')='0' ";
  734. return str;
  735. }
  736. /// <summary>
  737. ///工单列表
  738. /// </summary>
  739. ///
  740. 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,
  741. 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)
  742. {
  743. // int userId = CurrentUser.UserData.F_UserId;
  744. if (!string.IsNullOrEmpty(OpenId))
  745. {
  746. // Model.T_Sys_UserAccount ua = userAccountBLL.GetModel(userId);
  747. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  748. // if (source != 3)
  749. // {
  750. // if (ua == null)
  751. // {
  752. // return Error("你的账号已在别处登录,你确定要再次登录吗?");
  753. // }
  754. // }
  755. // Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  756. string sql = $" and F_IsDelete=0";
  757. DataTable dt = new DataTable();
  758. #region 筛选条件
  759. if (type > 0 && type < 6)//工单类型
  760. sql += $" and F_Type=" + type;
  761. if (source > 0)//工单来源
  762. {
  763. if (source == 1)
  764. sql += $" and (F_Source in (1,'')or F_Source is null )";
  765. else
  766. sql += $" and F_Source='" + source + "'";
  767. }
  768. if (!string.IsNullOrWhiteSpace(description))//问题描述
  769. sql += $" and F_Description like '%" + description.Trim() + "%'";
  770. if (!string.IsNullOrWhiteSpace(touser))//参与人
  771. sql += $" and F_DealBy like '%" + touser.Trim() + "%'";
  772. if (!string.IsNullOrWhiteSpace(code))//工单编号
  773. sql += $" and F_WorkOrderCode like '%" + code.Trim() + "%'";
  774. if (!string.IsNullOrWhiteSpace(keywords))//关键字搜索
  775. sql += $" and (F_QuestionType like '%" + keywords.Trim()
  776. + "%' or F_ZX_Area like '%" + keywords.Trim() + "%' or F_ZX_Branch like '%" + keywords.Trim()
  777. + "%' or F_CusName like '%" + keywords.Trim() + "%' or F_WorkOrderCode like '%" + keywords.Trim() + "%'or F_CusPhone like '%" + keywords.Trim() + "%' ) ";
  778. if (!string.IsNullOrWhiteSpace(cusname))//客户姓名
  779. sql += $" and F_CusName like '%" + cusname.Trim() + "%'";
  780. if (!string.IsNullOrWhiteSpace(cusphone))//客户电话
  781. sql += $" and F_CusPhone like '%" + cusphone.Trim() + "%'";
  782. if (!string.IsNullOrWhiteSpace(companyname))//公司名称
  783. sql += $" and F_CompanyName like '%" + companyname.Trim() + "%'";
  784. if (!string.IsNullOrWhiteSpace(category))//产品名称
  785. sql += $" and F_TS_Category like '%" + category.Trim() + "%'";
  786. if (!string.IsNullOrWhiteSpace(salebase))//销售基地
  787. sql += $" and F_SalesBase like '%" + salebase.Trim() + "%'";
  788. if (!string.IsNullOrWhiteSpace(province))//省
  789. sql += $" and F_IncidentProvince like '%" + province.Trim() + "%'";
  790. if (!string.IsNullOrWhiteSpace(province))//市
  791. sql += $" and F_IncidentCity like '%" + city.Trim() + "%'";
  792. if (!string.IsNullOrWhiteSpace(province))//县
  793. sql += $" and F_IncidentCountry like '%" + country.Trim() + "%'";
  794. if (!string.IsNullOrWhiteSpace(province))//乡
  795. sql += $" and F_IncidentTownship like '%" + township.Trim() + "%'";
  796. if (condition>-1)
  797. {
  798. if (condition == 5)
  799. {
  800. sql += $" and F_State in (2,3,4,5)";
  801. }
  802. else if (condition == 6)
  803. {
  804. sql += $" and F_State in (11)";
  805. sql += $" and F_IsVisit=" + 1; ;
  806. sql += $"and F_DealType != '当即办理' and F_VisitBy != ''";
  807. }
  808. else if (condition == 10)
  809. {
  810. sql += $" and F_State in (10,11)";
  811. }
  812. else if (condition == 12)
  813. {
  814. sql += $" and F_State=" + (int)EnumWorkOrderState.finish + " and F_IsVisit = '" + "1" + "' ";
  815. }
  816. else
  817. {
  818. sql += $" and F_State=" + condition;
  819. }
  820. if (ua != null)
  821. {
  822. Model.T_Sys_RoleInfo re = rolebll.GetModel(ua.F_RoleId);
  823. if (re.F_RoleCode == "QTJS" || re.F_RoleCode == "YWY")
  824. sql += $" and F_CreateBy like '%" + ua.F_UserCode.Trim() + "%'";
  825. else if (re.F_RoleCode == "DQJL" || re.F_RoleCode == "FGSJL" || re.F_RoleCode == "BLRY" || re.F_RoleCode == "ZG")
  826. {
  827. string detpid = "" + ua.F_DeptId;
  828. var deparmentlist = new List<Model.T_Sys_Department>();
  829. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  830. if (dModel != null)
  831. {
  832. if (dModel.F_Layer == 1)
  833. {
  834. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  835. if (deparmentlist.Count > 0)
  836. {
  837. foreach (var it in deparmentlist)
  838. {
  839. if (detpid != "")
  840. {
  841. detpid += "," + it.F_DeptId;
  842. }
  843. else
  844. {
  845. detpid = "" + it.F_DeptId;
  846. }
  847. }
  848. }
  849. }
  850. else
  851. {
  852. detpid = ua.F_DeptId.ToString();
  853. }
  854. if (state >= 0)
  855. {
  856. if (GetDeptWorkOrderID(detpid) != "")
  857. {
  858. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid) + ") ";
  859. }
  860. else
  861. {
  862. return Success("暂无工单"); ;
  863. }
  864. }
  865. else
  866. {
  867. if (GetDeptWorkOrderID(detpid) != "")
  868. {
  869. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid) + ") ";
  870. }
  871. else
  872. {
  873. return Success("暂无工单"); ;
  874. }
  875. }
  876. }
  877. else
  878. {
  879. return Error("加载失败");
  880. }
  881. }
  882. }
  883. }
  884. if (!string.IsNullOrWhiteSpace(createby))//创建人
  885. {
  886. sql += $" and F_CustomerID in(select F_CustomerCode from T_Cus_CustomerBaseNew where F_Salesman like '%" +createby+ "%' and F_IsDelete =0) ";
  887. }
  888. if (!string.IsNullOrWhiteSpace(createtel))//创建人
  889. {
  890. sql += $" and F_CustomerID in(select F_CustomerCode from T_Cus_CustomerBaseNew where F_SalesPhone like '%" + createtel + "%' and F_IsDelete =0) ";
  891. }
  892. if (!string .IsNullOrEmpty (handler))
  893. {
  894. Model.T_Sys_UserAccount user = userAccountBLL .GetworkModel(handler);
  895. if (user != null)
  896. {
  897. if (GetParticipate(user.F_UserCode) != "")
  898. {
  899. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetParticipate(user.F_UserCode) + ") ";
  900. }
  901. }
  902. else
  903. {
  904. Model.T_Sys_UserAccount userer = userAccountBLL.GetName(handler);
  905. if (userer != null)
  906. {
  907. if (GetParticipate(userer.F_UserCode) != "")
  908. {
  909. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetParticipate(userer.F_UserCode) + ") ";
  910. }
  911. }
  912. }
  913. }
  914. // sql += " and (F_CreateBy= '" + ua.F_UserCode + "' or T_Wo_WorkOrder.F_ID in ( " + GetCYWorkOrderID(ua.F_UserCode) + ")) ";
  915. if (source == 3)
  916. {
  917. sql += $" and F_WxOpenId ='" + OpenId + "'";
  918. }
  919. else if (ua != null)
  920. {
  921. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  922. if (state >-1)
  923. {
  924. switch (state)
  925. {
  926. case 0://待审批
  927. string uwhere = "";
  928. if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL")
  929. {
  930. if (GetApprovalOrderID(ua, OpenId, ro.F_RoleCode) != "")
  931. {
  932. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetApprovalOrderID(ua, OpenId, ro.F_RoleCode) + ") ";
  933. }
  934. else
  935. {
  936. return Success("暂无工单");
  937. }
  938. }
  939. else
  940. {
  941. return Success("无操作权限");
  942. }
  943. break;
  944. case 11://已创单
  945. sql += $" and F_CreateBy ='" + ua.F_UserCode + "'";
  946. break;
  947. case 12://退单
  948. if (GetBackid(ua) != "")
  949. {
  950. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetBackid(ua) + ") ";
  951. }
  952. else
  953. {
  954. return Success("暂无工单");
  955. }
  956. break;
  957. case 1://已审核
  958. if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "GC")
  959. {
  960. if (GetApprovedOrderID(ua.F_UserCode) != "")
  961. {
  962. sql += $" and F_ID in ( " + GetApprovedOrderID(ua.F_UserCode) + ") "; ;
  963. }
  964. else
  965. {
  966. return Error("暂无工单");
  967. }
  968. }
  969. else
  970. {
  971. return Success("暂无工单");
  972. }
  973. break;
  974. case 2://待完成的(待接单)
  975. string strsql = GetDeptWorkOrderID(ua.F_DeptId, ua.F_UserCode);
  976. if (strsql != "")
  977. {
  978. sql += $" and (F_State in(" + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.assign + ") ";
  979. sql += $" or F_State2 in(" + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.assign + ")) ";
  980. sql += " and T_Wo_WorkOrder.F_ID in ( " + strsql + ")";
  981. }
  982. else
  983. {
  984. return Success("暂无工单"); ;
  985. }
  986. break;
  987. case 5://待审批
  988. if (ro.F_RoleCode == "GC")
  989. {
  990. if (GetHApproval(ua.F_UserCode) != "")
  991. {
  992. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetHApproval(ua.F_UserCode) + ") "; ;
  993. }
  994. }
  995. else
  996. {
  997. return Success("暂无工单"); ;
  998. }
  999. break;
  1000. case 4://待完成的(待处理)
  1001. string dealstr = GetDWCWorkOrderID(ua.F_UserCode, ua.F_DeptId);
  1002. if (!string.IsNullOrEmpty(dealstr))
  1003. {
  1004. sql += " and ((F_State in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.revoke + ")";
  1005. sql += " or F_State2 in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.revoke + "))";
  1006. sql += " and T_Wo_WorkOrder.F_ID in ( " + dealstr + ") ";
  1007. if (!string.IsNullOrEmpty(GetRevokeWo(ua.F_UserCode)))
  1008. {
  1009. sql += " or ((F_State=" + (int)EnumWorkOrderState.assign + " or F_State2=" + (int)EnumWorkOrderState.assign + ") and T_Wo_WorkOrder.F_ID in (" + GetRevokeWo(ua.F_UserCode) + ")))";
  1010. }
  1011. else
  1012. {
  1013. sql += $")";
  1014. }
  1015. }
  1016. else
  1017. {
  1018. return Success("暂无工单"); ;
  1019. }
  1020. break;
  1021. case 10://已完成的
  1022. if (GetDeptUserCode(ua.F_DeptId) != "")
  1023. {
  1024. //sql += " and (F_State in(10,11) or F_State2 in(10,11))";
  1025. sql += " and (((F_State in(10,11) and isnull(F_Flag,0)=0 ) or (F_Flag=2 and F_State2 in(10,11)) or (F_Flag=1 and F_State in(10,11)) or (F_Flag=3 and(F_State in(10,11) or F_State2 in(10,11))))";
  1026. sql += " and F_DealBy in(" + GetDeptUserCode(ua.F_DeptId) + ") ";
  1027. sql += " or T_Wo_WorkOrder.F_ID in (" + GetOverWo(ua.F_UserCode) + "))";
  1028. }
  1029. // sql += " and F_State in(10,11) and F_DealBy = '" + ua.F_UserCode + "' ";
  1030. break;
  1031. case 3://我参与的
  1032. if (GetParticipateID(ua.F_UserCode) != "")
  1033. {
  1034. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetParticipateID(ua.F_UserCode) + ") ";
  1035. }
  1036. else
  1037. {
  1038. return Error("暂无工单");
  1039. }
  1040. break;
  1041. case 6://待回访
  1042. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "JDYBZZX")
  1043. {
  1044. uwhere = $" and F_Type <> 3";
  1045. }
  1046. else
  1047. {
  1048. return Success("无操作权限"); ;
  1049. }
  1050. sql += $" and ((F_State=" + (int)EnumWorkOrderState.finish + " and F_State2!=" + (int)EnumWorkOrderState.evaluate + ") or (F_State!=" + (int)EnumWorkOrderState.evaluate + " and F_State2=" + (int)EnumWorkOrderState.finish + ")) and F_IsVisit = '" + "1" + "' " + uwhere; ;
  1051. break;
  1052. case 7://已回访
  1053. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "JDYBZZX")
  1054. {
  1055. if (GetCYWorkOrderID(ua.F_UserCode) != "")
  1056. {
  1057. sql += " and (F_CreateBy= '" + ua.F_UserCode + "' or T_Wo_WorkOrder.F_ID in ( " + GetCYWorkOrderID(ua.F_UserCode) + ")) ";
  1058. }
  1059. else
  1060. {
  1061. return Success("暂无工单"); ;
  1062. }
  1063. sql += $" and F_State=" + (int)EnumWorkOrderState.evaluate;
  1064. }
  1065. else if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "ZG")
  1066. {
  1067. string detpid = "" + ua.F_DeptId;
  1068. var deparmentlist = new List<Model.T_Sys_Department>();
  1069. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  1070. if (dModel != null)
  1071. {
  1072. if (dModel.F_Layer == 1)
  1073. {
  1074. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  1075. if (deparmentlist.Count > 0)
  1076. {
  1077. foreach (var it in deparmentlist)
  1078. {
  1079. if (detpid != "")
  1080. {
  1081. detpid += "," + it.F_DeptId;
  1082. }
  1083. else
  1084. {
  1085. detpid = "" + it.F_DeptId; ;
  1086. }
  1087. }
  1088. }
  1089. }
  1090. else
  1091. {
  1092. detpid = ua.F_DeptId.ToString();
  1093. }
  1094. if (GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.evaluate + "") != "")
  1095. {
  1096. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.evaluate + "") + ") "; ;
  1097. }
  1098. else
  1099. {
  1100. return Success("暂无工单"); ;
  1101. }
  1102. }
  1103. else
  1104. {
  1105. return Error("加载失败");
  1106. }
  1107. }
  1108. else
  1109. {
  1110. return Success("无操作权限"); ;
  1111. }
  1112. sql += $" and F_State=" + (int)EnumWorkOrderState.evaluate;
  1113. break;
  1114. case 8://待完结
  1115. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "JDYBZZX")
  1116. {
  1117. uwhere = ""; ;
  1118. }
  1119. else
  1120. {
  1121. return Success("无操作权限"); ;
  1122. }
  1123. sql += $" and (F_State=" + (int)EnumWorkOrderState.finish + " or F_State2=" + (int)EnumWorkOrderState.finish + ") and ( F_IsVisit = '" + "0" + "' or F_Type = 3)"; ;
  1124. break;
  1125. case 9://待接单
  1126. string strsql2 = GetDeptWorkOrderID(ua.F_DeptId, ua.F_UserCode);
  1127. if (strsql2 != "")
  1128. {
  1129. sql += $" and (F_State in(" + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.assign + ") ";
  1130. sql += $" or F_State2 in(" + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.assign + ")) ";
  1131. sql += " and T_Wo_WorkOrder.F_ID in ( " + strsql2 + ")";
  1132. }
  1133. else
  1134. {
  1135. return Success("暂无工单"); ;
  1136. }
  1137. break;
  1138. case 20: //抄送工单列表
  1139. sql += $" and T_Wo_WorkOrder.F_ID in (select F_WorkOrderID from T_Wo_WorkCopy where F_SendCopyUser like '%{ua.F_UserCode}%'"
  1140. + $" or (F_Flag=1 and F_SendCopyDepts={ua.F_DeptId} )) ";
  1141. break;
  1142. }
  1143. }
  1144. else
  1145. {
  1146. if (ro.F_RoleCode == "QTJS" || ro.F_RoleCode == "YWY")
  1147. sql += $" and F_CreateBy like '%" + ua.F_UserCode.Trim() + "%'";
  1148. else if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "BLRY" || ro.F_RoleCode == "ZG")
  1149. {
  1150. string detpid = "" + ua.F_DeptId;
  1151. var deparmentlist = new List<Model.T_Sys_Department>();
  1152. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  1153. if (dModel != null)
  1154. {
  1155. if (dModel.F_Layer == 1)
  1156. {
  1157. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  1158. if (deparmentlist.Count > 0)
  1159. {
  1160. foreach (var it in deparmentlist)
  1161. {
  1162. if (detpid != "")
  1163. {
  1164. detpid += "," + it.F_DeptId;
  1165. }
  1166. else
  1167. {
  1168. detpid = "" + it.F_DeptId;
  1169. }
  1170. }
  1171. }
  1172. }
  1173. else
  1174. {
  1175. detpid = ua.F_DeptId.ToString();
  1176. }
  1177. if (state >= 0)
  1178. {
  1179. if (GetDeptWorkOrderID(detpid) != "")
  1180. {
  1181. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid) + ") ";
  1182. }
  1183. else
  1184. {
  1185. return Success("暂无工单"); ;
  1186. }
  1187. }
  1188. else
  1189. {
  1190. if (GetDeptWorkOrderID(detpid) != "")
  1191. {
  1192. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid) + ") ";
  1193. }
  1194. else
  1195. {
  1196. return Success("暂无工单"); ;
  1197. }
  1198. }
  1199. }
  1200. else
  1201. {
  1202. return Error("加载失败");
  1203. }
  1204. }
  1205. }
  1206. }
  1207. else
  1208. {
  1209. sql += $" and F_WxOpenId ='" + OpenId + "'";
  1210. }
  1211. #endregion
  1212. int recordCount = 0;
  1213. if (!string.IsNullOrWhiteSpace(sql))
  1214. {
  1215. dt = BLL.PagerBLL.GetListPager(
  1216. "T_Wo_WorkOrder",
  1217. "F_ID",
  1218. "*",
  1219. sql,
  1220. "ORDER BY T_Wo_WorkOrder.F_ID desc",
  1221. pagesize,
  1222. pageindex,
  1223. true,
  1224. out recordCount);
  1225. }
  1226. List<Model.T_Wo_WorkOrder> modlelist = new BLL.T_Wo_WorkOrder().DataTableToList(dt);
  1227. if (modlelist.Count > 0)
  1228. {
  1229. List<WorkOrderNewInput> Input = modeltooip(modlelist, ua,state);
  1230. var obj = new
  1231. {
  1232. state = "success",
  1233. message = "成功",
  1234. rows = Input,
  1235. total = recordCount
  1236. };
  1237. return Content(obj.ToJson()); ;
  1238. }
  1239. else
  1240. {
  1241. return Success("暂无工单"); ;
  1242. }
  1243. }
  1244. else
  1245. {
  1246. return Success("暂无工单"); ;
  1247. }
  1248. }
  1249. /// <summary>
  1250. /// 指派工单时撤回
  1251. /// </summary>
  1252. /// <param name="usercode"></param>
  1253. /// <returns></returns>
  1254. public string GetRevokeWo(string usercode, int flag = 0)
  1255. {
  1256. string str = string.Empty;
  1257. str = $"Select F_WoID from T_Wo_WorkOrderItem_New where F_IsUsed=0 and F_OptType=" + (int)EnumItemOpt.assign +
  1258. $" and F_CreateUser='{usercode}' group by F_WoID HAVING COUNT(*) >{flag}";
  1259. var modetab = DbHelperSQL.Query(str).Tables[0];
  1260. var modelarray = modetab.AsEnumerable().Select(c => c.Field<long>("F_WoID")).ToArray(); ;
  1261. str = string.Join(",", modelarray);
  1262. return str;
  1263. }
  1264. public string GetDeptUserCode(int deptid)
  1265. {
  1266. string deptuser = string.Empty;
  1267. var dept = userAccountBLL .GetModelList("F_DeptId=" + deptid);
  1268. if (dept != null)
  1269. {
  1270. foreach (var it in dept)
  1271. {
  1272. if (deptuser != "")
  1273. deptuser += "," + it.F_UserCode;
  1274. else
  1275. deptuser += it.F_UserCode;
  1276. }
  1277. }
  1278. return deptuser;
  1279. }
  1280. /// <summary>
  1281. /// 市场管理科 和质量管理科可以看到整个事业部的工单
  1282. /// </summary>
  1283. /// <param name="deptid"></param>
  1284. /// <param name="pdeptid"></param>
  1285. /// <returns></returns>
  1286. public string GetAllDepts(int deptid)
  1287. {
  1288. string sql = " F_State=1 ";
  1289. string dptcode = departmentBLL.GetModel(deptid).F_ParentCode;
  1290. string arrsql = " select F_DeptId from T_Sys_Department where F_DeptCode LIKE '" + dptcode + "%' ";
  1291. var deptlist = departmentBLL.GetModelList(sql).Select(p => p.F_DeptId).ToArray();
  1292. if (deptlist.Count() > 0)
  1293. return string.Join(",", deptlist);
  1294. else return "";
  1295. }
  1296. /// <summary>
  1297. /// 市场管理科 和质量管理科可以看到整个事业部的工单
  1298. /// </summary>
  1299. /// <param name="deptid"></param>
  1300. /// <returns></returns>
  1301. public string GetDeptAllWorkOrderID(int deptid)
  1302. {
  1303. string sql = " ";
  1304. string dptcode = departmentBLL.GetModel(deptid).F_ParentCode;
  1305. string arrsql = $"select F_DeptId from T_Sys_Department where F_DeptCode LIKE '" + dptcode + "%' ";
  1306. string ua = $"select F_UserCode from T_Sys_UserAccount where F_DeptId in ( " + arrsql + ") ";
  1307. sql = "select F_WoID from T_Wo_WorkOrderItem_New where (F_CreateUser in(" + ua + ") or F_NextDept in(" + arrsql + "))";
  1308. return sql;
  1309. }
  1310. /// <summary>
  1311. /// 高层可以看到本事业部的所有工单
  1312. /// </summary>
  1313. /// <param name="deptid"></param>
  1314. /// <returns></returns>
  1315. public string judgmentDept(int deptid)
  1316. {
  1317. string deptcode = "";
  1318. string sql = "";
  1319. if (CirculMarket(deptid, 11))
  1320. {
  1321. deptcode = "|0|1|11|";
  1322. }
  1323. else if (CirculMarket(deptid, 14))
  1324. {
  1325. deptcode = "|0|1|14|";
  1326. }
  1327. else if (CirculMarket(deptid, 15))
  1328. {
  1329. deptcode = "|0|1|15|";
  1330. }
  1331. else if (CirculMarket(deptid, 16))
  1332. {
  1333. deptcode = "|0|1|16|";
  1334. }
  1335. else if (CirculMarket(deptid, 18))
  1336. {
  1337. deptcode = "|0|1|18|";
  1338. }
  1339. else if (CirculMarket(deptid, 20))
  1340. {
  1341. deptcode = "|0|1|20|";
  1342. }
  1343. if (!string.IsNullOrEmpty(deptcode))
  1344. {
  1345. string arrsql = $"select F_DeptId from T_Sys_Department where F_DeptCode LIKE '" + deptcode + "%' ";
  1346. string ua = $"select F_UserCode from T_Sys_UserAccount where F_DeptId in ( " + arrsql + ") ";
  1347. sql = "select F_WoID from T_Wo_WorkOrderItem_New where (F_CreateUser in(" + ua + ") or F_NextDept in(" + arrsql + "))";
  1348. }
  1349. return sql;
  1350. }
  1351. /// <summary>
  1352. /// 找到事业部中的高层
  1353. /// </summary>
  1354. /// <param name="deptid"></param>
  1355. /// <returns></returns>
  1356. public int GetGCDept(int deptid)
  1357. {
  1358. string deptcode = "";
  1359. int gcdeptid = 0;
  1360. if (CirculMarket(deptid, 11))
  1361. {
  1362. deptcode = "|0|1|11|";
  1363. }
  1364. else if (CirculMarket(deptid, 14))
  1365. {
  1366. deptcode = "|0|1|14|";
  1367. }
  1368. else if (CirculMarket(deptid, 15))
  1369. {
  1370. deptcode = "|0|1|15|";
  1371. }
  1372. else if (CirculMarket(deptid, 16))
  1373. {
  1374. deptcode = "|0|1|16|";
  1375. }
  1376. else if (CirculMarket(deptid, 18))
  1377. {
  1378. deptcode = "|0|1|18|";
  1379. }
  1380. else if (CirculMarket(deptid, 20))
  1381. {
  1382. deptcode = "|0|1|20|";
  1383. }
  1384. if (!string.IsNullOrEmpty(deptcode))
  1385. {
  1386. var dept = departmentBLL.GetModelList($" F_DeptCode LIKE '" + deptcode + "%' and F_DeptName like '%总经理%'").FirstOrDefault();
  1387. if (dept != null)
  1388. gcdeptid = dept.F_DeptId;
  1389. }
  1390. return gcdeptid;
  1391. }
  1392. /// <summary>
  1393. ///综合查询列表
  1394. /// </summary>
  1395. public ActionResult GetComprehensive(string description,string OpenId, string code, string createby, string createtel, string cusname, string keywords, string cusphone, string companyname, string province, string city,
  1396. 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)
  1397. {
  1398. if (!string.IsNullOrEmpty(OpenId))
  1399. {
  1400. // Model.T_Sys_UserAccount ua = userAccountBLL.GetModel(userId);
  1401. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  1402. // if (ua == null)
  1403. // {
  1404. // return Error("你的账号已在别处登录,你确定要再次登录吗?");
  1405. // }
  1406. string sql = $" and F_IsDelete=0";
  1407. DataTable dt = new DataTable();
  1408. #region 筛选条件
  1409. if (type > 0 && type < 6)//工单类型
  1410. sql += $" and F_Type=" + type;
  1411. if (state >= 0)//
  1412. {
  1413. if (state == 5)
  1414. {
  1415. sql += $" and F_State in (2,3,4,5)";
  1416. }
  1417. else if (state == 6)
  1418. {
  1419. sql += $" and F_State in (11)";
  1420. sql += $" and F_IsVisit=" + 1; ;
  1421. sql += $"and F_DealType != '当即办理' and F_VisitBy != ''";
  1422. }
  1423. else if (state == 10)
  1424. {
  1425. sql += $" and F_State in (10,11)";
  1426. }
  1427. else if (state == 12)
  1428. {
  1429. sql += $" and F_State=" + (int)EnumWorkOrderState.finish + " and F_IsVisit = '" + "1" + "' ";
  1430. }
  1431. else
  1432. {
  1433. sql += $" and F_State=" + state;
  1434. }
  1435. }
  1436. if (source > 0)//工单来源
  1437. {
  1438. if (source == 1)
  1439. sql += $" and F_Source in (1,'')";
  1440. else
  1441. sql += $" and F_Source='" + source + "'";
  1442. }
  1443. if (!string.IsNullOrWhiteSpace(createby))//创建人
  1444. {
  1445. sql += $" and F_CustomerID in(select F_CustomerCode from T_Cus_CustomerBaseNew where F_Salesman like '%" + createby + "%' and F_IsDelete =0) ";
  1446. }
  1447. if (!string.IsNullOrWhiteSpace(createtel))//创建人
  1448. {
  1449. sql += $" and F_CustomerID in(select F_CustomerCode from T_Cus_CustomerBaseNew where F_SalesPhone like '%" + createtel + "%' and F_IsDelete =0) ";
  1450. }
  1451. if (!string.IsNullOrWhiteSpace(description))//问题描述
  1452. sql += $" and F_Description like '%" + description.Trim() + "%'";
  1453. if (!string.IsNullOrWhiteSpace(createby))//创建人
  1454. sql += $" and F_CreateBy like '%" + createby.Trim() + "%'";
  1455. if (!string.IsNullOrWhiteSpace(touser))//参与人
  1456. sql += $" and F_DealBy like '%" + touser.Trim() + "%'";
  1457. if (!string.IsNullOrWhiteSpace(code))//工单编号
  1458. sql += $" and F_WorkOrderCode like '%" + code.Trim() + "%'";
  1459. if (!string.IsNullOrWhiteSpace(keywords))//关键字搜索
  1460. {
  1461. var QuestionManage = quesBLL.GetModelList("F_QuestionName like '%" + keywords + "%' and F_IsDelete=0");
  1462. if (QuestionManage != null)
  1463. {
  1464. if (QuestionManage.FirstOrDefault().F_Type == EnumWOType.Complaint.ToString())
  1465. {
  1466. if (QuestionManage.FirstOrDefault().F_Label == "3")
  1467. {
  1468. string queststrs = string.Format("'{0}'", string.Join(",", QuestionManage.Select(T => T.F_Id)).Replace(",", "','"));
  1469. sql += $" and T_Wo_WorkOrder.F_QuestionType in (" + queststrs + ")";
  1470. }
  1471. else if (QuestionManage.FirstOrDefault().F_Label == "2")
  1472. {
  1473. sql += $" and T_Wo_WorkOrder.F_QuestionType in ('" + GetComplaint(keywords, 1) + "')"; ;
  1474. }
  1475. else
  1476. {
  1477. sql += $" and T_Wo_WorkOrder.F_QuestionType in ('" + GetComplaint(keywords, 0) + "')"; ;
  1478. }
  1479. }
  1480. else
  1481. {
  1482. sql += $" and (T_Wo_WorkOrder.F_QuestionType in (" + string.Join(",", QuestionManage.Select(t => t.F_Id).ToArray()) + ") or T_Wo_WorkOrder.F_QuestionType like '%" + keywords + "%')";
  1483. }
  1484. }
  1485. }
  1486. //sql += $" and ( F_QuestionType like '%" + keywords.Trim()
  1487. // + "%' or F_ZX_Area like '%" + keywords.Trim() + "%' or F_ZX_Branch like '%" + keywords.Trim()
  1488. // + "%' or F_CusName like '%" + keywords.Trim() + "%'or F_CusPhone like '%" + keywords.Trim() + "%') ";
  1489. if (!string.IsNullOrWhiteSpace(cusname))//客户姓名
  1490. sql += $" and F_CusName like '%" + cusname.Trim() + "%'";
  1491. if (!string.IsNullOrWhiteSpace(cusphone))//客户电话
  1492. sql += $" and F_CusPhone like '%" + cusphone.Trim() + "%'";
  1493. if (!string.IsNullOrWhiteSpace(companyname))//公司名称
  1494. sql += $" and F_CompanyName like '%" + companyname.Trim() + "%'";
  1495. if (!string.IsNullOrWhiteSpace(category))//产品名称
  1496. sql += $" and F_TS_Category like '%" + category.Trim() + "%'";
  1497. if (!string.IsNullOrWhiteSpace(salebase))//销售基地
  1498. sql += $" and F_SalesBase like '%" + salebase.Trim() + "%'";
  1499. if (!string.IsNullOrWhiteSpace(province))//省
  1500. sql += $" and F_IncidentProvince like '%" + province.Trim() + "%'";
  1501. if (!string.IsNullOrWhiteSpace(city))//市
  1502. sql += $" and F_IncidentCity like '%" + city.Trim() + "%'";
  1503. if (!string.IsNullOrWhiteSpace(country))//县
  1504. sql += $" and F_IncidentCountry like '%" + country.Trim() + "%'";
  1505. if (!string.IsNullOrWhiteSpace(township))//乡
  1506. sql += $" and F_IncidentTownship like '%" + township.Trim() + "%'";
  1507. if (ua != null)
  1508. {
  1509. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  1510. if (ro.F_RoleCode == "QTJS" || ro.F_RoleCode == "YWY")
  1511. {
  1512. sql += $" and F_CreateBy like '%" + ua.F_UserCode.Trim() + "%'";
  1513. }
  1514. else if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "BLRY" || ro.F_RoleCode == "ZG" || ro.F_RoleCode == "GC")
  1515. {
  1516. string markdepts = "37,57,74,88,268,295,339,422,213,427,433";
  1517. string qualdepts = "12,36,295,245";
  1518. string detpid = "" + ua.F_DeptId;
  1519. var deparmentlist = new List<Model.T_Sys_Department>();
  1520. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  1521. if (dModel != null)
  1522. {
  1523. #region 工单查询- 综合查询模块,权限增加,市场部和质管部可以看到事业部所有的工单,包含未经办的 20220519
  1524. if (markdepts.Contains(ua.F_DeptId.ToString()) || qualdepts.Contains(ua.F_DeptId.ToString()))
  1525. {
  1526. //detpid += "," + GetAllDepts(ua.F_DeptId);
  1527. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptAllWorkOrderID(ua.F_DeptId) + ") ";
  1528. }
  1529. #endregion
  1530. #region 高层可以看到本事业部的所有工单
  1531. else if (ro.F_RoleCode == "GC")
  1532. {
  1533. string strsq = judgmentDept(ua.F_DeptId);
  1534. if (!string.IsNullOrEmpty(strsq))
  1535. {
  1536. sql += $" and T_Wo_WorkOrder.F_ID in ( " + strsq + ") ";
  1537. }
  1538. else
  1539. {
  1540. sql += $" and 1!=1";
  1541. }
  1542. }
  1543. #endregion
  1544. else
  1545. {
  1546. if (dModel.F_Layer == 1)
  1547. {
  1548. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  1549. if (deparmentlist.Count > 0)
  1550. {
  1551. foreach (var it in deparmentlist)
  1552. {
  1553. if (detpid != "")
  1554. {
  1555. detpid += "," + it.F_DeptId;
  1556. }
  1557. else
  1558. {
  1559. detpid = "" + it.F_DeptId;
  1560. }
  1561. }
  1562. }
  1563. }
  1564. else
  1565. {
  1566. detpid = ua.F_DeptId.ToString();
  1567. }
  1568. #region 人员更换部门后,仍然需要查看、处理自己原部门的历史工单 20220307
  1569. //if (!string.IsNullOrEmpty(ua.F_Origdepts))
  1570. //{
  1571. // detpid += "," + ua.F_Origdepts;
  1572. //}
  1573. #endregion
  1574. if (state >= 0)
  1575. {
  1576. if (GetDeptWorkOrderID(detpid, "" + state + "") != "")
  1577. {
  1578. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid, "" + state + "") + ") ";
  1579. }
  1580. else
  1581. {
  1582. return Success("暂无工单"); ;
  1583. }
  1584. }
  1585. else
  1586. {
  1587. if (GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.neworder + ", " + (int)EnumWorkOrderState.assign + "," +
  1588. (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.finish
  1589. + "," + (int)EnumWorkOrderState.evaluate + "") != "")
  1590. {
  1591. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.neworder + ", " + (int)EnumWorkOrderState.assign + "," +
  1592. (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.finish
  1593. + "," + (int)EnumWorkOrderState.evaluate + "") + ") ";
  1594. }
  1595. else
  1596. {
  1597. return Success("暂无工单"); ;
  1598. }
  1599. }
  1600. }
  1601. }
  1602. else
  1603. {
  1604. return Error("加载失败");
  1605. }
  1606. }
  1607. }
  1608. else
  1609. {
  1610. return Error("无操作权限");
  1611. }
  1612. #endregion
  1613. int recordCount = 0;
  1614. if (!string.IsNullOrWhiteSpace(sql))
  1615. {
  1616. dt = BLL.PagerBLL.GetListPager(
  1617. "T_Wo_WorkOrder",
  1618. "F_ID",
  1619. "*",
  1620. sql,
  1621. "ORDER BY T_Wo_WorkOrder.F_ID desc",
  1622. pagesize,
  1623. pageindex,
  1624. true,
  1625. out recordCount);
  1626. }
  1627. List<Model.T_Wo_WorkOrder> modlelist = new BLL.T_Wo_WorkOrder().DataTableToList(dt);
  1628. if (modlelist.Count > 0)
  1629. {
  1630. List<WorkOrderNewInput> Input = modeltooip(modlelist, ua);
  1631. var obj = new
  1632. {
  1633. state = "success",
  1634. message = "成功",
  1635. rows = Input,
  1636. total = recordCount
  1637. };
  1638. return Content(obj.ToJson()); ;
  1639. }
  1640. else
  1641. {
  1642. return Success("暂无工单"); ;
  1643. }
  1644. }
  1645. else
  1646. {
  1647. return Error("无操作权限!");
  1648. }
  1649. }
  1650. /// <summary>
  1651. /// 获取问题类别
  1652. /// </summary>
  1653. /// <returns></returns>
  1654. public string GetComplaint(string msg, int type = 0)
  1655. {
  1656. string str = "";
  1657. string str1 = "";
  1658. string str3 = "";
  1659. if (type == 0)
  1660. {
  1661. str1 = " select F_Id from T_Wo_QuestionManage where F_QuestionName like '%"+ msg +"%'";
  1662. str3 = " select F_Id from T_Wo_QuestionManage where F_ParentId in(" + str1 + ")";
  1663. }
  1664. else if (type == 1)
  1665. {
  1666. str3 = " select F_Id from T_Wo_QuestionManage where F_QuestionName like '%" + msg + "%'";
  1667. }
  1668. var dept = quesBLL.GetModelList("F_ParentId in(" + str3 + ")");
  1669. if (dept != null)
  1670. {
  1671. foreach (var it in dept)
  1672. {
  1673. if (str != "")
  1674. str += "','" + it.F_Id.ToString();
  1675. else
  1676. str += it.F_Id.ToString();
  1677. }
  1678. }
  1679. // string str4 = " select F_Id from T_Wo_QuestionManage where F_ParentId in(" + str3 + ")";
  1680. return str;
  1681. }
  1682. /// <summary>
  1683. /// 根据部门获取工单号
  1684. /// </summary>
  1685. /// <returns></returns>
  1686. public string GetDeptWorkOrderID(string user)
  1687. {
  1688. string sql = " ";
  1689. string ua = "";
  1690. DataTable dt = new DataTable();
  1691. if (user != "")
  1692. {
  1693. sql += " and F_DeptId in ( " + user + ") ";
  1694. }
  1695. int recordCount;
  1696. dt = BLL.PagerBLL.GetListPager(
  1697. "T_Sys_UserAccount",
  1698. "F_UserId",
  1699. "*",
  1700. sql,
  1701. "ORDER BY F_UserId desc",
  1702. 10000,
  1703. 1,
  1704. true,
  1705. out recordCount);
  1706. List<Model.UserAccount> modelList = new BLL.UserAccount().DataTableToList(dt);
  1707. if (modelList != null)
  1708. {
  1709. foreach (var it in modelList)
  1710. {
  1711. if (ua != "")
  1712. ua += "," + it.F_UserCode;
  1713. else
  1714. ua += it.F_UserCode;
  1715. }
  1716. }
  1717. string str = string.Empty;
  1718. str = "select F_WoID from T_Wo_WorkOrderItem_New where (F_CreateUser in(" + ua + ") or F_NextDept in(" + user + "))"
  1719. ;
  1720. return str;
  1721. }
  1722. /// <summary>
  1723. /// 根据部门获取工单号
  1724. /// </summary>
  1725. /// <returns></returns>
  1726. public string GetDeptWorkOrderID(string user, string F_ItemType)
  1727. {
  1728. string sql = " ";
  1729. string ua = "";
  1730. DataTable dt = new DataTable();
  1731. if (user != "")
  1732. {
  1733. sql += " and F_DeptId in ( " + user + ") ";
  1734. }
  1735. int recordCount;
  1736. dt = BLL.PagerBLL.GetListPager(
  1737. "T_Sys_UserAccount",
  1738. "F_UserId",
  1739. "*",
  1740. sql,
  1741. "ORDER BY F_UserId desc",
  1742. 10000,
  1743. 1,
  1744. true,
  1745. out recordCount);
  1746. List<Model.UserAccount> modelList = new BLL.UserAccount().DataTableToList(dt);
  1747. if (modelList != null)
  1748. {
  1749. foreach (var it in modelList)
  1750. {
  1751. if (ua != "")
  1752. ua += "," + it.F_UserCode;
  1753. else
  1754. ua += it.F_UserCode;
  1755. }
  1756. }
  1757. string str = string.Empty;
  1758. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_OptType in(" + F_ItemType + ")"
  1759. + " and "
  1760. + "F_CreateUser in(" + ua + ")"
  1761. ;
  1762. return str;
  1763. }
  1764. /// <summary>
  1765. /// 获取完结审批的工单
  1766. /// </summary>
  1767. /// <param name="usercode"></param>
  1768. /// <returns></returns>
  1769. public string GetOverWo(string usercode)
  1770. {
  1771. string str = "";
  1772. str = $"Select F_WoID from T_Wo_WorkOrderItem_New where F_ItemType=" + (int)EnumItemType.deal + " and F_WoState in (" + (int)EnumWorkOrderState.audit + "," + (int)EnumWorkOrderState.finish + ") and F_OptType=" + (int)EnumItemOpt.end + " and F_CreateUser='" + usercode + "'";
  1773. return str;
  1774. }
  1775. /// <summary>
  1776. /// 获取待完成的工单编号
  1777. /// </summary>
  1778. /// <returns></returns>
  1779. public string GetDWCWorkOrderID(string user, int deptid, int flag = 1)
  1780. {
  1781. string str = string.Empty;
  1782. string strsql = "";
  1783. if (flag == 1)
  1784. {
  1785. strsql = "and F_Type in(1,3)";
  1786. }
  1787. else if (flag == 2)
  1788. {
  1789. strsql = "and F_Type in(2,3)";
  1790. }
  1791. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_ItemType=" + (int)EnumItemType.deal
  1792. + " and "
  1793. + "F_WoState in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.revoke + ") and (F_NextUser like '%" + user + "%' or F_NextDept='" + deptid + "') "//办理中和接单状态的操作人,退回下一步操作人,撤回下一步操作人
  1794. + " and isnull(F_IsUsed,'0')='0'";
  1795. return str;
  1796. }
  1797. public string GetHApproval(string user)
  1798. {
  1799. string str = string.Empty;
  1800. 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";
  1801. return str;
  1802. }
  1803. /// <summary>
  1804. /// 获取部门待完成的工单编号
  1805. /// </summary>
  1806. /// <returns></returns>
  1807. public string GetDeptWorkOrderID(int deptid, string user, int flag = 1)
  1808. {
  1809. string str = string.Empty;
  1810. string deptuser = string.Empty;
  1811. var dept = userAccountBLL.GetModelList("F_DeptId=" + deptid);
  1812. if (dept != null)
  1813. {
  1814. foreach (var it in dept)
  1815. {
  1816. //if (it.F_UserCode != user)
  1817. //{
  1818. if (deptuser != "")
  1819. deptuser += "','" + it.F_UserCode;
  1820. else
  1821. deptuser += it.F_UserCode;
  1822. //}
  1823. }
  1824. }
  1825. if (!string.IsNullOrEmpty(deptuser))
  1826. {
  1827. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_ItemType=" + (int)EnumItemType.deal
  1828. + " and isnull(F_IsUsed,'0')='0'" + " and "
  1829. + " F_WoState in(" + (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.abreback + ") and (F_NextUser in('" + deptuser + "') or F_NextDept =" + deptid + ") ";//办理中和接单状态的操作人
  1830. }
  1831. else
  1832. {
  1833. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_ItemType=" + (int)EnumItemType.deal
  1834. + " and F_WoState in(" + (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.abreback + ") and F_NextDept =" + deptid + " "//办理中和接单状态的操作人
  1835. + " and isnull(F_IsUsed,'0')='0'";
  1836. }
  1837. return str;
  1838. }
  1839. /// <summary>
  1840. /// 获取工单数量
  1841. /// </summary>
  1842. /// <returns></returns>
  1843. public ActionResult GetWorkCount(string OpenId)
  1844. {
  1845. if (string .IsNullOrEmpty (OpenId) )
  1846. return Success ("你的账号已在别处登录,你确定要再次登录吗?");
  1847. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  1848. if (ua == null)
  1849. {
  1850. return Success("你的账号已在别处登录,你确定要再次登录吗?");
  1851. }
  1852. DataTable dt = new DataTable();
  1853. #region 筛选条件
  1854. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  1855. string uwhere = " ";
  1856. string sql = "";
  1857. //if (!Refresh())
  1858. //{
  1859. // return Error("查询失败");
  1860. //}
  1861. Task.Run(() => Refresh());
  1862. int YCD = 0, DJD = 0, DCL = 0, DSP = 0, YCL = 0, GCDBL = 0, YBL = 0, CQGD = 0, TD = 0,YFP=0, ZHCX = 0, CSGD=0;
  1863. for (int i = 0; i <= 9; i++)
  1864. {
  1865. switch (i)
  1866. {
  1867. case 0://待接单的
  1868. sql = "";
  1869. sql += $" F_IsDelete=0";
  1870. string strsql = GetDeptWorkOrderID(ua.F_DeptId, ua.F_UserCode, ua.F_Flag);
  1871. if (strsql != "")
  1872. {
  1873. //if (ua.F_Flag == 1)
  1874. //{
  1875. sql += $" and (F_State in(" + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.assign + ") ";
  1876. //}
  1877. //else if (ua.F_Flag == 2)
  1878. //{
  1879. sql += $" or F_State2 in(" + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.assign + ")) ";
  1880. //}
  1881. sql += " and T_Wo_WorkOrder.F_ID in ( " + strsql + ")";
  1882. }
  1883. else
  1884. {
  1885. DJD = 0;
  1886. break;
  1887. }
  1888. DJD = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//接单
  1889. break;
  1890. case 1://待完成的(待处理)
  1891. sql = "";
  1892. sql += $" F_IsDelete=0";
  1893. string dealstr = GetDWCWorkOrderID(ua.F_UserCode, ua.F_DeptId);
  1894. if (!string.IsNullOrEmpty(dealstr))
  1895. {
  1896. //if (ua.F_Flag == 1)
  1897. //{
  1898. sql += " and ((F_State in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.revoke + ")";
  1899. //}
  1900. //else if (ua.F_Flag == 2)
  1901. //{
  1902. sql += " or F_State2 in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.revoke + "))";
  1903. //}
  1904. sql += " and T_Wo_WorkOrder.F_ID in ( " + dealstr + ") ";
  1905. if (!string.IsNullOrEmpty(GetRevokeWo(ua.F_UserCode)))
  1906. {
  1907. sql += " or ((F_State=" + (int)EnumWorkOrderState.assign + " or F_State2=" + (int)EnumWorkOrderState.assign + ") and T_Wo_WorkOrder.F_ID in (" + GetRevokeWo(ua.F_UserCode) + ")))";
  1908. }
  1909. else
  1910. {
  1911. sql += $")";
  1912. }
  1913. }
  1914. else
  1915. {
  1916. DCL = 0;
  1917. break;
  1918. }
  1919. DCL = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//已接单
  1920. break;
  1921. case 2://已完成的
  1922. sql = "";
  1923. sql += $" F_IsDelete=0";
  1924. //sql += " and (F_State in(10,11) or F_State2 in(10,11))";
  1925. sql += " and (((F_State in(10,11) and isnull(F_Flag,0)=0 ) or (F_Flag=2 and F_State2 in(10,11)) or (F_Flag=1 and F_State in(10,11)) or (F_Flag=3 and(F_State in(10,11) or F_State2 in(10,11))))";
  1926. sql += " and F_DealBy in(" + GetDeptUserCode(ua.F_DeptId) + ") ";
  1927. sql += " or T_Wo_WorkOrder.F_ID in (" + GetOverWo(ua.F_UserCode) + "))";
  1928. // sql += " and F_State in(10,11) and F_DealBy = '" + ua.F_UserCode + "' ";
  1929. YCL = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//已完成的
  1930. break;
  1931. case 3://待审批
  1932. sql = "";
  1933. sql += $" F_IsDelete=0";
  1934. if (ro.F_RoleCode == "GC")
  1935. {
  1936. if (GetHApproval(ua.F_UserCode) != "")
  1937. {
  1938. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetHApproval(ua.F_UserCode) + ") "; ;
  1939. }
  1940. }
  1941. else
  1942. {
  1943. GCDBL = 0;
  1944. break; ;
  1945. }
  1946. GCDBL = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//高层待审批
  1947. break;
  1948. case 4://已审批
  1949. sql = "";
  1950. sql += $" F_IsDelete=0";
  1951. if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "GC")
  1952. {
  1953. if (GetApprovedOrderID(ua.F_UserCode) != "")
  1954. {
  1955. sql += $" and F_ID in ( " + GetApprovedOrderID(ua.F_UserCode) + ") "; ;
  1956. }
  1957. else
  1958. {
  1959. YBL = 0;
  1960. break; ;
  1961. }
  1962. }
  1963. else
  1964. {
  1965. YBL = 0;
  1966. break; ;
  1967. }
  1968. YBL = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//已审批
  1969. break;
  1970. case 5://待审批
  1971. sql = "";
  1972. sql += $" F_IsDelete=0";
  1973. if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL")
  1974. {
  1975. if (GetApprovalOrderID(ua, OpenId, ro.F_RoleCode) != "")
  1976. {
  1977. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetApprovalOrderID(ua, OpenId, ro.F_RoleCode) + ") ";
  1978. }
  1979. else
  1980. {
  1981. DSP = 0;
  1982. break; ;
  1983. }
  1984. }
  1985. else
  1986. {
  1987. DSP = 0;
  1988. break; ;
  1989. }
  1990. DSP = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//待审批
  1991. break;
  1992. case 6:
  1993. sql = "";
  1994. sql += $" F_IsDelete=0";
  1995. sql += $" and F_CreateBy ='" + ua.F_UserCode + "'";
  1996. YCD = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//业务员已创单
  1997. break;
  1998. case 7://超期
  1999. sql = "";
  2000. sql += $" F_IsDelete=0";
  2001. //sql += $" and (F_IsOver=1 or F_IsOver=2)";
  2002. //sql += $" and F_State !=" + 11;
  2003. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "JDYBZZX" || ro.F_RoleCode == "XTGLY")
  2004. {
  2005. sql += $" and((F_IsOver in(1,3) and F_State !=11) or ( F_IsOver in (2,3) and F_State2!=11))";
  2006. }
  2007. else if (ua.F_Flag == 1)
  2008. {
  2009. sql += $" and F_IsOver in (1,3)";
  2010. sql += $" and F_State !=" + 11;
  2011. }
  2012. else if (ua.F_Flag == 2)
  2013. {
  2014. sql += $" and F_IsOver in (2,3)";
  2015. sql += $" and F_State2 !=" + 11;
  2016. }
  2017. #region 退换货的工单按未超期处理 20220302
  2018. sql += $" and F_ID not in (select F_ID from T_Wo_WorkOrder where F_SC_PreliminaryOpinion='退换货')";
  2019. #endregion
  2020. if (ro.F_RoleCode == "YWY" || ro.F_RoleCode == "BLRY")
  2021. {
  2022. sql += $" and F_DealBy like '%" + ua.F_UserCode.Trim() + "%'";
  2023. }
  2024. else if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "ZG")
  2025. {
  2026. string detpid = "" + ua.F_DeptId;
  2027. var deparmentlist = new List<Model.T_Sys_Department>();
  2028. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  2029. if (dModel != null)
  2030. {
  2031. if (dModel.F_Layer == 1)
  2032. {
  2033. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  2034. if (deparmentlist.Count > 0)
  2035. {
  2036. foreach (var it in deparmentlist)
  2037. {
  2038. if (detpid != "")
  2039. {
  2040. detpid += "," + it.F_DeptId;
  2041. }
  2042. else
  2043. {
  2044. detpid = "" + it.F_DeptId; ;
  2045. }
  2046. }
  2047. }
  2048. }
  2049. else
  2050. {
  2051. detpid = ua.F_DeptId.ToString();
  2052. }
  2053. if (GetDeptWorkOrderID(detpid) != "")
  2054. {
  2055. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid) + ") "; ;
  2056. }
  2057. else
  2058. {
  2059. CQGD = 0;
  2060. break; ;
  2061. }
  2062. }
  2063. else
  2064. {
  2065. CQGD = 0;
  2066. break; ;
  2067. }
  2068. }
  2069. else if (ro.F_RoleCode == "QTJS")
  2070. {
  2071. CQGD = 0;
  2072. break; ;
  2073. }
  2074. CQGD = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//超期
  2075. break;
  2076. case 8://综合查询
  2077. sql = "";
  2078. sql += $" F_IsDelete=0";
  2079. if (ro.F_RoleCode == "QTJS" || ro.F_RoleCode == "YWY")
  2080. sql += $" and F_CreateBy like '%" + ua.F_UserCode.Trim() + "%'";
  2081. else if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "BLRY" || ro.F_RoleCode == "ZG" || ro.F_RoleCode == "GC")
  2082. {
  2083. string markdepts = "37,57,74,88,268,295,339,422,213,427,433";
  2084. string qualdepts = "12,36,295,245";
  2085. string detpid = "" + ua.F_DeptId;
  2086. var deparmentlist = new List<Model.T_Sys_Department>();
  2087. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  2088. if (dModel != null)
  2089. {
  2090. #region 工单查询- 综合查询模块,权限增加,市场部和质管部可以看到事业部所有的工单,包含未经办的 20220519
  2091. if (markdepts.Contains(ua.F_DeptId.ToString()) || qualdepts.Contains(ua.F_DeptId.ToString()))
  2092. {
  2093. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptAllWorkOrderID(ua.F_DeptId) + ") ";
  2094. }
  2095. #endregion
  2096. #region 高层可以看到本事业部的所有工单
  2097. else if (ro.F_RoleCode == "GC")
  2098. {
  2099. string strsq = judgmentDept(ua.F_DeptId);
  2100. if (!string.IsNullOrEmpty(strsq))
  2101. {
  2102. sql += $" and T_Wo_WorkOrder.F_ID in ( " + strsq + ") ";
  2103. }
  2104. else
  2105. {
  2106. sql += $" and 1!=1";
  2107. }
  2108. }
  2109. #endregion
  2110. else
  2111. {
  2112. if (dModel.F_Layer == 1)
  2113. {
  2114. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  2115. if (deparmentlist.Count > 0)
  2116. {
  2117. foreach (var it in deparmentlist)
  2118. {
  2119. if (detpid != "")
  2120. {
  2121. detpid += "," + it.F_DeptId;
  2122. }
  2123. else
  2124. {
  2125. detpid = "" + it.F_DeptId;
  2126. }
  2127. }
  2128. }
  2129. }
  2130. else
  2131. {
  2132. detpid = ua.F_DeptId.ToString();
  2133. }
  2134. #region 人员更换部门后,仍然需要查看、处理自己原部门的历史工单 20220307
  2135. //if (!string.IsNullOrEmpty(ua.F_Origdepts))
  2136. //{
  2137. // detpid += "," + ua.F_Origdepts;
  2138. //}
  2139. #endregion
  2140. if (GetDeptWorkOrderID(detpid) != "")
  2141. {
  2142. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid) + ") ";
  2143. }
  2144. else
  2145. {
  2146. ZHCX = 0;
  2147. break;
  2148. }
  2149. }
  2150. }
  2151. else
  2152. {
  2153. ZHCX = 0;
  2154. break;
  2155. }
  2156. }
  2157. ZHCX = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//综合查询
  2158. break;
  2159. case 9: //抄送工单列表
  2160. sql = "";
  2161. sql += $" F_IsDelete=0";
  2162. sql += $" and T_Wo_WorkOrder.F_ID in (select F_WorkOrderID from T_Wo_WorkCopy where F_SendCopyUser like '%{ua.F_UserCode}%'"
  2163. +$" or (F_Flag=1 and F_SendCopyDepts={ua.F_DeptId} )) ";
  2164. CSGD = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;
  2165. break;
  2166. }
  2167. }
  2168. #endregion
  2169. var obj = new
  2170. {
  2171. state = "success",
  2172. message = "成功",
  2173. DJD = DJD,//待接单
  2174. DCL = DCL,//已接单(待处理)
  2175. YCL = YCL,//已完成的
  2176. GCDBL = GCDBL,//高层待审批
  2177. YBL = YBL,//已审批
  2178. DSP = DSP,//待审批
  2179. YCD = YCD,//业务员已创单
  2180. TD = TD,//退单
  2181. CQGD = CQGD,//超期
  2182. YFP= YFP,
  2183. ZHCX= ZHCX , //综合查询
  2184. CSGD= CSGD
  2185. };
  2186. return Content(obj.ToJson()); ;
  2187. }
  2188. /// <summary>
  2189. /// 注解
  2190. /// </summary>
  2191. /// <param name="orderid"></param>
  2192. /// <param name="cont"></param>
  2193. /// <returns></returns>
  2194. public ActionResult Annotation(string OpenId, int orderid, string cont, int flag = 0)
  2195. {
  2196. //注解给超级管理员开通编辑删除修改权限 20220221
  2197. if (!string.IsNullOrEmpty(OpenId))
  2198. {
  2199. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  2200. if (ua != null)
  2201. {
  2202. string Annotationstr = "";
  2203. Model.T_Wo_WorkOrder model = woBLL .GetModel(orderid);
  2204. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  2205. //验证信息
  2206. if (model != null)
  2207. {
  2208. #region 添加注解表
  2209. //Model.T_Wo_AnnotationTab annotab = new T_Wo_AnnotationTab();
  2210. //annotab.F_Contents = cont;
  2211. //annotab.F_AnnotationPerson = ua.F_UserCode;
  2212. //annotab.F_CreateTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  2213. //annotab.F_Wocode = model.F_ID;
  2214. //new BLL.T_Wo_AnnotationTab().Add(annotab);
  2215. #endregion
  2216. //Annotationstr = cont + "-" + ua.F_UserName + "(" + ua.F_WorkNumber + ")" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2217. Annotationstr = ua.F_UserName + "(" + ua.F_WorkNumber + ")" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + cont + ";";
  2218. if (flag == 1)
  2219. {
  2220. model.F_Annotation = Annotationstr;
  2221. }
  2222. else
  2223. {
  2224. if (string.IsNullOrEmpty(model.F_Annotation))
  2225. {
  2226. model.F_Annotation = Annotationstr;
  2227. }
  2228. else
  2229. {
  2230. model.F_Annotation = model.F_Annotation + "\n" + Annotationstr;
  2231. }
  2232. }
  2233. var res = woBLL.Update(model);
  2234. if (res)
  2235. #region 增加注解通知市场部功能 20220216
  2236. {
  2237. string touser = "";
  2238. string strwhere = "";
  2239. string contens = "";
  2240. strwhere = $" F_DeptId in (select top 1 F_NextDept from T_Wo_WorkOrderItem_New where F_WoID={model.F_ID} and F_NextDept in(37,57,74,88,268,295,339,422,213,427,433) order by F_CreateTime desc)";
  2241. var deptmodel = departmentBLL.GetModelList(strwhere).FirstOrDefault();
  2242. if (deptmodel != null)
  2243. {
  2244. var userlist = userAccountBLL.GetModelList("F_DeptId=" + deptmodel.F_DeptId);
  2245. if (userlist.Count > 0)
  2246. {
  2247. if (flag == 1)
  2248. contens = $" 修改注解,工单编号 <a href='./WorkOrder/commonHtml/orderDetails.html?oid={model.F_ID}'>" + model.F_WorkOrderCode + "</a>";
  2249. //< span class="top_notices_con">系统维护管理员 修改注解, 工单编号 20220527152927398</span>
  2250. else
  2251. contens = $" 附加注解,工单编号 <a href='./WorkOrder/commonHtml/orderDetails.html?oid={model.F_ID}'>" + model.F_WorkOrderCode + "</a>";
  2252. foreach (var item in userlist)
  2253. {
  2254. touser = item.F_UserCode; ;
  2255. Model.T_Msg_List msg = new Model.T_Msg_List();
  2256. msg.Type = (int)Model.MSGType.Annotation;
  2257. msg.ToUser = touser;
  2258. msg.ToID = (int)model.F_ID;
  2259. msg.Detail = $"<span class='top_notices_con'> " + ua.F_UserName + contens + "</span>";
  2260. msg.State = 0;
  2261. msg.IsDel = 0;
  2262. msg.CreateDate = DateTime.Now;
  2263. msg.ReadDate = DateTime.Now;
  2264. new BLL.T_Msg_List().Add(msg);
  2265. //sendsysmsg(model, ua, touser, (int)model.F_ID, "增加注解");
  2266. }
  2267. }
  2268. }
  2269. return Success("注解成功");
  2270. }
  2271. #endregion
  2272. else
  2273. return Error("注解失败!");
  2274. }
  2275. return Error("工单不存在");
  2276. }
  2277. }
  2278. return Error("无操作权限");
  2279. }
  2280. /// <summary>
  2281. /// 抄送工单
  2282. /// </summary>
  2283. /// <param name="id"></param>
  2284. /// <param name="content"></param>
  2285. /// <param name="user"></param>
  2286. /// <returns></returns>
  2287. [WechatActionFilter]
  2288. public ActionResult SendCopy(string OpenId, int id = 0, string content = "", string users = "")
  2289. {
  2290. if (!string.IsNullOrEmpty(OpenId))
  2291. {
  2292. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  2293. if (id <= 0)
  2294. return Error("请选择工单");
  2295. var model = woBLL.GetModel(id);
  2296. if (string.IsNullOrEmpty(users))
  2297. return Error("请选择抄送部门");
  2298. JavaScriptSerializer Serializer = new JavaScriptSerializer(); //实例化⼀个能够序列化数据的类
  2299. List<CopyMessage> list = Serializer.Deserialize<List<CopyMessage>>(users);
  2300. if (model != null)
  2301. {
  2302. string userstr = "";
  2303. string deptmessage = "", deptname1 = "";
  2304. var dept1 = new BLL.T_Sys_Department().GetModel(ua.F_DeptId);
  2305. if (dept1 != null)
  2306. deptname1 = dept1.F_DeptName;
  2307. if (list != null && list.Count > 0)
  2308. {
  2309. foreach (var item in list)
  2310. {
  2311. string username = string.Empty;
  2312. var deptmodel = new BLL.T_Sys_Department().GetModel(Convert.ToInt32(item.deptid));
  2313. if (deptmodel == null)
  2314. return Error("抄送部门不存在!");
  2315. var clus = item.ucodelist;
  2316. Model.T_Wo_WorkCopy t_Wo_WorkCopy = new Model.T_Wo_WorkCopy();
  2317. if (clus.Count > 0)
  2318. {
  2319. t_Wo_WorkCopy.F_Flag = 0;
  2320. t_Wo_WorkCopy.F_SendCopyUser = string.Join(",", clus.ToArray());
  2321. }
  2322. else
  2323. {
  2324. t_Wo_WorkCopy.F_Flag = 1;
  2325. t_Wo_WorkCopy.F_SendCopyUser = "";
  2326. }
  2327. t_Wo_WorkCopy.F_WorkOrderID = model.F_ID;
  2328. t_Wo_WorkCopy.F_CreateOn = DateTime.Now;
  2329. t_Wo_WorkCopy.F_Content = content;
  2330. t_Wo_WorkCopy.F_CreateBy = ua.F_UserId.ToString();
  2331. t_Wo_WorkCopy.F_SendCopyOn = DateTime.Now;
  2332. t_Wo_WorkCopy.F_State = model.F_State;
  2333. t_Wo_WorkCopy.F_SendCopyDepts = Convert.ToInt32(item.deptid);
  2334. if (new BLL.T_Wo_WorkCopy().Add(t_Wo_WorkCopy) > 0)
  2335. {
  2336. #region 发送短信
  2337. int sms = 0;
  2338. if (clus.Count > 0)
  2339. {
  2340. foreach (var noticlus in clus)
  2341. {
  2342. var usermodel = new BLL.T_Sys_UserAccount().GetModel(noticlus);
  2343. username = string.IsNullOrEmpty(username) ? usermodel.F_UserName : username + "," + usermodel.F_UserName;
  2344. string[] mag = { };
  2345. if (!string.IsNullOrEmpty(usermodel.F_Mobile))
  2346. {
  2347. //SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, noticlus.F_Mobile.Trim());
  2348. //bool n = new SMSController().AddSmS(noticlus.F_Mobile.Trim(), "抄送工单", ua.F_UserId);
  2349. }
  2350. }
  2351. }
  2352. else
  2353. {
  2354. var usermodel = new BLL.T_Sys_UserAccount().GetModelList($"F_DeptId={Convert.ToInt32(item.deptid)}");
  2355. if (usermodel.Count > 0)
  2356. {
  2357. foreach (var user in usermodel)
  2358. {
  2359. username = string.IsNullOrEmpty(username) ? user.F_UserName : username + "," + user.F_UserName;
  2360. string[] mag = { };
  2361. if (!string.IsNullOrEmpty(user.F_Mobile))
  2362. {
  2363. //SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, noticlus.F_Mobile.Trim());
  2364. //bool n = new SMSController().AddSmS(noticlus.F_Mobile.Trim(), "抄送工单", ua.F_UserId);
  2365. }
  2366. }
  2367. }
  2368. }
  2369. #endregion
  2370. }
  2371. deptmessage = string.IsNullOrEmpty(deptmessage) ? deptmodel.F_DeptName + "-" + username : deptmessage + ";" + deptmodel.F_DeptName + "-" + username;
  2372. }
  2373. string message = "抄送工单给" + deptmessage;
  2374. if (!string.IsNullOrEmpty(content))
  2375. message += ",抄送内容:" + content;
  2376. AddLog(model.F_ID, model.F_State.Value, deptname1 + ua.F_UserName + "(" + ua.F_WorkNumber + ")" + message, (int)EnumItemType.Copy, (int)EnumItemOpt.Copy, "", 0, ua, 0, 0, "", 1);
  2377. return Success("抄送成功");
  2378. }
  2379. }
  2380. else
  2381. return Error("工单不存在");
  2382. }
  2383. return Error("无操作权限!");
  2384. }
  2385. /// <summary>
  2386. /// 审核工单
  2387. /// </summary>
  2388. public ActionResult GetApproval(string OpenId, long orderid, string AuditCont, int IsAudit = 0, int AuditState = 0, float overtime = 0, int sms = 0)
  2389. {
  2390. if (!string.IsNullOrEmpty(OpenId))
  2391. {
  2392. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  2393. if (ua != null)
  2394. {
  2395. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  2396. if (model != null)
  2397. {
  2398. //var itemlast = itembll.GetModelList(" F_WoID='" + model.F_ID + "' order by F_ID desc").FirstOrDefault();
  2399. //if (itemlast!=null )
  2400. // sms = (int)itemlast.F_IsSMS;
  2401. var res = Approval(OpenId, orderid, AuditCont, ua, model, overtime, sms, IsAudit, AuditState);
  2402. if (res)
  2403. return Success("审核成功");
  2404. else
  2405. return Error("审核失败");
  2406. }
  2407. else
  2408. return Error("工单不存在");
  2409. }
  2410. }
  2411. return Error("OpenId不能为空");
  2412. }
  2413. /// <summary>
  2414. /// 填写超时原因
  2415. /// </summary>
  2416. /// <param name="input"></param>
  2417. /// <returns></returns>
  2418. [WechatActionFilter]
  2419. public ActionResult Reasontimeout(string OpenId, long orderid, string cont)
  2420. {
  2421. if (!string.IsNullOrEmpty(OpenId))
  2422. {
  2423. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  2424. if (ua != null)
  2425. {
  2426. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  2427. //验证信息
  2428. if (model != null)
  2429. {
  2430. model.F_Reasontimeout = cont;
  2431. bool n = woBLL.Update(model);
  2432. if (n)
  2433. return Success("填写成功");
  2434. else
  2435. return Error("填写失败!");
  2436. }
  2437. return Error("工单不存在");
  2438. }
  2439. }
  2440. return Error("无操作权限");
  2441. }
  2442. /// <summary>
  2443. /// 审核工单
  2444. /// </summary>
  2445. [WechatActionFilter]
  2446. 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)
  2447. {
  2448. int res = 1;
  2449. string touser = ""; string tousername = "";
  2450. string opt = "审核";
  2451. #region 获取接收人
  2452. string deptname = "";
  2453. string deptmodelsname = "";
  2454. int wostate = 0;
  2455. var toussers = "";
  2456. int woflag = 0;
  2457. #region 上报
  2458. if (IsAudit != 0)
  2459. {
  2460. if (GetUser(OpenId) != null)
  2461. {
  2462. var user = GetUser(OpenId);
  2463. var deptmodel = departmentBLL.GetModel(user.F_DeptId);
  2464. var deptmodels = departmentBLL.GetModel(nowUser.F_DeptId);
  2465. if (deptmodel != null)
  2466. {
  2467. deptname = deptmodel.F_DeptName + "-";
  2468. }
  2469. if (deptmodels != null)
  2470. {
  2471. deptmodelsname = deptmodels.F_DeptName + "-";
  2472. }
  2473. 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();
  2474. if (itemlast != null)
  2475. {
  2476. toussers = itemlast.F_CreateUser;
  2477. if (sms == -1)
  2478. {
  2479. sms = (int)itemlast.F_IsSMS;
  2480. }
  2481. }
  2482. else
  2483. {
  2484. if (sms == -1)
  2485. {
  2486. sms = 0;
  2487. }
  2488. }
  2489. wostate = 16;
  2490. if (AuditState == 0)
  2491. {
  2492. opt = "同意上报";
  2493. 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);
  2494. 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);
  2495. if (userid <= 0 || uaid <= 0)
  2496. res = 0;
  2497. else
  2498. {
  2499. if (sms ==1&& !string .IsNullOrEmpty(user .F_Mobile ))
  2500. {
  2501. SendSms(model.F_Type, user.F_Mobile, nowUser.F_UserId);
  2502. }
  2503. }
  2504. }
  2505. else if (AuditState == 1)
  2506. {
  2507. opt = "驳回修订";
  2508. 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);
  2509. if (userid <= 0)
  2510. res = 0;
  2511. }
  2512. else
  2513. {
  2514. opt = "强制结案";
  2515. wostate = 11;
  2516. 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);
  2517. if (userid <= 0)
  2518. res = 0;
  2519. }
  2520. }
  2521. else
  2522. {
  2523. Model.T_Sys_RoleInfo ro = rolebll.GetModel(nowUser.F_RoleId);
  2524. if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL")
  2525. {
  2526. 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();
  2527. if (itemlast != null)
  2528. {
  2529. toussers = itemlast.F_CreateUser;
  2530. if (sms == -1)
  2531. {
  2532. sms = (int)itemlast.F_IsSMS;
  2533. }
  2534. }
  2535. else
  2536. {
  2537. if (sms == -1)
  2538. {
  2539. sms = 0;
  2540. }
  2541. }
  2542. if (AuditState == 0)
  2543. {
  2544. opt = "同意上报";
  2545. 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);
  2546. res = GetDaQucirCulation(AuditCont, nowUser, DateTime.Now.ToString(), model.F_ID, true);
  2547. if (userid <= 0 || res==0)
  2548. res = 0;
  2549. wostate = 1;
  2550. woflag = 9;
  2551. }
  2552. else if (AuditState == 1)
  2553. {
  2554. opt = "驳回修订";
  2555. 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);
  2556. if (userid <= 0)
  2557. res = 0;
  2558. wostate = 16;
  2559. }
  2560. else
  2561. {
  2562. opt = "强制结案";
  2563. 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);
  2564. if (userid <= 0)
  2565. res = 0;
  2566. wostate = 11;
  2567. }
  2568. }
  2569. else
  2570. {
  2571. res = 0;
  2572. }
  2573. }
  2574. }
  2575. #endregion
  2576. #endregion
  2577. if (res>0)
  2578. {
  2579. if (res == 1)
  2580. {
  2581. model.F_State = wostate;
  2582. //if (woflag == 9)
  2583. //{
  2584. // model.F_State2 = 0;
  2585. //}
  2586. //else
  2587. //{
  2588. // model.F_State2 = wostate;
  2589. //}
  2590. model.F_State2 = wostate;
  2591. model.F_Flag = woflag;
  2592. }
  2593. else if (res == 2)
  2594. {
  2595. model.F_State = wostate;
  2596. model.F_State2 = wostate;
  2597. model.F_Flag = 3;
  2598. }
  2599. //处理内容
  2600. if (!string.IsNullOrEmpty(AuditCont))
  2601. model.F_AuditCont += AuditCont + ";";
  2602. model.F_IsAudit = IsAudit;
  2603. model.F_AuditState = AuditState;
  2604. model.F_AuditBy = nowUser.F_UserCode;
  2605. model.F_AuditOn = DateTime.Now;
  2606. woBLL.Update(model);
  2607. if (nowUser.F_UserCode != model.F_CreateBy)
  2608. {
  2609. sendsysmsg(model, nowUser, model.F_CreateBy, (int)model.F_ID, opt);//
  2610. }
  2611. #region 向下一级操作人员推送消息
  2612. if (!string.IsNullOrWhiteSpace(touser))
  2613. {
  2614. sendsysmsg(model, nowUser, touser, (int)model.F_ID, opt);//
  2615. }
  2616. #endregion 向下一级操作人员推送消息
  2617. }
  2618. else
  2619. return false;
  2620. return true;
  2621. }
  2622. public bool SendSms(string type,string F_Mobile,int userid)
  2623. {
  2624. string smscont = "";
  2625. if (type == "1")
  2626. {
  2627. smscont = "咨询";
  2628. }
  2629. else if (type == "2")
  2630. {
  2631. smscont = "投诉";
  2632. }
  2633. else if (type == "3")
  2634. {
  2635. smscont = "抽检";
  2636. }
  2637. else if (type == "5")
  2638. {
  2639. smscont = "业务协办";
  2640. }
  2641. else
  2642. {
  2643. smscont = "建议";
  2644. }
  2645. string[] mag = { smscont };
  2646. string smsmsg = "您好,您有一条新的" + smscont + "工单,请及时接单处理!";
  2647. SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, F_Mobile.Trim());
  2648. bool n = new SMSController().AddSmS(F_Mobile.Trim(), smsmsg, userid);
  2649. return n;
  2650. }
  2651. /// <summary>
  2652. /// 大区经理未审批流转市场管理科
  2653. /// </summary>
  2654. /// <param name="ua"></param>
  2655. /// <param name="time"></param>
  2656. /// <param name="id"></param>
  2657. public int GetDaQucirCulation(string AuditCont, Model.T_Sys_UserAccount ua, string time, long id, bool istrue)
  2658. {
  2659. DateTime times = DateTime.Parse(time).AddHours(24);
  2660. Model.T_Wo_WorkOrder model = woBLL.GetModel(id);
  2661. List<Model.T_Wo_WorkOrder> modeLlist = new List<Model.T_Wo_WorkOrder>();
  2662. modeLlist.Add(model);
  2663. List<WorkOrderNewInput> Input = modeltooip(modeLlist, ua);
  2664. string cont = "";
  2665. int dapt = 0, nextda = 0; string opt = ""; int nextda2 = 0; string opt2 = ""; string cont2 = "";
  2666. var itemlast = itembll.GetModelList(" F_WoID='" + model.F_ID + "' order by F_ID desc").FirstOrDefault();
  2667. int sms = (int)itemlast.F_IsSMS;
  2668. var deptmodel1 = departmentBLL.GetModel(ua.F_DeptId);
  2669. string deptname = "";
  2670. if (deptmodel1 != null)
  2671. {
  2672. dapt = deptmodel1.F_ParentId;
  2673. deptname = deptmodel1.F_DeptName;
  2674. }
  2675. int isbl = 0;
  2676. int flag = 9;
  2677. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  2678. //if (dapt != 0)
  2679. //{
  2680. if (CirculMarket(ua.F_DeptId, 11))
  2681. {
  2682. isbl = 1;
  2683. nextda = 427;
  2684. opt = "流转运营中心";
  2685. //nextda2 = 36;
  2686. //opt2 = "流转质量管理科";
  2687. //flag = 3;
  2688. }
  2689. else if (CirculMarket(ua.F_DeptId, 14))
  2690. {
  2691. isbl = 1;
  2692. nextda = 57;
  2693. opt = "流转营销管理处";
  2694. }
  2695. else if (CirculMarket(ua.F_DeptId, 15))
  2696. {
  2697. isbl = 1;
  2698. nextda = 74;
  2699. opt = "流转策划推广";
  2700. //nextda2 = 245;
  2701. //opt2 = "流转质量督察处";
  2702. //flag = 3;
  2703. }
  2704. else if (CirculMarket(ua.F_DeptId, 16))
  2705. {
  2706. isbl = 1;
  2707. nextda = 88;
  2708. opt = "流转销售部";
  2709. }
  2710. else if (CirculMarket(ua.F_DeptId, 18))
  2711. {
  2712. nextda = 268;
  2713. opt = "流转车用尿素";
  2714. }
  2715. else if (CirculMarket(ua.F_DeptId, 20))
  2716. {
  2717. nextda = 422;
  2718. opt = "流转营销中心市场科";
  2719. nextda2 = 295;
  2720. opt2 = "流转新乡黑科质检";
  2721. }
  2722. else if (CirculMarket(ua.F_DeptId, 332))
  2723. {
  2724. nextda = 339;
  2725. opt = "流转营销管理处";
  2726. }
  2727. else if (ua.F_DeptId == 17 || ua.F_DeptId == 19 || ua.F_DeptId == 20 || ua.F_DeptId == 21)
  2728. {
  2729. isbl = 1;
  2730. nextda = ua.F_DeptId;
  2731. opt = "流转" + deptname;
  2732. }
  2733. //}
  2734. if (istrue)
  2735. {
  2736. if (ro.F_RoleCode == "DQJL")
  2737. {
  2738. cont = "大区经理已审批:" + AuditCont + "," + opt;
  2739. if (!string.IsNullOrEmpty(opt2))
  2740. {
  2741. cont2 = "大区经理已审批: " + AuditCont + "," + opt2;
  2742. }
  2743. }
  2744. else
  2745. {
  2746. cont = "分公司经理已审批:" + AuditCont + "," + opt;
  2747. if (!string.IsNullOrEmpty(opt2))
  2748. {
  2749. cont2 = "分公司经理已审批: " + AuditCont + "," + opt2;
  2750. }
  2751. }
  2752. }
  2753. else
  2754. {
  2755. if (ro.F_RoleCode == "DQJL")
  2756. {
  2757. cont = "大区经理未审批" + opt;
  2758. if (!string.IsNullOrEmpty(opt2))
  2759. {
  2760. cont2 = "大区经理未审批" + opt2;
  2761. }
  2762. }
  2763. else
  2764. {
  2765. cont = "分公司经理未审批" + opt;
  2766. if (!string.IsNullOrEmpty(opt2))
  2767. {
  2768. cont2 = "分公司经理未审批" + opt2;
  2769. }
  2770. }
  2771. }
  2772. if (nextda != 0)
  2773. {
  2774. if (nextda2 != 0)
  2775. {
  2776. model.F_Flag = 3;
  2777. var res = AssignWO(ua, model, Input[0], cont, "", nextda, 0, model.F_limit, sms, 0, 0, 0, time.ToString(), isbl, 1, 3);
  2778. var res2 = AssignWO(ua, model, Input[0], cont2, "", nextda2, 0, model.F_limit, sms, 0, 0, 0, time.ToString(), isbl, 2);
  2779. return 2;
  2780. }
  2781. else
  2782. {
  2783. model.F_Flag = 9;
  2784. var res = AssignWO(ua, model, Input[0], cont, "", nextda, 0, model.F_limit, sms, 0, 0, 0, time.ToString(), isbl, 3, 9);
  2785. return 1;
  2786. }
  2787. }
  2788. else
  2789. {
  2790. return 0;
  2791. }
  2792. }
  2793. /// <summary>
  2794. /// 判断市场管理科
  2795. /// </summary>
  2796. /// <param name="deptid"></param>
  2797. /// <param name="pdeptid"></param>
  2798. /// <returns></returns>
  2799. public bool CirculMarket(int deptid, int pdeptid)
  2800. {
  2801. string sql = " F_State=1 ";
  2802. string dptcode = departmentBLL.GetModel(pdeptid).F_DeptCode;
  2803. string arrsql = " select F_DeptCode from T_Sys_Department where F_DeptCode LIKE '" + dptcode + "%' ";
  2804. sql += $" and F_DeptCode in ({arrsql}) and F_DeptId=" + deptid;
  2805. var modellist = departmentBLL.GetModelList(sql);
  2806. if (modellist.Count > 0)
  2807. return true;
  2808. else return false;
  2809. }
  2810. /// <summary>
  2811. /// 查询工单详情
  2812. /// </summary>
  2813. [WechatActionFilter]
  2814. public ActionResult GetCustomDetails(string OpenId, int id)
  2815. {
  2816. if (!string.IsNullOrEmpty(OpenId))
  2817. {
  2818. int woflag = 0;
  2819. string markdepts = "37,57,74,88,268,295,339,213,427,433";
  2820. string sqlstr = "";
  2821. if (id <= 0)
  2822. {
  2823. return Error("请输入正确的id");
  2824. }
  2825. DataTable FileUrl = new DataTable();
  2826. var list = new List<Model.T_Wo_WorkOrder>();
  2827. var model = woBLL.GetModel(id);
  2828. if (model != null)
  2829. list.Add(model);
  2830. var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  2831. if (!string.IsNullOrEmpty(model.F_Files))
  2832. {
  2833. FileUrl = GetFileData(model.F_Files, configfj.F_ParamValue);
  2834. }
  2835. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  2836. var itemlasts = itembll.GetModelList(" F_WoID=" + id + "");
  2837. var itemlast = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_IsUsed=0 and F_WoState =1 and F_WoID='" + id + "'and F_CreateUser='" + ua.F_UserCode + "' order by F_ID desc");
  2838. if (itemlast != null && itemlast.Count > 0)
  2839. {
  2840. if (markdepts.Contains(ua.F_DeptId.ToString()))
  2841. {
  2842. var itemnext = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoState =1 and F_WoID='" + model.F_ID + "'and F_NextUser like '%" + ua.F_UserCode + "%' order by F_ID desc").FirstOrDefault();
  2843. if (itemlast.Count == 2 || itemnext.F_Flag == 9)
  2844. {
  2845. woflag = 9;
  2846. }
  2847. }
  2848. }
  2849. //var itemlasts = itembll.GetModelList(" F_WoID=" + +id + " ");
  2850. if (list.Count > 0)
  2851. {
  2852. List<WorkOrderNewInput> Input = modeltooip(list, ua);
  2853. if (Input != null)
  2854. {
  2855. var obj = new
  2856. {
  2857. state = "success",
  2858. message = "成功",
  2859. rows = Input,
  2860. FileUrl,
  2861. total = itemlasts,
  2862. woflag = woflag
  2863. };
  2864. return Content(obj.ToJson());
  2865. }
  2866. else
  2867. {
  2868. return Error("没有查询到此工单");
  2869. }
  2870. }
  2871. else
  2872. return Error("没有查询到此工单");
  2873. }
  2874. else
  2875. {
  2876. return Error("无操作权限!");
  2877. }
  2878. }
  2879. /// <summary>
  2880. /// 查询工单详情
  2881. /// </summary>
  2882. [WechatActionFilter]
  2883. public ActionResult GetDetails(string OpenId, int id,int flag=1,int state=0)
  2884. {
  2885. if (!string.IsNullOrEmpty(OpenId))
  2886. {
  2887. if (id <= 0)
  2888. {
  2889. return Error("请输入正确的id");
  2890. }
  2891. DataTable FileUrl = new DataTable();
  2892. var list = new List<Model.T_Wo_WorkOrder>();
  2893. var model = woBLL.GetModel(id);
  2894. if (model != null)
  2895. {
  2896. //if (model.F_SC_PreliminaryOpinion == "退换货")
  2897. //{
  2898. List<T_Wo_MaterialItems> materlist = new BLL.T_Wo_MaterialItems().GetModelList($" F_WoID={model.F_ID}");
  2899. if (materlist != null)
  2900. {
  2901. model.MaterialItems = materlist;
  2902. }
  2903. //}
  2904. list.Add(model);
  2905. }
  2906. var itemlasts = itembll.GetModelList(" F_WoID=" + id + " ");
  2907. var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  2908. if (!string.IsNullOrEmpty(model.F_Files))
  2909. {
  2910. FileUrl = GetFileData(model.F_Files, configfj.F_ParamValue);
  2911. }
  2912. //if (!string.IsNullOrEmpty(model.F_Files))
  2913. //{
  2914. // var configfj = "http://192.168.8.9:1005/Upload/APP/2022/06/22/";
  2915. // FileUrl = GetFileData(model.F_Files, configfj);
  2916. //}
  2917. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  2918. if (model.F_Source != "3")
  2919. {
  2920. if (ua == null)
  2921. {
  2922. return Success("你的账号已在别处登录,你确定要再次登录吗?");
  2923. }
  2924. }
  2925. if (list.Count > 0)
  2926. {
  2927. List<WorkOrderNewInput> Input = modeltooip(list, ua,state);
  2928. if (Input != null)
  2929. {
  2930. var obj = new
  2931. {
  2932. state = "success",
  2933. message = "成功",
  2934. rows = Input,
  2935. FileUrl,
  2936. total = itemlasts,
  2937. };
  2938. return Content(obj.ToJson());
  2939. }
  2940. else
  2941. {
  2942. return Error("没有查询到此工单");
  2943. }
  2944. }
  2945. else
  2946. return Error("没有查询到此工单");
  2947. }
  2948. else
  2949. {
  2950. return Error("无操作权限!");
  2951. }
  2952. }
  2953. /// <summary>
  2954. /// 获取当前节点内外线状态
  2955. /// </summary>
  2956. /// <param name="fid"></param>
  2957. /// <returns></returns>
  2958. public int? GetNodeState(int fid, string usercode, int state = 0)
  2959. {
  2960. int? flag = 0;
  2961. string markdepts = "37,57,74,88,268,295,339,213,427,433";
  2962. if (!string.IsNullOrEmpty(usercode))
  2963. {
  2964. Model.T_Sys_UserAccount ua = userAccountBLL.GetModel(usercode);
  2965. var itemlast = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_OptType=1 and F_WoID='" + fid + "' and F_NextUser like '%" + ua.F_UserCode + "%' order by F_ID").FirstOrDefault();
  2966. if (itemlast != null)
  2967. {
  2968. int? wostate1 = 0, wostate2 = 0; int i = 0;
  2969. //if (!markdepts.Contains(ua.F_DeptId.ToString()))
  2970. //{
  2971. if (state == 2)
  2972. state = 1;
  2973. else if (state == 4)
  2974. state = 2;
  2975. else
  2976. state = 0;
  2977. if (itemlast.F_Flag != 9)
  2978. {
  2979. var itemnext = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_IsUsed=0 and F_WoID='" + fid + "' and F_NextUser like '%" + ua.F_UserCode + "%' order by F_ID desc");
  2980. if (itemnext.Count > 0 && itemnext.Count == 2)
  2981. {
  2982. foreach (var item in itemnext)
  2983. {
  2984. if (i == 0)
  2985. {
  2986. wostate1 = item.F_WoState;
  2987. }
  2988. else
  2989. {
  2990. wostate2 = item.F_WoState;
  2991. }
  2992. i++;
  2993. }
  2994. if (wostate1 == wostate2 || (wostate2 == 2 && wostate1 == 17) || (wostate1 == 2 && wostate2 == 17))
  2995. {
  2996. flag = 3;//需要判断处理内线还是外线
  2997. }
  2998. else if (state > 0 && state<=2)
  2999. {
  3000. flag = itemnext.Where(t => t.F_WoState == state || t.F_WoState == 17 || t.F_WoState == 4 || t.F_WoState == 3).FirstOrDefault()?.F_Type??0;
  3001. }
  3002. }
  3003. else if (itemnext.Count > 0)
  3004. {
  3005. flag = itemnext.FirstOrDefault().F_Type;
  3006. }
  3007. else
  3008. {
  3009. var itemnext2 = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_IsUsed=0 and F_WoID='" + fid + "' and F_CreateUser='" + ua.F_UserCode + "' order by F_ID desc");
  3010. if (itemnext2.Count > 0 && itemnext2.Count == 2)
  3011. {
  3012. flag = 3;
  3013. }
  3014. else if (itemnext2.Count > 0)
  3015. {
  3016. flag = itemnext2.FirstOrDefault().F_Type;
  3017. }
  3018. else
  3019. {
  3020. flag = itemlast.F_Type;
  3021. }
  3022. }
  3023. }
  3024. //}
  3025. else if (itemlast.F_Flag == 9)
  3026. {
  3027. var itemlest = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID='" + fid + "' and F_NextUser like '%" + ua.F_UserCode + "%' order by F_ID desc").FirstOrDefault();
  3028. if (itemlest.F_IsUsed == 0)
  3029. {
  3030. if (itemlest.F_Flag == 9)
  3031. flag = 9;
  3032. else
  3033. flag = itemlest.F_Type;
  3034. }
  3035. else
  3036. {
  3037. var itemnext = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_IsUsed=0 and F_WoID='" + fid + "' and F_NextUser like '%" + ua.F_UserCode + "%' order by F_ID desc");
  3038. if (itemnext.Count > 0 && itemnext.Count == 2)
  3039. {
  3040. foreach (var item in itemnext)
  3041. {
  3042. if (i == 0)
  3043. {
  3044. wostate1 = item.F_WoState;
  3045. }
  3046. else
  3047. {
  3048. wostate2 = item.F_WoState;
  3049. }
  3050. i++;
  3051. }
  3052. if (wostate1 == wostate2 || (wostate2 == 2 && wostate1 == 17) || (wostate1 == 2 && wostate2 == 17))
  3053. {
  3054. flag = 3;//需要判断处理内线还是外线
  3055. }
  3056. else if (state > 0 && state<=2)
  3057. {
  3058. flag = itemnext.Where(t => t.F_WoState == state || t.F_WoState == 17 || t.F_WoState == 4 || t.F_WoState == 3).FirstOrDefault()?.F_Type??0;
  3059. }
  3060. }
  3061. else if(itemnext.Count > 0)
  3062. {
  3063. flag = itemnext.FirstOrDefault().F_Type;
  3064. }
  3065. else
  3066. {
  3067. var itemnext2 = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_IsUsed=0 and F_WoID='" + fid + "' and F_CreateUser='" + ua.F_UserCode + "' order by F_ID desc");
  3068. if (itemnext2.Count > 0)
  3069. {
  3070. foreach (var item in itemnext2)
  3071. {
  3072. if (item.F_WoState != 11 && item.F_WoState != 10)
  3073. flag = item.F_Type;
  3074. }
  3075. }
  3076. }
  3077. }
  3078. }
  3079. }
  3080. }
  3081. return flag;
  3082. }
  3083. public string GetID(string str, long id)
  3084. {
  3085. if (str != "")
  3086. {
  3087. str += "," + id;
  3088. }
  3089. else
  3090. {
  3091. str += id;
  3092. }
  3093. return str;
  3094. }
  3095. public string GetDeptment(Model.T_Sys_UserAccount ua)
  3096. {
  3097. string detpid = "" + ua.F_DeptId;
  3098. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  3099. var deparmentlist = new List<Model.T_Sys_Department>();
  3100. if (dModel != null)
  3101. {
  3102. if (dModel.F_Layer == 1)
  3103. {
  3104. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  3105. if (deparmentlist.Count > 0)
  3106. {
  3107. foreach (var it in deparmentlist)
  3108. {
  3109. if (detpid != "")
  3110. {
  3111. detpid += "," + it.F_DeptId;
  3112. }
  3113. else
  3114. {
  3115. detpid = "" + it.F_DeptId;
  3116. }
  3117. }
  3118. }
  3119. }
  3120. else
  3121. {
  3122. detpid = ua.F_DeptId.ToString();
  3123. }
  3124. }
  3125. return detpid;
  3126. }
  3127. /// <summary>
  3128. /// 获取待审批的工单
  3129. /// </summary>
  3130. /// <param name="user"></param>
  3131. /// <returns></returns>
  3132. public string GetApprovalOrderID(Model.T_Sys_UserAccount ua, string OpenId, string F_RoleCode)
  3133. {
  3134. string str = string.Empty;
  3135. #region 查询自己名下未审批的工单列表
  3136. var itemlast = itembll.GetModelList(" isnull(F_IsUsed,'0')='0' and F_OptType in(" + (int)EnumItemOpt.audit + ")" + " and "
  3137. + "F_WoState in(" + (int)EnumWorkOrderState.audit + ") and F_NextUser='" + ua.F_UserCode + "' "
  3138. + "" + " ");
  3139. foreach (var it in itemlast)
  3140. {
  3141. float hours = (DateTime.Now - DateTime.Parse(it.F_CreateTime.ToString())).Hours;
  3142. int overtime = 0;
  3143. if (!string .IsNullOrEmpty (it.F_LimitTime))
  3144. {
  3145. overtime = int.Parse(it.F_LimitTime);
  3146. }
  3147. int sms = int.Parse (it.F_IsSMS.ToString ());
  3148. if (F_RoleCode == "DQJL" || F_RoleCode == "FGSJL")
  3149. {
  3150. if (hours >= 24)
  3151. {
  3152. GetDaQucirCulation("", ua, it.F_CreateTime.ToString(), it.F_WoID, false);
  3153. }
  3154. else
  3155. {
  3156. str = GetID(str, it.F_WoID);
  3157. }
  3158. }
  3159. else
  3160. {
  3161. //var user = GetUser(OpenId);
  3162. //string deptname = "";
  3163. //string deptmodelsname = "";
  3164. //var deptmodel = departmentBLL.GetModel(user.F_DeptId);
  3165. //var deptmodels = departmentBLL.GetModel(ua.F_DeptId);
  3166. //if (deptmodel != null)
  3167. //{
  3168. // deptname = deptmodel.F_DeptName + "-";
  3169. //}
  3170. //if (deptmodels != null)
  3171. //{
  3172. // deptmodelsname = deptmodels.F_DeptName + "-";
  3173. //}
  3174. if (hours >= 24)
  3175. {
  3176. var user = GetUser(OpenId);
  3177. string deptname = "";
  3178. string deptmodelsname = "";
  3179. string namestr = "";
  3180. Model.T_Sys_RoleInfo ro = rolebll.GetModel(user.F_RoleId);
  3181. if (ro.F_RoleCode == "DQJL")
  3182. {
  3183. namestr = "大区经理";
  3184. }
  3185. else
  3186. {
  3187. namestr = "分公司经理";
  3188. }
  3189. var deptmodel = departmentBLL.GetModel(user.F_DeptId);
  3190. var deptmodels = departmentBLL.GetModel(ua.F_DeptId);
  3191. if (deptmodel != null)
  3192. {
  3193. deptname = deptmodel.F_DeptName + "-";
  3194. }
  3195. if (deptmodels != null)
  3196. {
  3197. deptmodelsname = deptmodels.F_DeptName + "-";
  3198. }
  3199. DateTime time = DateTime.Parse(it.F_CreateTime.ToString()).AddHours(24);
  3200. Model.T_Wo_WorkOrder model = woBLL.GetModel(it.F_WoID);
  3201. AddLog(model.F_ID, model.F_State.Value, deptmodelsname + ua.F_UserName + "(" + ua.F_WorkNumber + ")" + "未审批流转"+ namestr + "", (int)EnumItemType.audit, (int)EnumItemOpt.audit, user.F_UserCode, user.F_DeptId, ua, overtime, sms);
  3202. 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);
  3203. }
  3204. else if (hours >= 48)
  3205. {
  3206. var user = GetUser(OpenId);
  3207. GetDaQucirCulation("", user, it.F_CreateTime.ToString(), it.F_WoID, false);
  3208. }
  3209. else
  3210. {
  3211. str = GetID(str, it.F_WoID);
  3212. }
  3213. }
  3214. }
  3215. #endregion
  3216. if (F_RoleCode == "DQJL")
  3217. {
  3218. if (!string.IsNullOrEmpty(GetDeptment(ua)))
  3219. {
  3220. var itemlasts = itembll.GetModelList(" isnull(F_IsUsed,'0')='0' and F_OptType in(" + (int)EnumItemOpt.audit + ")" + " and "
  3221. + "F_WoState in(" + (int)EnumWorkOrderState.audit + ") and F_NextUser in ( " + GetDeptment(ua) + ") ");
  3222. foreach (var it in itemlasts)
  3223. {
  3224. int overtime = 0;
  3225. if (!string.IsNullOrEmpty(it.F_LimitTime))
  3226. {
  3227. overtime = int.Parse(it.F_LimitTime);
  3228. }
  3229. int sms = int.Parse(it.F_IsSMS.ToString());
  3230. float hours = (DateTime.Now - DateTime.Parse(it.F_CreateTime.ToString())).Hours;
  3231. if (F_RoleCode == "DQJL")
  3232. {
  3233. if (hours >= 24)
  3234. {
  3235. Model.T_Sys_UserAccount user = userAccountBLL.GetModel(it.F_CreateUser);
  3236. DateTime time = DateTime.Parse(it.F_CreateTime.ToString()).AddHours(24);
  3237. Model.T_Wo_WorkOrder model = woBLL.GetModel(it.F_WoID);
  3238. string deptname = "";
  3239. string deptmodelsname = "";
  3240. var deptmodel = departmentBLL.GetModel(user.F_DeptId);
  3241. var deptmodels = departmentBLL.GetModel(ua.F_DeptId);
  3242. if (deptmodel != null)
  3243. {
  3244. deptname = deptmodel.F_DeptName + "-";
  3245. }
  3246. if (deptmodels != null)
  3247. {
  3248. deptmodelsname = deptmodels.F_DeptName + "-";
  3249. }
  3250. 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);
  3251. 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 );
  3252. if (hours < 48)
  3253. {
  3254. str = GetID(str, it.F_WoID);
  3255. }
  3256. else
  3257. {
  3258. GetDaQucirCulation("", ua, time.ToString(), it.F_WoID, false);
  3259. }
  3260. }
  3261. }
  3262. }
  3263. }
  3264. }
  3265. return str;
  3266. }
  3267. /// <summary>
  3268. /// 获取已审批的工单列表
  3269. /// </summary>
  3270. /// <param name="user"></param>
  3271. /// <returns></returns>
  3272. public string GetApprovedOrderID(string user)
  3273. {
  3274. string str = string.Empty;
  3275. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_OptType=" + (int)EnumItemOpt.reaudit
  3276. + " and F_CreateUser=" + user + " "//
  3277. ;
  3278. return str;
  3279. }
  3280. /// <summary>
  3281. /// 获取已审批的工单列表
  3282. /// </summary>
  3283. /// <param name="user"></param>
  3284. /// <returns></returns>
  3285. public string GetApprovedOrderID()
  3286. {
  3287. string str = string.Empty;
  3288. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_OptType=" + (int)EnumItemOpt.reaudit
  3289. //
  3290. ;
  3291. return str;
  3292. }
  3293. /// <summary>
  3294. /// 根据model返回CustomerBaseNewInput对象
  3295. /// </summary>
  3296. private List<WorkOrderNewInput> modeltooip(List<Model.T_Wo_WorkOrder> model1, Model.T_Sys_UserAccount ua,int state=0)
  3297. {
  3298. if (model1 != null && model1.Count > 0)
  3299. {
  3300. List<WorkOrderNewInput> Input = new List<WorkOrderNewInput>(model1.Count);
  3301. for (int i = 0; i < model1.Count; i++)
  3302. {
  3303. WorkOrderNewInput model = new WorkOrderNewInput();
  3304. Model.T_Cus_CustomerBaseNew cuModel = new Model.T_Cus_CustomerBaseNew();
  3305. if (!string.IsNullOrEmpty(model1[i].F_CustomerID))
  3306. {
  3307. cuModel = customerBaseBLL.GetModel(model1[i].F_CustomerID.ToString());//通过客户编号获取客户资料
  3308. }
  3309. else
  3310. {
  3311. var sql = $" and F_LegalPhone ='" + model1[i].F_CusPhone.Trim() + "'";
  3312. cuModel = new BLL.T_Cus_CustomerBaseNew().GetModelList(" F_IsDelete = 0 " + sql).FirstOrDefault();
  3313. }
  3314. if (cuModel != null)
  3315. {
  3316. if (!string.IsNullOrEmpty(cuModel.F_AreaID))
  3317. {
  3318. Model.T_Sys_Department pdModel = new Model.T_Sys_Department();
  3319. try
  3320. {
  3321. pdModel = departmentBLL.GetModel(int.Parse(cuModel.F_AreaID));//通过公司id获取部门
  3322. }
  3323. catch
  3324. {
  3325. pdModel = departmentBLL.GetModel(cuModel.F_AreaID);//通过公司id获取部门
  3326. }
  3327. if (pdModel != null)
  3328. {
  3329. model.F_AreaName = pdModel.F_DeptName;
  3330. }
  3331. }
  3332. if (!string.IsNullOrEmpty(cuModel.F_BranchID))
  3333. {
  3334. Model.T_Sys_Department pdModel1 = new Model.T_Sys_Department();
  3335. try
  3336. {
  3337. pdModel1 = departmentBLL.GetModel(int.Parse(cuModel.F_BranchID));//通过公司id获取部门
  3338. }
  3339. catch
  3340. {
  3341. pdModel1 = departmentBLL.GetModel(cuModel.F_BranchID);//通过公司id获取部门
  3342. }
  3343. if (pdModel1 != null)
  3344. {
  3345. model.F_BranchName = pdModel1.F_DeptName;
  3346. }
  3347. }
  3348. model.F_CompanyName = cuModel.F_CompanyName;//公司名称
  3349. model.F_CustomerID = cuModel.F_CustomerCode;//客户编码
  3350. model.F_Salesman = cuModel.F_Salesman;
  3351. model.F_SalesPhone = cuModel.F_SalesPhone;
  3352. model.F_Legal = cuModel.F_Legal;
  3353. model.F_LegalPhone = cuModel.F_LegalPhone;
  3354. model.F_AddressProvince = cuModel.F_AddressProvince;
  3355. model.F_AddressCity = cuModel.F_AddressCity;
  3356. model.F_AddressCountry = cuModel.F_AddressCountry;
  3357. model.F_AddressTownship = cuModel.F_AddressTownship;
  3358. model.F_AddressFull = cuModel.F_AddressFull;
  3359. model.F_Brands = cuModel.F_Brands;
  3360. model.F_Channel = cuModel.F_Channel;
  3361. model.F_IsRunXLX = cuModel.F_IsRunXLX;
  3362. model.F_AnnualSales = cuModel.F_AnnualSales;
  3363. model.F_Formula = cuModel.F_Formula;
  3364. model.F_RaiseCrops = cuModel.F_RaiseCrops;
  3365. model.F_PlantingArea = cuModel.F_PlantingArea;
  3366. model.F_FertilizerBrand = cuModel.F_FertilizerBrand;
  3367. }
  3368. if (valcode(model1[i].F_MaterialID.ToString(), 11))
  3369. {
  3370. model.F_MaterialID = model1[i].F_MaterialID;//验证物料编码为11位纯数字
  3371. Model.T_Wo_MaterialManage maModel = mmBLL.GetModel(model1[i].F_MaterialID.ToString());//通过物料编码获取物料信息
  3372. if (maModel != null)
  3373. {
  3374. model.F_MaterialName = maModel.F_MaterialName;
  3375. model.F_Model = maModel.F_Model;
  3376. model.F_Specs = maModel.F_Specs;
  3377. model.F_Level1 = maModel.F_Level1;
  3378. model.F_Level2 = maModel.F_Level2;
  3379. model.F_Level3 = maModel.F_Level3;
  3380. model.F_Brand = maModel.F_Brand;
  3381. model.F_MaterialEffect = maModel.F_MaterialEffect;
  3382. model.F_Pipeline = maModel.F_Pipeline;
  3383. model.F_Craft = maModel.F_Craft;
  3384. }
  3385. }
  3386. #region 基本字段
  3387. model.F_ID = model1[i].F_ID;//
  3388. model.F_WorkOrderCode = model1[i].F_WorkOrderCode;//工单编号
  3389. #region
  3390. if (!string.IsNullOrEmpty(model1[i].F_Source))
  3391. {
  3392. model.F_Source = int.Parse(model1[i].F_Source);//工单来源
  3393. }
  3394. if (model1[i].F_Source == "1")
  3395. {
  3396. model.F_SourceName = "电话";
  3397. }
  3398. else if (model1[i].F_Source == "2")
  3399. {
  3400. model.F_SourceName = "微信业务员";
  3401. }
  3402. else if (model1[i].F_Source == "3")
  3403. {
  3404. model.F_SourceName = "微信客户";
  3405. }
  3406. else
  3407. {
  3408. model.F_SourceName = "官网";
  3409. }
  3410. model.F_Type = int.Parse(model1[i].F_Type);//工单来源
  3411. if (model1[i].F_Type == "1")
  3412. {
  3413. model.F_TypeName = "咨询";//工单类型:咨询及需求、投诉、抽检、其他(其它手动输入别的点选)
  3414. }
  3415. else if (model1[i].F_Type == "2")
  3416. {
  3417. model.F_TypeName = "投诉";//工单类型:咨询及需求、投诉、抽检、其他(其它手动输入别的点选)
  3418. }
  3419. else if (model1[i].F_Type == "3")
  3420. {
  3421. model.F_TypeName = "抽检";//工单类型:咨询及需求、投诉、抽检、其他(其它手动输入别的点选)
  3422. }
  3423. else if (model1[i].F_Type == "5")
  3424. {
  3425. model.F_TypeName = "业务协办";//工单类型:咨询及需求、投诉、抽检、其他(其它手动输入别的点选)
  3426. }
  3427. else
  3428. {
  3429. model.F_TypeName = "建议及其他";//工单类型:咨询及需求、投诉、抽检、其他(其它手动输入别的点选)
  3430. }
  3431. model.F_State = model1[i].F_State;
  3432. if (model1[i].F_State == 0)//工单状态
  3433. {
  3434. model.F_StateName = "待指派";
  3435. }
  3436. else if (model1[i].F_State == 1)
  3437. {
  3438. model.F_StateName = "待接单";
  3439. }
  3440. else if (model1[i].F_State == 2)
  3441. {
  3442. model.F_StateName = "待处理";
  3443. }
  3444. else if (model1[i].F_State == 3)
  3445. {
  3446. model.F_StateName = "已退回";
  3447. }
  3448. else if (model1[i].F_State == 4)
  3449. {
  3450. model.F_StateName = "异常退回";
  3451. }
  3452. else if (model1[i].F_State == 5)
  3453. {
  3454. model.F_StateName = "处理中";
  3455. }
  3456. else if (model1[i].F_State == 6)
  3457. {
  3458. model.F_StateName = "待回访";
  3459. }
  3460. else if (model1[i].F_State == 7)
  3461. {
  3462. model.F_StateName = "待完结";
  3463. }
  3464. else if (model1[i].F_State == 10)
  3465. {
  3466. model.F_StateName = "已处理";
  3467. }
  3468. else if (model1[i].F_State == 11)
  3469. {
  3470. model.F_StateName = "已评价";
  3471. }
  3472. else if (model1[i].F_State == 12)
  3473. {
  3474. model.F_StateName = "已退回";
  3475. }
  3476. else if (model1[i].F_State == 14)
  3477. {
  3478. model.F_StateName = "待办理";
  3479. }
  3480. else if (model1[i].F_State == 15)
  3481. {
  3482. model.F_StateName = "微信未通过";
  3483. }
  3484. else if (model1[i].F_State == 16)
  3485. {
  3486. model.F_StateName = "待审批";
  3487. }
  3488. else if (model1[i].F_State == 17)
  3489. {
  3490. model.F_StateName = "已撤回待指派";
  3491. }
  3492. #region 内线工单状态
  3493. model.F_State2 = model1[i].F_State2;
  3494. if (model1[i].F_State2 == 0)//工单状态
  3495. {
  3496. model.F_StateName2 = "待指派";
  3497. }
  3498. else if (model1[i].F_State2 == 1)
  3499. {
  3500. model.F_StateName2 = "待接单";
  3501. }
  3502. else if (model1[i].F_State2 == 2)
  3503. {
  3504. model.F_StateName2 = "待处理";
  3505. }
  3506. else if (model1[i].F_State2 == 3)
  3507. {
  3508. model.F_StateName2 = "已退回";
  3509. }
  3510. else if (model1[i].F_State2 == 4)
  3511. {
  3512. model.F_StateName2 = "异常退回";
  3513. }
  3514. else if (model1[i].F_State2 == 5)
  3515. {
  3516. model.F_StateName2 = "处理中";
  3517. }
  3518. else if (model1[i].F_State2 == 6)
  3519. {
  3520. model.F_StateName2 = "待回访";
  3521. }
  3522. else if (model1[i].F_State2 == 7)
  3523. {
  3524. model.F_StateName2 = "待完结";
  3525. }
  3526. else if (model1[i].F_State2 == 10)
  3527. {
  3528. model.F_StateName2 = "已处理";
  3529. }
  3530. else if (model1[i].F_State2 == 11)
  3531. {
  3532. model.F_StateName2 = "已回访";
  3533. }
  3534. else if (model1[i].F_State2 == 12)
  3535. {
  3536. model.F_StateName2 = "已退回";
  3537. }
  3538. else if (model1[i].F_State2 == 13)
  3539. {
  3540. model.F_StateName2 = "导入工单";
  3541. }
  3542. else if (model1[i].F_State2 == 14)
  3543. {
  3544. model.F_StateName2 = "待办理";
  3545. }
  3546. else if (model1[i].F_State2 == 15)
  3547. {
  3548. model.F_StateName2 = "微信未通过";
  3549. }
  3550. else if (model1[i].F_State2 == 16)
  3551. {
  3552. model.F_StateName2 = "待审批";
  3553. }
  3554. else if (model1[i].F_State2 == 17)
  3555. {
  3556. model.F_StateName2 = "已撤回待指派";
  3557. }
  3558. #endregion 内线工单状态
  3559. #endregion
  3560. model.F_CusName = model1[i].F_CusName;//客户姓名
  3561. model.F_CusPhone = model1[i].F_CusPhone;//客户电话
  3562. model.F_Canal = model1[i].F_Canal;//
  3563. model.F_IncidentProvince = model1[i].F_IncidentProvince;//事发地-省
  3564. model.F_IncidentCity = model1[i].F_IncidentCity;//事发地-市
  3565. model.F_IncidentCountry = model1[i].F_IncidentCountry;//事发地-县
  3566. model.F_IncidentTownship = model1[i].F_IncidentTownship;//事发地-乡
  3567. model.F_IncidentDetailed = model1[i].F_IncidentDetailed;//事发地-详细
  3568. model.F_SalesBase = model1[i].F_SalesBase;//销售基地:新乡、新疆、九江、东北、其他(其它手动输入别的点选)
  3569. model.F_Description = model1[i].F_Description;//问题描述
  3570. model.F_Files = "0";//附件上传ids
  3571. model.F_DealType = model1[i].F_DealType;//处理方式:当即办理、电话转接、网络转办(点选)
  3572. #endregion
  3573. if (!string.IsNullOrEmpty(model1[i].F_QuestionType))
  3574. {
  3575. try
  3576. {
  3577. int b = int.Parse(model1[i].F_QuestionType.Trim());
  3578. Model.T_Wo_QuestionManage manage = quesBLL.GetModel(b);
  3579. if (manage != null)
  3580. {
  3581. model.F_QuestionType = manage.F_QuestionName;//问题类别3
  3582. model.F_QuestionTypeid = manage.F_Id;
  3583. #region 20220304 修改 肥效类增加作物字段
  3584. if (manage.F_Label == "3")
  3585. {
  3586. Model.T_Wo_QuestionManage Manage1 = quesBLL.GetModel(int.Parse(manage.F_ParentId.ToString()));//获取问题类别2
  3587. Model.T_Wo_QuestionManage Manage2 = quesBLL.GetModel(int.Parse(Manage1.F_ParentId.ToString()));//获取问题类别1
  3588. model.F_QuestionTypeone = Manage2.F_QuestionName;//问题类别1
  3589. model.F_QuestionTypeoneid = Manage2.F_Id;//问题类别1
  3590. model.F_QuestionTypetwo = Manage1.F_QuestionName;//问题类别2
  3591. model.F_QuestionTypetwoid = Manage1.F_Id;//问题类别2
  3592. var cropid = 0;
  3593. if (int.TryParse(model1[i].F_Crops.Trim(), out cropid))
  3594. {
  3595. model.F_QuestionTypefour = new BLL.T_Sys_DictionaryValue().GetModel(cropid)?.F_Name ?? "";//问题类别4
  3596. model.F_QuestionTypefourid = cropid;//问题类别4
  3597. }
  3598. }
  3599. #endregion
  3600. #region 修改前
  3601. //if (manage.F_Label == "3")
  3602. // {
  3603. // Model.T_Wo_QuestionManage Manage1 = quesBLL.GetModel(int.Parse(manage.F_ParentId.ToString()));//获取问题类别
  3604. // Model.T_Wo_QuestionManage Manage2 = quesBLL.GetModel(int.Parse(Manage1.F_ParentId.ToString()));//获取问题类别
  3605. // model.F_QuestionTypeone = Manage2.F_QuestionName;//问题类别1
  3606. // model.F_QuestionTypeoneid = Manage2.F_Id ;//问题类别1
  3607. // model.F_QuestionTypetwo = Manage1.F_QuestionName;//问题类别2
  3608. // model.F_QuestionTypetwoid = Manage1.F_Id;//问题类别2
  3609. //}
  3610. #endregion
  3611. }
  3612. }
  3613. catch (Exception)
  3614. {
  3615. model.F_QuestionType = model1[i].F_QuestionType; //问题类别(投诉抽捡和咨询类别不一样)
  3616. }
  3617. }
  3618. model.F_Annotation = model1[i].F_Annotation; ;//注解
  3619. #region 投诉类
  3620. model.F_BatchNumber = model1[i].F_BatchNumber;//生产批次号
  3621. model.F_TS_Formula = model1[i].F_TS_Formula;// 投诉-配方
  3622. model.F_TS_Category = model1[i].F_TS_Category;//投诉-产品种类:化肥、化工、其他
  3623. if (!string.IsNullOrEmpty(model1[i].F_TS_Quantity))
  3624. {
  3625. model.F_TS_Quantity = model1[i].F_TS_Quantity ;//投诉-问题数量(吨)
  3626. }
  3627. else
  3628. model.F_TS_Quantity = "";
  3629. model.F_TS_Level = model1[i].F_TS_Level;//投诉-重要级别:轻微、一般、较大、重大
  3630. List<T_Wo_MaterialItems> materlist = new BLL.T_Wo_MaterialItems().GetModelList($" F_WoID={model.F_ID}");
  3631. if (materlist != null)
  3632. {
  3633. model.MaterialItems = materlist;
  3634. model.F_ZL_Fquantity = materlist.Sum(x => x.F_ReturnQuantity).ToString();
  3635. }
  3636. model.F_CarNumber = model1[i].F_CarNumber;
  3637. model.F_LoadingFee = model1[i].F_LoadingFee;
  3638. model.F_UnLoadingFee = model1[i].F_UnLoadingFee;
  3639. model.F_MaterialFee = model1[i].F_MaterialFee;
  3640. model.F_EventReason = model1[i].F_EventReason;
  3641. model.F_EventReason2 = model1[i].F_EventReason2;
  3642. #endregion
  3643. #region 咨询类
  3644. // model.F_ZX_ProName = model1[i].F_ZX_ProName;//咨询-产品名称:三聚氰胺、甲醇、液氨、二甲醚、糠醇、其他
  3645. model.F_ZX_Quantity = model1[i].F_ZX_Quantity;// 咨询-问题数量(吨)
  3646. model.F_ZX_Area = model1[i].F_ZX_Area;// 咨询-大区
  3647. model.F_ZX_Branch = model1[i].F_ZX_Branch;// 咨询-分公司
  3648. #endregion
  3649. #region 抽检类
  3650. model.F_CJ_Time = model1[i].F_CJ_Time;// 抽检-抽检时间
  3651. model.F_CJ_Level = model1[i].F_CJ_Level;// 抽检-抽检级别:乡镇级、县级、市级、省级及以上、个人送检
  3652. model.F_CJ_Unit = model1[i].F_CJ_Unit;// 抽检-抽检单位:市场监督、农业部、土肥站、工商、联合执法、其他
  3653. model.F_CJ_TestUnit = model1[i].F_CJ_TestUnit;//抽检-化验单位
  3654. model.F_CJ_Tonnage = model1[i].F_CJ_Tonnage;//抽检-抽检吨数
  3655. model.F_CJ_BagNo = model1[i].F_CJ_BagNo;//抽检-抽检袋数
  3656. model.F_CJ_Outlay = model1[i].F_CJ_Outlay;//抽检-公关费用金额:单位元
  3657. model.F_Production = model1[i].F_Production;
  3658. model.F_WorkerBrand = model1[i].F_Brand;//工单品牌
  3659. model.F_DealBy = model1[i].F_DealBy;//处理人
  3660. model.F_DealTime = model1[i].F_DealTime;//处理时间
  3661. model.F_DealContent = model1[i].F_DealContent;//处理内容---外线
  3662. model.F_DealContent2 = model1[i].F_DealContent2;//处理内容---内线
  3663. model.F_DealResult = model1[i].F_DealResult;//处理结果
  3664. model.F_DealReasons = model1[i].F_DealReasons;//未处理原因
  3665. model.F_SC_ProductBase = model1[i].F_SC_ProductBase;//市场管理科-生产基地(新乡、新疆、九江、东北、贴牌、无法确定)
  3666. model.F_SC_PreliminaryOpinion = model1[i].F_SC_PreliminaryOpinion;// 市场管理科-初审意见:退货、换货、补偿、自行处理
  3667. model.F_SC_QualityMonth = model1[i].F_SC_QualityMonth;//市场管理科-超出质保期限(算法:工单创建日期-生产日期,生产日期根据生产批次号获取,单位:月)
  3668. model.F_SC_CJ_SpotResult = model1[i].F_SC_CJ_SpotResult;/// 市场管理科-抽检-抽检结果(视同合格、合格、不合格、复检后合格、未送检)
  3669. model.F_SC_CJ_SelfResult = model1[i].F_SC_CJ_SelfResult;//市场管理科-抽检-自检结果
  3670. model.F_SC_CJ_ApprovalNo = model1[i].F_SC_CJ_ApprovalNo;// 市场管理科-抽检-对应审批工作流单号
  3671. model.F_SC_CJ_ReturnAccount = model1[i].F_SC_CJ_ReturnAccount;//市场管理科-抽检-确认返账金额(元)
  3672. model.F_ZL_QualityEventLevel = model1[i].F_ZL_QualityEventLevel;// 质量管理科-质量事件等级(未遂、一般、较大、重大)
  3673. model.F_ZL_ClaimAmount = model1[i].F_ZL_ClaimAmount;//质量管理科-索赔金额(单位元,对应责任单位)
  3674. model.F_ZL_ResponsibleUnit = model1[i].F_ZL_ResponsibleUnit;//质量管理科-责任单位(需列出,可选多个)
  3675. model.F_ZL_ApprovalOpinions = model1[i].F_ZL_ApprovalOpinions;// 质量管理科-审批意见(同意、不同意,若选择不同意,增加输入框输入补充内容)
  3676. model.F_ZL_ApprovalDisagree = model1[i].F_ZL_ApprovalDisagree;// 质量管理科-审批不同意意见
  3677. model.F_ZL_CompensationMethod = model1[i].F_ZL_CompensationMethod;//质量管理科-补偿方式(实物、钱款【单位元】,若选择钱款,增加输入框输入补充内容)
  3678. model.F_ZL_CompensationMoney = model1[i].F_ZL_CompensationMoney;// 质量管理科-补偿钱款
  3679. model.F_ZL_CResponsibleUnits = model1[i].F_ZL_CResponsibleUnits;//质量管理科-对应责任单位(生产、研发、农化、物流、质量管理科,销售内勤)
  3680. //model.F_ZL_Fquantity = model1[i].F_ZL_Fquantity;// 质量管理科-确认实收数量(吨)
  3681. model.F_ZL_ImprovementRequirements = model1[i].F_ZL_ImprovementRequirements;//质量管理科-改进要求
  3682. model.F_ZL_CApprovalNo = model1[i].F_ZL_CApprovalNo;//质量管理科-对应审批工作流单号
  3683. model.F_ZL_CJ_IsRecord = model1[i].F_ZL_CJ_IsRecord;//质量管理科-抽检-未备案、已备案
  3684. model.F_VisitRemarks = model1[i].F_VisitRemarks;//回访备注
  3685. //model.SuperiorOpinion = AssCont(model1[i].F_ID);//上级处理意见
  3686. model.SuperiorOpinion = model1[i].F_SuperiorOpinion;//处理结果--外线
  3687. model.SuperiorOpinion2 = model1[i].F_SuperiorOpinion2;//处理结果--内线
  3688. model.F_Reasontimeout= model1[i].F_Reasontimeout;//超期原因
  3689. if (model1[i].F_SMSReply == 1)
  3690. {
  3691. model.F_SMSReply = "满意";//短信回访结果
  3692. }
  3693. else if (model1[i].F_SMSReply == 2)
  3694. {
  3695. model.F_SMSReply = "一般";//短信回访结果
  3696. }
  3697. else if (model1[i].F_SMSReply == 3)
  3698. {
  3699. model.F_SMSReply = "不满意";//短信回访结果
  3700. }
  3701. else
  3702. {
  3703. model.F_SMSReply = "";//短信回访结果
  3704. }
  3705. if (model1[i].F_IsVisit != 0)
  3706. {
  3707. model.F_IsVisit = "是";//是否回访
  3708. }
  3709. else
  3710. {
  3711. model.F_IsVisit = "否";//是否回访
  3712. }
  3713. model.F_IsAudit = model1[i].F_IsAudit;//是否审核
  3714. model.F_Highopinions = model1[i].F_Highopinions;//高层处理意见
  3715. model.F_CreateOn = model1[i].F_CreateOn; ;//添加时间
  3716. // model.F_CreateBy = model1[i].F_CreateBy; ;//添加人
  3717. if (!string.IsNullOrEmpty(model1[i].F_CreateBy))
  3718. {
  3719. Model.T_Sys_UserAccount creatname = userAccountBLL.GetModel(model1[i].F_CreateBy);
  3720. if (creatname != null)
  3721. {
  3722. model.F_CreateBy = creatname.F_WorkNumber; ;//添加人
  3723. model.F_CreateName = creatname.F_UserName; ;//添加人
  3724. model.F_CreatePhone = creatname.F_Mobile;
  3725. model.CreateName = creatname.F_UserName + "(" + creatname.F_WorkNumber + ")";
  3726. }
  3727. }
  3728. model.F_UpdateBy = model1[i].F_UpdateBy;//修改人工号
  3729. model.F_UpdateOn = model1[i].F_UpdateOn; ;//修改人工号
  3730. if (model1[i].F_IsAudit != 0 && model1[i].F_IsAudit != null)
  3731. {
  3732. if (model1[i].F_AuditState == 0)
  3733. {
  3734. model.F_AuditState = "同意上报";
  3735. }
  3736. else if (model1[i].F_AuditState == 1)
  3737. {
  3738. model.F_AuditState = "驳回修订";
  3739. }
  3740. else
  3741. {
  3742. model.F_AuditState = "强制结案";
  3743. }
  3744. }
  3745. else
  3746. {
  3747. model.F_AuditState = "";
  3748. }
  3749. model.F_AuditBy = model1[i].F_AuditBy;//审核人
  3750. model.F_AuditOn = model1[i].F_AuditOn;//审核时间
  3751. model.F_AuditCont = model1[i].F_AuditCont;//审核内容
  3752. // model.RemainingTime = float.Parse(string.Format("{0:f2}", TimeToOver(model1[i].F_ID, model1[i].F_limit)));
  3753. float c = TimeToOver(model1[i].F_ID, model1[i].F_limit);
  3754. float a = Math.Abs(c);
  3755. int days = (int)Math.Floor(Convert.ToDouble(a / 24));
  3756. int hours = days > 0
  3757. ? (int)Math.Floor(Convert.ToDouble((a - days * 24)))
  3758. : (int)Math.Floor(Convert.ToDouble(a));
  3759. float minutes = hours > 0
  3760. ? a * 60 - days * 1440 - hours * 60
  3761. : 0;
  3762. if (c > 0)
  3763. model.RemainingTime = string.Format("剩余{0:f0}天{1:f0}时{2:f0}分", days, hours, minutes);
  3764. else
  3765. model.RemainingTime = string.Format("超时{0:f0}天{1:f0}时{2:f0}分", days, hours, minutes);
  3766. #region 内线超时时间计算
  3767. float c2 = TimeToOver(model1[i].F_ID, model1[i].F_limit, 2);
  3768. float a2 = Math.Abs(c2);
  3769. int days2 = (int)Math.Floor(Convert.ToDouble(a2 / 24));
  3770. int hours2 = days2 > 0
  3771. ? (int)Math.Floor(Convert.ToDouble((a2 - days2 * 24)))
  3772. : (int)Math.Floor(Convert.ToDouble(a2));
  3773. float minutes2 = hours2 > 0
  3774. ? a2 * 60 - days2 * 1440 - hours2 * 60
  3775. : 0;
  3776. if (c2 > 0)
  3777. model.RemainingTime2 = string.Format("剩余{0:f0}天{1:f0}时{2:f0}分", days2, hours2, minutes2);
  3778. else
  3779. model.RemainingTime2 = string.Format("超时{0:f0}天{1:f0}时{2:f0}分", days2, hours2, minutes2);
  3780. #endregion
  3781. if (ua != null)
  3782. {
  3783. var itemlast = itembll.GetModelList(" F_WoID='" + model.F_ID + "' order by F_ID desc").FirstOrDefault();
  3784. if (itemlast != null)
  3785. model.F_UserCode = itemlast.F_CreateUser;
  3786. if (!string.IsNullOrEmpty(model.F_UserCode))
  3787. {
  3788. Model.T_Sys_UserAccount user = userAccountBLL.GetModel(model.F_UserCode);
  3789. if (user != null)
  3790. {
  3791. model.F_UserName = user?.F_UserName?? "";
  3792. Model.T_Sys_Department dept = departmentBLL.GetModel(user.F_DeptId);
  3793. if (dept != null)
  3794. {
  3795. model.F_NextDeptName = dept.F_DeptName;
  3796. }
  3797. }
  3798. }
  3799. }
  3800. model.F_limit = model1[i].F_limit;
  3801. int day = (int)Math.Floor(Convert.ToDouble(model.F_limit / 24));
  3802. int hour = day > 0
  3803. ? (int)Math.Floor(Convert.ToDouble((model.F_limit - day * 24)))
  3804. : (int)Math.Floor(Convert.ToDouble(model.F_limit));
  3805. string time = "";
  3806. if (day > 0) time += day + "天";
  3807. if (hour > 0) time += hour + "小时";
  3808. model.F_limitTime = time;
  3809. //if (model1[i].F_Type !="3")
  3810. //{
  3811. // #region 判断外线是否超时
  3812. // if (TimeToOver(model1[i].F_ID, model1[i].F_limit) < 0)
  3813. // {
  3814. // model.F_IsOver = 1;
  3815. // }
  3816. // #endregion
  3817. // #region 判断内线是否超时
  3818. // else if (TimeToOver(model1[i].F_ID, model1[i].F_limit, 2) < 0)
  3819. // {
  3820. // model.F_IsOver = 2; //内线超时
  3821. // }
  3822. // #endregion
  3823. // else
  3824. // {
  3825. // model.F_IsOver = model1[i].F_IsOver;
  3826. // }
  3827. //}
  3828. model.F_IsOver = model1[i].F_IsOver;
  3829. model.F_VisitResultScore = model1[i].F_VisitResultScore;
  3830. model.F_EffectiveScore = model1[i].F_EffectiveScore;
  3831. model.F_ServiceAttitude = model1[i].F_ServiceAttitude;
  3832. model.F_ProductQuality = model1[i].F_ProductQuality;
  3833. model.F_NPS = model1[i].F_NPS;
  3834. model.F_EvaluationResult = model1[i].F_EvaluationResult;
  3835. model.F_MailingNumber = model1[i].F_MailingNumber;
  3836. model.F_ExpressName = model1[i].F_ExpressName;
  3837. model.F_WorkmanShip = model1[i].F_WorkmanShip;//质量管理科-工艺
  3838. model.F_Manufacturers = model1[i].F_Manufacturers;//质量管理科-原料及厂家
  3839. model.F_ProductionNum = model1[i].F_ProductionNum;//质量管理科-该批次生产数量
  3840. model.F_Flag = model1[i].F_Flag;//1单线外 2单线内 3双线 9市场科可以双线指派工单 0 未指派工单
  3841. if (ua != null)
  3842. {
  3843. model.inout = GetNodeState(model1[i].F_ID, ua.F_UserCode, state);
  3844. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  3845. if (deptmodel != null)
  3846. {
  3847. model.F_Deptid = deptmodel.F_DeptId;
  3848. model.F_DeptName = deptmodel.F_DeptName;
  3849. }
  3850. }
  3851. #endregion
  3852. Input.Add(model);
  3853. }
  3854. return Input;
  3855. }
  3856. else
  3857. {
  3858. return null;
  3859. }
  3860. }
  3861. /// <summary>
  3862. /// 是否超时
  3863. /// </summary>
  3864. /// <param name="id"></param>
  3865. /// <returns></returns>
  3866. private float TimeToOver(int id, int limit, int flag = 1)
  3867. {
  3868. string strsql = "";
  3869. if (flag == 1)
  3870. {
  3871. strsql = " and F_Type in(1,3)";
  3872. }
  3873. else if (flag == 2)
  3874. {
  3875. strsql = " and F_Type in(2,3)";
  3876. }
  3877. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + "" + strsql + " and F_WoID=" + id);
  3878. string time1 = "", time2 = ""; int x = 0, y = 0;
  3879. if (itemlasts.Count > 0)
  3880. {
  3881. for (int z = 0; z < itemlasts.Count; z++)
  3882. {
  3883. if (itemlasts[z].F_WoState >= 1)
  3884. {
  3885. if (itemlasts[z].F_WoState == 1)
  3886. {
  3887. x = z;
  3888. time1 = itemlasts[z].F_CreateTime.ToString();
  3889. break;
  3890. }
  3891. }
  3892. }
  3893. for (int i = 0; i < itemlasts.Count; i++)
  3894. {
  3895. if (itemlasts[i].F_WoState >= 1)
  3896. {
  3897. if (itemlasts[i].F_WoState == 10 || itemlasts[i].F_WoState == 11)
  3898. {
  3899. y = i;
  3900. time2 = itemlasts[i].F_CreateTime.ToString();
  3901. }
  3902. }
  3903. }
  3904. if (time2 != "")
  3905. {
  3906. if (time1 != "")
  3907. {
  3908. if (y > x)
  3909. {
  3910. System.TimeSpan a = DateTime.Parse(time2) - DateTime.Parse(time1);
  3911. float b = limit - (float)a.TotalHours;
  3912. return b;
  3913. }
  3914. else
  3915. {
  3916. System.TimeSpan a = DateTime.Now - DateTime.Parse(time1);
  3917. float b = limit - (float)a.TotalHours;
  3918. return b;
  3919. }
  3920. }
  3921. else
  3922. {
  3923. return 0;
  3924. }
  3925. }
  3926. else if (time1 != "")
  3927. {
  3928. System.TimeSpan a = DateTime.Now - DateTime.Parse(time1);
  3929. float b = limit - (float)a.TotalHours;
  3930. return b;
  3931. }
  3932. else
  3933. {
  3934. return 0;
  3935. }
  3936. }
  3937. else
  3938. {
  3939. return 0;
  3940. }
  3941. }
  3942. private string AssCont(int id)
  3943. {
  3944. string cont = "";
  3945. var itemlist = itembll.GetModelList("F_WoID=" + id + "and F_IsUsed=0" + "order by F_ID desc");
  3946. if (itemlist.Count > 0)
  3947. {
  3948. cont = itemlist[0].F_OptContent;
  3949. }
  3950. return cont;
  3951. }
  3952. /// <summary>
  3953. /// 获取当前用户上一级的用户
  3954. /// </summary>
  3955. /// <param name="OpenId"></param>
  3956. /// <returns></returns>
  3957. public Model.T_Sys_UserAccount GetUser(string OpenId)
  3958. {
  3959. if (!string.IsNullOrEmpty(OpenId))
  3960. {
  3961. // int userId = CurrentUser.UserData.F_UserId;
  3962. // Model.T_Sys_UserAccount ua = userAccountBLL.GetModel(userId);
  3963. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  3964. if (ua != null)
  3965. {
  3966. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  3967. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  3968. // var dept = departmentBLL.GetModel(deptmodel.F_ParentId);
  3969. #region 业务员
  3970. if (ro.F_RoleCode == "YWY")
  3971. {
  3972. if (deptmodel != null)
  3973. {
  3974. Model.T_Sys_UserAccount userModel = userAccountBLL.GetModelList(" F_DeptId=" + deptmodel.F_DeptId + " and F_RoleId=60 ").FirstOrDefault();
  3975. if (userModel != null)
  3976. return userModel;
  3977. else
  3978. {
  3979. Model.T_Sys_UserAccount userModel1 = userAccountBLL.GetModelList(" F_DeptId=" + deptmodel.F_DeptId + " and F_RoleId=62 ").FirstOrDefault();
  3980. return userModel1;
  3981. }
  3982. //if (deptmodel.F_Layer == 2)
  3983. //{
  3984. // Model.T_Sys_UserAccount userModel = userAccountBLL.GetModelList(" F_DeptId=" + deptmodel.F_DeptId + " and F_RoleId=60 ").FirstOrDefault();
  3985. // if (userModel!=null )
  3986. // return userModel;
  3987. // else
  3988. // {
  3989. // var dept = departmentBLL.GetModel(deptmodel.F_ParentId);
  3990. // if (dept != null)
  3991. // {
  3992. // Model.T_Sys_UserAccount userModel1 = userAccountBLL.GetModelList(" F_DeptId=" + dept.F_DeptId + " and F_RoleId=62 ").FirstOrDefault();
  3993. // return userModel1;
  3994. // }
  3995. // }
  3996. //}
  3997. //if (deptmodel.F_Layer == 1)
  3998. //{
  3999. // Model.T_Sys_UserAccount userModel = userAccountBLL.GetModelList(" F_DeptId=" + deptmodel.F_DeptId + " and F_RoleId=62 ").FirstOrDefault();
  4000. // return userModel;
  4001. //}
  4002. }
  4003. else
  4004. {
  4005. return null;
  4006. }
  4007. }
  4008. #endregion
  4009. #region 大区经理
  4010. else if (ro.F_RoleCode == "DQJL")
  4011. {
  4012. return null;
  4013. }
  4014. #endregion
  4015. #region 分公司经理
  4016. else if (ro.F_RoleCode == "FGSJL")
  4017. {
  4018. if (deptmodel != null)
  4019. {
  4020. var dept = departmentBLL.GetModel(deptmodel.F_ParentId);
  4021. if (dept != null)
  4022. {
  4023. Model.T_Sys_UserAccount userModel = userAccountBLL.GetModelList(" F_DeptId=" + dept.F_DeptId + " and F_RoleId=62 ").FirstOrDefault();
  4024. if (userModel!=null )
  4025. return userModel;
  4026. }
  4027. else
  4028. {
  4029. return null;
  4030. }
  4031. }
  4032. else
  4033. {
  4034. return null;
  4035. }
  4036. }
  4037. #endregion
  4038. }
  4039. return null;
  4040. }
  4041. else
  4042. {
  4043. return null;
  4044. }
  4045. }
  4046. /// <summary>
  4047. /// 获取上一级管理员
  4048. /// </summary>
  4049. /// <param name="OpenId"></param>
  4050. /// <returns></returns>
  4051. [WechatActionFilter]
  4052. public ActionResult GetDpment(string OpenId)
  4053. {
  4054. if (!string.IsNullOrEmpty(OpenId))
  4055. {
  4056. if (GetUser(OpenId) != null)
  4057. {
  4058. return Success("获取成功!", GetUser(OpenId));
  4059. }
  4060. else
  4061. {
  4062. return Success("获取失败!", null);
  4063. }
  4064. }
  4065. else
  4066. {
  4067. return Error("OpenId不能为空!");
  4068. }
  4069. }
  4070. /// <summary>
  4071. /// 修改密码
  4072. /// </summary>
  4073. /// <returns></returns>
  4074. [WechatActionFilter]
  4075. public ActionResult UpdatePassWord()
  4076. {
  4077. string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  4078. //5--业主(客户档案会员)
  4079. int usertype = RequestString.GetInt("usertype", 0);
  4080. //原密码
  4081. string oldpwd = RequestString.GetFormString("oldpwd").Trim();
  4082. string pwd = RequestString.GetFormString("pwd").Trim();
  4083. string repeatpwd = RequestString.GetFormString("repeatpwd").Trim();
  4084. if (usertype == 0)
  4085. return Error("无权修改密码");
  4086. if (string.IsNullOrWhiteSpace(oldpwd))
  4087. return Error("请输入原密码");
  4088. if (string.IsNullOrWhiteSpace(pwd))
  4089. return Error("请输入新密码");
  4090. if (string.IsNullOrWhiteSpace(repeatpwd))
  4091. return Error("请再次输入新密码");
  4092. if (!pwd.Equals(repeatpwd))
  4093. return Error("两个新密码不同,请重新输入");
  4094. var model = new Model.T_Sys_UserAccount();
  4095. var modelCus = new Model.T_Cus_CustomerBaseNew();
  4096. //坐席表
  4097. if (usertype < 5)
  4098. {
  4099. model = userAccountBLL.GetModelByOpenid(stropenid);
  4100. if (model != null)
  4101. {
  4102. if (!model.F_Password.Equals(oldpwd)) return Error("原密码不正确");
  4103. model.F_Password = pwd;
  4104. if (userAccountBLL.Update(model))
  4105. return Success("重置密码成功");
  4106. }
  4107. return Error("重置密码失败");
  4108. }
  4109. //客户档案表
  4110. modelCus = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();//customerBaseBLL.GetModelByOpenid(stropenid);
  4111. if (modelCus != null)
  4112. {
  4113. if (!modelCus.F_WxPassword.Equals(oldpwd)) return Error("原密码不正确");
  4114. modelCus.F_WxPassword = pwd;
  4115. if (customerBaseBLL.Update(modelCus))
  4116. return Success("重置密码成功");
  4117. }
  4118. return Error("重置密码失败");
  4119. }
  4120. /// <summary>
  4121. /// 验证生产批次号为15位
  4122. /// </summary>
  4123. private bool vaBatchNumber(string code)
  4124. {
  4125. var res = false;
  4126. if (code.Length == 15)
  4127. {
  4128. char chr = code[12];
  4129. if (chr > 'A' && chr < 'Z')
  4130. {
  4131. string code1 = code.Substring(0, 12);
  4132. string code2 = code.Substring(15 - 2, 2);
  4133. if (Regex.IsMatch(code1, @"^\d{12}$") && Regex.IsMatch(code2, @"^\d{2}$"))
  4134. res = true;
  4135. }
  4136. else
  4137. {
  4138. res = false;
  4139. }
  4140. }
  4141. return res;
  4142. }
  4143. /// <summary>
  4144. /// 验证物料编码为10位纯数字
  4145. /// </summary>
  4146. private bool valcode(string code, int number)
  4147. {
  4148. var res = false;
  4149. //11位数字
  4150. if (code.Length == number && Regex.IsMatch(code, @"^\d{" + number + "}$"))
  4151. res = true;
  4152. return res;
  4153. }
  4154. /// <summary>
  4155. /// 验证物料编号是否唯一
  4156. /// </summary>
  4157. private bool gematerque(int id, string code)
  4158. {
  4159. var sql = " F_IsDelete=0 ";
  4160. sql += "and (F_MaterialCode='" + code + "')";
  4161. if (id > 0)
  4162. sql += " and F_Id<>" + id;
  4163. var count = mmBLL.GetModelList(sql).Count();
  4164. return count > 0;
  4165. }
  4166. /// <summary>
  4167. /// 验证客户编号是否唯一
  4168. /// </summary>
  4169. private bool getunique(int id, string code)
  4170. {
  4171. var sql = " F_IsDelete=0 ";
  4172. sql += "and (F_CustomerCode='" + code + "')";
  4173. if (id > 0)
  4174. sql += " and F_CustomerId<>" + id;
  4175. var count = customerBaseBLL.GetModelList(sql).Count();
  4176. return count > 0;
  4177. }
  4178. /// <summary>
  4179. /// 获取我参与的工单编号
  4180. /// </summary>
  4181. /// <param name="user"></param>
  4182. /// <returns></returns>
  4183. public string GetParticipateID(string user)
  4184. {
  4185. string str = string.Empty;
  4186. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_CreateUser in(" + user + ") and F_OptType in( 0,1,7 )";
  4187. ;
  4188. return str;
  4189. }
  4190. /// <summary>
  4191. /// 获取我参与的工单编号
  4192. /// </summary>
  4193. /// <param name="user"></param>
  4194. /// <returns></returns>
  4195. public string GetID(string user)
  4196. {
  4197. string str = string.Empty;
  4198. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_CreateUser in(" + user + ") ";
  4199. ;
  4200. return str;
  4201. }
  4202. /// <summary>
  4203. /// 获取我参与的工单编号
  4204. /// </summary>
  4205. /// <param name="user"></param>
  4206. /// <returns></returns>
  4207. public string GetParticipate(string user)
  4208. {
  4209. string str = string.Empty;
  4210. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_CreateUser in(" + user + ") ";
  4211. ;
  4212. return str;
  4213. }
  4214. private bool IsCustomerBaseNew(WorkOrderNewInput input)
  4215. {
  4216. bool n = false;
  4217. if (!string.IsNullOrEmpty(input.F_CustomerID) || !string.IsNullOrEmpty(input.F_CompanyName)
  4218. || !string.IsNullOrEmpty(input.F_AreaName) || !string.IsNullOrEmpty(input.F_BranchName)
  4219. || !string.IsNullOrEmpty(input.F_Salesman) || !string.IsNullOrEmpty(input.F_SalesPhone)
  4220. || !string.IsNullOrEmpty(input.F_Brands) )
  4221. {
  4222. n = true;
  4223. }
  4224. return n;
  4225. }
  4226. /// <summary>
  4227. /// 添加客户
  4228. /// </summary>
  4229. private Model.T_Cus_CustomerBaseNew inputtooCustomer(Model.T_Cus_CustomerBaseNew model, WorkOrderNewInput input)
  4230. {
  4231. var newmodel = model;
  4232. if (!string.IsNullOrWhiteSpace(input.F_CustomerID.ToString()))
  4233. model.F_CustomerCode = input.F_CustomerID.ToString();
  4234. else
  4235. model.F_CustomerCode = model.F_CustomerCode;
  4236. if (!string.IsNullOrWhiteSpace(input.F_CompanyName))
  4237. model.F_CompanyName = input.F_CompanyName;
  4238. #region 基本字段
  4239. if (!string.IsNullOrEmpty(input.F_AreaName))
  4240. {
  4241. Model.T_Sys_Department pdModel = new Model.T_Sys_Department();
  4242. try
  4243. {
  4244. pdModel = departmentBLL.GetModel(int.Parse(input.F_AreaName));
  4245. }
  4246. catch
  4247. {
  4248. pdModel = departmentBLL.GetModel(input.F_AreaName);
  4249. }
  4250. model.F_AreaID = pdModel.F_DeptId.ToString();
  4251. }
  4252. if (!string.IsNullOrEmpty(input.F_BranchName))
  4253. {
  4254. Model.T_Sys_Department pdModel = new Model.T_Sys_Department();
  4255. try
  4256. {
  4257. pdModel = departmentBLL.GetModel(int.Parse(input.F_BranchName));
  4258. }
  4259. catch
  4260. {
  4261. pdModel = departmentBLL.GetModel(input.F_BranchName);
  4262. }
  4263. model.F_BranchID = pdModel.F_DeptId.ToString();
  4264. }
  4265. model.F_Salesman = input.F_Salesman;//业务员
  4266. model.F_SalesPhone = input.F_SalesPhone;//业务员电话
  4267. model.F_Channel = input.F_Channel;// 渠道类型:总经销、二级商、种田大户、农户、化工客户、公司员工
  4268. model.F_Legal = input.F_CusName;//法人
  4269. model.F_LegalPhone = input.F_CusPhone;//法人电话
  4270. model.F_AddressProvince = input.F_AddressProvince;//省
  4271. model.F_AddressCity = input.F_AddressCity;//市
  4272. model.F_AddressCountry = input.F_AddressCountry;//县
  4273. model.F_AddressTownship = input.F_AddressTownship;//乡
  4274. model.F_AddressFull = input.F_AddressFull;//详细地址
  4275. model.F_Brands = input.F_Brands;// 经营品牌:心连心、手拉手、沃利沃、双心、空
  4276. model.F_IsRunXLX = input.F_IsRunXLX;// 是否经营心连心:是、否
  4277. model.F_AnnualSales = input.F_AnnualSales;//年销量
  4278. model.F_Formula = input.F_Formula;//配方
  4279. model.F_RaiseCrops = input.F_RaiseCrops;//种植作物
  4280. model.F_PlantingArea = input.F_PlantingArea;//种植面积
  4281. model.F_FertilizerBrand = input.F_FertilizerBrand;//用肥品牌
  4282. model.F_FileId = 0;
  4283. #endregion
  4284. return model;
  4285. }
  4286. private string GetCusCode(int i)
  4287. {
  4288. DateTime times = DateTime.Now.AddMinutes(i);
  4289. string time = times.ToString("yyMMddhhmm");
  4290. return time;
  4291. }
  4292. private string GetIntCode()
  4293. {
  4294. string time = DateTime.Now.ToString("hhmmss");
  4295. Random ran = new Random();
  4296. int RandKey = ran.Next(1000, 9999);
  4297. string timecode = 3 + "" + RandKey + "" + time;
  4298. return timecode;
  4299. }
  4300. private bool IsMaterial(WorkOrderNewInput input)
  4301. {
  4302. bool n = false;
  4303. if (!string.IsNullOrEmpty(input.F_MaterialID) || !string.IsNullOrEmpty(input.F_MaterialName)
  4304. || !string.IsNullOrEmpty(input.F_Model) || !string.IsNullOrEmpty(input.F_Specs)
  4305. || !string.IsNullOrEmpty(input.F_Level1) || !string.IsNullOrEmpty(input.F_Level2)
  4306. || !string.IsNullOrEmpty(input.F_Level3) || !string.IsNullOrEmpty(input.F_Brand)
  4307. || !string.IsNullOrEmpty(input.F_MaterialEffect) || !string.IsNullOrEmpty(input.F_Craft)
  4308. || !string.IsNullOrEmpty(input.F_Pipeline))
  4309. {
  4310. n = true;
  4311. }
  4312. return n;
  4313. }
  4314. private void AddMait(WorkOrderNewInput input, string usercode)
  4315. {
  4316. Model.T_Wo_MaterialManage dModel = new Model.T_Wo_MaterialManage();
  4317. dModel.F_MaterialCode = input.F_MaterialID.ToString();//物料编号
  4318. dModel.F_MaterialName = input.F_MaterialName;//物料名称
  4319. dModel.F_Model = input.F_Model;//型号
  4320. dModel.F_Specs = input.F_Specs;//规格
  4321. dModel.F_Level1 = input.F_Level1;//一级分类
  4322. dModel.F_Level2 = input.F_Level2;//二级分类
  4323. dModel.F_Level3 = input.F_Level3;//三级分类
  4324. dModel.F_Brand = input.F_Brand;//品牌
  4325. dModel.F_MaterialEffect = input.F_MaterialEffect;//复合肥肥效
  4326. dModel.F_Craft = input.F_Craft;//工艺
  4327. dModel.F_Pipeline = input.F_Pipeline;//产品线
  4328. dModel.F_IsDelete = 0;
  4329. dModel.F_CreateOn = DateTime.Now;
  4330. dModel.F_CreateBy = usercode;
  4331. int f = mmBLL.Add(dModel);
  4332. }
  4333. /// <summary>
  4334. /// 根据传入的对象和input的内容返回对象(添加修改使用)
  4335. /// </summary>
  4336. private Model.T_Wo_WorkOrder inputtoobj(Model.T_Sys_UserAccount ua, Model.T_Wo_WorkOrder model, WorkOrderNewInput input, int type)
  4337. {
  4338. string usercode = "";
  4339. if (ua != null)
  4340. {
  4341. usercode = ua.F_UserCode;
  4342. }
  4343. var newmodel = model;
  4344. if (input.F_ID != 0)
  4345. {
  4346. model.F_ID = input.F_ID;
  4347. }
  4348. else
  4349. {
  4350. model.F_ID = model.F_ID;//工单ID
  4351. }
  4352. if (type == 2)
  4353. {
  4354. model.F_WorkOrderCode = DateTime.Now.ToString("yyyyMMddHHmmssfff"); //工单编号
  4355. model.F_Source = model.F_Source;
  4356. }
  4357. else
  4358. {
  4359. model.F_WorkOrderCode = model.F_WorkOrderCode;//工单编号
  4360. model.F_Source = model.F_Source.ToString();//工单来源
  4361. }
  4362. if (input.F_Type == 2 || input.F_Type == 3)
  4363. {
  4364. if (string.IsNullOrEmpty(input.F_CustomerID))
  4365. {
  4366. var sql = $" and F_LegalPhone = '" + input.F_CusPhone.Trim() + "'";
  4367. var Customer = new BLL.T_Cus_CustomerBaseNew().GetModelList(" F_IsDelete = 0 " + sql).FirstOrDefault(); ;
  4368. if (Customer != null)
  4369. {
  4370. model.F_CustomerID = Customer.F_CustomerCode;
  4371. if (!string.IsNullOrEmpty(input.F_Salesman))
  4372. Customer.F_Salesman = input.F_Salesman;
  4373. if (!string.IsNullOrEmpty(input.F_SalesPhone))
  4374. Customer.F_SalesPhone = input.F_SalesPhone;
  4375. if (!string.IsNullOrEmpty(input.F_Channel))
  4376. Customer.F_Channel = input.F_Channel;
  4377. if (!string.IsNullOrEmpty(input.F_Brands))
  4378. Customer.F_Brands = input.F_Brands;
  4379. if (!string.IsNullOrEmpty(input.F_AreaName))
  4380. {
  4381. Model.T_Sys_Department pdModel = new Model.T_Sys_Department();
  4382. try
  4383. {
  4384. pdModel = departmentBLL.GetModel(int.Parse(input.F_AreaName));
  4385. }
  4386. catch
  4387. {
  4388. pdModel = departmentBLL.GetModel(input.F_AreaName);
  4389. }
  4390. Customer.F_AreaID = pdModel.F_DeptId.ToString();
  4391. }
  4392. else
  4393. {
  4394. Customer.F_AreaID = "";
  4395. }
  4396. if (!string.IsNullOrEmpty(input.F_BranchName))
  4397. {
  4398. Model.T_Sys_Department pdModel = new Model.T_Sys_Department();
  4399. try
  4400. {
  4401. pdModel = departmentBLL.GetModel(int.Parse(input.F_BranchName));
  4402. }
  4403. catch
  4404. {
  4405. pdModel = departmentBLL.GetModel(input.F_BranchName);
  4406. }
  4407. Customer.F_BranchID = pdModel.F_DeptId.ToString();
  4408. }
  4409. else
  4410. {
  4411. Customer.F_BranchID = "";
  4412. }
  4413. if (!string.IsNullOrEmpty(input.F_CompanyName ))
  4414. Customer.F_CompanyName = input.F_CompanyName;
  4415. customerBaseBLL.Update(Customer);
  4416. }
  4417. else
  4418. {
  4419. if (IsCustomerBaseNew(input))
  4420. {
  4421. if (string.IsNullOrEmpty(input.F_CustomerID))
  4422. {
  4423. int i = 0;
  4424. while (true)
  4425. {
  4426. if (!getunique(0, GetCusCode(i)))
  4427. {
  4428. input.F_CustomerID = GetCusCode(i);
  4429. break;
  4430. }
  4431. else
  4432. {
  4433. i++;
  4434. }
  4435. }
  4436. }
  4437. var CustomerBaseNewmodel = new Model.T_Cus_CustomerBaseNew();
  4438. CustomerBaseNewmodel.F_CustomerCode = input.F_CustomerID;
  4439. CustomerBaseNewmodel.F_CreateBy = usercode;
  4440. CustomerBaseNewmodel.F_CreateOn = DateTime.Now;
  4441. CustomerBaseNewmodel.F_IsDelete = 0;
  4442. customerBaseBLL.Add(inputtooCustomer(CustomerBaseNewmodel, input));
  4443. }
  4444. }
  4445. }
  4446. else
  4447. {
  4448. var Customer = customerBaseBLL.GetModel(input.F_CustomerID.Trim());
  4449. if (Customer != null)
  4450. {
  4451. if (!string.IsNullOrEmpty(input.F_Salesman))
  4452. Customer.F_Salesman = input.F_Salesman;
  4453. if (!string.IsNullOrEmpty(input.F_SalesPhone))
  4454. Customer.F_SalesPhone = input.F_SalesPhone;
  4455. if (!string.IsNullOrEmpty(input.F_Brands))
  4456. Customer.F_Brands = input.F_Brands;
  4457. if (!string.IsNullOrEmpty(input.F_CompanyName))
  4458. Customer.F_CompanyName = input.F_CompanyName.Trim();
  4459. if (!string.IsNullOrEmpty(input.F_Channel))
  4460. Customer.F_Channel = input.F_Channel;
  4461. if (!string.IsNullOrEmpty(input.F_AreaName))
  4462. {
  4463. Model.T_Sys_Department pdModel = new Model.T_Sys_Department();
  4464. try
  4465. {
  4466. pdModel = departmentBLL.GetModel(int.Parse(input.F_AreaName));
  4467. }
  4468. catch
  4469. {
  4470. pdModel = departmentBLL.GetModel(input.F_AreaName);
  4471. }
  4472. Customer.F_AreaID = pdModel.F_DeptId.ToString();
  4473. }
  4474. else
  4475. {
  4476. Customer.F_AreaID = "";
  4477. }
  4478. if (!string.IsNullOrEmpty(input.F_BranchName))
  4479. {
  4480. {
  4481. Model.T_Sys_Department pdModel = new Model.T_Sys_Department();
  4482. try
  4483. {
  4484. pdModel = departmentBLL.GetModel(int.Parse(input.F_BranchName));
  4485. }
  4486. catch
  4487. {
  4488. pdModel = departmentBLL.GetModel(input.F_BranchName);
  4489. }
  4490. Customer.F_BranchID = pdModel.F_DeptId.ToString();
  4491. }
  4492. }
  4493. else
  4494. {
  4495. Customer.F_BranchID = "";
  4496. }
  4497. if (!string.IsNullOrEmpty(input.F_CompanyName))
  4498. Customer.F_CompanyName = input.F_CompanyName;
  4499. customerBaseBLL .Update(Customer);
  4500. }
  4501. }
  4502. }
  4503. #region 基本字段
  4504. if (!string.IsNullOrEmpty(input.F_MaterialID))
  4505. {
  4506. model.F_MaterialID = input.F_MaterialID.ToString();//物料编码为11为纯数字
  4507. }
  4508. model.F_Source = input.F_Source.ToString();//工单来源
  4509. model.F_Type = input.F_Type.ToString();//工单类型:咨询及需求、投诉、抽检、其他(其它手动输入别的点选)
  4510. model.F_Production = input.F_Production;//生产单位
  4511. LogFactory.GetLogger("123").Debug(input.F_Production);
  4512. model.F_CusName = input.F_CusName;//客户姓名
  4513. model.F_CusPhone = input.F_CusPhone;//客户电话
  4514. model.F_CompanyName = input.F_CompanyName;//公司名称
  4515. model.F_IncidentProvince = input.F_IncidentProvince;//事发地-省
  4516. model.F_IncidentCity = input.F_IncidentCity;//事发地-市
  4517. model.F_IncidentCountry = input.F_IncidentCountry;//事发地-县
  4518. model.F_IncidentTownship = input.F_IncidentTownship;//事发地-乡
  4519. model.F_IncidentDetailed = input.F_IncidentDetailed;//事发地-详细
  4520. model.F_SalesBase = input.F_SalesBase;//销售基地:新乡、新疆、九江、东北、其他(其它手动输入别的点选)
  4521. model.F_Description = input.F_Description;//问题描述
  4522. model.F_ZX_Area = input.F_ZX_Area;// 大区
  4523. model.F_ZX_Branch = input.F_ZX_Branch;//分公司
  4524. if (!string.IsNullOrEmpty(input.F_Files))
  4525. model.F_Files = input.F_Files;//附件上传ids
  4526. else
  4527. model.F_Files = model.F_Files;//附件上传ids
  4528. model.F_Brand = input.F_WorkerBrand;//
  4529. model.F_DealType = model.F_DealType;//处理方式:当即办理、电话转接、网络转办(点选)
  4530. model.F_Canal = input.F_Canal;//处理方式:当即办理、电话转接、网络转办(点选)
  4531. #endregion
  4532. model.F_QuestionType = input.F_QuestionType;//问题类别(投诉抽捡和咨询类别不一样)
  4533. model.F_CustomerID = input.F_CustomerID;//客户编号为10为纯数字
  4534. model.F_MaterialID = input.F_MaterialID;//物料编码为11为纯数字
  4535. #region 投诉类
  4536. model.F_BatchNumber = input.F_BatchNumber;//生产批次号
  4537. model.F_TS_Formula = input.F_TS_Formula;// 投诉-配方
  4538. model.F_TS_Category = input.F_TS_Category;//投诉-产品种类:化肥、化工、其他
  4539. model.F_TS_Quantity = input.F_TS_Quantity;//投诉-问题数量(吨)
  4540. model.F_TS_Level = input.F_TS_Level;//投诉-重要级别:轻微、一般、较大、重大
  4541. #region 肥效类增加作物字段 20220307
  4542. if (!string.IsNullOrEmpty(input.F_Crops))
  4543. {
  4544. model.F_Crops = input.F_Crops;
  4545. }
  4546. #endregion
  4547. #endregion
  4548. #region 咨询类
  4549. // model.F_ZX_ProName = input.F_ZX_ProName;//咨询-产品名称:三聚氰胺、甲醇、液氨、二甲醚、糠醇、其他
  4550. model.F_ZX_Quantity = input.F_ZX_Quantity;// 咨询-问题数量(吨)
  4551. #endregion
  4552. #region 抽检类
  4553. model.F_CJ_Time = input.F_CJ_Time;// 抽检-抽检时间
  4554. model.F_CJ_Level = input.F_CJ_Level;// 抽检-抽检级别:乡镇级、县级、市级、省级及以上、个人送检
  4555. model.F_CJ_Unit = input.F_CJ_Unit;// 抽检-抽检单位:市场监督、农业部、土肥站、工商、联合执法、其他
  4556. model.F_CJ_TestUnit = input.F_CJ_TestUnit;//抽检-化验单位
  4557. model.F_CJ_Tonnage = input.F_CJ_Tonnage;//抽检-抽检吨数
  4558. model.F_CJ_BagNo = input.F_CJ_BagNo;//抽检-抽检袋数
  4559. model.F_CJ_Outlay = input.F_CJ_Outlay;//抽检-公关费用金额:单位元】
  4560. model.F_WxOpenId = input.F_WxOpenId;
  4561. // model.F_VisitRemarks = input.F_VisitRemarks;//回访备注
  4562. //if (!string.IsNullOrEmpty(input.F_BatchNumber))
  4563. //{
  4564. // if (type == 1)
  4565. // {
  4566. // model.F_SC_QualityMonth = new WorkOrderController().GetProTime(input.F_BatchNumber, DateTime.Parse(model.F_CreateOn.ToString())).ToString();
  4567. // }
  4568. // else
  4569. // {
  4570. // model.F_SC_QualityMonth = new WorkOrderController().GetProTime(input.F_BatchNumber, DateTime.Now).ToString();
  4571. // }
  4572. //}
  4573. if (type == 1)
  4574. {
  4575. model.F_State = model.F_State;//工单状态
  4576. model.F_CreateOn = model.F_CreateOn;//添加时间
  4577. model.F_CreateBy = model.F_CreateBy;//添加人
  4578. model.F_UpdateBy = usercode;//修改人工号
  4579. model.F_UpdateOn = DateTime.Now;//修改人工号
  4580. if (input.F_UpdateCount != null)
  4581. {
  4582. model.F_UpdateCount = model.F_UpdateCount + 1;//修改次数
  4583. }
  4584. else
  4585. {
  4586. model.F_UpdateCount = 1;//修改次数
  4587. }
  4588. model.F_limit = model.F_limit;
  4589. }
  4590. else
  4591. {
  4592. model.F_limit = 0;
  4593. model.F_State = (int)EnumWorkOrderState.neworder;
  4594. model.F_State2= (int)EnumWorkOrderState.neworder;
  4595. model.F_CreateBy = usercode;
  4596. model.F_CreateOn = DateTime.Now;
  4597. }
  4598. model.F_IsVisit = 1;
  4599. model.F_IsDelete = 0;
  4600. model.F_IsOver = 0;
  4601. #endregion
  4602. return model;
  4603. }
  4604. /// <summary>
  4605. /// 获取我参与的工单编号
  4606. /// </summary>
  4607. /// <param name="user"></param>
  4608. /// <returns></returns>
  4609. public string GetCYWorkOrderID(string user)
  4610. {
  4611. string str = string.Empty;
  4612. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_CreateUser in(" + user + ") and F_OptType in( 1,3,13 )";
  4613. return str;
  4614. }
  4615. /// <summary>
  4616. /// 获取高层
  4617. /// </summary>
  4618. /// <param name="deptId"></param>
  4619. /// <returns></returns>
  4620. public ActionResult GetHighlevel()
  4621. {
  4622. var user = userAccountBLL.GetModelList(" F_RoleId=61");
  4623. if (user != null)
  4624. return Success("获取高层信息成功", new
  4625. {
  4626. user
  4627. });
  4628. return Error("获取高层信息失败");
  4629. }
  4630. /// <summary>
  4631. /// 验证客户电话是否唯一
  4632. /// </summary>
  4633. private bool getunphone(int id, string phone)
  4634. {
  4635. var sql = " F_IsDelete=0 ";
  4636. sql += "and (F_LegalPhone='" + phone + "')";
  4637. if (id > 0)
  4638. sql += " and F_CustomerId<>" + id;
  4639. var count = customerBaseBLL.GetModelList(sql).Count();
  4640. return count > 0;
  4641. }
  4642. /// <summary>
  4643. /// 添加工单
  4644. /// </summary>
  4645. /// <returns></returns>
  4646. public ActionResult CustomAdd(WorkOrderNewInput input, int overtime = 0, int sms = 0)
  4647. {
  4648. if (string.IsNullOrEmpty(input.F_CusName))
  4649. return Error("请输入客户姓名!");
  4650. if (string.IsNullOrEmpty(input.F_CusPhone))
  4651. return Error("请输入客户电话!");
  4652. if (input.F_Type == 3)
  4653. {
  4654. if (string.IsNullOrEmpty(input.F_Files))
  4655. return Error("请上传抽检单");
  4656. if (string.IsNullOrEmpty(input.F_CJ_Time.ToString()))
  4657. return Error("请选择抽检时间");
  4658. }
  4659. if (!string.IsNullOrEmpty(input.F_SalesPhone))
  4660. {
  4661. if (!IsNumeric(input.F_SalesPhone))
  4662. return Error("请输入正确的业务员电话");
  4663. }
  4664. var model = new Model.T_Wo_WorkOrder();
  4665. #region 保存客户基本信息
  4666. model = inputtoobj(null , model, input, 2);
  4667. model.F_State = (int)EnumWorkOrderState.customers;
  4668. model.F_limit = overtime;
  4669. #endregion
  4670. long n = woBLL.Add(model);
  4671. if (n > 0)
  4672. {
  4673. #region 流转上一级领导审批
  4674. Model.T_Wo_WorkOrder modlelist = new BLL.T_Wo_WorkOrder().GetModel(n);
  4675. if (modlelist != null)
  4676. {
  4677. AddLog(modlelist.F_ID, 0, "客户" + "创建工单", (int)EnumItemType.deal, (int)EnumItemOpt.create, "", 0, null, overtime, sms);
  4678. return Success("添加成功");
  4679. }
  4680. #endregion
  4681. return Success("添加成功!");
  4682. }
  4683. else
  4684. return Error("添加失败!");
  4685. }
  4686. /// <summary>
  4687. /// 添加工单
  4688. /// </summary>
  4689. /// <returns></returns>
  4690. public ActionResult Add(WorkOrderNewInput input, int overtime = 0, int sms = 0, int tempid = 0)
  4691. {
  4692. if (!string.IsNullOrEmpty(input.F_WxOpenId))
  4693. {
  4694. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + input.F_WxOpenId + "'").FirstOrDefault();
  4695. // string usercode = CurrentUser.UserData.F_UserCode;
  4696. // Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModel(userId);
  4697. if (ua == null && input.F_Source != 3)
  4698. {
  4699. return Error("无操作权限!");
  4700. }
  4701. if (input .F_Source !=3& input.F_Type == 2 || input.F_Type == 5)
  4702. {
  4703. if (string.IsNullOrEmpty(input.F_SalesBase))
  4704. return Error("请输入基地!");
  4705. if (string.IsNullOrEmpty(input.F_QuestionType))
  4706. return Error("请选择问题类别!");
  4707. }
  4708. //if (!string.IsNullOrEmpty(input.F_BatchNumber) && !vaBatchNumber(input.F_BatchNumber))
  4709. //{
  4710. // return Error("请输入正确的生产批次号!");
  4711. //}
  4712. //else
  4713. //{
  4714. // if (!string.IsNullOrEmpty(input.F_BatchNumber))
  4715. // {
  4716. // var prono = input.F_BatchNumber.Substring(0, 6);
  4717. // try
  4718. // {
  4719. // var pronos = DateTime.ParseExact(prono, "yyMMdd", null).ToString("yyyy-MM-dd");
  4720. // var protime = Convert.ToDateTime(pronos);
  4721. // if (DateTime.Parse(pronos) > DateTime.Now)
  4722. // {
  4723. // return Error("生产批次号错误,生产日期不能大于当前时间!");
  4724. // }
  4725. // }
  4726. // catch
  4727. // {
  4728. // return Error("生产批次号错误,日期格式错误!");
  4729. // }
  4730. // }
  4731. //}
  4732. if (!string.IsNullOrEmpty(input.F_CustomerID) && !valcode(input.F_CustomerID.ToString(), 10))
  4733. return Error("客户编号为10为纯数字!");
  4734. if (!string.IsNullOrEmpty(input.F_MaterialID) && !valcode(input.F_MaterialID.ToString(), 11))
  4735. return Error("物料编码为11为纯数字!");
  4736. if (string.IsNullOrEmpty(input.F_CusName))
  4737. return Error("请输入客户姓名!");
  4738. if (string.IsNullOrEmpty(input.F_CusPhone))
  4739. return Error("请输入客户电话!");
  4740. if (!string.IsNullOrEmpty(input.F_CustomerID))
  4741. {
  4742. var Customer = customerBaseBLL.GetModel(input.F_CustomerID.Trim());
  4743. if (Customer == null)
  4744. return Error("无此客户编码!");
  4745. }
  4746. if (!string.IsNullOrWhiteSpace(input.F_MaterialID))
  4747. {
  4748. var Customer = mmBLL.GetModel(input.F_MaterialID.Trim());
  4749. if (Customer == null)
  4750. return Error("无此物料编码!");
  4751. }
  4752. if (input.F_Type == 3)
  4753. {
  4754. if (string.IsNullOrEmpty(input.F_Files))
  4755. return Error("请上传抽检单");
  4756. if (string.IsNullOrEmpty(input.F_CJ_Time.ToString()))
  4757. return Error("请选择抽检时间");
  4758. if (overtime==0)
  4759. {
  4760. overtime = 2160;
  4761. }
  4762. }
  4763. if (!string.IsNullOrEmpty(input.F_SalesPhone))
  4764. {
  4765. if (!IsNumeric(input.F_SalesPhone))
  4766. return Error("请输入正确的业务员电话");
  4767. }
  4768. #region 暂存数据删除
  4769. if (tempid > 0)
  4770. {
  4771. var tempmodel = new BLL.T_Wo_TempStorage().GetModel(tempid);
  4772. if (tempmodel != null)
  4773. new BLL.T_Wo_TempStorage().DelteByWhere($"F_CreateBy={ua.F_UserCode}");
  4774. }
  4775. #endregion
  4776. var model = new Model.T_Wo_WorkOrder();
  4777. #region 保存客户基本信息
  4778. model = inputtoobj(ua, model, input, 2);
  4779. LogFactory.GetLogger("635").Debug("添加中。。。。");
  4780. if (model.F_Source == "3")
  4781. {
  4782. model.F_State = (int)EnumWorkOrderState.customers;
  4783. model.F_State2 = (int)EnumWorkOrderState.customers;
  4784. }
  4785. else
  4786. {
  4787. model.F_State = (int)EnumWorkOrderState.audit;
  4788. model.F_State2 = (int)EnumWorkOrderState.audit;
  4789. }
  4790. model.F_limit = overtime;
  4791. #endregion
  4792. long n = woBLL.Add(model);
  4793. if (n > 0)
  4794. {
  4795. #region 流转上一级领导审批
  4796. Model.T_Wo_WorkOrder modlelist = new BLL.T_Wo_WorkOrder().GetModel(n);
  4797. if (modlelist != null)
  4798. {
  4799. if (ua != null && model.F_Source != "3")
  4800. {
  4801. if (GetUser(input.F_WxOpenId) != null)
  4802. {
  4803. var user = GetUser(input.F_WxOpenId);
  4804. string deptname = "", deptname1 = "";
  4805. var deptmodel = departmentBLL.GetModel(user.F_DeptId);
  4806. if (deptmodel != null)
  4807. {
  4808. deptname = deptmodel.F_DeptName + "-";
  4809. }
  4810. var deptmodel1 = departmentBLL.GetModel(ua.F_DeptId);
  4811. if (deptmodel1 != null)
  4812. {
  4813. deptname1 = deptmodel1.F_DeptName + "-";
  4814. }
  4815. 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);
  4816. 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);
  4817. if (sms == 1 && !string.IsNullOrEmpty(user.F_Mobile))
  4818. {
  4819. SendSms(model.F_Type, user.F_Mobile, ua.F_UserId);
  4820. }
  4821. }
  4822. else
  4823. {
  4824. string deptname1 = "";
  4825. int dapt = 0, nextda = 0, nextda2 = 0;
  4826. string deptment = "";
  4827. var deptmodel1 = departmentBLL.GetModel(ua.F_DeptId);
  4828. if (deptmodel1 != null)
  4829. {
  4830. deptname1 = deptmodel1.F_DeptName + "-";
  4831. dapt = deptmodel1.F_ParentId;
  4832. deptment = deptmodel1.F_DeptName;
  4833. }
  4834. AddLog(modlelist.F_ID, 0, deptname1 + ua.F_UserName + "(" + ua.F_WorkNumber + ")" + "创建工单", (int)EnumWorkOrderState.neworder, (int)EnumItemOpt.create, "", 0, ua, overtime, sms);
  4835. string opt = "", opt2 = "";
  4836. //if (dapt != 0)
  4837. //{
  4838. if (CirculMarket(ua.F_DeptId, 11))
  4839. {
  4840. nextda = 427;
  4841. opt = "流转运营中心";
  4842. }
  4843. else if (CirculMarket(ua.F_DeptId, 14))
  4844. {
  4845. nextda = 57;
  4846. opt = "流转营销管理处";
  4847. }
  4848. else if (CirculMarket(ua.F_DeptId, 15))
  4849. {
  4850. nextda = 74;
  4851. opt = "流转策划推广";
  4852. }
  4853. else if (CirculMarket(ua.F_DeptId, 16))
  4854. {
  4855. nextda = 88;
  4856. opt = "流转销售部";
  4857. }
  4858. else if (CirculMarket(ua.F_DeptId, 18))
  4859. {
  4860. nextda = 268;
  4861. opt = "流转车用尿素";
  4862. }
  4863. else if (CirculMarket(ua.F_DeptId, 20))
  4864. {
  4865. nextda = 422;
  4866. opt = "流转营销中心市场科";
  4867. nextda2 = 295;
  4868. opt2 = "流转新乡黑科质检";
  4869. }
  4870. else if (CirculMarket(ua.F_DeptId, 332))
  4871. {
  4872. nextda = 339;
  4873. opt = "流转营销管理处";
  4874. }
  4875. else if (ua.F_DeptId == 17 || ua.F_DeptId == 19 || ua.F_DeptId == 20 || ua.F_DeptId == 21)
  4876. {
  4877. nextda = ua.F_DeptId;
  4878. opt = "流转" + deptment;
  4879. }
  4880. //}
  4881. if (nextda != 0)
  4882. {
  4883. if (nextda2 != 0)
  4884. {
  4885. modlelist.F_Flag = 3;
  4886. AssignWO(ua, modlelist, input, opt, "", nextda, 0, 0, 0, 0, 0, 0, "", 1, 1, 3);
  4887. var res2 = AssignWO(ua, modlelist, input, opt2, "", nextda2, 0, 0, 0, 0, 0, 0, "", 1, 2, 3);
  4888. }
  4889. else
  4890. {
  4891. modlelist.F_State = 1;
  4892. modlelist.F_State2 = 1;
  4893. modlelist.F_Flag = 9;
  4894. var res = AssignWO(ua, modlelist, input, opt, "", nextda, 0, overtime, sms, 0, 0, 0, "", 1, 3, 9);
  4895. }
  4896. return Success("添加成功");
  4897. }
  4898. else
  4899. {
  4900. return Error("流转失败!");
  4901. }
  4902. }
  4903. }
  4904. else
  4905. {
  4906. AddLog(modlelist.F_ID, 0, "客户" + "创建工单", (int)EnumItemType.deal, (int)EnumItemOpt.create, "", 0, null, overtime, sms);
  4907. LogFactory.GetLogger("456").Debug("添加成功");
  4908. return Success("添加成功");
  4909. }
  4910. }
  4911. #endregion
  4912. return Success("添加成功!");
  4913. }
  4914. else
  4915. return Error("添加失败!");
  4916. }
  4917. else
  4918. {
  4919. return Error("OpenId不能为空!");
  4920. }
  4921. }
  4922. /// <summary>
  4923. /// 工单暂存
  4924. /// </summary>
  4925. /// <param name="contents"></param>
  4926. /// <param name="type"></param>
  4927. /// <param name="title"></param>
  4928. /// <param name="fid"></param>
  4929. /// <returns></returns>
  4930. public ActionResult TempStorageWo(string OpenId,string contents, string type, string title, int tid = 0)
  4931. {
  4932. if (!string.IsNullOrEmpty(OpenId))
  4933. {
  4934. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  4935. Model.T_Wo_TempStorage temp = new T_Wo_TempStorage();
  4936. if (tid > 0)
  4937. {
  4938. temp = new BLL.T_Wo_TempStorage().GetModel(tid);
  4939. }
  4940. temp.F_Contents = contents;
  4941. temp.F_Title = title;
  4942. temp.F_Type = Convert.ToInt32(type);
  4943. temp.F_CreateTime = DateTime.Now;
  4944. temp.F_CreateBy = ua.F_UserCode;
  4945. if (tid > 0)
  4946. new BLL.T_Wo_TempStorage().Update(temp);
  4947. else
  4948. new BLL.T_Wo_TempStorage().Add(temp);
  4949. return Success("暂存成功!");
  4950. }
  4951. else
  4952. {
  4953. return Error("无操作权限!");
  4954. }
  4955. }
  4956. /// <summary>
  4957. /// 获取最新暂存数据 一个用户只能暂存一次
  4958. /// </summary>
  4959. /// <returns></returns>
  4960. public ActionResult GetStorageWo(string OpenId)
  4961. {
  4962. if (!string.IsNullOrEmpty(OpenId))
  4963. {
  4964. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  4965. string strsql = $" F_CreateBy={ua.F_UserCode} order by F_CreateTime desc";
  4966. var temp = new BLL.T_Wo_TempStorage().GetModelList(strsql).FirstOrDefault();
  4967. return Success(temp.ToJson());
  4968. }
  4969. else
  4970. {
  4971. return Error("无操作权限!");
  4972. }
  4973. }
  4974. /// <summary>
  4975. /// 更新市场管理科,质量管理科
  4976. /// </summary>
  4977. /// <param name="model"></param>
  4978. /// <param name="input"></param>
  4979. /// <returns></returns>
  4980. private Model.T_Wo_WorkOrder InToworkModel(Model.T_Wo_WorkOrder model, WorkOrderNewInput input)
  4981. {
  4982. if (!string.IsNullOrEmpty(input.F_SC_ProductBase))
  4983. model.F_SC_ProductBase = input.F_SC_ProductBase;//市场管理科-生产基地(新乡、新疆、九江、东北、贴牌、无法确定)
  4984. if (!string.IsNullOrEmpty(input.F_SC_PreliminaryOpinion))
  4985. model.F_SC_PreliminaryOpinion = input.F_SC_PreliminaryOpinion;// 市场管理科-初审意见:退货、换货、补偿、自行处理
  4986. if (!string.IsNullOrEmpty(input.F_SC_QualityMonth))
  4987. model.F_SC_QualityMonth = input.F_SC_QualityMonth;//市场管理科-超出质保期限(算法:工单创建日期-生产日期,生产日期根据生产批次号获取,单位:月)
  4988. if (!string.IsNullOrEmpty(input.F_SC_CJ_SpotResult))
  4989. model.F_SC_CJ_SpotResult = input.F_SC_CJ_SpotResult;/// 市场管理科-抽检-抽检结果(视同合格、合格、不合格、复检后合格、未送检)
  4990. if (!string.IsNullOrEmpty(input.F_SC_CJ_SelfResult))
  4991. model.F_SC_CJ_SelfResult = input.F_SC_CJ_SelfResult;//市场管理科-抽检-自检结果
  4992. if (!string.IsNullOrEmpty(input.F_SC_CJ_ApprovalNo))
  4993. model.F_SC_CJ_ApprovalNo = input.F_SC_CJ_ApprovalNo;// 市场管理科-抽检-对应审批工作流单号
  4994. if (!string.IsNullOrEmpty(input.F_SC_CJ_ReturnAccount))
  4995. model.F_SC_CJ_ReturnAccount = input.F_SC_CJ_ReturnAccount;//市场管理科-抽检-确认返账金额(元)
  4996. if (!string.IsNullOrEmpty(input.F_ZL_QualityEventLevel))
  4997. model.F_ZL_QualityEventLevel = input.F_ZL_QualityEventLevel;// 质量管理科-质量事件等级(未遂、一般、较大、重大)
  4998. if (!string.IsNullOrEmpty(input.F_ZL_ClaimAmount))
  4999. model.F_ZL_ClaimAmount = input.F_ZL_ClaimAmount;//质量管理科-索赔金额(单位元,对应责任单位)
  5000. if (!string.IsNullOrEmpty(input.F_ZL_ResponsibleUnit))
  5001. model.F_ZL_ResponsibleUnit = input.F_ZL_ResponsibleUnit;//质量管理科-责任单位(需列出,可选多个)
  5002. if (!string.IsNullOrEmpty(input.F_ZL_ApprovalOpinions))
  5003. model.F_ZL_ApprovalOpinions = input.F_ZL_ApprovalOpinions;// 质量管理科-审批意见(同意、不同意,若选择不同意,增加输入框输入补充内容)
  5004. if (!string.IsNullOrEmpty(input.F_ZL_ApprovalDisagree))
  5005. model.F_ZL_ApprovalDisagree = input.F_ZL_ApprovalDisagree;// 质量管理科-审批不同意意见
  5006. if (!string.IsNullOrEmpty(input.F_ZL_CompensationMethod))
  5007. model.F_ZL_CompensationMethod = input.F_ZL_CompensationMethod;//质量管理科-补偿方式(实物、钱款【单位元】,若选择钱款,增加输入框输入补充内容)
  5008. if (!string.IsNullOrEmpty(input.F_ZL_CompensationMoney))
  5009. model.F_ZL_CompensationMoney = input.F_ZL_CompensationMoney;// 质量管理科-补偿钱款
  5010. if (!string.IsNullOrEmpty(input.F_ZL_CResponsibleUnits))
  5011. model.F_ZL_CResponsibleUnits = input.F_ZL_CResponsibleUnits;//质量管理科-对应责任单位(生产、研发、农化、物流、质量管理科,销售内勤)
  5012. if (!string.IsNullOrEmpty(input.F_ZL_Fquantity))
  5013. model.F_ZL_Fquantity = input.F_ZL_Fquantity;// 质量管理科-确认实收数量(吨)
  5014. if (!string.IsNullOrEmpty(input.F_ZL_ImprovementRequirements))
  5015. model.F_ZL_ImprovementRequirements = input.F_ZL_ImprovementRequirements;//质量管理科-改进要求
  5016. if (!string.IsNullOrEmpty(input.F_ZL_CApprovalNo))
  5017. model.F_ZL_CApprovalNo = input.F_ZL_CApprovalNo;//质量管理科-对应审批工作流单号
  5018. if (!string.IsNullOrEmpty(input.F_ZL_CJ_IsRecord))
  5019. model.F_ZL_CJ_IsRecord = input.F_ZL_CJ_IsRecord;//质量管理科-抽检-未备案、已备案
  5020. if (input.F_IsVisit != null)
  5021. {
  5022. try
  5023. {
  5024. model.F_IsVisit = int.Parse(input.F_IsVisit);
  5025. }
  5026. catch
  5027. {
  5028. model.F_IsVisit = 1;
  5029. }
  5030. }
  5031. if (!string.IsNullOrEmpty(input.F_CarNumber))//返厂车牌号
  5032. model.F_CarNumber = input.F_CarNumber;
  5033. if (input.F_LoadingFee > 0)//装车费
  5034. model.F_LoadingFee = input.F_LoadingFee;
  5035. if (input.F_UnLoadingFee > 0) //卸车费
  5036. model.F_UnLoadingFee = input.F_UnLoadingFee;
  5037. if (input.F_MaterialFee > 0) //返料费
  5038. model.F_MaterialFee = input.F_MaterialFee;
  5039. if (!string.IsNullOrEmpty(input.F_EventReason))
  5040. model.F_EventReason = input.F_EventReason;//质量管理科-事件原因
  5041. if (!string.IsNullOrEmpty(input.F_DrivePhone))
  5042. model.F_DrivePhone = input.F_DrivePhone;//电话号码
  5043. if (!string.IsNullOrEmpty(input.F_WorkmanShip))
  5044. model.F_WorkmanShip = input.F_WorkmanShip;//质量管理科-工艺
  5045. if (!string.IsNullOrEmpty(input.F_Manufacturers))
  5046. model.F_Manufacturers = input.F_Manufacturers;//质量管理科-原料及厂家
  5047. if (input.F_ProductionNum > 0)
  5048. model.F_ProductionNum = input.F_ProductionNum;//质量管理科-该批次生产数量
  5049. if (!string.IsNullOrEmpty(input.F_TS_Level))
  5050. model.F_TS_Level = input.F_TS_Level;//投诉-重要级别:轻微、一般、较大、重大
  5051. return model;
  5052. }
  5053. /// <summary>
  5054. /// 指派/转派工单
  5055. /// <param name="orderid">工单id</param>
  5056. /// <param name="cont">指派说明</param>
  5057. /// <param name="clbm">指派部门</param>
  5058. /// <param name="clid">指派人</param>
  5059. /// </summary>
  5060. /// <returns></returns>
  5061. [WechatActionFilter]
  5062. public ActionResult AssignWorkOrder(string OpenId, long orderid, string cont, WorkOrdeDeptment deptment, string F_Files, int isvisit = 1,
  5063. int overtime = 0, int sms = -1, int clbm = 0, int clid = 0, int isApprovalp = 0, int hclbm = 0, int hclid = 0, int clbm2 = 0, int clid2 = 0,string jsonstr="", int flag = 1,int inoutflag = 0, string Supercont = "", int opttype = 1, string cont2 = "")
  5064. {
  5065. if (!string.IsNullOrEmpty(OpenId))
  5066. {
  5067. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  5068. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  5069. if (model == null)
  5070. {
  5071. return Error("工单不存在!");
  5072. }
  5073. if (model.F_State == 1 && model.F_CreateBy == ua.F_UserCode)
  5074. {
  5075. return Error("工单已转派请勿重复操作!");
  5076. }
  5077. if (model.F_State != 0)
  5078. {
  5079. //string strsql = " and F_Type in(3,"+ua.F_Flag+")";
  5080. var modellist = new BLL.T_Wo_WorkOrderItem_New().GetModelList($"F_WoID={model.F_ID} and F_NextUser like '%{ua.F_UserCode}%' and F_IsUsed=0 order by F_ID desc ");
  5081. if (modellist.Count<=0)
  5082. {
  5083. //if (modellist.F_NextUser != ua.F_UserCode)
  5084. return Error("非接单人不可操作工单");
  5085. }
  5086. if (modellist.Count > 1 && model.F_Flag == 9)
  5087. {
  5088. foreach (var item in modellist)
  5089. {
  5090. if (item.F_WoState != 2)
  5091. return Error("操作失败!");
  5092. }
  5093. }
  5094. }
  5095. if (sms ==-1)
  5096. {
  5097. var itemlast = itembll.GetModelList(" F_WoID='" + model.F_ID + "' order by F_ID desc").FirstOrDefault();
  5098. sms = (int)itemlast.F_IsSMS;
  5099. }
  5100. WorkOrderNewInput input = new WorkOrderNewInput();
  5101. string markdepts = "37,57,74,88,268,295,339,422,213,427,433";
  5102. string qualdepts = "12,36,295,245";
  5103. if (ua != null)
  5104. {
  5105. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  5106. if (clid != 0)
  5107. {
  5108. Model.T_Sys_UserAccount clus = userAccountBLL .GetModel(clid);
  5109. if (clus != null)
  5110. {
  5111. if (clus.F_WorkNumber == "7000")
  5112. return Error("不能转派到市场管理员");
  5113. else if (clus.F_RoleId == 1 || clus.F_RoleId == 4)
  5114. return Error("不能转派到话务人员");
  5115. else if (clus.F_RoleId == 58)
  5116. return Error("不能转派到业务员");
  5117. else if (clus.F_RoleId == 60)
  5118. return Error("不能转派到分公司经理");
  5119. else if (clus.F_RoleId == 62)
  5120. return Error("不能转派到大区经理");
  5121. }
  5122. }
  5123. //if (hclid == 0 && hclbm == 0 && isApprovalp != 0)
  5124. //{
  5125. // return Error("请选择接收部门");
  5126. //}
  5127. #region 五要素
  5128. input.F_ZL_ResponsibleUnit = deptment.ResponsibleUnit;// 责任单位
  5129. input.F_EventReason = deptment.EventReason;// 事件原因
  5130. input.F_ZL_ImprovementRequirements = deptment.ImprovementRequirements;// 改进要求
  5131. input.F_TS_Level = deptment.TS_Level;//投诉-重要级别:轻微、一般、较大、重大
  5132. #endregion
  5133. if (markdepts.Contains(ua.F_DeptId.ToString()) && model.F_Flag == 9)
  5134. {
  5135. if (markdepts.Contains(ua.F_DeptId.ToString()))
  5136. {
  5137. if (model.F_Type == "2" || model.F_Type == "5")
  5138. {
  5139. input.F_SC_PreliminaryOpinion = deptment.PreliminaryOpinion;//市场管理科-初审意见:退货、换货、补偿、自行处理
  5140. input.F_ZL_ClaimAmount = deptment.ClaimAmount;// 质量管理科-索赔金额(单位元,对应责任单位)
  5141. }
  5142. else if (model.F_Type == "3")
  5143. {
  5144. input.F_SC_CJ_SpotResult = deptment.SpotResult;//市场管理科-抽检-抽检结果(视同合格、合格、不合格、复检后合格、未送检)
  5145. input.F_SC_CJ_SelfResult = deptment.SelfResult;//市场管理科-抽检-自检结果
  5146. input.F_SC_CJ_ApprovalNo = deptment.ApprovalNo;//市场管理科-抽检-对应审批工作流单号
  5147. input.F_SC_CJ_ReturnAccount = deptment.ReturnAccount;//市场管理科-抽检-确认返账金额
  5148. }
  5149. }
  5150. model.F_Flag = flag;
  5151. var modellast = new BLL.T_Wo_WorkOrderItem_New().GetModelList($"F_WoID={model.F_ID} and F_NextUser like '%{ua.F_UserCode}%' and F_IsUsed=0 order by F_ID desc ").FirstOrDefault();
  5152. if (flag == 3)
  5153. {
  5154. if ((clbm == 0 && clid == 0) || (clbm2 == 0 && clid2 == 0))
  5155. {
  5156. return Error("请选择接收部门");
  5157. }
  5158. var res = AssignWO(ua, model, input, cont, F_Files, clbm, clid, overtime, sms, isApprovalp, hclbm, hclid, "", 0, 1, flag,Supercont);
  5159. var res1 = AssignWO(ua, model, input, cont, F_Files, clbm2, clid2, overtime, sms, isApprovalp, hclbm, hclid, "", 0, 2, flag);
  5160. }
  5161. else if (flag == 2)
  5162. {
  5163. if (clbm2 == 0 && clid2 == 0)
  5164. {
  5165. return Error("请选择接收部门");
  5166. }
  5167. if (opttype == 2) //填写处理结果
  5168. {
  5169. flag = 3;
  5170. DealWO(ua, model,"", input, cont2, 1, "", 1,"", flag,isApprovalp);
  5171. }
  5172. else if (opttype == 3) // 待处理状态
  5173. {
  5174. flag = 3;
  5175. modellast.F_Type = 1;
  5176. modellast.F_Flag = flag;
  5177. modellast.F_NextDept = 0;
  5178. itembll.Update(modellast);
  5179. }
  5180. else //完结工单
  5181. {
  5182. Overorder(ua, model, 1);
  5183. }
  5184. model.F_Flag = flag;
  5185. var res1 = AssignWO(ua, model, input, cont, F_Files, clbm2, clid2, overtime, sms, isApprovalp, hclbm, hclid, "", 0, 2, flag,Supercont);
  5186. }
  5187. else
  5188. {
  5189. if (clbm == 0 && clid == 0)
  5190. {
  5191. return Error("请选择接收部门");
  5192. }
  5193. if (opttype == 2) //填写处理结果
  5194. {
  5195. flag = 3;
  5196. DealWO(ua, model,"", input, cont2, 1, "", 2,"", flag,isApprovalp);
  5197. }
  5198. else if (opttype == 3) // 待处理状态
  5199. {
  5200. flag = 3;
  5201. modellast.F_Type = 2;
  5202. modellast.F_Flag = flag;
  5203. modellast.F_NextDept = 0;
  5204. itembll.Update(modellast);
  5205. }
  5206. else //完结工单
  5207. {
  5208. Overorder(ua, model, 2);
  5209. }
  5210. model.F_Flag = flag;
  5211. var res = AssignWO(ua, model, input, cont, F_Files, clbm, clid, overtime, sms, isApprovalp, hclbm, hclid, "", 0, 1, flag, Supercont);
  5212. }
  5213. return Success("转派成功");
  5214. }
  5215. else
  5216. {
  5217. if (clbm == 0 && clid == 0)
  5218. {
  5219. return Error("请选择接收部门");
  5220. }
  5221. else
  5222. {
  5223. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  5224. if (deptmodel != null)
  5225. {
  5226. if (model != null)
  5227. {
  5228. if (deptmodel.F_DeptId == 12 || deptmodel.F_DeptId == 36)
  5229. {
  5230. input.F_WorkmanShip = deptment.WorkmanShip;//质量管理科-工艺
  5231. input.F_Manufacturers = deptment.Manufacturers;//质量管理科-原料及厂家
  5232. input.F_ProductionNum = deptment.ProductionNum;//质量管理科-该批次生产数量
  5233. }
  5234. if (model.F_Type == "2" || model.F_Type == "5")
  5235. {
  5236. if (deptmodel.F_DeptId == 37)
  5237. {
  5238. // input. F_SC_QualityMonth = QualityMonth;//市场管理科-超出质保期限
  5239. input.F_SC_PreliminaryOpinion = deptment.PreliminaryOpinion;//市场管理科-初审意见:退货、换货、补偿、自行处理
  5240. }
  5241. else if (deptmodel.F_DeptId == 12 || deptmodel.F_DeptId == 36)
  5242. {
  5243. input.F_IsVisit = isvisit.ToString();
  5244. input.F_ZL_QualityEventLevel = deptment.QualityEventLevel;//质量管理科-质量事件等级(未遂、一般、较大、重大)
  5245. input.F_ZL_ClaimAmount = deptment.ClaimAmount;// 质量管理科-索赔金额(单位元,对应责任单位)
  5246. input.F_ZL_ApprovalOpinions = deptment.ApprovalOpinions;// 质量管理科-审批意见(同意、不同意,若选择不同意,增加输入框输入补充内容)
  5247. input.F_ZL_ApprovalDisagree = deptment.ApprovalDisagree;// 质量管理科-审批不同意意见
  5248. input.F_ZL_CompensationMethod = deptment.CompensationMethod;// 质量管理科-补偿方式(实物、钱款【单位元】,若选择钱款,增加输入框输入补充内容)
  5249. input.F_ZL_CompensationMoney = deptment.CompensationMoney;// 质量管理科-补偿钱款
  5250. input.F_ZL_CResponsibleUnits = deptment.CResponsibleUnits;//质量管理科-对应责任单位(生产、研发、农化、物流、质量管理科,销售内勤)
  5251. //input.F_ZL_Fquantity = deptment.Fquantity;//质量管理科-确认实收数量(吨)
  5252. //input.F_ZL_ImprovementRequirements = deptment.ImprovementRequirements;// 质量管理科-改进要求
  5253. input.F_ZL_CApprovalNo = deptment.CApprovalNo;// 质量管理科-对应审批工作流单号
  5254. //if (string.IsNullOrEmpty(deptment.EventReason))
  5255. // return Error("请填写事件原因!");
  5256. //if (string.IsNullOrEmpty(deptment.ResponsibleUnit))
  5257. // return Error("请填写责任单位!");
  5258. //input.F_EventReason = deptment.EventReason;// 质量管理科-事件原因
  5259. input.F_ZL_ResponsibleUnit = deptment.ResponsibleUnit;// 质量管理科-责任单位(需列出,可选多个)
  5260. }
  5261. //else if (deptmodel.F_DeptName == "成品库" && model.F_SC_PreliminaryOpinion == "退换货" ) //退换货成品库录入物料信息
  5262. //{
  5263. // if (!string.IsNullOrEmpty(jsonstr))
  5264. // {
  5265. // JavaScriptSerializer Serializer = new JavaScriptSerializer(); //实例化⼀个能够序列化数据的类
  5266. // List<Material> list = Serializer.Deserialize<List<Material>>(jsonstr);
  5267. // List<T_Wo_MaterialItems> itemlist = new List<T_Wo_MaterialItems>();
  5268. // if (list != null && list.Count > 0)
  5269. // {
  5270. // foreach (var item in list)
  5271. // {
  5272. // T_Wo_MaterialItems itemodel = new T_Wo_MaterialItems();
  5273. // itemodel.F_MaterialCode = item.materialcode;
  5274. // itemodel.F_MaterialName = item.materialname;
  5275. // itemodel.F_Formula = item.formula;
  5276. // itemodel.F_ReturnQuantity = item.returnum??0;
  5277. // itemodel.F_WoID = model.F_ID;//工单id
  5278. // itemodel.F_CreateOn = DateTime.Now;
  5279. // itemodel.F_Remark = item.specs;//规格
  5280. // itemlist.Add(itemodel);
  5281. // }
  5282. // model.MaterialItems = itemlist;
  5283. // }
  5284. // }
  5285. //}
  5286. else if (deptmodel.F_DeptId == 248)
  5287. {
  5288. input.F_CarNumber = deptment.CarNumber;
  5289. input.F_UnLoadingFee = deptment.UnLoadingFee;//卸车费
  5290. input.F_MaterialFee = deptment.MaterialFee;//返料费
  5291. input.F_DrivePhone = deptment.DrivePhone;//电话号码nt.CarNumber;//返厂车牌号
  5292. input.F_LoadingFee = deptment.LoadingFee;//装车费
  5293. if (!string.IsNullOrEmpty(jsonstr))
  5294. {
  5295. JavaScriptSerializer Serializer = new JavaScriptSerializer(); //实例化⼀个能够序列化数据的类
  5296. List<Material> list = Serializer.Deserialize<List<Material>>(jsonstr);
  5297. List<T_Wo_MaterialItems> itemlist = new List<T_Wo_MaterialItems>();
  5298. if (list != null && list.Count > 0)
  5299. {
  5300. foreach (var item in list)
  5301. {
  5302. T_Wo_MaterialItems itemodel = new T_Wo_MaterialItems();
  5303. if (!string.IsNullOrEmpty(item.fid))
  5304. {
  5305. itemodel.F_Id = Convert.ToInt32(item.fid);
  5306. }
  5307. itemodel.F_MaterialCode = item.materialcode;
  5308. itemodel.F_MaterialName = item.materialname;
  5309. itemodel.F_Formula = item.formula;
  5310. itemodel.F_ReturnQuantity = item.returnum ?? 0;
  5311. itemodel.F_WoID = model.F_ID;//工单id
  5312. itemodel.F_CreateOn = DateTime.Now;
  5313. itemodel.F_Remark = item.specs;//规格
  5314. itemlist.Add(itemodel);
  5315. }
  5316. model.MaterialItems = itemlist;
  5317. }
  5318. }
  5319. }
  5320. //else if (deptmodel.F_DeptName == "销售内勤" && (model.F_SC_PreliminaryOpinion == "退货" || model.F_SC_PreliminaryOpinion == "换货"))//部门id=193
  5321. //{
  5322. // model.F_SC_CJ_ReturnAccount = deptment.ReturnAccount;//销售内勤-确认返账金额
  5323. //}
  5324. }
  5325. else if (model.F_Type == "3")
  5326. {
  5327. if (deptmodel.F_DeptId == 37)
  5328. {
  5329. input.F_SC_CJ_SpotResult = deptment.SpotResult;//市场管理科-抽检-抽检结果(视同合格、合格、不合格、复检后合格、未送检)
  5330. input.F_SC_CJ_SelfResult = deptment.SelfResult;//市场管理科-抽检-自检结果
  5331. input.F_SC_CJ_ApprovalNo = deptment.ApprovalNo;//市场管理科-抽检-对应审批工作流单号
  5332. input.F_SC_CJ_ReturnAccount = deptment.ReturnAccount;//市场管理科-抽检-确认返账金额
  5333. }
  5334. else if (deptmodel.F_DeptId == 12)
  5335. {
  5336. input.F_IsVisit = isvisit.ToString();
  5337. input.F_ZL_CJ_IsRecord = deptment.IsRecord;//质量管理科-抽检-未备案、已备案
  5338. input.F_ZL_ClaimAmount = deptment.ClaimAmount;// 质量管理科-索赔金额(单位元,对应责任单位)
  5339. }
  5340. }
  5341. if (deptmodel.F_DeptName == "销售内勤")//部门id=193
  5342. {
  5343. input.F_SC_CJ_ReturnAccount = deptment.ReturnAccount2;//销售内勤-确认返账金额
  5344. }
  5345. if (deptmodel.F_DeptId == 260)//销售财务
  5346. {
  5347. input.F_SC_CJ_ReturnAccount = deptment.ReturnAccount3;//销售内勤-确认返账金额
  5348. }
  5349. if (deptmodel.F_DeptId == 36)
  5350. {
  5351. input.F_ZL_Fquantity = deptment.Fquantity;//质量管理科-确认实收数量(吨)
  5352. }
  5353. }
  5354. else
  5355. return Error("工单不存在!");
  5356. }
  5357. else
  5358. {
  5359. return Error("请选择接收部门");
  5360. }
  5361. }
  5362. var modellist = new BLL.T_Wo_WorkOrderItem_New().GetModelList($"F_WoID={model.F_ID} and F_NextUser like '%{ua.F_UserCode}%' and F_IsUsed=0 order by F_ID desc ");
  5363. int? zflag = 0;
  5364. if (inoutflag != 0)
  5365. {
  5366. zflag = inoutflag;
  5367. }
  5368. else if (modellist.Count > 0)
  5369. {
  5370. zflag = modellist.FirstOrDefault().F_Type;
  5371. }
  5372. if (zflag != 3)
  5373. {
  5374. var modeldpts = new BLL.T_Wo_WorkOrderItem_New().GetModelList($"F_WoID={model.F_ID} and F_NextDept={clbm} and F_Type not in({zflag},3) and F_Flag=3 and F_OptType not in(15,4,5) order by F_ID desc ").FirstOrDefault();
  5375. if (modeldpts != null)
  5376. return Error("不允许同一个部门出现在两条线内,请重新指派!");
  5377. }
  5378. var res = AssignWO(ua, model, input, cont, F_Files, clbm, clid, overtime, sms, isApprovalp, hclbm, hclid, "", 0, Convert.ToInt32(zflag),0, Supercont);
  5379. if (res)
  5380. {
  5381. return Success("转派成功");
  5382. }
  5383. else
  5384. return Error("转派失败!");
  5385. }
  5386. }
  5387. }
  5388. return Error("无操作权限!");
  5389. }
  5390. /// <summary>
  5391. /// 完结工单
  5392. /// </summary>
  5393. /// <param name="nowUser"></param>
  5394. /// <param name="model"></param>
  5395. /// <param name="isOver"></param>
  5396. /// <param name="flag"></param>
  5397. /// <returns></returns>
  5398. public bool Overorder(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, int isOver = 0)
  5399. {
  5400. #region 工单处理
  5401. int sms = 0;
  5402. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.visit + " and F_WoID=" + model.F_ID + " ");
  5403. if (itemlasts.Count > 0)
  5404. {
  5405. foreach (var it in itemlasts)
  5406. {
  5407. if (it.F_WoState == 1)
  5408. {
  5409. sms = int.Parse(it.F_IsSMS.ToString());
  5410. }
  5411. }
  5412. }
  5413. int optbut = (int)EnumItemOpt.end;
  5414. int wostate = (int)EnumWorkOrderState.evaluate;
  5415. #region 读取当前登录人部门
  5416. string deptname = "";
  5417. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  5418. if (deptmodel != null)
  5419. {
  5420. deptname = deptmodel.F_DeptName + "-";
  5421. }
  5422. #endregion
  5423. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ") 自动关闭工单";
  5424. //var itemid = AddLog((int)model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, touser, 0, nowUser, model.F_limit, sms);
  5425. if (isOver >= 1)
  5426. {
  5427. #region 处理工单
  5428. //model.F_VisitOn = DateTime.Now;
  5429. if (isOver == 1)
  5430. {
  5431. AddLog((int)model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, "", 0, nowUser, model.F_limit, sms, "", 0, 1);
  5432. model.F_State = wostate; //外线关闭
  5433. }
  5434. else if (isOver == 2)
  5435. {
  5436. AddLog((int)model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, "", 0, nowUser, model.F_limit, sms, "", 0, 2);
  5437. model.F_State2 = wostate; //内线关闭
  5438. }
  5439. woBLL.Update(model);
  5440. #endregion
  5441. return true;
  5442. }
  5443. else
  5444. return false;
  5445. #endregion
  5446. }
  5447. /// <summary>
  5448. /// 转派工单
  5449. /// </summary>
  5450. 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, int flag = 1, int flagstate = 0, string Supercont = "")
  5451. {
  5452. if (model.F_limit > 0)
  5453. overtime = model.F_limit;
  5454. string smscont = "";
  5455. if (model.F_Type == "1")
  5456. {
  5457. smscont = "咨询";
  5458. }
  5459. else if (model.F_Type == "2")
  5460. {
  5461. smscont = "投诉";
  5462. }
  5463. else if (model.F_Type == "3")
  5464. {
  5465. smscont = "抽检";
  5466. }
  5467. else if (model.F_Type == "5")
  5468. {
  5469. smscont = "业务协办";
  5470. }
  5471. else
  5472. {
  5473. smscont = "建议";
  5474. }
  5475. string[] mag = { smscont };
  5476. string smsmsg = "您好,您有一条新的" + smscont + "工单,请及时接单处理!";
  5477. string touser = ""; string tousername = "";
  5478. #region 获取接收人
  5479. int deptid = 0;
  5480. if (clid != 0)
  5481. {
  5482. Model.T_Sys_UserAccount clus = userAccountBLL.GetModel(clid);
  5483. deptid = clus.F_DeptId;
  5484. clbm = clus.F_DeptId;
  5485. if (clus != null)
  5486. {
  5487. touser = clus.F_UserCode;
  5488. tousername = clus.F_UserName + "(" + clus.F_WorkNumber + ")";
  5489. }
  5490. if (sms != 0)
  5491. {
  5492. if (!string.IsNullOrEmpty(clus.F_Mobile))
  5493. {
  5494. SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, clus.F_Mobile);
  5495. bool n = new SMSController().AddSmS(clus.F_Mobile, smsmsg, nowUser.F_UserId);
  5496. }
  5497. }
  5498. }
  5499. else
  5500. {
  5501. string users = string.Empty;
  5502. deptid = clbm;
  5503. string sql = "";
  5504. if (isbl>0)
  5505. {
  5506. sql = " and F_RoleId in(select F_RoleId from T_Sys_RoleInfo where F_RoleCode='BLRY')";
  5507. }
  5508. var list = userAccountBLL.GetModelList(" F_DeptId='" + clbm + "'and F_DeleteFlag=0" + sql);
  5509. foreach (var l in list)
  5510. {
  5511. if (string.IsNullOrEmpty(users))
  5512. {
  5513. users = l.F_UserCode;
  5514. tousername = l.F_UserName + "(" + l.F_WorkNumber + ")";
  5515. }
  5516. else
  5517. {
  5518. users = users + "," + l.F_UserCode;
  5519. tousername = tousername + "," + l.F_UserName + "(" + l.F_WorkNumber + ")";
  5520. }
  5521. if (sms != 0)
  5522. {
  5523. if (!string.IsNullOrEmpty(l.F_Mobile))
  5524. {
  5525. SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, l.F_Mobile);
  5526. bool n = new SMSController().AddSmS(l.F_Mobile, smsmsg, nowUser.F_UserId);
  5527. }
  5528. }
  5529. }
  5530. touser = users;
  5531. }
  5532. string htouser = "", htousername = "";
  5533. //if (isApprovalp != 0 && nowUser.F_DeptId == 37)
  5534. //{
  5535. // if (hclid != 0)
  5536. // {
  5537. // Model.T_Sys_UserAccount clus = userAccountBLL.GetModel(hclid);
  5538. // if (clus != null)
  5539. // {
  5540. // if (string.IsNullOrEmpty(htouser))
  5541. // {
  5542. // htouser = clus.F_UserCode;
  5543. // htousername = clus.F_UserName + "(" + clus.F_WorkNumber + ")";
  5544. // }
  5545. // }
  5546. // }
  5547. // else
  5548. // {
  5549. // var list = userAccountBLL.GetModelList(" F_DeptId='" + hclbm + "'");
  5550. // foreach (var l in list)
  5551. // {
  5552. // if (string.IsNullOrEmpty(htouser))
  5553. // {
  5554. // htouser = l.F_UserCode;
  5555. // htousername = l.F_UserName + "(" + l.F_UserCode + ")";
  5556. // }
  5557. // else
  5558. // {
  5559. // htouser = htouser + "," + l.F_UserCode;
  5560. // htousername = htousername + "," + l.F_UserName + "(" + l.F_WorkNumber + ")";
  5561. // }
  5562. // }
  5563. // }
  5564. // AddLog(model.F_ID, (int)EnumWorkOrderState.assign, htousername + "高层待审批", (int)EnumItemType.audit, (int)EnumItemOpt.audit, htouser, hclbm, nowUser, overtime, sms, creat, 2);
  5565. //}
  5566. #region 财务审核后,填单人员可以收到到账提醒(短信到账提醒)20220217
  5567. if (nowUser.F_DeptId == 260)
  5568. {
  5569. var noticlus = userAccountBLL.GetModel(model.F_CreateBy);
  5570. if (!string.IsNullOrEmpty(noticlus.F_Mobile))
  5571. {
  5572. //SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, noticlus.F_Mobile.Trim());
  5573. //bool n = new SMSController().AddSmS(noticlus.F_Mobile.Trim(), "返款已到账", nowUser.F_UserId);
  5574. }
  5575. }
  5576. #endregion
  5577. #endregion
  5578. #region 工单处理
  5579. var opt = "指派";
  5580. int optbut = (int)EnumItemOpt.assign;
  5581. int wostate = (int)EnumWorkOrderState.assign;//已指派待接单
  5582. #region 读取当前登录人部门
  5583. string deptname = "";
  5584. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  5585. if (deptmodel != null)
  5586. {
  5587. deptname = deptmodel.F_DeptName + "-";
  5588. }
  5589. #endregion
  5590. var optcont = "";
  5591. if (!string.IsNullOrEmpty(cont))
  5592. optcont = ",说明:" + cont;
  5593. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + opt + "工单给 " + tousername + optcont;
  5594. var itemid = AddLog(model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, touser, clbm, nowUser, overtime, sms, creat,0,flag,flagstate);
  5595. if (itemid > 0)
  5596. {
  5597. #region 处理工单
  5598. //工单完结要更新工单的状态
  5599. // model.F_DealBy = touser;
  5600. if (flag == 1 || ((model.F_Flag == null || model.F_Flag == 0) && flag == 3))
  5601. {
  5602. model.F_State = wostate;
  5603. }
  5604. else if (flag == 2)
  5605. {
  5606. model.F_State2 = wostate;
  5607. }
  5608. if (model.F_limit == 0)
  5609. model.F_limit = overtime;
  5610. //处理内容
  5611. if (!string.IsNullOrEmpty(cont))
  5612. if (flag == 2)
  5613. {
  5614. model.F_DealContent2 += cont + ";";
  5615. }
  5616. else
  5617. {
  5618. model.F_DealContent += cont + ";";
  5619. }
  5620. if (!string.IsNullOrEmpty(Supercont))
  5621. {
  5622. if (flag == 1 || ((model.F_Flag == null || model.F_Flag == 0) && flag == 3))
  5623. {
  5624. if (model.F_SuperiorOpinion.Trim() != Supercont.Trim())
  5625. {
  5626. model.F_SuperiorOpinion = nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ") " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + Supercont;
  5627. }
  5628. }
  5629. else if (flag == 2)
  5630. {
  5631. if (model.F_SuperiorOpinion2.Trim() != Supercont.Trim())
  5632. {
  5633. model.F_SuperiorOpinion2 = nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ") " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + Supercont;
  5634. }
  5635. }
  5636. }
  5637. InToworkModel(model, input);
  5638. if (!string.IsNullOrEmpty(F_Files))
  5639. {
  5640. if (!string.IsNullOrEmpty(model.F_Files))
  5641. model.F_Files = model.F_Files + "," + F_Files;
  5642. else
  5643. model.F_Files = F_Files;
  5644. }
  5645. woBLL.Update(model);
  5646. #region 添加物料信息
  5647. if (model.MaterialItems != null && model.MaterialItems.Count > 0)
  5648. {
  5649. //var delmodels = new BLL.T_Wo_MaterialItems().GetModelList($" F_WoID ={ model.F_ID}");
  5650. //if (delmodels != null && delmodels.Count > 0)
  5651. //{
  5652. // string delids = string.Join(",", delmodels.Select(p => p.F_Id).ToArray());
  5653. // new BLL.T_Wo_MaterialItems().DeleteList(delids);
  5654. //}
  5655. foreach (var item in model.MaterialItems)
  5656. {
  5657. if (item.F_Id > 0)
  5658. {
  5659. new BLL.T_Wo_MaterialItems().Update(item);
  5660. }
  5661. else
  5662. {
  5663. new BLL.T_Wo_MaterialItems().Add(item);
  5664. }
  5665. }
  5666. }
  5667. #endregion
  5668. #endregion
  5669. #region 推送消息
  5670. #region 推送消息给添加的坐席 -转派和处理
  5671. if (nowUser.F_UserCode != model.F_CreateBy)
  5672. {
  5673. sendsysmsg(model, nowUser, model.F_CreateBy, (int)model.F_ID, opt);//推送系统消息
  5674. // var createmodel = userAccountBLL.GetModel(model.F_CreateBy); //被指派人
  5675. // if (createmodel != null)
  5676. // {
  5677. // if (!string.IsNullOrEmpty(createmodel.F_WxOpenId))
  5678. // {
  5679. // sendwxmsg(model, createmodel.F_WxOpenId, nowUser, opt);
  5680. // }
  5681. // }
  5682. }
  5683. #endregion
  5684. #region 向下一级操作人员推送消息
  5685. if (!string.IsNullOrWhiteSpace(touser))
  5686. {
  5687. sendsysmsg(model, nowUser, touser, (int)model.F_ID, opt);//推送系统消息
  5688. // var modelUser2 = userAccountBLL.GetModel(touser); //被指派人
  5689. // if (modelUser2 != null)
  5690. // {
  5691. // if (!string.IsNullOrEmpty(modelUser2.F_WxOpenId))
  5692. // {
  5693. // sendwxmsg(model, modelUser2.F_WxOpenId, nowUser, "指派");
  5694. // }
  5695. //}
  5696. }
  5697. #endregion
  5698. #endregion
  5699. return true;
  5700. }
  5701. else
  5702. return false;
  5703. #endregion
  5704. }
  5705. /// <summary>
  5706. /// 查询超时工单列表
  5707. /// </summary>
  5708. [WechatActionFilter]
  5709. public ActionResult GetOvertime(string OpenId, string code, string keywords, string cusname, string cusphone, string companyname, string province, string city,
  5710. string country, string township, string touser, int source = 0, int type = 0, int pageindex = 1, int pagesize = 10, int state = 0)
  5711. {
  5712. if (!string.IsNullOrEmpty(OpenId))
  5713. {
  5714. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  5715. if (ua == null)
  5716. {
  5717. return Success("你的账号已在别处登录,你确定要再次登录吗?");
  5718. }
  5719. //if (!Refresh())
  5720. //{
  5721. // return Error("查询失败");
  5722. //}
  5723. Task.Run(() => Refresh());
  5724. string sql = $" and F_IsDelete=0";
  5725. // sql += "and F_Type !=3";
  5726. DataTable dt = new DataTable();
  5727. #region 筛选条件
  5728. if (type > 0 && type < 6)//工单类型
  5729. sql += $" and F_Type=" + type;
  5730. if (source > 0)//工单来源
  5731. {
  5732. if (source == 1)
  5733. sql += $" and F_Source in (1,'')";
  5734. else
  5735. sql += $" and F_Source='" + source + "'";
  5736. }
  5737. if (!string.IsNullOrWhiteSpace(touser))//参与人
  5738. sql += $" and F_DealBy like '%" + touser.Trim() + "%'";
  5739. if (!string.IsNullOrWhiteSpace(code))//工单编号
  5740. sql += $" and F_WorkOrderCode like '%" + code.Trim() + "%'";
  5741. if (!string.IsNullOrWhiteSpace(keywords))//关键字搜索
  5742. sql += $" and (F_WorkOrderCode like '%" + keywords.Trim() + "%' or F_CusName like '%" + keywords.Trim() + "%'or F_CusPhone like '%" + keywords.Trim() + "%' )";
  5743. if (!string.IsNullOrWhiteSpace(cusname))//客户姓名
  5744. sql += $" and F_CusName like '%" + cusname.Trim() + "%'";
  5745. if (!string.IsNullOrWhiteSpace(cusphone))//客户电话
  5746. sql += $" and F_CusPhone like '%" + cusphone.Trim() + "%'";
  5747. if (!string.IsNullOrWhiteSpace(companyname))//公司名称
  5748. sql += $" and F_CompanyName like '%" + companyname.Trim() + "%'";
  5749. if (!string.IsNullOrWhiteSpace(province))//省
  5750. sql += $" and F_IncidentProvince like '%" + province.Trim() + "%'";
  5751. if (!string.IsNullOrWhiteSpace(province))//市
  5752. sql += $" and F_IncidentCity like '%" + city.Trim() + "%'";
  5753. if (!string.IsNullOrWhiteSpace(province))//县
  5754. sql += $" and F_IncidentCountry like '%" + country.Trim() + "%'";
  5755. if (!string.IsNullOrWhiteSpace(province))//乡
  5756. sql += $" and F_IncidentTownship like '%" + township.Trim() + "%'";
  5757. //sql += $" and F_State in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," +
  5758. //(int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + ")";
  5759. sql += $" and F_IsOver=" + 1;
  5760. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  5761. if (state > 0)
  5762. {
  5763. sql += $" and F_State =" + state;
  5764. }
  5765. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "JDYBZZX" || ro.F_RoleCode == "XTGLY")
  5766. {
  5767. sql += $" and((F_IsOver in(1,3) and F_State !=11) or ( F_IsOver in (2,3) and F_State2!=11))";
  5768. }
  5769. else if (ua.F_Flag == 1)
  5770. {
  5771. sql += $" and F_IsOver in (1,3)";
  5772. sql += $" and F_State !=" + 11;
  5773. }
  5774. else if (ua.F_Flag == 2)
  5775. {
  5776. sql += $" and F_IsOver in (2,3)";
  5777. sql += $" and F_State2 !=" + 11;
  5778. }
  5779. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "YWY" || ro.F_RoleCode == "BLRY")
  5780. {
  5781. sql += $" and F_DealBy like '%" + ua.F_UserCode.Trim() + "%'";
  5782. }
  5783. else if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "ZG")
  5784. {
  5785. string detpid = "" + ua.F_DeptId;
  5786. var deparmentlist = new List<Model.T_Sys_Department>();
  5787. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  5788. if (dModel != null)
  5789. {
  5790. if (dModel.F_Layer == 1)
  5791. {
  5792. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  5793. if (deparmentlist.Count > 0)
  5794. {
  5795. foreach (var it in deparmentlist)
  5796. {
  5797. if (detpid != "")
  5798. {
  5799. detpid += "," + it.F_DeptId;
  5800. }
  5801. else
  5802. {
  5803. detpid = "" + it.F_DeptId; ;
  5804. }
  5805. }
  5806. }
  5807. }
  5808. else
  5809. {
  5810. detpid = ua.F_DeptId.ToString();
  5811. }
  5812. if (GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.dealing + ", " + (int)EnumWorkOrderState.receive + "," +
  5813. (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "") != "")
  5814. {
  5815. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," +
  5816. (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "") + ") "; ;
  5817. }
  5818. else
  5819. {
  5820. return Success("暂无工单"); ;
  5821. }
  5822. }
  5823. else
  5824. {
  5825. return Error("加载失败");
  5826. }
  5827. }
  5828. else if (ro.F_RoleCode == "JDYBZZX")
  5829. {
  5830. sql += $" and F_CreateBy like '%" + ua.F_UserCode.Trim() + "%'";
  5831. }
  5832. else if (ro.F_RoleCode == "QTJS")
  5833. {
  5834. return Error("无操作权限!");
  5835. }
  5836. #endregion
  5837. #region 退换货的工单按未超期处理 20220302
  5838. sql += $" and F_ID not in (select F_ID from T_Wo_WorkOrder where F_SC_PreliminaryOpinion='退换货')";
  5839. #endregion
  5840. int recordCount = 0;
  5841. if (!string.IsNullOrWhiteSpace(sql))
  5842. {
  5843. dt = BLL.PagerBLL.GetListPager(
  5844. "T_Wo_WorkOrder",
  5845. "F_ID",
  5846. "*",
  5847. sql,
  5848. "ORDER BY T_Wo_WorkOrder.F_ID desc",
  5849. pagesize,
  5850. pageindex,
  5851. true,
  5852. out recordCount);
  5853. }
  5854. List<long> woid = new List<long>();
  5855. List<Model.T_Wo_WorkOrder> modlelist = new BLL.T_Wo_WorkOrder().DataTableToList(dt);
  5856. List<WorkOrderNewInput> Input = modeltooip(modlelist, ua);
  5857. var obj = new
  5858. {
  5859. state = "success",
  5860. message = "成功",
  5861. rows = Input,
  5862. total = recordCount
  5863. };
  5864. return Content(obj.ToJson()); ;
  5865. }
  5866. else
  5867. {
  5868. return Error("无操作权限!");
  5869. }
  5870. }
  5871. /// 是否超时
  5872. /// </summary>
  5873. /// <param name="id"></param>
  5874. /// <returns></returns>
  5875. private bool TimeforOver(int id, int flag = 1)
  5876. {
  5877. string strsql = "";
  5878. if (flag == 1)
  5879. {
  5880. strsql = " and F_Type in(1,3)";
  5881. }
  5882. else if (flag == 2)
  5883. {
  5884. strsql = " and F_Type in(2,3)";
  5885. }
  5886. var itemlasts = itembll.GetModelList(" F_WoID=" + id + strsql + "");
  5887. string time1 = "", time2 = ""; int x = 0, y = 0;
  5888. float time = 0;
  5889. if (itemlasts.Count > 0)
  5890. {
  5891. for (int z = 0; z < itemlasts.Count; z++)
  5892. {
  5893. if (itemlasts[z].F_WoState >= 1)
  5894. {
  5895. if (itemlasts[z].F_WoState == 1)
  5896. {
  5897. x = z;
  5898. time1 = itemlasts[z].F_CreateTime.ToString();
  5899. time = float.Parse(itemlasts[z].F_LimitTime);
  5900. break; ;
  5901. }
  5902. }
  5903. }
  5904. for (int i = 0; i < itemlasts.Count; i++)
  5905. {
  5906. if (itemlasts[i].F_WoState >= 1)
  5907. {
  5908. if (itemlasts[i].F_WoState == 10)
  5909. {
  5910. y = i;
  5911. time2 = itemlasts[i].F_CreateTime.ToString();
  5912. }
  5913. }
  5914. }
  5915. if (time2 != "")
  5916. {
  5917. if (time1 != "")
  5918. {
  5919. if (y > x )
  5920. {
  5921. System.TimeSpan a = DateTime.Parse(time2) - DateTime.Parse(time1);
  5922. if ((float)a.TotalHours > time)
  5923. {
  5924. return false;
  5925. }
  5926. }
  5927. else
  5928. {
  5929. System.TimeSpan a = DateTime.Now - DateTime.Parse(time1);
  5930. if ((float)a.TotalHours > time)
  5931. {
  5932. return false;
  5933. }
  5934. }
  5935. }
  5936. else
  5937. {
  5938. return true;
  5939. }
  5940. }
  5941. else if (time1 != "")
  5942. {
  5943. System.TimeSpan a = DateTime.Now - DateTime.Parse(time1);
  5944. if ((float)a.TotalHours > time)
  5945. {
  5946. return false;
  5947. }
  5948. }
  5949. else
  5950. {
  5951. return true;
  5952. }
  5953. }
  5954. else
  5955. {
  5956. return true;
  5957. }
  5958. return true;
  5959. }
  5960. /// <summary>
  5961. /// 接单 - 确认工单
  5962. /// </summary>
  5963. /// <returns></returns>
  5964. [WechatActionFilter]
  5965. public ActionResult SureWorkOrder(long orderid, string OpenId,int inoutflag=0)
  5966. {
  5967. if (!string.IsNullOrEmpty(OpenId))
  5968. {
  5969. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  5970. if (ua != null)
  5971. {
  5972. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  5973. if (model != null)
  5974. {
  5975. int? zflag = 0;
  5976. //string strsql = "";
  5977. //if (ua.F_Flag == 1)
  5978. //{
  5979. // strsql = " and F_Type in(1,3)";
  5980. //}
  5981. //else if (ua.F_Flag == 2)
  5982. //{
  5983. // strsql = " and F_Type in(2,3)";
  5984. //}
  5985. var modellist = new BLL.T_Wo_WorkOrderItem_New().GetModelList("F_WoID=" + model.F_ID + " and F_WoState in(1,4) and F_IsUsed=0 and F_NextUser like '%" + ua.F_UserCode + "%' order by F_ID desc ").FirstOrDefault();
  5986. if (modellist == null)
  5987. {
  5988. return Error("非接单人不可操作工单");
  5989. }
  5990. var modellast = new BLL.T_Wo_WorkOrderItem_New().GetModelList("F_WoID=" + model.F_ID + " and F_WoState in(1,4) and F_NextUser like '%" + ua.F_UserCode + "%' order by F_ID desc ");
  5991. if (modellast.Count > 0)
  5992. {
  5993. int isused = modellast.Select(p => p.F_IsUsed == 0).Count();
  5994. if (isused <= 0)
  5995. return Error("工单已接单无需重新接单");
  5996. }
  5997. if (inoutflag != 0)
  5998. {
  5999. zflag = inoutflag;
  6000. }
  6001. else
  6002. {
  6003. zflag = modellist.F_Type;
  6004. }
  6005. var res = SureWO(ua, model, Convert.ToInt32(zflag));
  6006. if (res)
  6007. return Success("接单成功");
  6008. else
  6009. return Error("接单失败");
  6010. }
  6011. else
  6012. return Error("工单不存在");
  6013. }
  6014. return Error("OpenId不能为空");
  6015. }
  6016. return Error("无操作权限");
  6017. }
  6018. /// <summary>
  6019. /// 高层审批
  6020. /// </summary>
  6021. /// <param name="input"></param>
  6022. /// <returns></returns>
  6023. [WechatActionFilter]
  6024. public ActionResult HigApprovalOrder(string OpenId, long orderid, string cont, int isApproval = 0)
  6025. {
  6026. if (!string.IsNullOrEmpty(OpenId))
  6027. {
  6028. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  6029. if (ua != null)
  6030. {
  6031. string isagreestr = "";
  6032. string touser = "";
  6033. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  6034. //验证信息
  6035. if (model != null)
  6036. {
  6037. 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);
  6038. if (itemlast.Count > 0)
  6039. {
  6040. foreach (var it in itemlast)
  6041. {
  6042. it.F_IsUsed = 1;
  6043. itembll.Update(it);
  6044. }
  6045. }
  6046. model.F_Highopinions = cont;
  6047. if (isApproval == 1)
  6048. isagreestr = " 通过 " + cont;
  6049. else
  6050. isagreestr = " 未通过 " + cont;
  6051. string deptname = "";
  6052. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  6053. if (deptmodel != null)
  6054. {
  6055. deptname = deptmodel.F_DeptName + "-";
  6056. }
  6057. if (itemlast.Count > 0)
  6058. {
  6059. foreach (var item in itemlast)
  6060. {
  6061. int type = Convert.ToInt32(item.F_Type);
  6062. if (isApproval == 1)
  6063. {
  6064. if (type == 1 || type == 3)
  6065. {
  6066. model.F_State = (int)EnumWorkOrderState.finish;
  6067. }
  6068. else if (type == 2)
  6069. {
  6070. model.F_State2 = (int)EnumWorkOrderState.finish;
  6071. }
  6072. AddLog(model.F_ID, (int)EnumWorkOrderState.finish, deptname + ua.F_UserName + "(" + ua.F_WorkNumber + ")" + "高层已审批" + isagreestr, (int)EnumItemType.audit, (int)EnumItemOpt.reaudit, "", 0, ua, 0, 0, "", 1, type);
  6073. }
  6074. else
  6075. {
  6076. touser = item.F_CreateUser;
  6077. if (type == 1 || type == 3)
  6078. {
  6079. model.F_State = (int)EnumWorkOrderState.receive;
  6080. }
  6081. else if (type == 2)
  6082. {
  6083. model.F_State2 = (int)EnumWorkOrderState.receive;
  6084. }
  6085. AddLog(model.F_ID, (int)EnumWorkOrderState.receive, deptname + ua.F_UserName + "(" + ua.F_WorkNumber + ")" + "高层已审批" + isagreestr, (int)EnumItemType.deal, (int)EnumItemOpt.reaudit, touser, 0, ua, 0, 0, "", 0, type);
  6086. }
  6087. }
  6088. }
  6089. else
  6090. return Error("无操作权限!");
  6091. //AddLog(model.F_ID, model.F_State.Value, deptname + ua.F_UserName + "(" + ua.F_WorkNumber + ")" + "高层已审批"+ isagreestr, (int)EnumItemType.audit, (int)EnumItemOpt.reaudit, touser, 0, ua, 0, 0, "", 1);
  6092. bool n = woBLL.Update(model);
  6093. if (n)
  6094. return Success("审批成功");
  6095. else
  6096. return Error("审批失败!");
  6097. }
  6098. return Error("工单不存在");
  6099. }
  6100. }
  6101. return Error("无操作权限");
  6102. }
  6103. /// <summary>
  6104. /// 接单
  6105. /// </summary>
  6106. public bool SureWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, int flag = 3)
  6107. {
  6108. int overtime = 0, sms = 0;
  6109. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID=" + model.F_ID + " ");
  6110. if (itemlasts.Count > 0)
  6111. {
  6112. foreach (var it in itemlasts)
  6113. {
  6114. if (it.F_WoState == 1)
  6115. {
  6116. overtime = int.Parse(it.F_LimitTime);
  6117. sms = int.Parse(it.F_IsSMS.ToString());
  6118. }
  6119. }
  6120. }
  6121. #region 工单处理
  6122. var opt = "处理接单";
  6123. int optbut = (int)EnumItemOpt.receive;
  6124. int wostate = (int)EnumWorkOrderState.receive;
  6125. #region 读取当前登录人部门
  6126. string deptname = "";
  6127. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  6128. if (deptmodel != null)
  6129. {
  6130. deptname = deptmodel.F_DeptName + "-";
  6131. }
  6132. #endregion
  6133. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + opt;
  6134. var itemid = AddLog((int)model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, nowUser.F_UserCode, nowUser.F_DeptId, nowUser, overtime, sms,"",0,flag);
  6135. if (itemid > 0)
  6136. {
  6137. #region 处理工单
  6138. if (flag == 1 || ((model.F_Flag == null || model.F_Flag == 0) && flag == 3))
  6139. {
  6140. model.F_State = wostate;//已接单待处理
  6141. }
  6142. else if (flag == 2)
  6143. {
  6144. model.F_State2 = wostate;//已接单待处理
  6145. }
  6146. else
  6147. {
  6148. model.F_State = wostate;//已接单待处理
  6149. model.F_State2 = wostate;//已接单待处理
  6150. }
  6151. //model.F_DealBy = nowUser.F_UserCode;//已接单待处理
  6152. woBLL.Update(model);
  6153. #endregion
  6154. #region 推送消息
  6155. //读取上一级指派人员以及添加坐席并推送系统消息和微信消息
  6156. #region 给添加坐席推送系统消息和微信消息
  6157. sendsysmsg(model, nowUser, model.F_CreateBy, (int)itemid, "处理接单");
  6158. // var createUser = userAccountBLL.GetModel(model.F_CreateBy);
  6159. // if (createUser != null && !string.IsNullOrEmpty(createUser.F_WxOpenId))
  6160. // sendwxmsg(model, createUser.F_WxOpenId, nowUser, "接单");
  6161. #endregion
  6162. #region 读取上一级指派人员推送系统消息和微信消息
  6163. 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();
  6164. if (itemlast != null)
  6165. {
  6166. if (itemlast.F_CreateUser != model.F_CreateBy)
  6167. {
  6168. sendsysmsg(model, nowUser, itemlast.F_CreateUser, (int)itemid, "处理接单");
  6169. // var lastUser = userAccountBLL.GetModel(itemlast.F_CreateUser);
  6170. // if (lastUser != null && !string.IsNullOrEmpty(lastUser.F_WxOpenId))
  6171. // sendwxmsg(model, lastUser.F_WxOpenId, nowUser, "接单");
  6172. }
  6173. }
  6174. #endregion
  6175. #endregion
  6176. return true;
  6177. }
  6178. else
  6179. return false;
  6180. #endregion
  6181. }
  6182. /// <summary>
  6183. /// 工单处理
  6184. /// </summary>
  6185. /// <returns></returns>
  6186. [WechatActionFilter]
  6187. public ActionResult DealWorkOrder(string OpenId, long orderid, string F_Files, string cont, WorkOrdeDeptment deptment,
  6188. string uncont = "",
  6189. int isvisit = 1, int isover = 0, int inoutflag = 0, int isApprovalp = 0)
  6190. {
  6191. string markdepts = "37,57,74,88,268,295,339,422,213,427,433";
  6192. string qualdepts = "12,36,295,245";
  6193. if (!string.IsNullOrEmpty(OpenId))
  6194. {
  6195. if (string.IsNullOrEmpty(cont))
  6196. return Error("请输入处理内容");
  6197. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  6198. WorkOrderNewInput input = new WorkOrderNewInput();
  6199. if (ua != null)
  6200. {
  6201. if (!markdepts.Contains(ua.F_DeptId.ToString()) && !qualdepts.Contains(ua.F_DeptId.ToString()))
  6202. return Error("权限不足");
  6203. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  6204. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  6205. if (deptmodel != null)
  6206. {
  6207. if (model != null)
  6208. {
  6209. //string strsql = "";
  6210. //if (ua.F_Flag == 1)
  6211. //{
  6212. // strsql = " and F_Type in(1,3)";
  6213. //}
  6214. //else if (ua.F_Flag == 2)
  6215. //{
  6216. // strsql = " and F_Type in(2,3)";
  6217. //}
  6218. var modellist = new BLL.T_Wo_WorkOrderItem_New().GetModelList("F_WoID=" + model.F_ID + " and F_IsUsed=0 and F_NextUser like '%" + ua.F_UserCode + "%' order by F_ID desc ").FirstOrDefault();
  6219. //int? zflag = 0;
  6220. //if (inoutflag != 0)
  6221. //{
  6222. // zflag = inoutflag;
  6223. //}
  6224. //else
  6225. //{
  6226. // zflag = modellist.F_Type;
  6227. //}
  6228. if (modellist == null)
  6229. {
  6230. //if (modellist.F_NextUser != ua.F_UserCode)
  6231. return Error("非接单人不可操作工单");
  6232. }
  6233. //if (model.F_Flag == 9)
  6234. //{
  6235. // return Error("操作失败!");
  6236. //}
  6237. if (markdepts.Contains(ua.F_DeptId.ToString()) || qualdepts.Contains(ua.F_DeptId.ToString()))
  6238. {
  6239. input.F_ZL_ResponsibleUnit = deptment.ResponsibleUnit;// 责任单位
  6240. input.F_EventReason = deptment.EventReason;// 事件原因
  6241. input.F_ZL_ImprovementRequirements = deptment.ImprovementRequirements;// 改进要求
  6242. input.F_IsVisit = isvisit.ToString();
  6243. input.F_WorkmanShip = deptment.WorkmanShip;//质量管理科-工艺
  6244. input.F_Manufacturers = deptment.Manufacturers;//质量管理科-原料及厂家
  6245. input.F_ProductionNum = deptment.ProductionNum;//质量管理科-该批次生产数量
  6246. input.F_TS_Level = deptment.TS_Level;//投诉-重要级别:轻微、一般、较大、重大
  6247. }
  6248. int? zflag = 0;
  6249. if (model.F_Flag == 9)
  6250. {
  6251. model.F_Flag = 1;//默认外线操作
  6252. zflag = 1;
  6253. Overorder(ua, model, 2);
  6254. }
  6255. else
  6256. {
  6257. if (inoutflag != 0)
  6258. {
  6259. zflag = inoutflag;
  6260. }
  6261. else
  6262. {
  6263. zflag = modellist.F_Type;
  6264. }
  6265. }
  6266. var modellast = new BLL.T_Wo_WorkOrderItem_New().GetModelList("F_WoID=" + model.F_ID + "and F_IsUsed=0 order by F_ID desc ").FirstOrDefault();
  6267. if (model.F_State == 10 && model.F_State2 == 10)
  6268. return Error("工单已处理请勿重复操作!");
  6269. else
  6270. {
  6271. var res = DealWO(ua, model, F_Files, input, cont, isover, uncont, Convert.ToInt32(zflag),"", 0, isApprovalp);
  6272. if (res)
  6273. return Success("处理成功");
  6274. else
  6275. return Error("处理失败!");
  6276. }
  6277. }
  6278. else
  6279. return Error("工单不存在!");
  6280. }
  6281. else
  6282. {
  6283. return Error("请选择接收部门");
  6284. }
  6285. }
  6286. }
  6287. return Error("无操作权限!");
  6288. }
  6289. /// <summary>
  6290. /// 更新工单
  6291. /// </summary>
  6292. private bool Refresh()
  6293. {
  6294. int type = 0;
  6295. var modlelist = woBLL.GetModelList(" F_IsDelete=0" + "and F_IsOver=0" + " and F_State in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," +
  6296. (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.finish + ")");
  6297. if (modlelist.Count > 0)
  6298. {
  6299. foreach (var it in modlelist)
  6300. {
  6301. if (TimeforOver(it.F_ID))
  6302. {
  6303. type = 0;
  6304. }
  6305. else
  6306. {
  6307. type = 1;
  6308. }
  6309. if (type != it.F_IsOver)
  6310. {
  6311. it.F_IsOver = type;
  6312. bool n = woBLL.Update(it);
  6313. if (!n)
  6314. {
  6315. return false;
  6316. }
  6317. }
  6318. }
  6319. }
  6320. return true;
  6321. }
  6322. /// <summary>
  6323. /// 更新工单---判断内线超时工单
  6324. /// </summary>
  6325. private bool Refresh2()
  6326. {
  6327. int type = 0;
  6328. var modlelist = woBLL.GetModelList(" F_IsDelete=0" + "and F_IsOver in(0,1)" + " and F_State2 in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," +
  6329. (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.finish + ")");
  6330. if (modlelist.Count > 0)
  6331. {
  6332. foreach (var it in modlelist)
  6333. {
  6334. if (TimeforOver(it.F_ID, 2))
  6335. {
  6336. type = 0;
  6337. }
  6338. else
  6339. {
  6340. type = 2;
  6341. }
  6342. if (type != it.F_IsOver)
  6343. {
  6344. if (it.F_IsOver == 1)
  6345. {
  6346. if (type == 2)
  6347. {
  6348. it.F_IsOver = 3;
  6349. }
  6350. else
  6351. {
  6352. it.F_IsOver = 1;
  6353. }
  6354. }
  6355. else
  6356. {
  6357. it.F_IsOver = type;
  6358. }
  6359. bool n = woBLL.Update(it);
  6360. if (!n)
  6361. {
  6362. return false;
  6363. }
  6364. }
  6365. }
  6366. }
  6367. return true;
  6368. }
  6369. /// <summary>
  6370. /// 退回工单
  6371. /// </summary>
  6372. /// <param name="input"></param>
  6373. /// <returns></returns>
  6374. [WechatActionFilter]
  6375. public ActionResult BackWorkOrder(string OpenId, long orderid, string cont, int type = 0, int inoutflag = 0)
  6376. {//办理人员和监管可以退回工单
  6377. if (!string.IsNullOrEmpty(OpenId))
  6378. {
  6379. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  6380. //河南心连心化学工业集团股份有限公司-系统维护管理员(8000)指派工单给 李波(80324),张绍申(80325),杜爱国(80326),说明:无
  6381. if (ua != null)
  6382. {
  6383. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  6384. //验证信息
  6385. if (model != null)
  6386. {
  6387. int flag = 0;
  6388. string markdepts = "37,57,74,88,268,295,339,422,213,427,433";
  6389. var modellist = new BLL.T_Wo_WorkOrderItem_New().GetModelList($"F_WoID={model.F_ID} and F_IsUsed=0 and F_NextUser like '%{ua.F_UserCode}%' order by F_ID desc ");
  6390. var itemnext = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoState =1 and F_WoID='" + model.F_ID + "'and F_NextUser like '%" + ua.F_UserCode + "%' order by F_ID desc").FirstOrDefault();
  6391. if (modellist.Count <= 0)
  6392. {
  6393. return Error("非接单人不可操作工单");
  6394. }
  6395. if (markdepts.Contains(ua.F_DeptId.ToString()) && itemnext.F_Flag == 9)
  6396. {
  6397. if (modellist.Count >= 2)
  6398. {
  6399. flag = 3;
  6400. }
  6401. else
  6402. return Error("异常退回工单失败!");
  6403. }
  6404. else
  6405. {
  6406. if (inoutflag != 0)
  6407. {
  6408. flag = inoutflag;
  6409. }
  6410. else
  6411. {
  6412. flag = Convert.ToInt32(modellist.FirstOrDefault().F_Type);
  6413. }
  6414. }
  6415. var res = BackWO(ua, model, cont, type, flag);
  6416. if (res)
  6417. return Success("退回成功");
  6418. else
  6419. return Error("退回失败!");
  6420. }
  6421. return Error("工单不存在");
  6422. }
  6423. }
  6424. return Error("无操作权限");
  6425. }
  6426. /// <summary>
  6427. /// 撤回工单
  6428. /// </summary>
  6429. /// <param name="orderid"></param>
  6430. /// <param name="cont"></param>
  6431. /// <returns></returns>
  6432. [WechatActionFilter]
  6433. public ActionResult RevokeWo(string OpenId, long orderid, string cont, int inoutflag = 0)
  6434. {
  6435. if (!string.IsNullOrEmpty(OpenId))
  6436. {
  6437. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  6438. //增加撤回功能
  6439. if (ua != null)
  6440. {
  6441. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  6442. //验证信息
  6443. if (model != null)
  6444. {
  6445. int flag = 0;
  6446. string markdepts = "37,57,74,88,268,295,339,422,213,427,433";
  6447. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  6448. var modelnext = new BLL.T_Wo_WorkOrderItem_New().GetModelList($"F_WoID={model.F_ID} and F_OptType=1 and F_CreateUser={ua.F_UserCode} order by F_ID desc ");
  6449. if (modelnext != null)
  6450. {
  6451. if (inoutflag != 0)
  6452. {
  6453. flag = inoutflag;
  6454. }
  6455. else
  6456. {
  6457. var modellist = itembll.GetModelList($"F_WoID={model.F_ID} and F_IsUsed=0 and F_CreateUser={ua.F_UserCode} order by F_ID desc ");
  6458. if (modellist.Count <= 0)
  6459. return Error("撤回失败,无法撤回!");
  6460. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "JDYBZZX" || ro.F_RoleCode == "XTGLY")
  6461. {
  6462. if (modellist != null && modellist.Count < 2)
  6463. return Error("撤回失败,无法撤回!");
  6464. flag = 3;
  6465. }
  6466. else if (modellist != null && modellist.Count > 0)
  6467. {
  6468. if (markdepts.Contains(ua.F_DeptId.ToString()))
  6469. {
  6470. var itemnext = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoState =1 and F_WoID='" + model.F_ID + "'and F_NextUser like '%" + ua.F_UserCode + "%' order by F_ID desc").FirstOrDefault();
  6471. if (modellist.Count == 2)
  6472. {
  6473. flag = 3;
  6474. model.F_Flag = 9;
  6475. }
  6476. else if (itemnext != null && itemnext.F_Flag == 9)
  6477. {
  6478. if (modellist != null && modellist.Count < 2)
  6479. return Error("撤回失败,无法撤回!");
  6480. flag = 3;
  6481. model.F_Flag = 9;
  6482. }
  6483. }
  6484. if (flag == 0)
  6485. {
  6486. flag = Convert.ToInt32(modellist.FirstOrDefault().F_Type);
  6487. }
  6488. }
  6489. else
  6490. {
  6491. return Error("无操作权限");
  6492. }
  6493. }
  6494. var res = RevWO(ua, model, cont, flag);
  6495. if (res)
  6496. return Success("撤回成功");
  6497. //}
  6498. //else
  6499. // return Error("撤回失败!");
  6500. }
  6501. return Error("操作失败!");
  6502. }
  6503. return Error("工单不存在");
  6504. }
  6505. }
  6506. return Error("无操作权限");
  6507. }
  6508. /// <summary>
  6509. ///申请延期
  6510. /// </summary>
  6511. /// <returns></returns>
  6512. [WechatActionFilter]
  6513. public ActionResult DelayWorkOrder(string OpenId, long orderid, string cont, float limit = 0)
  6514. {
  6515. if (!string.IsNullOrEmpty(OpenId))
  6516. {
  6517. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  6518. if (ua != null)
  6519. {
  6520. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  6521. //验证信息
  6522. if (model != null)
  6523. {
  6524. var res = DeWO(ua, model, cont, limit);
  6525. if (res)
  6526. return Success("延期成功");
  6527. else
  6528. return Error("延期失败!");
  6529. }
  6530. return Error("工单不存在");
  6531. }
  6532. }
  6533. return Error("无操作权限");
  6534. }
  6535. /// <summary>
  6536. /// 申请延期
  6537. /// </summary>
  6538. public bool DeWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, string cont, float limit)
  6539. {
  6540. #region 工单处理
  6541. int sms = 0; int wostate = 0;
  6542. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID=" + model.F_ID + " ");
  6543. if (itemlasts.Count > 0)
  6544. {
  6545. foreach (var it in itemlasts)
  6546. {
  6547. if (it.F_WoState == 1)
  6548. {
  6549. sms = int.Parse(it.F_IsSMS.ToString());
  6550. }
  6551. itembll.Update(it);
  6552. wostate = int.Parse(it.F_WoState.ToString());
  6553. }
  6554. }
  6555. int optbut = (int)EnumItemOpt.Delay;
  6556. #region 读取当前登录人部门
  6557. string deptname = "";
  6558. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  6559. if (deptmodel != null)
  6560. {
  6561. deptname = deptmodel.F_DeptName + "-";
  6562. }
  6563. #endregion
  6564. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + "延期工单,延期说明:" + cont;
  6565. //获取上一级处理人员
  6566. var touser = "";
  6567. 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();
  6568. if (itemlast != null)
  6569. touser = itemlast.F_CreateUser;
  6570. var itemid = AddLog((int)model.F_ID, wostate, content, (int)EnumItemType.Delay, optbut, touser, 0, nowUser, limit + model.F_limit, sms, "", 1);
  6571. #endregion
  6572. return true;
  6573. }
  6574. /// <summary>
  6575. /// 退回工单
  6576. /// </summary>
  6577. public bool BackWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, string cont, int type, int flag = 1)
  6578. {
  6579. #region 工单处理
  6580. int sms = 0;
  6581. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID=" + model.F_ID + " ");
  6582. if (itemlasts.Count > 0)
  6583. {
  6584. foreach (var it in itemlasts)
  6585. {
  6586. if (it.F_WoState == 1)
  6587. {
  6588. sms = int.Parse(it.F_IsSMS.ToString());
  6589. }
  6590. }
  6591. }
  6592. var opt = "退回";
  6593. int F_OptType = 1;
  6594. int optbut = (int)EnumItemOpt.reback;
  6595. int wostate = (int)EnumWorkOrderState.reback;
  6596. if (type == 1)
  6597. {
  6598. opt = "异常退回";
  6599. optbut = (int)EnumItemOpt.abreback;
  6600. wostate = (int)EnumWorkOrderState.abreback;
  6601. F_OptType = 2;
  6602. }
  6603. #region 读取当前登录人部门
  6604. string deptname = "";
  6605. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  6606. if (deptmodel != null)
  6607. {
  6608. deptname = deptmodel.F_DeptName + "-";
  6609. }
  6610. #endregion
  6611. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + opt + "工单,退回说明:" + cont;
  6612. //获取上一级处理人员
  6613. var touser = ""; var deptid = 0;
  6614. string strsql = "";
  6615. if (flag == 1)
  6616. {
  6617. strsql = $" and F_Type in(1,3)";
  6618. }
  6619. else if (flag == 2)
  6620. {
  6621. strsql = $" and F_Type in(2,3)";
  6622. }
  6623. 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 + "'" + strsql + " order by F_ID desc").FirstOrDefault();
  6624. if (itemlast != null)
  6625. {
  6626. touser = itemlast.F_CreateUser;
  6627. if (!string.IsNullOrEmpty(touser))
  6628. {
  6629. var ua = userAccountBLL.GetModel(touser);
  6630. if (ua != null)
  6631. {
  6632. deptid = ua.F_DeptId;
  6633. }
  6634. }
  6635. }
  6636. var itemid = AddLog((int)model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, touser, deptid, nowUser, model.F_limit, sms, "", 0, flag);
  6637. if (itemid > 0)
  6638. {
  6639. string smscont = "";
  6640. if (model.F_Type == "1")
  6641. {
  6642. smscont = "咨询";
  6643. }
  6644. else if (model.F_Type == "2")
  6645. {
  6646. smscont = "投诉";
  6647. }
  6648. else if (model.F_Type == "3")
  6649. {
  6650. smscont = "抽检";
  6651. }
  6652. else if (model.F_Type == "5")
  6653. {
  6654. smscont = "业务协办";
  6655. }
  6656. else
  6657. {
  6658. smscont = "建议";
  6659. }
  6660. string[] mag = { smscont };
  6661. string smsmsg = "您好,您有一条新的" + smscont + "工单,请及时接单处理!";
  6662. var tousermodel = new BLL.T_Sys_UserAccount().GetModel(touser);
  6663. if (tousermodel != null)
  6664. {
  6665. if (!string.IsNullOrEmpty(tousermodel.F_Mobile))
  6666. {
  6667. SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, tousermodel.F_Mobile.Trim());
  6668. bool n = new SMSController().AddSmS(tousermodel.F_Mobile.Trim(), smsmsg, nowUser.F_UserId);
  6669. }
  6670. }
  6671. #region 处理工单
  6672. if (deptid == 2)
  6673. {
  6674. if (flag == 1 || ((model.F_Flag == null || model.F_Flag == 0) && flag == 3))
  6675. {
  6676. model.F_State = (int)EnumWorkOrderState.reassign;
  6677. }
  6678. else if (flag == 2)
  6679. {
  6680. model.F_State2 = (int)EnumWorkOrderState.reassign;
  6681. }
  6682. else
  6683. {
  6684. model.F_State = (int)EnumWorkOrderState.reassign;
  6685. model.F_State2 = (int)EnumWorkOrderState.reassign;
  6686. }
  6687. }
  6688. else
  6689. {
  6690. if (flag == 1 || ((model.F_Flag == null || model.F_Flag == 0) && flag == 3))
  6691. {
  6692. model.F_State = wostate;
  6693. }
  6694. else if (flag == 2)
  6695. {
  6696. model.F_State2 = wostate;
  6697. }
  6698. else
  6699. {
  6700. model.F_Flag = 9;
  6701. model.F_State = wostate;
  6702. model.F_State2 = wostate;
  6703. }
  6704. }
  6705. woBLL.Update(model);
  6706. #endregion
  6707. #region 推送消息
  6708. #region 向上一级操作人员推送消息
  6709. if (!string.IsNullOrWhiteSpace(touser) && touser != nowUser.F_UserCode)
  6710. {//排除上一级指派人是自己
  6711. sendsysmsg(model, nowUser, touser, (int)itemid, opt);
  6712. // var lastUser = userAccountBLL.GetModel(touser);
  6713. // if (lastUser != null && !string.IsNullOrEmpty(lastUser.F_WxOpenId))
  6714. // sendwxmsg(model, lastUser.F_WxOpenId, nowUser, opt);
  6715. }
  6716. #endregion
  6717. #endregion
  6718. return true;
  6719. }
  6720. else
  6721. return false;
  6722. #endregion
  6723. }
  6724. /// <summary>
  6725. /// 撤回工单
  6726. /// </summary>
  6727. public bool RevWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, string cont,int flag=1)
  6728. {
  6729. #region 工单处理
  6730. int sms = 0;
  6731. string markdepts = "37,57,74,88,268,295,339,422,213,427,433";
  6732. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID=" + model.F_ID + " ");
  6733. if (itemlasts.Count > 0)
  6734. {
  6735. foreach (var it in itemlasts)
  6736. {
  6737. if (it.F_WoState == 1)
  6738. {
  6739. sms = int.Parse(it.F_IsSMS.ToString());
  6740. }
  6741. }
  6742. }
  6743. var opt = "撤回";
  6744. int F_OptType = 1;
  6745. int optbut = (int)EnumItemOpt.revoke;
  6746. int wostate = (int)EnumWorkOrderState.revoke;
  6747. #region 读取当前登录人部门
  6748. string deptname = "";
  6749. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  6750. if (deptmodel != null)
  6751. {
  6752. deptname = deptmodel.F_DeptName + "-";
  6753. }
  6754. #endregion
  6755. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + opt + "工单,撤回说明:" + cont;
  6756. //获取上一级处理人员
  6757. var touser = ""; var deptid = 0;
  6758. string strsql = "";
  6759. if (flag == 1)
  6760. {
  6761. strsql = " and F_Type in(1,3)";
  6762. }
  6763. else if (flag == 2)
  6764. {
  6765. strsql = " and F_Type in(2,3)";
  6766. }
  6767. else
  6768. {
  6769. strsql = "";
  6770. }
  6771. var itemlast = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_IsUsed=0 and F_WoState =" + F_OptType + " and F_WoID='" + model.F_ID + "'and F_CreateUser='" + nowUser.F_UserCode + "' order by F_ID desc");
  6772. if (itemlast != null && itemlast.Count > 0)
  6773. {
  6774. //if (markdepts.Contains(nowUser.F_DeptId.ToString()))
  6775. //{
  6776. // var itemnext = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoState =" + F_OptType + " and F_WoID='" + model.F_ID + "'and F_NextUser like '%" + nowUser.F_UserCode + "%' order by F_ID desc").FirstOrDefault();
  6777. // if (itemlast.Count == 2 || itemnext.F_Flag == 9)
  6778. // {
  6779. // flag = 3;
  6780. // model.F_Flag = 9;
  6781. // }
  6782. //}
  6783. foreach (var item in itemlast)
  6784. {
  6785. touser = item.F_NextUser;
  6786. if (!string.IsNullOrEmpty(touser))
  6787. {
  6788. var ua = userAccountBLL.GetModel(touser);
  6789. if (ua != null)
  6790. {
  6791. deptid = ua.F_DeptId;
  6792. }
  6793. }
  6794. }
  6795. }
  6796. var itemid = AddLog((int)model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, nowUser.F_UserCode, nowUser.F_DeptId, nowUser, model.F_limit, sms,"",0,flag);
  6797. if (itemid > 0)
  6798. {
  6799. #region 发短信
  6800. //string smscont = "";
  6801. //if (model.F_Type == "1")
  6802. //{
  6803. // smscont = "咨询";
  6804. //}
  6805. //else if (model.F_Type == "2")
  6806. //{
  6807. // smscont = "投诉";
  6808. //}
  6809. //else if (model.F_Type == "3")
  6810. //{
  6811. // smscont = "抽检";
  6812. //}
  6813. //else
  6814. //{
  6815. // smscont = "建议";
  6816. //}
  6817. //string[] mag = { smscont };
  6818. //string smsmsg = "您好,您有一条待处理的工单已被撤回,请留意!";
  6819. //var tousermodel = new BLL.T_Sys_UserAccount().GetModel(touser);
  6820. //if (tousermodel != null)
  6821. //{
  6822. // if (!string.IsNullOrEmpty(tousermodel.F_Mobile))
  6823. // {
  6824. // SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, tousermodel.F_Mobile.Trim());
  6825. // //SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, "15225066843");
  6826. // bool n = new SMSController().AddSmS(tousermodel.F_Mobile.Trim(), smsmsg, nowUser.F_UserId);
  6827. // }
  6828. //}
  6829. #endregion
  6830. #region 处理工单
  6831. if (flag == 1 || ((model.F_Flag == null || model.F_Flag == 0) && flag == 3))
  6832. {
  6833. model.F_State = wostate;
  6834. }
  6835. else if (flag == 2)
  6836. {
  6837. model.F_State2 = wostate;
  6838. }
  6839. else
  6840. {
  6841. model.F_State = wostate;
  6842. model.F_State2 = wostate;
  6843. }
  6844. woBLL.Update(model);
  6845. #endregion
  6846. #region 推送消息
  6847. #region 向上一级操作人员推送消息
  6848. //if (!string.IsNullOrWhiteSpace(touser) && touser != nowUser.F_UserCode)
  6849. //{//排除上一级指派人是自己
  6850. // sendsysmsg(model, nowUser, touser, (int)itemid, opt);
  6851. //}
  6852. #endregion
  6853. #endregion
  6854. return true;
  6855. }
  6856. else
  6857. return false;
  6858. #endregion
  6859. }
  6860. /// <summary>
  6861. /// 处理工单
  6862. /// </summary>
  6863. 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 = "",int flag=1, string eventreason = "", int flagstate = 0, int isApprovalp = 0)
  6864. {
  6865. #region 工单处理
  6866. int sms = 0;
  6867. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID=" + model.F_ID + " ");
  6868. if (itemlasts.Count > 0)
  6869. {
  6870. foreach (var it in itemlasts)
  6871. {
  6872. if (it.F_WoState == 1)
  6873. {
  6874. sms = int.Parse(it.F_IsSMS.ToString());
  6875. }
  6876. }
  6877. }
  6878. var opt = "处理";
  6879. int optbut = (int)EnumItemOpt.deal;
  6880. int wostate = (int)EnumWorkOrderState.receive;
  6881. string nextuser = "";
  6882. int nextdept = 0;
  6883. if (isover == 1)
  6884. {
  6885. model.F_DealResult = "已处理";//处理结果
  6886. opt = "处理完结";
  6887. optbut = (int)EnumItemOpt.end;
  6888. wostate = (int)EnumWorkOrderState.finish;
  6889. model.F_DealBy = nowUser.F_UserCode;
  6890. model.F_DealTime = DateTime.Now;
  6891. }
  6892. else
  6893. {
  6894. model.F_DealResult = "未处理";//处理结果
  6895. model.F_DealReasons = uncont;//未处理原因
  6896. nextuser = nowUser.F_UserCode;
  6897. nextdept = nowUser.F_DeptId;
  6898. }
  6899. #region 高层审批
  6900. string htouser = "", htousername = ""; int hclbm = 0;
  6901. if (isApprovalp != 0)
  6902. {
  6903. hclbm = GetGCDept(nowUser.F_DeptId);
  6904. if (hclbm != 0)
  6905. {
  6906. var cluslist = userAccountBLL.GetModelList($"F_DeptId = {hclbm}");
  6907. if (cluslist.Count > 0)
  6908. {
  6909. foreach (var l in cluslist)
  6910. {
  6911. if (string.IsNullOrEmpty(htouser))
  6912. {
  6913. htouser = string.IsNullOrEmpty(htouser) ? l.F_UserCode : htouser + "," + l.F_UserCode;
  6914. htousername = string.IsNullOrEmpty(htousername) ? l.F_UserName + "(" + l.F_WorkNumber + ")" : htousername + "," + l.F_UserName + "(" + l.F_WorkNumber + ")";
  6915. }
  6916. }
  6917. }
  6918. wostate = (int)EnumWorkOrderState.audit;
  6919. }
  6920. }
  6921. #endregion
  6922. #region 读取当前登录人部门
  6923. string deptname = "";
  6924. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  6925. if (deptmodel != null)
  6926. {
  6927. deptname = deptmodel.F_DeptName + "-";
  6928. }
  6929. #endregion
  6930. var optcont = "";
  6931. if (!string.IsNullOrEmpty(cont))
  6932. optcont = ",处理内容:" + cont;
  6933. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + opt + "工单" + optcont;
  6934. var itemid = AddLog(model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, nextuser, nextdept, nowUser, model.F_limit, sms, "", 0, flag, flagstate);
  6935. if (hclbm>0)
  6936. AddLog(model.F_ID, (int)EnumWorkOrderState.audit, htousername + "高层待审批", (int)EnumItemType.audit, (int)EnumItemOpt.audit, htouser, hclbm, nowUser, model.F_limit, sms, "", 2, flag);
  6937. if (itemid > 0)
  6938. {
  6939. #region 处理工单
  6940. if (flag == 1 || ((model.F_Flag == null || model.F_Flag == 0) && flag == 3))
  6941. {
  6942. model.F_State = wostate;
  6943. }
  6944. else if (flag == 2)
  6945. {
  6946. model.F_State2 = wostate;
  6947. }
  6948. //处理内容
  6949. if (!string.IsNullOrEmpty(F_Files))
  6950. {
  6951. if (!string.IsNullOrEmpty(model.F_Files))
  6952. model.F_Files = model.F_Files + "," + F_Files;
  6953. else
  6954. model.F_Files = F_Files;
  6955. }
  6956. if (!string.IsNullOrEmpty(cont))
  6957. {
  6958. if (model.F_Source == "3")
  6959. {
  6960. if (flag == 2)
  6961. {
  6962. model.F_DealContent2 = cont;
  6963. }
  6964. else
  6965. {
  6966. model.F_DealContent = cont;
  6967. }
  6968. }
  6969. else
  6970. {
  6971. if (flag == 2)
  6972. {
  6973. model.F_DealContent2 += cont + ";";
  6974. }
  6975. else
  6976. {
  6977. model.F_DealContent += cont + ";";
  6978. }
  6979. }
  6980. if (flag == 1 || ((model.F_Flag == null || model.F_Flag == 0) && flag == 3))
  6981. {
  6982. if (model.F_SuperiorOpinion.Trim() != cont.Trim())
  6983. {
  6984. model.F_SuperiorOpinion = nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ") " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + cont;
  6985. }
  6986. }
  6987. else if (flag == 2)
  6988. {
  6989. if (model.F_SuperiorOpinion2.Trim() != cont.Trim())
  6990. {
  6991. model.F_SuperiorOpinion2 = nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ") " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + cont;
  6992. }
  6993. }
  6994. //model.F_SuperiorOpinion = string.IsNullOrEmpty(model.F_SuperiorOpinion) ? cont : model.F_SuperiorOpinion + "; " + cont;
  6995. }
  6996. //if (!string.IsNullOrEmpty(eventreason))
  6997. //{
  6998. // if (flag == 1)
  6999. // {
  7000. // model.F_EventReason = eventreason;
  7001. // }
  7002. // else if (flag == 2)
  7003. // {
  7004. // model.F_EventReason2 = eventreason;
  7005. // }
  7006. //}
  7007. model.F_DealTime = DateTime.Now;
  7008. InToworkModel(model, input);
  7009. woBLL.Update(model);
  7010. #endregion
  7011. #region 推送消息
  7012. #region 推送消息给添加的坐席 -处理情况
  7013. if (nowUser.F_UserCode != model.F_CreateBy)
  7014. {
  7015. sendsysmsg(model, nowUser, model.F_CreateBy, (int)model.F_ID, opt);//推送系统消息
  7016. if (model.F_State == (int)EnumWorkOrderState.finish)
  7017. {
  7018. var createmodel = userAccountBLL.GetModel(model.F_CreateBy); //被指派人
  7019. if (createmodel != null)
  7020. {
  7021. if (!string.IsNullOrEmpty(createmodel.F_WxOpenId))
  7022. {
  7023. sendwxmsg(model, createmodel.F_WxOpenId, nowUser, "工单完结");
  7024. }
  7025. }
  7026. }
  7027. }
  7028. #endregion
  7029. #region 向上一级操作人员推送消息
  7030. 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();
  7031. if (itemlast != null)
  7032. {
  7033. if (itemlast.F_CreateUser != model.F_CreateBy)
  7034. {
  7035. sendsysmsg(model, nowUser, itemlast.F_CreateUser, (int)itemid, opt);
  7036. // var lastUser = userAccountBLL.GetModel(itemlast.F_CreateUser);
  7037. // if (lastUser != null && !string.IsNullOrEmpty(lastUser.F_WxOpenId))
  7038. // sendwxmsg(model, lastUser.F_WxOpenId, nowUser, opt);
  7039. }
  7040. }
  7041. #endregion
  7042. #region 办理完结向客户发送消息
  7043. //if (model.F_State == (int)EnumWorkOrderState.finish)
  7044. //{
  7045. // if (!string.IsNullOrEmpty(model.F_CustomerID))
  7046. // {
  7047. // var cusmodel = customerBaseBLL.GetModel(model.F_CustomerID.Trim());
  7048. // if (cusmodel != null && !string.IsNullOrEmpty(cusmodel.F_WxOpenId))
  7049. // {
  7050. // sendwxmsg(model, cusmodel.F_WxOpenId, nowUser, opt);
  7051. // }
  7052. // }
  7053. //}
  7054. if (isover == 1)
  7055. {
  7056. // if (!string.IsNullOrEmpty(model.F_WxOpenId))
  7057. //sendwxmsg(model, model.F_WxOpenId, nowUser, model.F_DealContent);
  7058. }
  7059. #endregion
  7060. #endregion
  7061. return true;
  7062. }
  7063. else
  7064. return false;
  7065. #endregion
  7066. }
  7067. //推送系统提醒
  7068. public void sendsysmsg(Model.T_Wo_WorkOrder womodel, Model.T_Sys_UserAccount nowUser, string touser, int toid, string opt)
  7069. {
  7070. #region 消息提醒
  7071. string strmsg = string.Empty;
  7072. strmsg = nowUser.F_UserName + "(" + nowUser.F_UserCode + ")" + "操作" + opt + "工单";
  7073. Model.T_Msg_List msg = new Model.T_Msg_List();
  7074. msg.Type = (int)Model.MSGType.workorder;//处理
  7075. msg.ToUser = touser;
  7076. msg.ToID = toid;
  7077. msg.Detail = strmsg;
  7078. msg.State = 0;
  7079. msg.IsDel = 0;
  7080. msg.CreateUser = nowUser.F_UserCode;
  7081. msg.CreateDate = DateTime.Now;
  7082. new BLL.T_Msg_List().Add(msg);
  7083. #endregion
  7084. }
  7085. //推送微信消息
  7086. public void sendwxmsg(Model.T_Wo_WorkOrder womodel, string openid, Model.T_Sys_UserAccount nowUser, string opt)
  7087. {
  7088. #region 推送微信
  7089. try
  7090. {
  7091. if (!string.IsNullOrEmpty(openid))
  7092. {
  7093. var dicv = dicvalueBll.GetModel(int.Parse(womodel.F_Type));
  7094. string content = string.Empty;
  7095. var wotype = "";
  7096. if (dicv != null)
  7097. {
  7098. wotype = dicv.F_Name;
  7099. }
  7100. content = opt;
  7101. var msg = WxHelper.SendWechatMsg1(DateTime .Now .ToString ("yyyy-MM-dd HH:mm:ss"), "你的工单已处理", wotype, womodel.F_State.ToString(), content, womodel.F_ID.ToString(), openid, "");
  7102. Error("推送微信::::::" + msg.ToString());
  7103. }
  7104. }
  7105. catch { }
  7106. #endregion
  7107. }
  7108. public static bool IsNumeric(string value)
  7109. {
  7110. return Regex.IsMatch(value, @"^[+-]?\d*[.]?\d*$");
  7111. }
  7112. /// <summary>
  7113. /// 修改工单
  7114. /// </summary>
  7115. /// <returns></returns>
  7116. [WechatActionFilter]
  7117. public ActionResult Update(WorkOrderNewInput input )
  7118. {
  7119. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + input.F_WxOpenId + "'").FirstOrDefault();
  7120. if (ua != null)
  7121. {
  7122. #region 添加验证判断
  7123. if (input.F_ID <= 0)
  7124. return Error("参数错误!");
  7125. if (!(input.F_Type > 0 && input.F_Type < 6))
  7126. return Error("工单类型错误!");
  7127. if (string.IsNullOrEmpty(input.F_CusName))
  7128. return Error("请输入客户姓名!");
  7129. if (string.IsNullOrEmpty(input.F_CusPhone))
  7130. return Error("请输入客户电话!");
  7131. if(input.F_Type == 2 || input.F_Type == 5)
  7132. {
  7133. if (string.IsNullOrEmpty(input.F_SalesBase))
  7134. return Error("请输入基地!");
  7135. if (string.IsNullOrEmpty(input.F_QuestionType))
  7136. return Error("请选择问题类别!");
  7137. }
  7138. //if (!string.IsNullOrEmpty(input.F_BatchNumber) && !vaBatchNumber(input.F_BatchNumber))
  7139. //{
  7140. // return Error("请输入正确的生产批次号!");
  7141. //}
  7142. if (!string.IsNullOrEmpty(input.F_CustomerID))
  7143. {
  7144. var Customer = customerBaseBLL.GetModel(input.F_CustomerID.Trim());
  7145. if (Customer == null)
  7146. return Error("无此客户编码!");
  7147. }
  7148. if (!string.IsNullOrWhiteSpace(input.F_MaterialID))
  7149. {
  7150. var Customer = mmBLL.GetModel(input.F_MaterialID.Trim());
  7151. if (Customer == null)
  7152. return Error("无此物料编码!");
  7153. }
  7154. //if (!string.IsNullOrEmpty(input.F_BatchNumber))
  7155. //{
  7156. // var prono = input.F_BatchNumber.Substring(0, 6);
  7157. // try
  7158. // {
  7159. // var pronos = DateTime.ParseExact(prono, "yyMMdd", null).ToString("yyyy-MM-dd");
  7160. // var protime = Convert.ToDateTime(pronos);
  7161. // if (DateTime.Parse(pronos) > DateTime.Now)
  7162. // {
  7163. // return Error("生产批次号错误,生产日期不能大于当前时间!");
  7164. // }
  7165. // }
  7166. // catch
  7167. // {
  7168. // return Error("生产批次号错误,日期格式错误!");
  7169. // }
  7170. //}
  7171. if (!string.IsNullOrEmpty(input.F_CustomerID) && !valcode(input.F_CustomerID.ToString(), 10))
  7172. return Error("客户编号为10为纯数字!");
  7173. if (!string.IsNullOrEmpty(input.F_MaterialID) && !valcode(input.F_MaterialID.ToString(), 11))
  7174. return Error("物料编码为11为纯数字!");
  7175. #endregion
  7176. var model = woBLL.GetModel(input.F_ID);
  7177. if (model == null)
  7178. return Error("查询不到此工单!");
  7179. if (model.F_State == 2)
  7180. {
  7181. return Error("此工单已接单不能修改!");
  7182. }
  7183. else if (model.F_State == 11 || model.F_State == 10)
  7184. {
  7185. return Error("此工单已处理不能修改!");
  7186. }
  7187. if (!string.IsNullOrEmpty(input.F_SalesPhone))
  7188. {
  7189. if (!IsNumeric(input.F_SalesPhone))
  7190. return Error("请输入正确的业务员电话");
  7191. }
  7192. var itemlasts = itembll.GetModelList(" F_WoID=" + model.F_ID + "order by F_ID desc ").FirstOrDefault ();
  7193. int overtime = 0, sms = 0;
  7194. if (itemlasts!=null )
  7195. {
  7196. if (itemlasts.F_LimitTime != "")
  7197. overtime = int.Parse(itemlasts.F_LimitTime);
  7198. sms = int.Parse(itemlasts.F_IsSMS.ToString());
  7199. }
  7200. #region 保存客户基本信息
  7201. model = inputtoobj(ua, model, input, 1);
  7202. #endregion
  7203. bool n = woBLL.Update(model);
  7204. if (n)
  7205. {
  7206. WriteWorkOrderLog(model.F_WorkOrderCode, ua.F_UserCode, 0, "", 1, "修改工单");
  7207. #region 读取当前登录人的部门
  7208. string deptname = "";
  7209. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  7210. if (deptmodel != null)
  7211. {
  7212. deptname = deptmodel.F_DeptName + "-";
  7213. }
  7214. #endregion
  7215. 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);
  7216. if (GetUser(input.F_WxOpenId) != null)
  7217. {
  7218. var user = GetUser(input.F_WxOpenId);
  7219. string deptname1 = "";
  7220. var deptmode = departmentBLL.GetModel(user.F_DeptId);
  7221. if (deptmode != null)
  7222. {
  7223. deptname1 = deptmode.F_DeptName + "-";
  7224. }
  7225. var deptmodel1 = departmentBLL.GetModel(ua.F_DeptId);
  7226. 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);
  7227. if (sms == 1 && !string.IsNullOrEmpty(user.F_Mobile))
  7228. {
  7229. SendSms(model.F_Type, user.F_Mobile, ua.F_UserId);
  7230. }
  7231. }
  7232. else
  7233. {
  7234. string deptname1 = "";
  7235. int dapt = 0, nextda = 0, nextda2 = 0; string opt = "", opt2 = "";
  7236. var deptmodel1 = departmentBLL.GetModel(ua.F_DeptId);
  7237. if (deptmodel1 != null)
  7238. {
  7239. deptname1 = deptmodel1.F_DeptName;
  7240. dapt = deptmodel1.F_ParentId;
  7241. }
  7242. //if (dapt != 0)
  7243. //{
  7244. if (CirculMarket(ua.F_DeptId, 11))
  7245. {
  7246. nextda = 427;
  7247. opt = "流转运营中心";
  7248. }
  7249. else if (CirculMarket(ua.F_DeptId, 14))
  7250. {
  7251. nextda = 57;
  7252. opt = "流转营销管理处";
  7253. }
  7254. else if (CirculMarket(ua.F_DeptId, 15))
  7255. {
  7256. nextda = 74;
  7257. opt = "流转策划推广";
  7258. }
  7259. else if (CirculMarket(ua.F_DeptId, 16))
  7260. {
  7261. nextda = 88;
  7262. opt = "流转销售部";
  7263. }
  7264. else if (CirculMarket(ua.F_DeptId, 18))
  7265. {
  7266. nextda = 268;
  7267. opt = "流转车用尿素";
  7268. }
  7269. else if (CirculMarket(ua.F_DeptId, 20))
  7270. {
  7271. nextda = 422;
  7272. opt = "流转营销中心市场科";
  7273. nextda2 = 295;
  7274. opt2 = "流转新乡黑科质检";
  7275. }
  7276. else if (CirculMarket(ua.F_DeptId, 332))
  7277. {
  7278. nextda = 339;
  7279. opt = "流转营销管理处";
  7280. }
  7281. else if (ua.F_DeptId == 17 || ua.F_DeptId == 19 || ua.F_DeptId == 20 || ua.F_DeptId == 21)
  7282. {
  7283. nextda = ua.F_DeptId;
  7284. opt = "流转" + deptname1;
  7285. }
  7286. //}
  7287. if (nextda != 0)
  7288. {
  7289. if (nextda2 != 0)
  7290. {
  7291. model.F_Flag = 3;
  7292. AssignWO(ua, model, input, opt, "", nextda, 0, model.F_limit, sms, 0, 0, 0, "", 1, 1, 3);
  7293. var res2 = AssignWO(ua, model, input, opt2, "", nextda2, 0, model.F_limit, sms, 0, 0, 0, "", 1, 2, 3);
  7294. }
  7295. else
  7296. {
  7297. model.F_State = 1;
  7298. model.F_State2 = 1;
  7299. model.F_Flag = 9;
  7300. var res = AssignWO(ua, model, input, opt, "", nextda, 0, model.F_limit, sms, 0, 0, 0, "", 1, 3, 9);
  7301. }
  7302. return Success("保存成功");
  7303. }
  7304. else
  7305. {
  7306. return Error("流转失败!");
  7307. }
  7308. }
  7309. return Success("保存成功!");
  7310. }
  7311. else
  7312. return Error("保存失败!");
  7313. }
  7314. else
  7315. {
  7316. return Error("OpenId不能为空!!");
  7317. }
  7318. }
  7319. public void WriteWorkOrderLog(string WorkOrderID, string UserCode, int IsDelete, string DelUserCode, int TypeId, string Remark)
  7320. {
  7321. var model = new Model.T_Wo_WorkOrder_Logs();
  7322. model.WorkOrderID = WorkOrderID; //工单编号
  7323. model.UserCode = UserCode; //修改人code
  7324. model.AddTime = DateTime.Now; //添加时间
  7325. model.IsDelete = IsDelete; //是否删除(0正常1删除)
  7326. model.DelUserCode = DelUserCode; //删除人code
  7327. model.TypeId = TypeId; //类型(0添加,1修改)
  7328. model.Remark = Remark; //备注
  7329. blllogs.Add(model);
  7330. }
  7331. /// <summary>
  7332. /// 添加工单记录
  7333. /// </summary>
  7334. 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, int flag = 3,int flagstate = 0)
  7335. {
  7336. Model.T_Wo_WorkOrderItem_New itemModel = new Model.T_Wo_WorkOrderItem_New();
  7337. #region
  7338. string strsql = "";
  7339. if (nowUser != null)
  7340. {
  7341. string flagstr = "";
  7342. if (flag != 3)
  7343. flagstr = $" and F_Type in({ flag},3)";
  7344. Model.T_Sys_RoleInfo ro = rolebll.GetModel(nowUser.F_RoleId);
  7345. strsql = $" isnull(F_IsUsed,'0')='0' and F_ItemType={itemtype} and F_WoID={woid} and (F_CreateUser={nowUser.F_UserCode} or F_NextUser like '%{nowUser.F_UserCode}%'){flagstr}";
  7346. //if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "JDYBZZX" || ro.F_RoleCode == "XTGLY")
  7347. //{
  7348. // strsql = $" F_OptType !=1 and isnull(F_IsUsed,'0')='0' and F_ItemType={itemtype} and F_WoID={woid} and F_CreateUser={nowUser.F_UserCode}{flagstr}";
  7349. //}
  7350. //else
  7351. //{
  7352. // strsql = $" isnull(F_IsUsed,'0')='0' and F_ItemType={itemtype} and F_WoID={woid} and (F_CreateUser={nowUser.F_UserCode} or F_NextUser like '%{nowUser.F_UserCode}%'){flagstr}";
  7353. //}
  7354. }
  7355. else
  7356. {
  7357. strsql = $" isnull(F_IsUsed,'0')='0' and F_ItemType={itemtype} and F_WoID={woid}";
  7358. }
  7359. //处理当前工单的记录之前的记录过期
  7360. //var itemlast = itembll.GetModelList(" isnull(F_IsUsed,'0')='0' and F_ItemType=" + itemtype + " and F_WoID=" + woid + " ");
  7361. var itemlast = itembll.GetModelList(strsql);
  7362. if (F_IsUsed == 0)
  7363. {
  7364. if (itemlast != null && itemlast.Count > 0)
  7365. {
  7366. foreach (var it in itemlast)
  7367. {
  7368. it.F_IsUsed = 1;
  7369. it.F_LimitTime = overtime.ToString();
  7370. itembll.Update(it);
  7371. }
  7372. itemModel.F_LastTime = itemlast.LastOrDefault().F_CreateTime;
  7373. }
  7374. }
  7375. #endregion
  7376. itemModel.F_WoID = woid;
  7377. itemModel.F_IsSMS = sms;
  7378. itemModel.F_WoState = wostate;
  7379. itemModel.F_ItemType = itemtype;
  7380. itemModel.F_OptType = opttype;
  7381. itemModel.F_OptContent = content;
  7382. itemModel.F_NextUser = nextuser;
  7383. itemModel.F_NextDept = nextdept;
  7384. itemModel.F_IsUsed = F_IsUsed;
  7385. itemModel.F_LimitTime = overtime.ToString();
  7386. itemModel.F_Type = flag;//区分内外线和公共部门
  7387. if (flagstate != 0)
  7388. itemModel.F_Flag = flagstate;
  7389. else
  7390. itemModel.F_Flag = new BLL.T_Wo_WorkOrder().GetModel(woid).F_Flag;
  7391. if (nowUser != null)
  7392. {
  7393. itemModel.F_CreateUser = nowUser.F_UserCode;
  7394. }
  7395. else
  7396. {
  7397. itemModel.F_CreateUser = "";
  7398. }
  7399. if (create != "")
  7400. {
  7401. itemModel.F_CreateTime = DateTime.Parse(create);
  7402. }
  7403. else
  7404. {
  7405. itemModel.F_CreateTime = DateTime.Now;
  7406. }
  7407. var res = itembll.Add(itemModel);
  7408. return res;
  7409. }
  7410. #region
  7411. //workorder.WoBillController blcon = new WoBillController();
  7412. ///// <summary>
  7413. ///// 获取所有业务
  7414. ///// </summary>
  7415. ///// <returns></returns>
  7416. //[WechatActionFilter]
  7417. //public ActionResult GetBusList()
  7418. //{
  7419. // var list = blcon.GetBusAllList();
  7420. // return Success("获取信息列表成功", list);
  7421. //}
  7422. ///// <summary>
  7423. ///// 获取业务内容
  7424. ///// </summary>
  7425. ///// <returns></returns>
  7426. //[WechatActionFilter]
  7427. //public ActionResult GetBusInfo()
  7428. //{
  7429. // string strbusid = HttpUtility.UrlDecode(RequestString.GetQueryString("busid"));
  7430. // if (string.IsNullOrEmpty(strbusid))
  7431. // return Error("参数错误");
  7432. // var model = blcon.GetBusInfo(strbusid);
  7433. // if (model != null)
  7434. // return Success("获取信息成功", model);
  7435. // else
  7436. // return Error("获取信息失败");
  7437. //}
  7438. ///// <summary>
  7439. ///// 获取开票列表
  7440. ///// </summary>
  7441. ///// <returns></returns>
  7442. //[WechatActionFilter]
  7443. //public ActionResult GetBillList()
  7444. //{
  7445. // DataTable dt = new DataTable();
  7446. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  7447. // string strbtime = HttpUtility.UrlDecode(RequestString.GetQueryString("btime"));
  7448. // string stretime = HttpUtility.UrlDecode(RequestString.GetQueryString("etime"));
  7449. // string strpageindex = RequestString.GetQueryString("pageindex");
  7450. // int pageindex = 1;
  7451. // string strpagesize = RequestString.GetQueryString("pagesize");
  7452. // int pagesize = 10;
  7453. // if (strpageindex.Trim() != "")
  7454. // {
  7455. // pageindex = Convert.ToInt32(strpageindex);
  7456. // }
  7457. // if (strpagesize.Trim() != "")
  7458. // {
  7459. // pagesize = Convert.ToInt32(strpagesize);
  7460. // }
  7461. // var obj=blcon.GetLists(stropenid, strbtime, stretime, pageindex, pagesize);
  7462. // return Content(obj.ToJson());
  7463. //}
  7464. ///// <summary>
  7465. ///// 获取开票详情
  7466. ///// </summary>
  7467. ///// <returns></returns>
  7468. //[WechatActionFilter]
  7469. //public ActionResult GetBillInfo()
  7470. //{
  7471. // string strbillid = HttpUtility.UrlDecode(RequestString.GetQueryString("billid"));
  7472. // if (string.IsNullOrEmpty(strbillid))
  7473. // return Error("参数错误");
  7474. // var model = blcon.GetBillInfo(strbillid);
  7475. // if (model != null)
  7476. // return Success("获取信息成功", model);
  7477. // else
  7478. // return Error("获取信息失败");
  7479. //}
  7480. ///// <summary>
  7481. ///// 开票
  7482. ///// </summary>
  7483. ///// <returns></returns>
  7484. //[WechatActionFilter]
  7485. //public ActionResult AddBill()
  7486. //{
  7487. // string billtype = RequestString.GetFormString("billtype");//发票类型
  7488. // string cusname = RequestString.GetFormString("cusname");//客户名称
  7489. // string taxidnum = RequestString.GetFormString("taxidnum");//纳税人识别号
  7490. // string address = RequestString.GetFormString("address");//地址
  7491. // string phone = RequestString.GetFormString("phone");//电话
  7492. // string bank = RequestString.GetFormString("bank");//开户行
  7493. // string bankaccount = RequestString.GetFormString("bankaccount");//开户行账号
  7494. // string proname = RequestString.GetFormString("proname");//项目名称
  7495. // string models = RequestString.GetFormString("models");//型号
  7496. // string unit = RequestString.GetFormString("unit");//单位
  7497. // string amount = RequestString.GetFormString("amount");//数量
  7498. // string unitprice = RequestString.GetFormString("unitprice");//单价
  7499. // string sumprice = RequestString.GetFormString("sumprice");//金额
  7500. // string taxrate = RequestString.GetFormString("taxrate");//税率
  7501. // string taxamount = RequestString.GetFormString("taxamount");//税额
  7502. // string billingMethod = RequestString.GetFormString("billingmethod");//开票方式:快递/自取
  7503. // string billingTime = RequestString.GetFormString("billingtime");//开票时间
  7504. // string remark = RequestString.GetFormString("remark");//备注
  7505. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  7506. // Model.T_Wo_Bill dModel = new Model.T_Wo_Bill();
  7507. // #region 保存基本信息
  7508. // dModel.F_BillType = billtype;
  7509. // dModel.F_CusName = cusname;
  7510. // dModel.F_TaxIDNum = taxidnum;
  7511. // dModel.F_Address = address;
  7512. // dModel.F_Phone = phone;
  7513. // dModel.F_Bank = bank;
  7514. // dModel.F_BankAccount = bankaccount;
  7515. // dModel.F_ProName = proname;
  7516. // dModel.F_Models = models;
  7517. // dModel.F_Unit = unit;
  7518. // dModel.F_Amount = amount;
  7519. // dModel.F_UnitPrice = unitprice;
  7520. // dModel.F_SumPrice = sumprice;
  7521. // dModel.F_TaxRate = taxrate;
  7522. // dModel.F_TaxAmount = taxamount;
  7523. // dModel.F_BillingMethod = billingMethod;
  7524. // dModel.F_BillingTime = billingTime;
  7525. // dModel.F_Remark = remark;
  7526. // dModel.F_Openid = stropenid;
  7527. // dModel.F_CreateOn = DateTime.Now;
  7528. // dModel.F_State = 0;
  7529. // #endregion
  7530. // var res=blcon.addbills(dModel);
  7531. // if (res)
  7532. // return Success("保存成功");
  7533. // else
  7534. // return Error("保存失败");
  7535. //}
  7536. #endregion
  7537. #region 获取公司详情
  7538. ////获取公司信息
  7539. //[WechatActionFilter]
  7540. //public ActionResult GetInfo()
  7541. //{
  7542. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  7543. // if (string.IsNullOrEmpty(stropenid))
  7544. // return Error("参数错误!");
  7545. // var model=customerBaseBLL.GetModelByOpenid(stropenid);
  7546. // if (model != null)
  7547. // {
  7548. // var sqlwo = " IsDel=0 and State <>2 "; var sqlno = " F_isDel=0 ";
  7549. // var nowUser = userAccountBLL.GetModelByOpenid(stropenid);
  7550. // var nowCus = customerBaseBLL.GetModelByOpenid(stropenid);
  7551. // if (nowUser != null)
  7552. // {
  7553. // workorder.WorkOrderController wo = new workorder.WorkOrderController();
  7554. // sqlwo += " and State =1 and WorkOrderID in ( '" + wo.GetDWCWorkOrderID(nowUser.F_UserCode) + "') ";
  7555. // sqlno += " and (ISNULL(F_UserId,'') = '' or ISNULL(F_UserId,'') like '%," + nowUser.F_UserId + ",%')";
  7556. // }
  7557. // else if (nowCus != null)
  7558. // {
  7559. // sqlwo += " and ( CustomerID=" + model.F_CustomerId + " or County like '%" + model.F_CompanyName + "%' )";
  7560. // 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)";
  7561. // }
  7562. // var ordercount = woBLL.GetRecordCount(sqlwo);
  7563. // var noticecount = new BLL.T_Msg_NoticeInfo().GetRecordCount(sqlno);
  7564. // var obj = new
  7565. // {
  7566. // model.F_CompanyName,//公司名称
  7567. // model.F_CompanyLogo,//logo
  7568. // model.F_CustomerCode,//编号
  7569. // model.F_CycleStart,//服务周期-开始时间
  7570. // model.F_CycleEnd,//服务周期-结束时间
  7571. // model.F_ChargeType,//收费类型:1月度,2季度,3年度
  7572. // model.F_Charges,//收费
  7573. // model.F_TaxNumber,//公司税号
  7574. // model.F_CompanyAddress,//公司地址
  7575. // ordercount,//待处理工单数量
  7576. // noticecount,//未读公告数量
  7577. // };
  7578. // return Success("获取成功", obj);
  7579. // }
  7580. // return Error("获取失败");
  7581. //}
  7582. ////获取财税信息
  7583. ////[WechatActionFilter]
  7584. //public ActionResult GetFinc()
  7585. //{
  7586. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  7587. // var model = customerBaseBLL.GetModelByOpenid(stropenid);
  7588. // if (model != null)
  7589. // {
  7590. // var finmodel = finbll.GetModelList(" F_CustomerId=" + model.F_CustomerId).FirstOrDefault();
  7591. // if (finmodel != null)
  7592. // {
  7593. // var obj = new
  7594. // {
  7595. // model.F_CompanyName,//公司名称
  7596. // model.F_CompanyLogo,//logo
  7597. // model.F_CustomerCode,//编号
  7598. // finmodel.F_CusFinId,
  7599. // finmodel.F_CustomerId,
  7600. // finmodel.F_MonthState,
  7601. // finmodel.F_AnnualIncome,
  7602. // finmodel.F_AnnualProfit,
  7603. // finmodel.F_AnnualCost,
  7604. // finmodel.F_AnnualPersonCount,
  7605. // finmodel.F_AnnualWages,
  7606. // finmodel.F_QuarterlyCost,
  7607. // finmodel.F_QuarterlyPersonCount,
  7608. // finmodel.F_QuarterlyWages,
  7609. // finmodel.F_QuarterlyIncome,
  7610. // finmodel.F_QPVAT,
  7611. // finmodel.F_QPSurtax,
  7612. // finmodel.F_QPTaxes,
  7613. // finmodel.F_QPConTax,
  7614. // finmodel.F_QPPerinTax,
  7615. // finmodel.F_QPStampTax,
  7616. // finmodel.F_QPOtherTax
  7617. // };
  7618. // return Success("获取成功", obj);
  7619. // }
  7620. // }
  7621. // return Error("获取失败");
  7622. //}
  7623. #endregion
  7624. #region 工单
  7625. /// <summary>
  7626. /// 工单列表
  7627. /// </summary>
  7628. [WechatActionFilter]
  7629. public ActionResult GetWoList()
  7630. {
  7631. workorder.WorkOrderController wo = new workorder.WorkOrderController();
  7632. var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='TimeLimitDays' ").FirstOrDefault();
  7633. int days = config != null ? Convert.ToInt32(config.F_ParamValue) : 60; //默认60天
  7634. DataTable dt = new DataTable();
  7635. int recordCount = 0;
  7636. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  7637. //客户姓名,电话,工单号
  7638. string keyword = HttpUtility.UrlDecode(RequestString.GetQueryString("keyword"));
  7639. //工单状态
  7640. int states = RequestString.GetInt("states", -1);
  7641. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  7642. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  7643. string strpageindex = RequestString.GetQueryString("page");
  7644. int pageindex = 1;
  7645. string strpagesize = RequestString.GetQueryString("pagesize");
  7646. int pagesize = 10;
  7647. //#region sql 语句相关处理
  7648. string sql = " ";
  7649. //获取坐席表信息
  7650. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  7651. //获取客户档案(业主)表信息
  7652. var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  7653. if (!string.IsNullOrEmpty(sql))
  7654. {
  7655. //sql += " and IsDel=0 ";
  7656. ////客户姓名,电话,房间号,工单号,接待描述
  7657. //if (!string.IsNullOrEmpty(keyword))
  7658. //{
  7659. // sql += " and (CustomerTel like '%" + keyword + "%' or Customer like '%" + keyword + "%' or WorkOrderID like '%" + keyword + "%' or Detail like '%" + keyword + "%' or County like '%" + keyword + "%' ) ";
  7660. //}
  7661. //if (states >= 0)
  7662. //{
  7663. // #region 权限限制
  7664. // if (ua != null)
  7665. // {
  7666. // string uwhere = " ";
  7667. // switch (states)
  7668. // {
  7669. // case 0://待指派的
  7670. // //sql += " and State ='0' and CreateUser= '" + ua.F_UserCode + "' ";
  7671. // //3区域客服可以看到区域待指派工单
  7672. // if (ua.F_RoleId != 17)
  7673. // {
  7674. // uwhere += " and CreateUser='" + ua.F_UserCode + "' ";
  7675. // }
  7676. // sql += " and State =0 " + uwhere;
  7677. // break;
  7678. // case 1://待接单的
  7679. // sql += " and State =" + (int)EnumWorkOrderState.assign + " and T_Wo_WorkOrder.ID in ( " + wo.GetDJDWorkOrderID(ua.F_UserCode) + ") ";
  7680. // break;
  7681. // case 2://待完成的(待处理)
  7682. // 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) + ") ";
  7683. // break;
  7684. // case 3://已完成的
  7685. // sql += " and State =" + (int)EnumWorkOrderState.finish + " and LastDealUser = '" + ua.F_UserCode + "' ";
  7686. // break;
  7687. // case 4://我参与的
  7688. // sql += " and (CreateUser= '" + ua.F_UserCode + "' or T_Wo_WorkOrder.ID in ( " + wo.GetCYWorkOrderID(ua.F_UserCode) + ")) ";
  7689. // break;
  7690. // case 5://超期工单 - 设置两个月的处理时效,两个月内未解决的工单都直接汇总到这里
  7691. // sql += $" and DATEADD(DAY,{days},CreateTime) < GETDATE() AND State < " + (int)EnumWorkOrderState.finish + " ";
  7692. // break;
  7693. // }
  7694. // }
  7695. // else if (modelCustomer != null)
  7696. // {
  7697. // sql += " and ( CustomerID=" + modelCustomer.F_CustomerId + " or County like '%"+modelCustomer.F_CompanyName+"%' )";
  7698. // }
  7699. // else
  7700. // {
  7701. // sql = "";
  7702. // }
  7703. // #endregion
  7704. //}
  7705. //if (strstarttime.Trim() != "" && strstarttime != "undefined")
  7706. //{
  7707. // sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
  7708. //}
  7709. //if (strendtime.Trim() != "" && strendtime != "undefined")
  7710. //{
  7711. // sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0 ";
  7712. //}
  7713. //#endregion
  7714. //if (strpageindex.Trim() != "")
  7715. //{
  7716. // pageindex = Convert.ToInt32(strpageindex);
  7717. //}
  7718. //if (strpagesize.Trim() != "")
  7719. //{
  7720. // pagesize = Convert.ToInt32(strpagesize);
  7721. //}
  7722. //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";
  7723. //dt = BLL.PagerBLL.GetListPager(
  7724. // "T_Wo_WorkOrder (NOLOCK)",
  7725. // "WorkOrderID",
  7726. // cols,
  7727. // sql,
  7728. // "ORDER BY CreateTime DESC,State asc",
  7729. // pagesize,
  7730. // pageindex,
  7731. // true,
  7732. // out recordCount);
  7733. }
  7734. var obj = new
  7735. {
  7736. state = "success",
  7737. message = "成功",
  7738. rows = dt,
  7739. total = recordCount
  7740. };
  7741. return Content(obj.ToJson());
  7742. }
  7743. /// <summary>
  7744. /// 工单详情
  7745. /// </summary>
  7746. [WechatActionFilter]
  7747. public ActionResult GetWoInfo()
  7748. {
  7749. string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
  7750. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  7751. if (string.IsNullOrEmpty(strworkorderid))
  7752. return Error("参数错误");
  7753. if (string.IsNullOrEmpty(stropenid))
  7754. return Error("参数错误!");
  7755. //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 "
  7756. // + " from T_Wo_WorkOrder where T_Wo_WorkOrder.ID ='" + strworkorderid + "' ";
  7757. //var dt = DbHelperSQL.Query(sql).Tables[0];
  7758. //if (dt.Rows.Count > 0)
  7759. //{
  7760. // var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
  7761. // var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  7762. // if (configfj != null)
  7763. // {
  7764. // dt = BindFileData(dt, configfj.F_ParamValue);
  7765. // }
  7766. // string gcsql = "select *,dbo.GetUserName(F_NextUser) as F_NextUserName, dbo.GetDeptName(F_NextDept) as F_NextDeptName,dbo.GetUserName(F_CreateUser) as F_CreateUserName "
  7767. // + "from T_Wo_WorkOrderItem_New where F_WoID ='" + strworkorderid + "'";
  7768. // var gcdt = DbHelperSQL.Query(gcsql).Tables[0];
  7769. // dt.Columns.Add("FilePath", typeof(string));
  7770. // if (configfj != null || config != null)
  7771. // {
  7772. // foreach (DataRow bldr in dt.Rows)
  7773. // {
  7774. // if (bldr["CallID"] != null && config != null)
  7775. // {
  7776. // bldr["FilePath"] = GetCallPath(bldr["CallID"].ToString(), config.F_ParamValue);
  7777. // }
  7778. // }
  7779. // }
  7780. // var obj = new
  7781. // {
  7782. // data = dt,
  7783. // item = gcdt
  7784. // };
  7785. // return Success("查询成功", obj);
  7786. //}
  7787. return Error("查询失败");
  7788. }
  7789. #region 在用工单操作
  7790. ///// <summary>
  7791. ///// 处理工单
  7792. ///// </summary>
  7793. ///// <returns></returns>
  7794. //[WechatActionFilter]
  7795. //public ActionResult DealWorkOrder(long orderid, string cont, int isover = 0)
  7796. //{
  7797. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  7798. // if (!string.IsNullOrEmpty(stropenid))
  7799. // {
  7800. // Model.T_Sys_UserAccount ua = userAccountBLL.GetModelByOpenid(stropenid);
  7801. // if (ua != null)
  7802. // {
  7803. // Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  7804. // if (model != null)
  7805. // {
  7806. // bool res = new workorder.WorkOrderController().DealWO(ua, model, cont, isover);
  7807. // if (res)
  7808. // return Success("处理成功");
  7809. // else
  7810. // return Error("操作失败");
  7811. // }
  7812. // else
  7813. // return Error("工单不存在");
  7814. // }
  7815. // else
  7816. // return Error("无操作权限");
  7817. // }
  7818. // else
  7819. // return Error("参数错误");
  7820. //}
  7821. ///// <summary>
  7822. ///// 接单 - 确认工单
  7823. ///// </summary>
  7824. ///// <returns></returns>
  7825. //[WechatActionFilter]
  7826. //public ActionResult SureWorkOrder(long orderid)
  7827. //{
  7828. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  7829. // if (!string.IsNullOrEmpty(stropenid))
  7830. // {
  7831. // var ua = userAccountBLL.GetModelByOpenid(stropenid);
  7832. // if (ua != null)
  7833. // {
  7834. // Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  7835. // if (model != null)
  7836. // {
  7837. // bool res = new workorder.WorkOrderController().SureWO(ua, model);
  7838. // if (res)
  7839. // return Success("接单成功");
  7840. // else
  7841. // return Error("操作失败");
  7842. // }
  7843. // else
  7844. // return Error("工单不存在");
  7845. // }
  7846. // else
  7847. // return Error("无操作权限");
  7848. // }
  7849. // else
  7850. // return Error("参数错误");
  7851. //}
  7852. ///// <summary>
  7853. ///// 指派/转派工单
  7854. ///// </summary>
  7855. ///// <returns></returns>
  7856. //[WechatActionFilter]
  7857. //public ActionResult AssignWorkOrder(long orderid, string cont, int clbm = 0, int clid = 0)
  7858. //{
  7859. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  7860. // if (!string.IsNullOrEmpty(stropenid))
  7861. // {
  7862. // var ua = userAccountBLL.GetModelByOpenid(stropenid);
  7863. // if (ua != null)
  7864. // {
  7865. // if (clbm != 0 && clid == 0)
  7866. // return Error("请选择接收人");
  7867. // Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  7868. // if (model != null)
  7869. // {
  7870. // var res = new workorder.WorkOrderController().AssignWO(ua, model, cont, clbm, clid);
  7871. // if (res)
  7872. // return Success("转派成功");
  7873. // else
  7874. // return Error("转派失败!");
  7875. // }
  7876. // else
  7877. // return Error("工单不存在!");
  7878. // }
  7879. // }
  7880. // return Error("无操作权限!");
  7881. //}
  7882. ///// <summary>
  7883. ///// 退回工单
  7884. ///// </summary>
  7885. ///// <param name="input"></param>
  7886. ///// <returns></returns>
  7887. //[WechatActionFilter]
  7888. //public ActionResult BackWorkOrder(long orderid, string cont,int type=0)
  7889. //{//办理人员和监管可以退回工单
  7890. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  7891. // if (!string.IsNullOrEmpty(stropenid))
  7892. // {
  7893. // var ua = userAccountBLL.GetModelByOpenid(stropenid);
  7894. // if (ua != null)
  7895. // {
  7896. // Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  7897. // //验证信息
  7898. // if (model != null)
  7899. // {
  7900. // var res = new workorder.WorkOrderController().BackWO(ua, model, cont, type);
  7901. // if (res)
  7902. // return Success("处理成功");
  7903. // else
  7904. // return Error("处理失败!");
  7905. // }
  7906. // return Error("工单不存在");
  7907. // }
  7908. // }
  7909. // return Error("无操作权限");
  7910. //}
  7911. ///// <summary>
  7912. ///// 催办工单
  7913. ///// </summary>
  7914. ///// <returns></returns>
  7915. //[WechatActionFilter]
  7916. //public ActionResult AddWorkOrderRemind(long orderid, string cont)
  7917. //{
  7918. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  7919. // if (!string.IsNullOrEmpty(stropenid))
  7920. // {
  7921. // var ua = userAccountBLL.GetModelByOpenid(stropenid);
  7922. // if (ua != null)
  7923. // {
  7924. // Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  7925. // if (model != null)
  7926. // {
  7927. // var res = new workorder.WorkOrderController().RemindWO(ua, model, cont);
  7928. // if (res)
  7929. // Success("催办成功!");
  7930. // else
  7931. // Success("操作失败!");
  7932. // }
  7933. // return Error("工单不存在!");
  7934. // }
  7935. // }
  7936. // return Error("无操作权限!");
  7937. //}
  7938. #endregion
  7939. #endregion
  7940. #region 公告通知
  7941. /// <summary>
  7942. /// 获取公告列表
  7943. /// </summary>
  7944. /// <returns></returns>
  7945. //[WechatActionFilter]
  7946. public ActionResult GetNoticeList()
  7947. {
  7948. DataTable dt = new DataTable(); int recordCount = 0;
  7949. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  7950. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  7951. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  7952. string strpageindex = RequestString.GetQueryString("page");
  7953. int pageindex = 1;
  7954. string strpagesize = RequestString.GetQueryString("pagesize");
  7955. int pagesize = 10;
  7956. #region sql 语句相关处理
  7957. string sql = " and F_isDel=0 ";
  7958. //获取坐席表信息
  7959. var ua = userAccountBLL.GetModelByOpenid(stropenid);
  7960. //获取客户档案(业主)表信息
  7961. var modelCustomer = customerBaseBLL.GetModelByOpenid(stropenid);
  7962. if (ua != null)
  7963. {
  7964. sql += " and (ISNULL(F_UserId,'') = '' or ISNULL(F_UserId,'') like '%," + ua.F_UserId + ",%')";
  7965. }
  7966. else if (modelCustomer != null) {
  7967. sql += " and F_isCus=1";
  7968. }
  7969. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  7970. {
  7971. sql += " and datediff(day,F_CreateOn,'" + strstarttime + "')<=0 ";
  7972. }
  7973. if (strendtime.Trim() != "" && strendtime != "undefined")
  7974. {
  7975. sql += " and datediff(day,F_CreateOn,'" + strendtime + "')>=0 ";
  7976. }
  7977. #endregion
  7978. if (strpageindex.Trim() != "")
  7979. {
  7980. pageindex = Convert.ToInt32(strpageindex);
  7981. }
  7982. if (strpagesize.Trim() != "")
  7983. {
  7984. pagesize = Convert.ToInt32(strpagesize);
  7985. }
  7986. dt = BLL.PagerBLL.GetListPager(
  7987. "T_Msg_NoticeInfo",
  7988. "F_NoticeId",
  7989. "*",
  7990. sql,
  7991. "ORDER BY F_NoticeId desc",
  7992. pagesize,
  7993. pageindex,
  7994. true,
  7995. out recordCount);
  7996. List<Model.T_Msg_NoticeInfo> msgList = new BLL.T_Msg_NoticeInfo().DataTableToList(dt);
  7997. List<Model.T_Sys_UserAccount> userList = new BLL.T_Sys_UserAccount().GetModelList("");
  7998. var obj = new
  7999. {
  8000. rows = msgList.Select(m =>
  8001. {
  8002. Model.T_Sys_UserAccount usermodel = userList.Where(u => u.F_UserId == m.F_CreateBy.Value).FirstOrDefault();
  8003. var uname = "";
  8004. if (usermodel != null)
  8005. uname = usermodel.F_UserName;
  8006. return new
  8007. {
  8008. F_NoticeId = m.F_NoticeId,
  8009. F_Title = m.F_Title,
  8010. F_Content = m.F_Content,
  8011. F_isCus = m.F_isCus,
  8012. F_CreateOn = m.F_CreateOn,
  8013. F_CreateBy = m.F_CreateBy,
  8014. F_CreateByName = uname
  8015. };
  8016. }),
  8017. total = recordCount
  8018. };
  8019. return Content(obj.ToJson());
  8020. }
  8021. /// <summary>
  8022. /// 获取公告详情
  8023. /// </summary>
  8024. /// <returns></returns>
  8025. //[WechatActionFilter]
  8026. public ActionResult GetNoticeInfo()
  8027. {
  8028. string strnoticeid = HttpUtility.UrlDecode(RequestString.GetQueryString("noticeid"));
  8029. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  8030. if (string.IsNullOrEmpty(strnoticeid))
  8031. return Error("参数错误");
  8032. if (string.IsNullOrEmpty(stropenid))
  8033. return Error("参数错误!");
  8034. var dModel = new BLL.T_Msg_NoticeInfo().GetModel(int.Parse(strnoticeid.Trim()));
  8035. Model.T_Sys_UserAccount userModel = new Model.T_Sys_UserAccount();
  8036. if (dModel != null)
  8037. {
  8038. if (dModel.F_CreateBy != null)
  8039. userModel = userAccountBLL.GetModel(dModel.F_CreateBy.Value);
  8040. var uname = "";
  8041. if (userModel != null)
  8042. uname = userModel.F_UserName;
  8043. #region 标记为已读
  8044. var nowUser = userAccountBLL.GetModelByOpenid(stropenid);
  8045. var nowCus = customerBaseBLL.GetModelByOpenid(stropenid);
  8046. var usercode = "";
  8047. if (nowUser != null)
  8048. {
  8049. usercode = nowUser.F_UserCode;
  8050. var msglist = new BLL.T_Msg_List().GetModelList(" State=0 and ToUser='" + usercode + "' and Type=5 and ToID=" + dModel.F_NoticeId);
  8051. foreach (var item in msglist)
  8052. {
  8053. item.State = 1;
  8054. item.ReadDate = DateTime.Now;
  8055. new BLL.T_Msg_List().Update(item);
  8056. }
  8057. }
  8058. else if (nowCus != null)
  8059. {
  8060. usercode = nowCus.F_CustomerCode;
  8061. Model.T_Msg_List msg = new Model.T_Msg_List();
  8062. msg.Type = (int)Model.MSGType.cusnotice;
  8063. msg.ToUser = usercode;
  8064. msg.ToID = dModel.F_NoticeId;
  8065. msg.Detail = "客户" + usercode + "查看了公告《" + dModel.F_Title + "》";
  8066. msg.State = 1;
  8067. msg.IsDel = 0;
  8068. msg.CreateDate = DateTime.Now;
  8069. msg.ReadDate = DateTime.Now;
  8070. new BLL.T_Msg_List().Add(msg);
  8071. }
  8072. #endregion
  8073. var obj = new
  8074. {
  8075. F_NoticeId = dModel.F_NoticeId,
  8076. F_Title = dModel.F_Title,
  8077. F_Content = dModel.F_Content,
  8078. F_isCus = dModel.F_isCus,
  8079. F_CreateOn = dModel.F_CreateOn,
  8080. F_CreateBy = dModel.F_CreateBy,
  8081. F_CreateByName = uname,
  8082. F_UserId = dModel.F_UserId,
  8083. F_RoleId = dModel.F_RoleId,
  8084. };
  8085. return Success("获取公告详情成功", dModel);
  8086. }
  8087. else
  8088. return Error("获取公告详情失败");
  8089. }
  8090. #endregion
  8091. #region 微信工单
  8092. ///// <summary>
  8093. ///// 获取工单列表
  8094. ///// </summary>
  8095. ///// <returns></returns>
  8096. //[WechatActionFilter]
  8097. //public ActionResult GetList()
  8098. //{
  8099. // workorder.WorkOrderController wo = new workorder.WorkOrderController();
  8100. // var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='TimeLimitDays' ").FirstOrDefault();
  8101. // int days = config != null ? Convert.ToInt32(config.F_ParamValue) : 60; //默认60天
  8102. // DataTable dt = new DataTable();
  8103. // int recordCount = 0;
  8104. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  8105. // //客户姓名,电话,房间号,工单号
  8106. // string keyword = HttpUtility.UrlDecode(RequestString.GetQueryString("keyword"));
  8107. // //工单状态(ltype:)
  8108. // string strltype = HttpUtility.UrlDecode(RequestString.GetQueryString("ltype"));
  8109. // //工单状态
  8110. // int states = RequestString.GetInt("states", -1);
  8111. // //工单来源
  8112. // int strtype = RequestString.GetInt("type", 0);
  8113. // //工单类型
  8114. // int strtypeclass = RequestString.GetInt("typeclass", 0);
  8115. // //工单起止时间
  8116. // string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  8117. // string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  8118. // //来电单位
  8119. // string lddep = HttpUtility.UrlDecode(RequestString.GetQueryString("lddep"));
  8120. // //20180329 来电弹屏工单记录根据反馈单位获取列表 可以看到同一坐席组的所有人的工单记录
  8121. // string fkdep = HttpUtility.UrlDecode(RequestString.GetQueryString("fkdep"));
  8122. // int isldtp = RequestString.GetQueryInt("isldtp", 0);
  8123. // //微信列表(0未审核微信列表,1已审核微信列表)
  8124. // int isaudit = RequestString.GetInt("isaudit", -1);
  8125. // string strpageindex = RequestString.GetQueryString("page");
  8126. // int pageindex = 1;
  8127. // string strpagesize = RequestString.GetQueryString("pagesize");
  8128. // int pagesize = 10;
  8129. // #region sql 语句相关处理
  8130. // string sql = " ";
  8131. // //获取坐席表信息
  8132. // var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  8133. // //获取客户档案(业主)表信息
  8134. // var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  8135. // #region 权限限制
  8136. // string mobile = "", roomno = "";
  8137. // int customerid = 0, areaid = 0, proid = 0, buildingid = 0;
  8138. // if (ua != null)
  8139. // {
  8140. // int deptid = ua.F_DeptId; //部门id
  8141. // string deptCode = ua.F_DeptCode; //部门code
  8142. // int userRegionId = ua.RegionId; //项目id
  8143. // //部门信息
  8144. // var modelDep = new BLL.T_Sys_Department().GetModel(deptid);
  8145. // int depType = 0, depRegion = 0;
  8146. // if (modelDep != null)
  8147. // {
  8148. // depType = modelDep.F_Type ?? 0; //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  8149. // depRegion = modelDep.F_Header ?? 0; //部门权限范围:9全部,1区域,2项目,3期
  8150. // }
  8151. // if (ua.F_RoleId != 17)
  8152. // {
  8153. // if (depType == 2)
  8154. // {
  8155. // if (depRegion == 1)
  8156. // {
  8157. // // 查看该区域工单
  8158. // //sql += $" and IsUserSend = (SELECT TOP 1 F_ParentId FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = {userRegionId}) ";
  8159. // sql += $" and IsUserSend = {userRegionId} ";
  8160. // }
  8161. // else if (depRegion == 2)
  8162. // {
  8163. // // 查看该项目工单
  8164. // sql += $" and IsAdminSend = {userRegionId} ";
  8165. // }
  8166. // }
  8167. // else if (depType == 3)
  8168. // {
  8169. // if (depRegion == 1)
  8170. // {
  8171. // // 查看该区域工单
  8172. // //sql += $" and IsUserSend = (SELECT TOP 1 F_ParentId FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = {userRegionId}) ";
  8173. // sql += $" and IsUserSend = {userRegionId} ";
  8174. // }
  8175. // }
  8176. // else if (depType == 4)
  8177. // {
  8178. // if (depRegion == 2)
  8179. // {
  8180. // // 查看该项目工单
  8181. // sql += $" and IsAdminSend = {userRegionId} ";
  8182. // }
  8183. // else if (depRegion == 9)
  8184. // {
  8185. // // 查看该部门工单(包括一级,二级)
  8186. // string deptCodeNew = String.Empty;
  8187. // int deptCodeIndex = 0; //变量声明
  8188. // string deptCodeN = deptCode.TrimEnd('|'); //去掉最后一个|
  8189. // deptCodeIndex = deptCodeN.LastIndexOf("|"); //获得|的索引
  8190. // deptCodeNew = deptCodeN.Substring(0, deptCodeIndex + 1); //获得目标字符串(//去掉最后一个|后面的字符串)
  8191. // //============== 部门权限条件 - 部门 ================
  8192. // string arrUser = " select F_UserCode from T_Sys_UserAccount where F_DeptCode LIKE '" + deptCodeNew + "%' ";
  8193. // sql += $" and WorkOrderID in (SELECT DISTINCT WorkOrderID FROM dbo.T_Wo_WorkOrderItem WHERE ToUser IN ({arrUser})) ";
  8194. // }
  8195. // }
  8196. // }
  8197. // string uwhere = " ";
  8198. // switch (strltype)
  8199. // {
  8200. // case "0"://待指派的
  8201. // //sql += " and State ='0' and CreateUser= '" + ua.F_UserCode + "' ";
  8202. // if (ua.F_RoleId != 17 && depType != 1 && depType != 3)
  8203. // {
  8204. // uwhere += " and CreateUser='" + ua.F_UserCode + "' ";
  8205. // }
  8206. // sql += " and State ='0' " + uwhere;
  8207. // break;
  8208. // case "1"://待接单的
  8209. // sql += " and State ='1' and WorkOrderID in ( '" + wo.GetDJDWorkOrderID(ua.F_UserCode) + "') ";
  8210. // break;
  8211. // case "2"://待完成的
  8212. // sql += " and State ='1' and WorkOrderID in ( '" + wo.GetDWCWorkOrderID(ua.F_UserCode) + "') ";
  8213. // break;
  8214. // case "3"://已完成的
  8215. // sql += " and State ='2' and LastDealUser = '" + ua.F_UserCode + "' ";
  8216. // break;
  8217. // case "4"://我参与的
  8218. // sql += " and (CreateUser= '" + ua.F_UserCode + "' or WorkOrderID in ( '" + wo.GetCYWorkOrderID(ua.F_UserCode) + "')) ";
  8219. // break;
  8220. // case "5"://超期工单 - 设置两个月的处理时效,两个月内未解决的工单都直接汇总到这里
  8221. // sql += $" and DATEADD(DAY,{days},CreateTime) < GETDATE() AND State < 2 ";
  8222. // break;
  8223. // }
  8224. // }
  8225. // else if (modelCustomer != null)
  8226. // {
  8227. // #region 根据openid获取所有工单号
  8228. // //var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  8229. // //if (wxuser != null)
  8230. // //{
  8231. // // sql += " and id in (select distinct F_WorkOrderID from T_WO_UserWorkOrder where F_UserId='" + wxuser.F_Id + "') ";
  8232. // //}
  8233. // #endregion
  8234. // // ============== 项目权限 - 项目 ============== 不通过项目查询,因为客户可能有多个项目的房产
  8235. // // ============== 电话,区域,项目,楼号,房间号权限条件 - 电话 ================
  8236. // //通过相关电话,区域,项目,楼号,房间号(CustomerTel,IsUserSend,IsAdminSend,IsTimeOut,Address)查询该用户查看的工单
  8237. // //mobile = modelCustomer.F_LegalTel;
  8238. // customerid = modelCustomer.F_CustomerId;
  8239. // //int CustomerClassID = modelCustomer.F_CustomerClassID ?? 0;
  8240. // ////F_Layer区域id F_CategoryId所购项目id F_CustomerType楼号 F_BusinessLicenseID房间号
  8241. // //areaid = modelCustomer.F_Layer ?? 0;
  8242. // //proid = modelCustomer.F_CategoryId ?? 0;
  8243. // //buildingid = modelCustomer.F_CustomerType ?? 0;
  8244. // //roomno = modelCustomer.F_BusinessLicenseID;
  8245. // ////查询业主和相关的亲属租户名下工单
  8246. // //sql += $" and CustomerTel IN (SELECT DISTINCT F_Mobile FROM dbo.T_Cus_CustomerBase WHERE F_CustomerClassID = {customerid} OR F_CustomerId = {customerid}) ";
  8247. // //if (CustomerClassID == 0)
  8248. // //{
  8249. // // //业主查看房屋所有工单
  8250. // // sql += $" and CustomerID IN (SELECT DISTINCT F_CustomerId FROM dbo.T_Cus_CustomerBase WHERE F_CustomerClassID = {customerid} OR F_CustomerId = {customerid}) ";
  8251. // //}
  8252. // //else
  8253. // //{
  8254. // // //租户只可查看自己工单
  8255. // // sql += $" and CustomerID = {customerid} ";
  8256. // //}
  8257. // ////查询相关房间号下工单
  8258. // //if (areaid > 0 && proid > 0 && buildingid > 0 && !string.IsNullOrEmpty(roomno))
  8259. // //{
  8260. // // sql += $" and F_Layer = {areaid} and F_CategoryId = {proid} and F_CustomerType = {buildingid} and F_BusinessLicenseID = '{roomno}' ";
  8261. // //}
  8262. // }
  8263. // else
  8264. // {
  8265. // sql = "";
  8266. // }
  8267. // #endregion
  8268. // if (!string.IsNullOrEmpty(sql))
  8269. // {
  8270. // sql += " and IsDel=0 ";
  8271. // //客户姓名,电话,房间号,工单号,接待描述
  8272. // if (!string.IsNullOrEmpty(keyword))
  8273. // {
  8274. // sql += " and (CustomerTel like '%" + keyword + "%' or Customer like '%" + keyword + "%' or Address like '%" + keyword + "%' or WorkOrderID like '%" + keyword + "%' or Detail like '%" + keyword + "%' ) ";
  8275. // }
  8276. // if (isaudit >= 0)
  8277. // {
  8278. // sql += " and IsAudit = " + isaudit + " "; // ANd Type = (SELECT F_DictionaryValueId FROM dbo.T_Sys_DictionaryValue (NOLOCK) WHERE F_DictionaryFlag = 'GDLY' AND F_Name = '微信')
  8279. // }
  8280. // if (states >= 0)
  8281. // sql += " and State = " + states + " ";
  8282. // if (strtype > 0)
  8283. // {
  8284. // sql += " and Type = " + strtype + " ";
  8285. // }
  8286. // if (strtypeclass > 0)
  8287. // {
  8288. // sql += " and TypeClass = " + strtypeclass + " ";
  8289. // }
  8290. // if (lddep.Trim() != "" && lddep != "undefined")
  8291. // {
  8292. // sql += " and Address = '" + lddep.Trim() + "' ";
  8293. // }
  8294. // if (fkdep.Trim() != "" && fkdep != "undefined")
  8295. // {
  8296. // sql += " and Source = '" + fkdep.Trim() + "' ";
  8297. // }
  8298. // if (strstarttime.Trim() != "" && strstarttime != "undefined")
  8299. // {
  8300. // sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
  8301. // }
  8302. // if (strendtime.Trim() != "" && strendtime != "undefined")
  8303. // {
  8304. // sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0 ";
  8305. // }
  8306. // #endregion
  8307. // if (strpageindex.Trim() != "")
  8308. // {
  8309. // pageindex = Convert.ToInt32(strpageindex);
  8310. // }
  8311. // if (strpagesize.Trim() != "")
  8312. // {
  8313. // pagesize = Convert.ToInt32(strpagesize);
  8314. // }
  8315. // 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";
  8316. // dt = BLL.PagerBLL.GetListPager(
  8317. // "T_Wo_WorkOrder (NOLOCK)",
  8318. // "WorkOrderID",
  8319. // cols,
  8320. // sql,
  8321. // "ORDER BY CreateTime DESC",
  8322. // pagesize,
  8323. // pageindex,
  8324. // true,
  8325. // out recordCount);
  8326. // }
  8327. // var obj = new
  8328. // {
  8329. // state = "success",
  8330. // message = "成功",
  8331. // rows = dt,
  8332. // total = recordCount
  8333. // };
  8334. // return Content(obj.ToJson());
  8335. //}
  8336. ///// <summary>
  8337. ///// 获取可催办工单列表
  8338. ///// </summary>
  8339. ///// <returns></returns>
  8340. //[WechatActionFilter]
  8341. //public ActionResult GetNotDoneWorkList()
  8342. //{
  8343. // workorder.WorkOrderController wo = new workorder.WorkOrderController();
  8344. // DataTable dt = new DataTable();
  8345. // int recordCount = 0;
  8346. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  8347. // //客户姓名,电话,房间号,工单号
  8348. // string keyword = HttpUtility.UrlDecode(RequestString.GetQueryString("keyword"));
  8349. // //工单状态
  8350. // string strltype = HttpUtility.UrlDecode(RequestString.GetQueryString("ltype"));
  8351. // //工单状态
  8352. // int states = RequestString.GetInt("states", -1);
  8353. // //工单来源
  8354. // int strtype = RequestString.GetInt("type", 0);
  8355. // //工单类型
  8356. // int strtypeclass = RequestString.GetInt("typeclass", 0);
  8357. // //工单起止时间
  8358. // string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  8359. // string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  8360. // //区域id
  8361. // int areaid = RequestString.GetInt("areaid", 0);
  8362. // //项目id
  8363. // int regionid = RequestString.GetInt("regionid", 0);
  8364. // //期id
  8365. // int buldingid = RequestString.GetInt("buldingid", 0);
  8366. // string uid = HttpUtility.UrlDecode(RequestString.GetQueryString("userid") == "" ? "0" : HttpUtility.UrlDecode(RequestString.GetQueryString("userid")));
  8367. // string strpageindex = RequestString.GetQueryString("page");
  8368. // int pageindex = 1;
  8369. // string strpagesize = RequestString.GetQueryString("pagesize");
  8370. // int pagesize = 10;
  8371. // string sql = " and isdel=0 and State != 2 ";
  8372. // //获取坐席表信息
  8373. // var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  8374. // //获取客户档案(业主)表信息
  8375. // var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  8376. // if (ua != null)
  8377. // {
  8378. // #region 权限限制
  8379. // int deptid = ua.F_DeptId; //部门id
  8380. // string deptCode = ua.F_DeptCode; //部门code
  8381. // int userRegionId = ua.RegionId; //项目id
  8382. // //部门信息
  8383. // var modelDep = new BLL.T_Sys_Department().GetModel(deptid);
  8384. // int depType = 0, depRegion = 0;
  8385. // if (modelDep != null)
  8386. // {
  8387. // depType = modelDep.F_Type ?? 0; //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  8388. // depRegion = modelDep.F_Header ?? 0; //部门权限范围:9全部,1区域,2项目,3期
  8389. // }
  8390. // if (ua.F_RoleId != 17)
  8391. // {
  8392. // if (depType == 2)
  8393. // {
  8394. // if (depRegion == 1)
  8395. // {
  8396. // // 查看该区域工单
  8397. // //sql += $" and IsUserSend = (SELECT TOP 1 F_ParentId FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = {userRegionId}) ";
  8398. // sql += $" and IsUserSend = {userRegionId} ";
  8399. // }
  8400. // else if (depRegion == 2)
  8401. // {
  8402. // // 查看该项目工单
  8403. // sql += $" and IsAdminSend = {userRegionId} ";
  8404. // }
  8405. // }
  8406. // else if (depType == 3)
  8407. // {
  8408. // if (depRegion == 1)
  8409. // {
  8410. // // 查看该区域工单
  8411. // //sql += $" and IsUserSend = (SELECT TOP 1 F_ParentId FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = {userRegionId}) ";
  8412. // sql += $" and IsUserSend = {userRegionId} ";
  8413. // }
  8414. // }
  8415. // else if (depType == 4)
  8416. // {
  8417. // if (depRegion == 2)
  8418. // {
  8419. // // 查看该项目工单
  8420. // sql += $" and IsAdminSend = {userRegionId} ";
  8421. // }
  8422. // else if (depRegion == 9)
  8423. // {
  8424. // // 查看该部门工单(包括一级,二级)
  8425. // string deptCodeNew = String.Empty;
  8426. // int deptCodeIndex = 0; //变量声明
  8427. // string deptCodeN = deptCode.TrimEnd('|'); //去掉最后一个|
  8428. // deptCodeIndex = deptCodeN.LastIndexOf("|"); //获得|的索引
  8429. // deptCodeNew = deptCodeN.Substring(0, deptCodeIndex + 1); //获得目标字符串(//去掉最后一个|后面的字符串)
  8430. // //============== 部门权限条件 - 部门 ================
  8431. // string arrUser = " select F_UserCode from T_Sys_UserAccount where F_DeptCode LIKE '" + deptCodeNew + "%' ";
  8432. // sql += $" and WorkOrderID in (SELECT DISTINCT WorkOrderID FROM dbo.T_Wo_WorkOrderItem WHERE ToUser IN ({arrUser})) ";
  8433. // }
  8434. // }
  8435. // }
  8436. // #endregion
  8437. // //客户姓名,电话,房间号,工单号
  8438. // if (!string.IsNullOrEmpty(keyword))
  8439. // {
  8440. // sql += " and (CustomerTel like '%" + keyword + "%' or Customer like '%" + keyword + "%' or Address like '%" + keyword + "%' or WorkOrderID like '%" + keyword + "%' ) ";
  8441. // }
  8442. // if (states >= 0)
  8443. // sql += " and State = " + states + " ";
  8444. // if (areaid > 0)
  8445. // sql += " and IsUserSend = " + areaid + " ";
  8446. // if (regionid > 0)
  8447. // sql += " and IsAdminSend = " + regionid + " ";
  8448. // if (buldingid > 0)
  8449. // sql += " and IsTimeOut = " + buldingid + " ";
  8450. // //坐席工号
  8451. // if (uid.Trim() != "" && uid != "0")
  8452. // {
  8453. // sql += " and CreateUser = '" + uid + "' ";
  8454. // }
  8455. // if (strtype > 0)
  8456. // {
  8457. // sql += " and Type = " + strtype + " ";
  8458. // }
  8459. // if (strtypeclass > 0)
  8460. // {
  8461. // sql += " and TypeClass = " + strtype + " ";
  8462. // }
  8463. // if (strstarttime.Trim() != "" && strstarttime != "undefined")
  8464. // {
  8465. // sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
  8466. // }
  8467. // if (strendtime.Trim() != "" && strendtime != "undefined")
  8468. // {
  8469. // sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0 ";
  8470. // }
  8471. // if (strpageindex.Trim() != "")
  8472. // {
  8473. // pageindex = Convert.ToInt32(strpageindex);
  8474. // }
  8475. // if (strpagesize.Trim() != "")
  8476. // {
  8477. // pagesize = Convert.ToInt32(strpagesize);
  8478. // }
  8479. // dt = BLL.PagerBLL.GetListPager(
  8480. // "T_Wo_WorkOrder",
  8481. // "T_Wo_WorkOrder.ID",
  8482. // "*,(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",
  8483. // sql,
  8484. // "ORDER BY T_Wo_WorkOrder.ID desc",
  8485. // pagesize,
  8486. // pageindex,
  8487. // true,
  8488. // out recordCount);
  8489. // dt.Columns.Add("CBCount", typeof(int));
  8490. // foreach (DataRow dr in dt.Rows)
  8491. // {
  8492. // 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];
  8493. // dr["CBCount"] = list.Rows.Count;
  8494. // }
  8495. // }
  8496. // var obj = new
  8497. // {
  8498. // state = "success",
  8499. // message = "成功",
  8500. // rows = dt,
  8501. // total = recordCount
  8502. // };
  8503. // return Content(obj.ToJson());
  8504. //}
  8505. ///// <summary>
  8506. ///// 新增工单
  8507. ///// </summary>
  8508. ///// <returns></returns>
  8509. //[WechatActionFilter]
  8510. //public ActionResult AddWorkOrder()
  8511. //{
  8512. // DataTable dt = new DataTable();
  8513. // //工单来源
  8514. // int gdly = RequestString.GetFormInt("gdly", 0);
  8515. // //工单类型
  8516. // int gdlx = RequestString.GetFormInt("gdlx", 0);
  8517. // //客户id
  8518. // int customerid = RequestString.GetFormInt("customerid", 0);
  8519. // //客户姓名
  8520. // string callCustomer = RequestString.GetFormString("callCustomer");
  8521. // //联系电话
  8522. // string tel = RequestString.GetFormString("tel");
  8523. // //处理部门
  8524. // string fkdep = RequestString.GetFormString("fkdep");
  8525. // //客服类类型
  8526. // string kfdepid = RequestString.GetFormString("kfdepid");
  8527. // //受理人 - 审核人工号
  8528. // string auditusercode = RequestString.GetFormString("auditusercode");
  8529. // //工单状态
  8530. // int gdzt = RequestString.GetFormInt("gdzt", 0);
  8531. // //接待描述 - 反馈内容
  8532. // string fkcont = RequestString.GetFormString("fkcont");
  8533. // string callid = HttpUtility.UrlDecode(RequestString.GetFormString("callid"));
  8534. // string files = RequestString.GetFormString("files");
  8535. // //咨询类工单指派部门
  8536. // int clbm = RequestString.GetFormInt("clbm", 0);
  8537. // //备注
  8538. // string note = RequestString.GetFormString("note");
  8539. // #region 添加验证判断
  8540. // if (string.IsNullOrEmpty(callCustomer))
  8541. // return Error("姓名不能为空!");
  8542. // if (string.IsNullOrEmpty(tel))
  8543. // return Error("电话不能为空!");
  8544. // #endregion
  8545. // string workOrder = DateTime.Now.ToString("yyyyMMddHHmmssfff"); //工单编号
  8546. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  8547. // var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  8548. // var model = userAccountBLL.GetModelByOpenid(stropenid);
  8549. // var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault(); //customerBaseBLL.GetModelByOpenid(stropenid);
  8550. // string usercode = "";
  8551. // if (model != null)
  8552. // {
  8553. // usercode = model.F_UserCode;
  8554. // }
  8555. // else if (modelCustomer != null)
  8556. // {
  8557. // usercode = modelCustomer.F_CustomerCode;
  8558. // customerid = modelCustomer.F_CustomerId;
  8559. // }
  8560. // workorder.WorkOrderController wo = new workorder.WorkOrderController();
  8561. // string workorderid = wo.AddWXWorkOrder(workOrder, gdly, gdlx, customerid, callCustomer, tel, fkdep, kfdepid, auditusercode, fkcont, files, gdzt, note, usercode,-1);
  8562. // if (string.IsNullOrEmpty(workorderid))
  8563. // {
  8564. // return Error("新增失败");
  8565. // }
  8566. // else
  8567. // {
  8568. // #region 咨询类工单指派至部门
  8569. // //工单类型(107咨询,108投诉)
  8570. // if (gdlx == 107)
  8571. // {
  8572. // //需要审核后,再处理
  8573. // //bool b = wo.DealWXWorkOrder(workOrder, 0, 0, clbm, 0, "", fkcont, stropenid);
  8574. // }
  8575. // #endregion
  8576. // //暂时排除客户档案用户(F_UserId无法区分是住户添加 还是管理员添加) - 后期完善
  8577. // if (wxuser != null)
  8578. // {
  8579. // Model.T_WO_UserWorkOrder tbu = new Model.T_WO_UserWorkOrder();
  8580. // tbu.F_UserId = wxuser.F_Id;
  8581. // tbu.F_WorkOrderId = workorderid;
  8582. // new BLL.T_WO_UserWorkOrder().Add(tbu);
  8583. // }
  8584. // return Success("新增成功", workorderid);
  8585. // }
  8586. //}
  8587. ///// <summary>
  8588. ///// 修改工单
  8589. ///// </summary>
  8590. ///// <returns></returns>
  8591. //[WechatActionFilter]
  8592. //public ActionResult UpdateWorkOrder()
  8593. //{
  8594. // DataTable dt = new DataTable();
  8595. // //工单id
  8596. // string workorderid = RequestString.GetFormString("orderid");
  8597. // //工单来源
  8598. // int gdly = RequestString.GetFormInt("gdly", 0);
  8599. // //工单类型
  8600. // int gdlx = RequestString.GetFormInt("gdlx", 0);
  8601. // //客户id
  8602. // int customerid = RequestString.GetFormInt("customerid", 0);
  8603. // //客户姓名
  8604. // string callCustomer = RequestString.GetFormString("callCustomer");
  8605. // //联系电话
  8606. // string tel = RequestString.GetFormString("tel");
  8607. // //处理部门
  8608. // string fkdep = RequestString.GetFormString("fkdep");
  8609. // //客服类类型
  8610. // string kfdepid = RequestString.GetFormString("kfdepid");
  8611. // //受理人 - 审核人工号
  8612. // string auditusercode = RequestString.GetFormString("auditusercode");
  8613. // //接待描述 - 反馈内容
  8614. // string fkcont = RequestString.GetFormString("fkcont");
  8615. // string files = RequestString.GetFormString("files");
  8616. // //备注
  8617. // string note = RequestString.GetFormString("note");
  8618. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  8619. // //var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  8620. // if (!string.IsNullOrEmpty(stropenid))
  8621. // {
  8622. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  8623. // if (ua != null)
  8624. // {
  8625. // WorkOrderController wo = new WorkOrderController();
  8626. // if (!string.IsNullOrEmpty(workorderid))
  8627. // {
  8628. // var models = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + workorderid + "'");
  8629. // if (models.Count > 0)
  8630. // {
  8631. // var model = models.FirstOrDefault();
  8632. // string detail = model.Detail;
  8633. // model.Type = gdly; //工单来源
  8634. // model.TypeClass = gdlx; //投诉类型 -工单类型
  8635. // model.Customer = callCustomer; //客户姓名
  8636. // model.CustomerTel = tel; //联系电话
  8637. // //model.CustomerID = customerid; //用户档案Id
  8638. // model.Source = fkdep; //处理部门 反馈单位
  8639. // model.CreateUserID = kfdepid; //客服类类型
  8640. // model.AuditUser = auditusercode; //受理人 - 审核人工号
  8641. // //model.CreateUser = ua.F_UserCode; //接待人(工号)
  8642. // //model.State = 0; //工单状态
  8643. // //反馈内容
  8644. // var detailutf8 = System.Web.HttpUtility.UrlDecode(fkcont, System.Text.Encoding.UTF8);
  8645. // model.Detail = detailutf8;
  8646. // if (new BLL.T_Wo_WorkOrder().Update(model))
  8647. // {
  8648. // //添加工单修改操作日志
  8649. // wo.WriteWorkOrderLog(workorderid, detail, detailutf8, ua.F_UserCode, 0, "", 1, "修改工单(微信端)");
  8650. // return Success("修改成功!");
  8651. // }
  8652. // }
  8653. // }
  8654. // }
  8655. // }
  8656. // return Error("修改失败!");
  8657. //}
  8658. ///// <summary>
  8659. ///// 处理工单
  8660. ///// </summary>
  8661. ///// <returns></returns>
  8662. //[WechatActionFilter]
  8663. //public ActionResult DealWorkOrder()
  8664. //{
  8665. // DataTable dt = new DataTable();
  8666. // string orderid = RequestString.GetFormString("orderid");
  8667. // int isend = RequestString.GetInt("isend", 0); //0转派
  8668. // int ltype = RequestString.GetInt("ltype", 0); //处理方式 1结束 0转派
  8669. // int clbm = RequestString.GetInt("clbm", 0); //部门id
  8670. // int clid = RequestString.GetInt("clid", 0); //用户接收人id
  8671. // string cont = RequestString.GetFormString("cont"); //处理内容
  8672. // string detail = RequestString.GetFormString("detail");
  8673. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  8674. // workorder.WorkOrderController wo = new workorder.WorkOrderController();
  8675. // bool res = wo.DealWXWorkOrder(orderid, isend, ltype, clbm, clid, cont, detail, stropenid);
  8676. // if (res)
  8677. // {
  8678. // return Success("操作成功");
  8679. // }
  8680. // else
  8681. // {
  8682. // return Error("操作失败");
  8683. // }
  8684. //}
  8685. ///// <summary>
  8686. ///// 接单 - 确认工单
  8687. ///// </summary>
  8688. ///// <returns></returns>
  8689. //[WechatActionFilter]
  8690. //public ActionResult SureWorkOrder()
  8691. //{
  8692. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  8693. // string orderid = RequestString.GetFormString("orderid");
  8694. // if (!string.IsNullOrEmpty(stropenid))
  8695. // {
  8696. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  8697. // if (ua != null)
  8698. // {
  8699. // Model.T_Wo_WorkOrder model = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + orderid + "'").FirstOrDefault();
  8700. // if (model != null)
  8701. // {
  8702. // Model.T_Wo_WorkOrderItem item = new BLL.T_Wo_WorkOrderItem().GetModelList(" WorkOrderID='" + orderid + "' and isdel=0 and Type=1 ").OrderByDescending(p => p.CreateTime).FirstOrDefault();
  8703. // if (item != null && item.State == 0 && ("," + item.ToUser + ",").Contains("," + ua.F_UserCode + ","))
  8704. // {
  8705. // item.SureUser = ua.F_UserCode;
  8706. // item.State = 1;
  8707. // item.SureTime = DateTime.Now;
  8708. // if (new BLL.T_Wo_WorkOrderItem().Update(item))
  8709. // {
  8710. // return Success("接单成功!");
  8711. // }
  8712. // }
  8713. // return Error("操作失败,工单还没有派单!");
  8714. // }
  8715. // }
  8716. // return Error("操作失败");
  8717. // }
  8718. // return Error("参数错误");
  8719. //}
  8720. ///// <summary>
  8721. ///// 催办工单(管理员,业主)
  8722. ///// </summary>
  8723. ///// <returns></returns>
  8724. //[WechatActionFilter]
  8725. //public ActionResult RemindWorkOrder()
  8726. //{
  8727. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  8728. // if (!string.IsNullOrEmpty(stropenid))
  8729. // {
  8730. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  8731. // string usercode = string.Empty;
  8732. // string username = string.Empty;
  8733. // if (ua != null)
  8734. // {
  8735. // usercode = ua.F_UserCode;
  8736. // username = ua.F_UserName;
  8737. // }
  8738. // else
  8739. // {
  8740. // //获取客户档案(业主)表信息
  8741. // var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  8742. // if (modelCustomer != null)
  8743. // {
  8744. // usercode = modelCustomer.F_CustomerCode;
  8745. // username = modelCustomer.F_CompanyName;
  8746. // }
  8747. // }
  8748. // if (string.IsNullOrEmpty(usercode))
  8749. // return Error("参数错误!");
  8750. // string orderid = RequestString.GetFormString("orderid");
  8751. // string cont = RequestString.GetFormString("cont");
  8752. // string callid = RequestString.GetFormString("callid");
  8753. // Model.T_Wo_WorkOrder model = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + orderid + "'").FirstOrDefault();
  8754. // if (model != null)
  8755. // {
  8756. // 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();
  8757. // Model.T_Wo_WorkOrderItem item = new Model.T_Wo_WorkOrderItem();
  8758. // if (itemlast != null)
  8759. // {
  8760. // item.ToDept = itemlast.ToDept;
  8761. // item.ToUser = itemlast.ToUser;
  8762. // }
  8763. // else
  8764. // {
  8765. // var cu = new BLL.T_Sys_UserAccount().GetModel(model.CreateUser);
  8766. // if (cu != null)
  8767. // {
  8768. // item.ToDept = cu.F_DeptId;
  8769. // item.ToUser = cu.F_UserCode;
  8770. // }
  8771. // else {
  8772. // var modelCus = customerBaseBLL.GetModelList(" F_CustomerCode='" + model.CreateUser + "'").FirstOrDefault(); //customerBaseBLL.GetModel(model.CreateUser);
  8773. // if (modelCus != null)
  8774. // {
  8775. // item.ToDept = 0;
  8776. // item.ToUser = modelCus.F_LegalTel;
  8777. // }
  8778. // }
  8779. // }
  8780. // item.WorkOrderID = orderid;
  8781. // item.Type = 2;
  8782. // item.Detail = cont;
  8783. // item.CallID = callid;
  8784. // item.State = 0;
  8785. // item.IsDel = 0;
  8786. // item.IsLast = 0;
  8787. // item.IsStart = 0;
  8788. // item.IsTimeOut = 0;
  8789. // item.CreateUser = usercode; // ua.F_UserCode;
  8790. // item.CreateTime = DateTime.Now;
  8791. // long itemid = new BLL.T_Wo_WorkOrderItem().Add(item);
  8792. // if (itemid > 0 && !string.IsNullOrEmpty(item.ToUser))
  8793. // {
  8794. // foreach (string ur in item.ToUser.Split(','))
  8795. // {
  8796. // Model.T_Msg_List msg = new Model.T_Msg_List();
  8797. // msg.Type = 1;
  8798. // msg.ToUser = ur;
  8799. // msg.ToID = Int32.Parse(itemid.ToString());
  8800. // msg.Detail = username + "向你催办了工单,单号:" + model.WorkOrderID;
  8801. // msg.State = 0;
  8802. // msg.IsDel = 0;
  8803. // msg.CreateUser = usercode;
  8804. // msg.CreateDate = DateTime.Now;
  8805. // new BLL.T_Msg_List().Add(msg);
  8806. // }
  8807. // return Success("催办成功!");
  8808. // }
  8809. // }
  8810. // }
  8811. // return Error("参数错误");
  8812. //}
  8813. ///// <summary>
  8814. ///// 退回工单
  8815. ///// </summary>
  8816. ///// <param name="input"></param>
  8817. ///// <returns></returns>
  8818. //[WechatActionFilter]
  8819. //public ActionResult BackWorkOrder()
  8820. //{
  8821. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  8822. // if (!string.IsNullOrEmpty(stropenid))
  8823. // {
  8824. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  8825. // if (ua != null)
  8826. // {
  8827. // string orderid = RequestString.GetFormString("orderid");
  8828. // var model = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + orderid + "'").FirstOrDefault();
  8829. // //验证信息
  8830. // if (model == null)
  8831. // {
  8832. // return Error("工单不存在");
  8833. // }
  8834. // model.State = 0;
  8835. // if (new BLL.T_Wo_WorkOrder().Update(model))
  8836. // {
  8837. // 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();
  8838. // if (modelItem != null)
  8839. // {
  8840. // modelItem.State = 6;
  8841. // new BLL.T_Wo_WorkOrderItem().Update(modelItem);
  8842. // }
  8843. // return Success("操作成功");
  8844. // }
  8845. // return Error("操作失败");
  8846. // }
  8847. // }
  8848. // return Error("操作失败");
  8849. //}
  8850. ///// <summary>
  8851. ///// 评论工单(管理人员,业主)
  8852. ///// </summary>
  8853. ///// <returns></returns>
  8854. //[WechatActionFilter]
  8855. //public ActionResult CommentWorkOrder()
  8856. //{
  8857. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  8858. // if (!string.IsNullOrEmpty(stropenid))
  8859. // {
  8860. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  8861. // string usercode = string.Empty;
  8862. // string username = string.Empty;
  8863. // if (ua != null)
  8864. // {
  8865. // usercode = ua.F_UserCode;
  8866. // username = ua.F_UserName;
  8867. // }
  8868. // else
  8869. // {
  8870. // //获取客户档案(业主)表信息
  8871. // var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  8872. // if (modelCustomer != null)
  8873. // {
  8874. // usercode = modelCustomer.F_CustomerCode;
  8875. // username = modelCustomer.F_CompanyName;
  8876. // }
  8877. // }
  8878. // if (string.IsNullOrEmpty(usercode))
  8879. // return Error("参数错误!");
  8880. // string orderid = RequestString.GetFormString("orderid");
  8881. // string cont = RequestString.GetFormString("cont");
  8882. // string file = RequestString.GetFormString("file");
  8883. // Model.T_Wo_WorkOrder model = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + orderid + "'").FirstOrDefault();
  8884. // if (model != null)
  8885. // {
  8886. // Model.T_Wo_WorkOrderItem item = new Model.T_Wo_WorkOrderItem();
  8887. // item.WorkOrderID = orderid;
  8888. // item.Type = 3; //评论
  8889. // item.Detail = cont;
  8890. // item.Files = file;
  8891. // item.State = 0;
  8892. // item.IsDel = 0;
  8893. // item.IsStart = 0;
  8894. // item.IsTimeOut = 0;
  8895. // item.IsLast = 0;
  8896. // item.CreateUser = usercode;
  8897. // item.CreateTime = DateTime.Now;
  8898. // if (new BLL.T_Wo_WorkOrderItem().Add(item) > 0)
  8899. // {
  8900. // return Success("评论成功!");
  8901. // }
  8902. // }
  8903. // }
  8904. // return Error("操作失败");
  8905. //}
  8906. ///// <summary>
  8907. ///// 刪除工单
  8908. ///// </summary>
  8909. ///// <returns></returns>
  8910. //[WechatActionFilter]
  8911. //public ActionResult DelWorkOrder(string[] ids)
  8912. //{
  8913. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  8914. // if (!string.IsNullOrEmpty(stropenid))
  8915. // {
  8916. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  8917. // if (ua != null)
  8918. // {
  8919. // if (ids != null && ids.Length > 0)
  8920. // {
  8921. // string idd = " ";
  8922. // foreach (string str in ids)
  8923. // {
  8924. // idd += str + ",";
  8925. // }
  8926. // string sql = "update T_Wo_WorkOrder set IsDel=1,DelUser='" + ua.F_UserCode + "',DelTime=getdate() where ID in (" + idd.TrimEnd(',') + ")";
  8927. // if (!string.IsNullOrEmpty(idd.Trim()))
  8928. // {
  8929. // if (DbHelperSQL.ExecuteSql(sql) > 0)
  8930. // {
  8931. // return Success("删除成功");
  8932. // }
  8933. // }
  8934. // else
  8935. // {
  8936. // return Error("请选择记录");
  8937. // }
  8938. // }
  8939. // else
  8940. // {
  8941. // return Error("获取参数失败");
  8942. // }
  8943. // }
  8944. // }
  8945. // return Error("操作失败");
  8946. //}
  8947. ///// <summary>
  8948. ///// 获取工单详情
  8949. ///// </summary>
  8950. ///// <returns></returns>
  8951. //[WechatActionFilter]
  8952. //public ActionResult GetWorkOrder()
  8953. //{
  8954. // string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
  8955. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  8956. // if (string.IsNullOrEmpty(strworkorderid))
  8957. // return Error("参数错误");
  8958. // if (string.IsNullOrEmpty(stropenid))
  8959. // return Error("参数错误!");
  8960. // #region pc端工单也可以查看,所以注释(注释功能只能查看自己创建的工单)
  8961. // //var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  8962. // //if (wxuser != null)
  8963. // //{
  8964. // // var tbu = new BLL.T_WO_UserWorkOrder().GetList(" F_UserId='" + wxuser.F_Id + "' and F_WorkOrderId=" + strworkorderid + " ").Tables[0];
  8965. // // if (tbu.Rows.Count > 0)
  8966. // // {
  8967. // // }
  8968. // //}
  8969. // #endregion
  8970. // 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 "
  8971. // + " from T_Wo_WorkOrder where WorkOrderID ='" + strworkorderid + "' ";
  8972. // var dt = DbHelperSQL.Query(sql).Tables[0];
  8973. // if (dt.Rows.Count > 0)
  8974. // {
  8975. // var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
  8976. // var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  8977. // if (configfj != null)
  8978. // {
  8979. // dt = BindFileData(dt, configfj.F_ParamValue);
  8980. // }
  8981. // string gcsql = "select *,dbo.GetUserName(CreateUser) as UserName "
  8982. // + "from T_Wo_WorkOrderItem where IsDel=0 and WorkOrderID ='" + dt.Rows[0]["WorkOrderId"] + "'";
  8983. // var gcdt = DbHelperSQL.Query(gcsql).Tables[0];
  8984. // dt.Columns.Add("FilePath", typeof(string));
  8985. // if (configfj != null || config != null)
  8986. // {
  8987. // foreach (DataRow bldr in dt.Rows)
  8988. // {
  8989. // if (bldr["CallID"] != null && config != null)
  8990. // {
  8991. // bldr["FilePath"] = GetCallPath(bldr["CallID"].ToString(), config.F_ParamValue);
  8992. // }
  8993. // }
  8994. // }
  8995. // var obj = new
  8996. // {
  8997. // data = dt,
  8998. // item = gcdt
  8999. // };
  9000. // return Success("查询成功", obj);
  9001. // }
  9002. // return Error("查询失败");
  9003. //}
  9004. ///// <summary>
  9005. ///// 获取工单明细列表
  9006. ///// </summary>
  9007. ///// <returns></returns>
  9008. //[WechatActionFilter]
  9009. //public ActionResult GetItemList()
  9010. //{
  9011. // string sql = " and IsDel=0 ";
  9012. // DataTable dt = new DataTable();
  9013. // string strid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
  9014. // string strtype = HttpUtility.UrlDecode(RequestString.GetQueryString("type"));
  9015. // string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  9016. // string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  9017. // string strpageindex = RequestString.GetQueryString("page");
  9018. // int pageindex = 1;
  9019. // string strpagesize = RequestString.GetQueryString("pagesize");
  9020. // int pagesize = 10;
  9021. // if (strid.Trim() != "" && strid != "undefined")
  9022. // {
  9023. // sql += " and WorkOrderID = '" + strid.Trim() + "' ";
  9024. // }
  9025. // if (strtype.Trim() != "" && strtype != "undefined")
  9026. // {
  9027. // sql += " and Type = '" + strtype.Trim() + "' ";
  9028. // }
  9029. // if (strstarttime.Trim() != "" && strstarttime != "undefined")
  9030. // {
  9031. // sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
  9032. // }
  9033. // if (strendtime.Trim() != "" && strendtime != "undefined")
  9034. // {
  9035. // sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0 ";
  9036. // }
  9037. // if (strpageindex.Trim() != "")
  9038. // {
  9039. // pageindex = Convert.ToInt32(strpageindex);
  9040. // }
  9041. // if (strpagesize.Trim() != "")
  9042. // {
  9043. // pagesize = Convert.ToInt32(strpagesize);
  9044. // }
  9045. // int recordCount = 0;
  9046. // dt = BLL.PagerBLL.GetListPager(
  9047. // "T_Wo_WorkOrderItem",
  9048. // "T_Wo_WorkOrderItem.ID",
  9049. // "*,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",
  9050. // sql,
  9051. // "ORDER BY T_Wo_WorkOrderItem.ID desc",
  9052. // pagesize,
  9053. // pageindex,
  9054. // true,
  9055. // out recordCount);
  9056. // var obj = new
  9057. // {
  9058. // state = "success",
  9059. // message = "成功",
  9060. // rows = dt,
  9061. // total = recordCount
  9062. // };
  9063. // return Content(obj.ToJson());
  9064. //}
  9065. ///// <summary>
  9066. ///// 获取工作动态列表 - 工单明细动态列表 - 管理员功能
  9067. ///// </summary>
  9068. ///// <returns></returns>
  9069. //[WechatActionFilter]
  9070. //public ActionResult GetWorkOrderItemList()
  9071. //{
  9072. // DataTable dt = new DataTable();
  9073. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  9074. // //string stropenid = "oXF5e1mWpX5DajW5_yjNLPKb8ThE";
  9075. // //获取客户档案(业主)表信息
  9076. // var model = userAccountBLL.GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  9077. // string sql = " and IsDel=0 ";
  9078. // string daytype = HttpUtility.UrlDecode(RequestString.GetQueryString("daytype"));
  9079. // string strpageindex = RequestString.GetQueryString("page");
  9080. // int pageindex = 1;
  9081. // string strpagesize = RequestString.GetQueryString("pagesize");
  9082. // int pagesize = 10;
  9083. // #region 权限限制
  9084. // //if (model != null) {
  9085. // // var sqlUser = "";
  9086. // // //部门信息
  9087. // // var modelDep = new BLL.T_Sys_Department().GetModel(model.F_DeptId);
  9088. // // int depType = 0, depRegion = 0;
  9089. // // if (modelDep != null)
  9090. // // {
  9091. // // depType = modelDep.F_Type ?? 0; //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  9092. // // depRegion = modelDep.F_Header ?? 0; //部门权限范围:9全部,1区域,2项目,3期
  9093. // // }
  9094. // // //根据部门查询工单(可查看当前部门工单)
  9095. // // string deptCode = model.F_DeptCode; //部门code
  9096. // // int userRegionId = model.RegionId; //项目id
  9097. // // ////接待部(坐席)可以看到所有的工单
  9098. // // //if (model.F_RoleId != 17 && depType != 1)
  9099. // // //{
  9100. // // // //if (depType == 2 || depType == 3)
  9101. // // // //{
  9102. // // // // // ============== 项目权限 - 项目 ==============
  9103. // // // // sqlUser += $" and IsAdminSend = {userRegionId} ";
  9104. // // // //}
  9105. // // // //else if (depType == 4)
  9106. // // // //{
  9107. // // // // // 查看该部门工单(包括一级,二级)
  9108. // // // // string deptCodeNew = String.Empty;
  9109. // // // // int deptCodeIndex = 0; //变量声明
  9110. // // // // string deptCodeN = deptCode.TrimEnd('|'); //去掉最后一个|
  9111. // // // // deptCodeIndex = deptCodeN.LastIndexOf("|"); //获得|的索引
  9112. // // // // deptCodeNew = deptCodeN.Substring(0, deptCodeIndex + 1); //获得目标字符串(//去掉最后一个|后面的字符串)
  9113. // // // // // ============== 部门权限条件 - 部门 ================
  9114. // // // // string arrUser = " select F_UserCode from T_Sys_UserAccount where F_DeptCode LIKE '" + deptCodeNew + "%' ";
  9115. // // // // sql += $" and ToUser IN ({arrUser}) and WorkOrderID IN (SELECT WorkOrderID FROM dbo.T_Wo_WorkOrder WHERE 1=1 {sqlUser} ) ";
  9116. // // // //}
  9117. // // //}
  9118. // //}
  9119. // #endregion
  9120. // switch (daytype)
  9121. // {
  9122. // case "today":
  9123. // sql += " and DateDiff(dd,CreateTime,getdate())=0 ";
  9124. // break;
  9125. // case "yesterday":
  9126. // sql += " and DateDiff(dd,CreateTime,getdate())=1 ";
  9127. // break;
  9128. // case "month":
  9129. // sql += " and DateDiff(mm,CreateTime,getdate())=0 ";
  9130. // break;
  9131. // default:
  9132. // break;
  9133. // }
  9134. // if (strpageindex.Trim() != "")
  9135. // {
  9136. // pageindex = Convert.ToInt32(strpageindex);
  9137. // }
  9138. // if (strpagesize.Trim() != "")
  9139. // {
  9140. // pagesize = Convert.ToInt32(strpagesize);
  9141. // }
  9142. // int recordCount = 0;
  9143. // dt = BLL.PagerBLL.GetListPager(
  9144. // "T_Wo_WorkOrderItem",
  9145. // "T_Wo_WorkOrderItem.ID",
  9146. // "*,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",
  9147. // sql,
  9148. // "ORDER BY T_Wo_WorkOrderItem.ID desc",
  9149. // pagesize,
  9150. // pageindex,
  9151. // true,
  9152. // out recordCount);
  9153. // var obj = new
  9154. // {
  9155. // state = "success",
  9156. // message = "成功",
  9157. // rows = dt,
  9158. // total = recordCount
  9159. // };
  9160. // return Content(obj.ToJson());
  9161. //}
  9162. #endregion
  9163. #region 附件和语音文件
  9164. /// <summary>
  9165. /// 获取留言路径
  9166. /// </summary>
  9167. /// <param name="lid">留言id</param>
  9168. /// <param name="prefix">前缀</param>
  9169. /// <returns></returns>
  9170. public string GetLeavePath(string lid, string prefix)
  9171. {
  9172. string path = string.Empty;
  9173. var liuyan = new BLL.T_Call_LeaveRecord().GetModelList(" F_Id='" + lid + "' ").FirstOrDefault();
  9174. if (liuyan != null)
  9175. {
  9176. if (!string.IsNullOrEmpty(liuyan.F_RecFileUrl))
  9177. {
  9178. path = prefix + liuyan.F_RecFileUrl;
  9179. }
  9180. }
  9181. return path;
  9182. }
  9183. /// <summary>
  9184. /// 获取通话录音路径
  9185. /// </summary>
  9186. /// <param name="cid">通话id</param>
  9187. /// <param name="prefix">前缀</param>
  9188. /// <returns></returns>
  9189. public string GetCallPath(string cid, string prefix)
  9190. {
  9191. string path = string.Empty;
  9192. var luyin = new BLL.T_Call_CallRecords().GetModelList(" callid='" + cid + "' ").FirstOrDefault();
  9193. if (luyin != null)
  9194. {
  9195. if (!string.IsNullOrEmpty(luyin.FilePath))
  9196. {
  9197. var ym = prefix;
  9198. ym = ym.Substring(0, ym.Length - 1);
  9199. path = ym + luyin.FilePath.Substring(luyin.FilePath.IndexOf(':') + 1).Replace('\\', '/');
  9200. }
  9201. }
  9202. return path;
  9203. }
  9204. /// <summary>
  9205. /// 获取附件数据
  9206. /// </summary>
  9207. /// <param name="ids">附件id,多个用英文逗号,隔开</param>
  9208. /// <param name="prefix">前缀</param>
  9209. /// <returns></returns>
  9210. public DataTable GetFileData(string ids, string prefix)
  9211. {
  9212. DataTable dt = DbHelperSQL.Query("select * from T_Sys_Accessories where F_FileId in (" + ids + ")").Tables[0];
  9213. foreach (DataRow dr in dt.Rows)
  9214. {
  9215. dr["F_FileUrl"] = prefix + dr["F_FileUrl"].ToString();
  9216. }
  9217. return dt;
  9218. }
  9219. /// <summary>
  9220. /// 绑定附件信息
  9221. /// </summary>
  9222. /// <param name="dt"></param>
  9223. /// <param name="prefix"></param>
  9224. /// <returns></returns>
  9225. public DataTable BindFileData(DataTable dt, string prefix)
  9226. {
  9227. dt.Columns.Add("File", typeof(object));
  9228. foreach (DataRow dr in dt.Rows)
  9229. {
  9230. if (dr["Files"] != null && dr["Files"].ToString() != "")
  9231. {
  9232. dr["File"] = GetFileData(dr["Files"].ToString(), prefix);
  9233. }
  9234. }
  9235. return dt;
  9236. }
  9237. #endregion
  9238. #region 上传附件
  9239. /// <summary>
  9240. /// 上传附件
  9241. /// </summary>
  9242. /// <returns></returns>
  9243. public ActionResult UpLoadProcess(string id, string name, string type, string lastModifiedDate, int size, HttpPostedFileBase file)
  9244. {
  9245. try
  9246. {
  9247. string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  9248. string filePathName = string.Empty;
  9249. string path = "/Upload/Files/" + DateTime.Now.ToString("yyyy/MM/dd") + "/";
  9250. string localPath = Server.MapPath(Path.Combine(HttpRuntime.AppDomainAppPath, path));
  9251. if (Request.Files.Count == 0)
  9252. {
  9253. return Error("保存失败");
  9254. }
  9255. string ex = Path.GetExtension(file.FileName);
  9256. filePathName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + Guid.NewGuid().ToString("N") + ex;
  9257. if (!System.IO.Directory.Exists(localPath))
  9258. {
  9259. System.IO.Directory.CreateDirectory(localPath);
  9260. }
  9261. file.SaveAs(Path.Combine(localPath, filePathName));
  9262. #region 添加日志
  9263. Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
  9264. model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
  9265. model_T_Sys_Accessories.F_FileName = filePathName;//附件名称
  9266. model_T_Sys_Accessories.F_FileType = type;//附件类型
  9267. model_T_Sys_Accessories.F_FileUrl = path + filePathName;//附件地址
  9268. model_T_Sys_Accessories.F_Size = size;
  9269. model_T_Sys_Accessories.F_UserCode = stropenid;//上传人
  9270. int fid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
  9271. #endregion
  9272. if (fid > 0)
  9273. {//返回附件的ID
  9274. model_T_Sys_Accessories.F_FileId = fid;//修改为返回对象以便查看图片
  9275. return Success("文件日志都成功", model_T_Sys_Accessories);
  9276. }
  9277. else
  9278. return Success("文件成功");
  9279. }
  9280. catch (Exception ex)
  9281. {
  9282. return Error(ex.Message);
  9283. }
  9284. }
  9285. }
  9286. #endregion
  9287. }