Нет описания

WxLoginController.cs 471KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113
  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.customer;
  6. using CallCenterApi.Interface.Controllers.workorder;
  7. using CallCenterApi.Interface.Models.Enum;
  8. using CallCenterApi.Interface.Models.Input;
  9. using CallCenterApi.Model;
  10. using CallCenterAPI.WechatSDK;
  11. using CallCenterAPI.WechatSDK.Models;
  12. using Newtonsoft.Json;
  13. using Newtonsoft.Json.Linq;
  14. using qcloudsms_csharp;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Data;
  18. using System.IO;
  19. using System.Linq;
  20. using System.Net;
  21. using System.Security.Cryptography;
  22. using System.Text;
  23. using System.Text.RegularExpressions;
  24. using System.Threading.Tasks;
  25. using System.Web;
  26. using System.Web.Mvc;
  27. using System.Web.Script.Serialization;
  28. using System.Xml;
  29. namespace CallCenterApi.Interface.Controllers.weixin
  30. {
  31. public class WxLoginController : BaseController
  32. {
  33. private readonly BLL.T_Sys_UserAccount userAccountBLL = new BLL.T_Sys_UserAccount();
  34. private readonly BLL.T_Sys_RoleInfo roleBLL = new BLL.T_Sys_RoleInfo();
  35. private readonly BLL.T_Cus_CustomerBaseNew customerBaseBLL = new BLL.T_Cus_CustomerBaseNew();
  36. private readonly BLL.T_Cus_CustomerFinance finbll = new BLL.T_Cus_CustomerFinance();
  37. private readonly BLL.T_Wo_WorkOrder woBLL = new BLL.T_Wo_WorkOrder();
  38. private readonly BLL.T_Sys_Department departmentBLL = new BLL.T_Sys_Department();
  39. private readonly BLL.T_Wo_WorkOrderItem_New itembll = new BLL.T_Wo_WorkOrderItem_New();
  40. private readonly BLL.T_Wo_WorkOrder_Logs blllogs = new BLL.T_Wo_WorkOrder_Logs();
  41. private readonly BLL.T_Sys_RoleInfo rolebll = new BLL.T_Sys_RoleInfo();
  42. private readonly BLL.T_Sys_DictionaryValue dicvalueBll = new BLL.T_Sys_DictionaryValue();
  43. private readonly BLL.T_Wo_MaterialManage mmBLL = new BLL.T_Wo_MaterialManage();
  44. BLL.T_Wo_QuestionManage quesBLL = new BLL.T_Wo_QuestionManage();
  45. ///// <summary>
  46. ///// 绑定微信号
  47. ///// </summary>
  48. ///// <param name="wxLoginDto"></param>
  49. ///// <returns></returns>
  50. //public ActionResult Login(WxLoginDto wxLoginDto)
  51. //{
  52. // var res = Redirect("获取微信openId", wxLoginDto.RedirectUrl);
  53. // var temp = WxHelper.GetOpenId(wxLoginDto);
  54. // if (string.IsNullOrWhiteSpace(temp.OpenId))
  55. // return res;
  56. // //openId => 用户
  57. // //如果不存在,跳转至登录页面
  58. // res = Redirect("绑定微信号", "");
  59. // return res;
  60. //}
  61. /// <summary>
  62. /// 绑定微信号 - 员工和业主分开登陆
  63. /// </summary>
  64. /// <param name="login"></param>
  65. /// <returns></returns>
  66. public ActionResult Login(WxLoginDto login)
  67. {
  68. #region 把其他OpenId更新为空
  69. var userAccount = userAccountBLL.GetModelByOpenid(login.OpenId);
  70. if (userAccount != null)
  71. {
  72. userAccount.F_WxOpenId = "";
  73. //userAccountBLL.Update(userAccount);
  74. string sql = $"update T_Sys_UserAccount set F_WxOpenId='' where F_UserId=" + userAccount.F_UserId;
  75. DbHelperSQL.ExecuteSql(sql);
  76. }
  77. var modelcustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + login.OpenId + "'").FirstOrDefault(); //customerBaseBLL.GetModelByOpenid(login.OpenId);
  78. if (modelcustomer != null)
  79. {
  80. modelcustomer.F_WxOpenId = "";
  81. //customerBaseBLL.Update(modelcustomer);
  82. string strsql = $"update T_Cus_CustomerBaseNew set F_WxOpenId='' where F_CustomerId=" + modelcustomer.F_CustomerId;
  83. DbHelperSQL.ExecuteSql(strsql);
  84. }
  85. #endregion
  86. if (string.IsNullOrEmpty(login.UserCode))
  87. return Error("账号不能为空!");
  88. if (string.IsNullOrEmpty(login.Password))
  89. return Error("密码不能为空!");
  90. Model.T_Sys_UserAccount loginCode = new BLL.T_Sys_UserAccount().LoginGetModel(login.UserCode, login.Password);
  91. Model.T_Sys_UserAccount loginwork = new BLL.T_Sys_UserAccount().LogworkGetModel(login.UserCode, login.Password);
  92. if (loginCode != null || loginwork != null)
  93. {
  94. Model.T_Sys_UserAccount loginUser = null;
  95. string deptcode = "";
  96. if (loginCode != null)
  97. loginUser = loginCode;
  98. else
  99. loginUser = loginwork;
  100. loginUser.F_WxOpenId = login.OpenId;
  101. int UserType = 0; string rolecode = ""; string UserName = ""; string rolename = "";
  102. UserName = loginUser.F_UserName;
  103. //部门
  104. Model.T_Sys_Department modelDep = new BLL.T_Sys_Department().GetModel(loginUser.F_DeptId);
  105. if (modelDep == null)
  106. return Error("获取失败!");
  107. #region 读取角色code
  108. var rolemodel = roleBLL.GetModel(loginUser.F_RoleId);
  109. if (rolemodel != null)
  110. rolecode = rolemodel.F_RoleCode;
  111. string area="", offic = "", region = "";
  112. region = loginUser.F_Remark;
  113. if (rolemodel.F_RoleCode == "DQJL")
  114. {
  115. area = modelDep.F_DeptName;
  116. }
  117. else if (rolemodel.F_RoleCode == "FGSJL")
  118. {
  119. var dept = departmentBLL.GetModel(modelDep.F_ParentId);
  120. if (dept != null)
  121. {
  122. area = dept.F_DeptName;
  123. offic = modelDep.F_DeptName;
  124. }
  125. }
  126. else if (rolemodel.F_RoleCode == "YWY")
  127. {
  128. if (modelDep != null)
  129. {
  130. if (modelDep.F_Layer == 2)
  131. {
  132. var dept = departmentBLL.GetModel(modelDep.F_ParentId);
  133. if (dept != null)
  134. {
  135. area = dept.F_DeptName;
  136. offic = modelDep.F_DeptName;
  137. }
  138. }
  139. if (modelDep.F_Layer == 1)
  140. {
  141. area = modelDep.F_DeptName;
  142. }
  143. }
  144. }
  145. #endregion
  146. #region 部门角色
  147. //部门角色(-1管理员,1接待部,2案场经理、项目负责人,3销售部总经理、物业部总经理、工程总经理、设计总经理,4区域客服,5业主(客户档案))
  148. //if (loginUser.F_RoleId == 17)
  149. //{
  150. // //-1管理员
  151. // return Error("无操作权限");
  152. //}
  153. //else
  154. //{
  155. if (loginUser.F_RoleId == 60)
  156. {
  157. UserType = 0;
  158. rolename = "分公司经理";
  159. }
  160. else if (loginUser.F_RoleId == 62)
  161. {
  162. UserType = 0;
  163. rolename = "大区经理";
  164. }
  165. else if (loginUser.F_RoleId == 61)
  166. {
  167. UserType = 2;
  168. rolename = "高层";
  169. }
  170. else if (loginUser.F_RoleId == 58)
  171. {
  172. UserType = 4;
  173. rolename = "业务员";
  174. }
  175. else if (rolemodel.F_RoleCode== "BLRY")
  176. {
  177. UserType = 3;
  178. rolename = "办理人员";
  179. }
  180. else if (rolemodel.F_RoleCode == "JDYPTZX" || rolemodel.F_RoleCode == "XTGLY")
  181. {
  182. UserType = 5;
  183. rolename = "客服";
  184. }
  185. //else if (loginUser.F_RoleId == 59)
  186. //{
  187. // UserType = 3;
  188. // rolename = "办理人员";
  189. //}
  190. else
  191. {
  192. return Error("无操作权限");
  193. }
  194. #region
  195. ////部门操作权限:1接待部,2办理人员,3区域客服,4监管
  196. //IF (MODELDEP.F_TYPE == 1)
  197. //{
  198. // //1--接待部
  199. // USERTYPE = 1;
  200. //}
  201. //ELSE IF (MODELDEP.F_TYPE == 2)
  202. //{
  203. // //2--办理人员
  204. // USERTYPE = 2;
  205. //}
  206. //ELSE IF (MODELDEP.F_TYPE == 3)
  207. //{
  208. // //3--区域客服
  209. // USERTYPE = 3;
  210. //}
  211. //ELSE IF (MODELDEP.F_TYPE == 4)
  212. //{
  213. // //4--监管
  214. // USERTYPE = 4;
  215. //}
  216. //ELSE
  217. //{
  218. // USERTYPE = 0;
  219. //}
  220. #endregion
  221. //}
  222. #endregion
  223. var obj = new
  224. {
  225. openid = login.OpenId,
  226. usercode = login.UserCode,
  227. usertype = UserType,
  228. UserName = UserName,
  229. rolename = rolename,
  230. rolecode = rolecode,
  231. area = area ,
  232. offic =offic ,
  233. region =region ,
  234. flag= loginUser.F_Flag
  235. };
  236. if (userAccountBLL.Update(loginUser))
  237. return Success("绑定成功", obj);
  238. else
  239. return Error("绑定失败");
  240. }
  241. return Error("账号或密码错误,请重新登录");
  242. //else if (login.UserType == 5)
  243. //{
  244. // //客户档案登录 - 用戶信息不存在时,登录客户档案业主账号
  245. // Dictionary<string, string> paras_Customer = new Dictionary<string, string>();
  246. // // F_RelationShipClassID IN (1,2) 用户类型:0来电用户; 1准业主; 2不是准业主或是亲戚朋友
  247. // //首次密码默认为身份证后6位信息
  248. // //F_CustomerClassID >= 0 为业主或租户,且F_RelationShipClassID = 0为会员账号 2、登录最早的信息
  249. // 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 ";
  250. // paras_Customer.Add("@F_UserCode", login.UserCode);
  251. // paras_Customer.Add("@F_PassWord", login.Password);
  252. // var dt_Customer = DbHelperSQL.Query(sql_Customer, paras_Customer).Tables[0];
  253. // if (dt_Customer != null && dt_Customer.Rows.Count > 0)
  254. // {
  255. // //var customer = customerBaseBLL.GetModel(login.UserCode); //20180926 次方法查询有漏洞
  256. // var customer = customerBaseBLL.DataTableToList(dt_Customer).ToList().FirstOrDefault();
  257. // customer.F_WxOpenId = login.OpenId;
  258. // #region 新加 - 登录后同时获取用户账号,openid,和角色
  259. // //5--业主(客户档案会员)
  260. // //int UserType = 5;
  261. // var obj = new
  262. // {
  263. // openid = login.OpenId,
  264. // usercode = login.UserCode,
  265. // companyname = customer.F_CompanyName,
  266. // //companyaddress=customer.F_CompanyAddress,
  267. // };
  268. // #endregion
  269. // if (customerBaseBLL.Update(customer))
  270. // return Success("绑定成功!", obj);
  271. // else
  272. // return Error("绑定失败!");
  273. // }
  274. // return Error("账号或密码错误或者没有注册,请重新登录");
  275. //}
  276. return Error("绑定失败");
  277. }
  278. /// <summary>
  279. /// 绑定微信号 - 员工和业主统一登陆 - 不用
  280. /// </summary>
  281. /// <param name="login"></param>
  282. /// <returns></returns>
  283. [WechatActionFilter]
  284. public ActionResult Login2(WxLoginDto login)
  285. {
  286. Dictionary<string, string> paras = new Dictionary<string, string>();
  287. string sql = " select * from T_Sys_UserAccount (NOLOCK) where F_UserCode=@F_UserCode and F_PassWord=@F_PassWord and F_DeleteFlag = 0 ";
  288. paras.Add("@F_UserCode", login.UserCode);
  289. paras.Add("@F_PassWord", login.Password);
  290. var dt = DbHelperSQL.Query(sql, paras).Tables[0];
  291. #region 把其他OpenId更新为空
  292. var userAccount = userAccountBLL.GetModelByOpenid(login.OpenId);
  293. if (userAccount != null)
  294. {
  295. userAccount.F_WxOpenId = "";
  296. userAccountBLL.Update(userAccount);
  297. }
  298. var modelcustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + login.OpenId + "'").FirstOrDefault();//.GetModelByOpenid(login.OpenId);
  299. if (modelcustomer != null)
  300. {
  301. modelcustomer.F_WxOpenId = "";
  302. customerBaseBLL.Update(modelcustomer);
  303. }
  304. #endregion
  305. if (dt != null && dt.Rows.Count > 0)
  306. {
  307. var user = userAccountBLL.GetModel(login.UserCode);
  308. user.F_WxOpenId = login.OpenId;
  309. //int UserType = 0;
  310. //部门
  311. Model.T_Sys_Department modelDep = new BLL.T_Sys_Department().GetModel(user.F_DeptId);
  312. if (modelDep == null)
  313. return Error("获取失败!");
  314. #region 部门角色
  315. ////部门角色(-1管理员,1接待部,2案场经理、项目负责人,3销售部总经理、物业部总经理、工程总经理、设计总经理,4区域客服,5业主(客户档案))
  316. //if (user.F_RoleId == 17)
  317. //{
  318. // //-1管理员
  319. // UserType = -1;
  320. //}
  321. //else
  322. //{
  323. // //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  324. // if (modelDep.F_Type == 1)
  325. // {
  326. // //1--接待部
  327. // UserType = 1;
  328. // }
  329. // else if (modelDep.F_Type == 2)
  330. // {
  331. // //2--办理人员
  332. // UserType = 2;
  333. // }
  334. // else if (modelDep.F_Type == 3)
  335. // {
  336. // //3--区域客服
  337. // UserType = 3;
  338. // }
  339. // else if (modelDep.F_Type == 4)
  340. // {
  341. // //4--监管
  342. // UserType = 4;
  343. // }
  344. // else
  345. // {
  346. // UserType = 0;
  347. // }
  348. //}
  349. #endregion
  350. var obj = new
  351. {
  352. openid = login.OpenId,
  353. usercode = login.UserCode,
  354. //usertype = UserType
  355. };
  356. if (userAccountBLL.Update(user))
  357. {
  358. return Success("绑定成功", obj);
  359. }
  360. else
  361. {
  362. return Error("绑定失败");
  363. }
  364. }
  365. else
  366. {
  367. //客户档案登录 - 用戶信息不存在时,登录客户档案业主账号
  368. Dictionary<string, string> paras_Customer = new Dictionary<string, string>();
  369. // F_RelationShipClassID IN (1,2) 用户类型:0来电用户; 1准业主; 2不是准业主或是亲戚朋友
  370. //首次密码默认为身份证后6位信息
  371. //F_CustomerClassID >= 0 为业主或租户,且F_RelationShipClassID = 0为会员账号 2、登录最早的信息
  372. string sql_Customer = " select * from dbo.T_Cus_CustomerBaseNew (NOLOCK) where F_CustomerCode=@F_UserCode and F_PassWord=@F_PassWord and F_DeleteFlag = 0 ";
  373. paras_Customer.Add("@F_UserCode", login.UserCode);
  374. paras_Customer.Add("@F_PassWord", login.Password);
  375. var dt_Customer = DbHelperSQL.Query(sql_Customer, paras_Customer).Tables[0];
  376. if (dt_Customer != null && dt_Customer.Rows.Count > 0)
  377. {
  378. var customer = customerBaseBLL.GetModelList(" F_CustomerCode='" + login.UserCode + "'").FirstOrDefault(); //customerBaseBLL.GetModel(login.UserCode);
  379. customer.F_WxOpenId = login.OpenId;
  380. #region 新加 - 登录后同时获取用户账号,openid,和角色
  381. //5--业主(客户档案会员)
  382. //int UserType = 5;
  383. var obj = new
  384. {
  385. openid = login.OpenId,
  386. usercode = login.UserCode,
  387. //usertype = UserType
  388. };
  389. #endregion
  390. if (customerBaseBLL.Update(customer))
  391. {
  392. return Success("绑定成功!", obj);
  393. }
  394. else
  395. {
  396. return Error("绑定失败!");
  397. }
  398. }
  399. else
  400. {
  401. return Error("账号或密码错误,请重新登录");
  402. }
  403. //return Error("账号或密码错误,请重新登录");
  404. }
  405. }
  406. /// <summary>
  407. /// 随机字符串数组集合
  408. /// </summary>
  409. private static readonly string[] NonceStrings = new string[]
  410. {
  411. "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",
  412. "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"
  413. };
  414. /// <summary>
  415. /// 生成签名的随机串
  416. /// </summary>
  417. /// <returns></returns>
  418. public static string CreateNonceStr()
  419. {
  420. Random random = new Random();
  421. var sb = new StringBuilder();
  422. var length = NonceStrings.Length;
  423. //生成15位数的随机字符串,当然也可以通过控制对应字符串大小生成,但是至多不超过32位
  424. for (int i = 0; i < 16; i++)
  425. {
  426. sb.Append(NonceStrings[random.Next(length - 1)]);//通过random获得的随机索引到,NonceStrings数组中获取对应数组值
  427. }
  428. return sb.ToString();
  429. }
  430. /// <summary>
  431. /// 获取签名
  432. /// </summary>
  433. /// <param name="url"></param>
  434. /// <returns></returns>
  435. public ActionResult GetJsSdk(string url)
  436. {
  437. var timestamp = GetCurrentUinxTime();
  438. var nonceStr = CreateNonceStr();
  439. var obj = new
  440. {
  441. state = "success",
  442. message = "成功",
  443. appId = AppId,
  444. timestamp = timestamp,
  445. nonceStr = nonceStr,
  446. token = GetToken(),
  447. ticket= Getticket(GetToken()),
  448. url,
  449. signature = GetSignature(Getticket(GetToken()), nonceStr, timestamp, url)
  450. };
  451. return Content(obj.ToJson()); ;
  452. }
  453. string AppId = Configs.GetValue("WechatAppid");
  454. string AppSecret = Configs.GetValue("WechatAppsecret");
  455. public class Token
  456. {
  457. public string token;
  458. public DateTime time;
  459. }
  460. public class AssedToken
  461. {
  462. public string access_token { get; set; }
  463. public int expires_in { get; set; }
  464. }
  465. public string GetToken()
  466. {
  467. WebClient web = new WebClient();
  468. web.Encoding = Encoding.UTF8;
  469. string msg = "";
  470. var model = new BLL.T_Sys_AssToken().GetModelList("F_IsDelete=0 order by F_ID desc").FirstOrDefault();
  471. if (model!=null )
  472. {
  473. System.TimeSpan id = DateTime.Now - DateTime.Parse(model.F_CreatTime .ToString());
  474. if (id.TotalMinutes>=120)
  475. {
  476. string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + AppId + "&secret=" + AppSecret;
  477. string Dataaa = web.DownloadString(url);//这一句话就能请求到数据了
  478. JObject jo = (JObject)JsonConvert.DeserializeObject(Dataaa);
  479. string access_token = jo["access_token"].ToString();
  480. var asser = new Model.T_Sys_AssToken();
  481. asser.F_CreatTime = DateTime.Now;
  482. asser.F_IsDelete = 0;
  483. asser.F_Token = access_token;
  484. int a = new BLL.T_Sys_AssToken().Add(asser);
  485. if (a >0)
  486. {
  487. msg = access_token;
  488. }
  489. }
  490. else
  491. {
  492. msg = model.F_Token ;
  493. }
  494. }
  495. else
  496. {
  497. string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + AppId + "&secret=" + AppSecret;
  498. string Dataaa = web.DownloadString(url);//这一句话就能请求到数据了
  499. JObject jo = (JObject)JsonConvert.DeserializeObject(Dataaa);
  500. string access_token = jo["access_token"].ToString();
  501. var asser = new Model.T_Sys_AssToken();
  502. asser.F_CreatTime = DateTime.Now;
  503. asser.F_IsDelete = 0;
  504. asser.F_Token = access_token;
  505. int a = new BLL.T_Sys_AssToken().Add(asser);
  506. if (a > 0)
  507. {
  508. msg = access_token;
  509. }
  510. }
  511. return msg;
  512. }
  513. public string Getticket(string token)
  514. {
  515. WebClient web = new WebClient();
  516. web.Encoding = Encoding.UTF8;
  517. string msg = "";
  518. string urltoken = " https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + token + "&type=jsapi";
  519. string Dataaasig = web.DownloadString(urltoken);//这一句话就能请求到数据了
  520. JObject jo = (JObject)JsonConvert.DeserializeObject(Dataaasig);
  521. string ticket = jo["ticket"].ToString();
  522. string errmsg = jo["errmsg"].ToString();
  523. return ticket;
  524. }
  525. public class Accesstoken
  526. {
  527. public string access_token;
  528. public int expires_in;
  529. }
  530. /// <summary>
  531. /// 获取jsapi_ticket
  532. /// </summary>
  533. /// <param name="jsapi_ticket">微信公众号调用微信JS临时票据</param>
  534. /// <param name="nonceStr">随机串</param>
  535. /// <param name="timestamp">时间戳</param>
  536. /// <param name="url">当前网页URL</param>
  537. /// <returns></returns>
  538. public static string GetSignature(string jsapi_ticket, string nonceStr, long timestamp, string url)
  539. {
  540. var string1Builder = new StringBuilder();
  541. //注意这里参数名必须全部小写,且必须有序
  542. string1Builder.Append("jsapi_ticket=").Append(jsapi_ticket).Append("&")
  543. .Append("noncestr=").Append(nonceStr).Append("&")
  544. .Append("timestamp=").Append(timestamp).Append("&")
  545. .Append("url=").Append(url.IndexOf("#") >= 0 ? url.Substring(0, url.IndexOf("#")) : url);
  546. return Sha1Sign(string1Builder.ToString());
  547. }
  548. public static string Sha1Sign(string data)
  549. {
  550. byte[] temp1 = Encoding.UTF8.GetBytes(data);
  551. SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();
  552. byte[] temp2 = sha.ComputeHash(temp1);
  553. sha.Clear();
  554. // 注意, 不能用这个
  555. // string output = Convert.ToBase64String(temp2);// 不能直接转换成base64string
  556. var output = BitConverter.ToString(temp2);
  557. output = output.Replace("-", "");
  558. output = output.ToLower();
  559. return output;
  560. }
  561. /// <summary>
  562. /// 获取当前时间戳
  563. /// </summary>
  564. /// <returns></returns>
  565. public static long GetCurrentUinxTime()
  566. {
  567. DateTime currentDate = DateTime.Now;//当前时间
  568. //转化为时间戳
  569. DateTime localTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  570. return long.Parse((currentDate - localTime).TotalSeconds.ToString().Split('.')[0]);
  571. // var ticks = currentDate.ToUniversalTime().Ticks - new DateTime(1970, 1, 1, 0, 0, 0, //DateTimeKind.Utc).Ticks;
  572. // var timeSpan = ticks / TimeSpan.TicksPerSecond;
  573. //return timeSpan;
  574. }
  575. /// <summary>
  576. /// 获取微信openid
  577. /// </summary>
  578. /// <param name="login"></param>
  579. /// <returns></returns>
  580. public ActionResult GetOpenId(WxLoginDto wld)
  581. {
  582. //wld.RedirectUrl = RequestString.GetUrlReferrer();
  583. if (string.IsNullOrEmpty(wld.OpenId))
  584. {
  585. var temp = WxHelper.GetOpenId(wld);
  586. if (string.IsNullOrWhiteSpace(temp.OpenId))
  587. {
  588. //Request.QueryString[ ] == null
  589. return Redirect("请求", temp.RedirectUrl);
  590. }
  591. wld.OpenId = temp.OpenId;
  592. #region 获取是否绑定用户表
  593. //获取是否绑定用户表
  594. var usertemp = new BLL.T_Sys_UserAccount().GetModelByOpenid(wld.OpenId);
  595. if (usertemp != null)
  596. {
  597. //部门
  598. Model.T_Sys_Department modelDep = new BLL.T_Sys_Department().GetModel(usertemp.F_DeptId);
  599. if (modelDep == null)
  600. return Error("获取失败!");
  601. wld.UserCode = usertemp.F_UserCode;
  602. wld.Flag = usertemp.F_Flag;
  603. #region 读取角色code
  604. var rolemodel = roleBLL.GetModel(usertemp.F_RoleId);
  605. if (rolemodel != null)
  606. wld.RoleCode = rolemodel.F_RoleCode;
  607. #endregion
  608. #region 部门角色
  609. if (usertemp.F_RoleId == 17)
  610. {
  611. //-1管理员
  612. wld.UserType = -1;
  613. }
  614. else
  615. {
  616. if (usertemp.F_RoleId == 60 || usertemp.F_RoleId == 62)
  617. {
  618. wld.UserType = 0;
  619. }
  620. else if (usertemp.F_RoleId == 61)
  621. {
  622. wld.UserType = 2;
  623. }
  624. else if (usertemp.F_RoleId == 58)
  625. {
  626. wld.UserType = 4;
  627. }
  628. else if (rolemodel.F_RoleCode== "BLRY")
  629. {
  630. wld.UserType = 3;
  631. }
  632. else
  633. {
  634. wld.UserType = 1;
  635. }
  636. #region
  637. ////部门操作权限:1接待部,2办理人员,3区域客服,4监管
  638. //IF (MODELDEP.F_TYPE == 1)
  639. //{
  640. // //1--接待部
  641. // USERTYPE = 1;
  642. //}
  643. //ELSE IF (MODELDEP.F_TYPE == 2)
  644. //{
  645. // //2--办理人员
  646. // USERTYPE = 2;
  647. //}
  648. //ELSE IF (MODELDEP.F_TYPE == 3)
  649. //{
  650. // //3--区域客服
  651. // USERTYPE = 3;
  652. //}
  653. //ELSE IF (MODELDEP.F_TYPE == 4)
  654. //{
  655. // //4--监管
  656. // USERTYPE = 4;
  657. //}
  658. //ELSE
  659. //{
  660. // USERTYPE = 0;
  661. //}
  662. #endregion
  663. #region
  664. ////部门操作权限:1接待部,2办理人员,3区域客服,4监管
  665. //if (modelDep.F_Type == 1)
  666. //{
  667. // //1--接待部
  668. // wld.UserType = 1;
  669. //}
  670. //else if (modelDep.F_Type == 2)
  671. //{
  672. // //2--办理人员
  673. // wld.UserType = 2;
  674. //}
  675. //else if (modelDep.F_Type == 3)
  676. //{
  677. // //3--区域客服
  678. // wld.UserType = 3;
  679. //}
  680. //else if (modelDep.F_Type == 4)
  681. //{
  682. // //4--监管
  683. // wld.UserType = 4;
  684. //}
  685. //else
  686. //{
  687. // wld.UserType = 0;
  688. //}
  689. #endregion
  690. }
  691. #endregion
  692. }
  693. else
  694. {
  695. var customertemp = customerBaseBLL.GetModelByOpenid(wld.OpenId);
  696. if (customertemp != null)
  697. {
  698. wld.UserCode = customertemp.F_CustomerCode;
  699. //5--业主(客户档案会员)
  700. wld.UserType = 5;
  701. }
  702. else
  703. {
  704. wld.UserCode = "";
  705. }
  706. //wld.UserCode = "";
  707. }
  708. #endregion
  709. }
  710. var model = new BLL.T_Sys_Users().GetModel(wld.OpenId);
  711. if (model == null)
  712. {
  713. model = new Model.T_Sys_Users();
  714. model.F_OpenId = wld.OpenId;
  715. model.F_Type = 1;
  716. model.F_CreateTime = DateTime.Now;
  717. new BLL.T_Sys_Users().Add(model);
  718. }
  719. var newobj = new
  720. {
  721. openid = wld.OpenId,
  722. usercode = wld.UserCode,
  723. usertype = wld.UserType,
  724. rolecode = wld.RoleCode,
  725. flag=wld.Flag
  726. };
  727. return Success("成功", newobj);
  728. }
  729. /// <summary>
  730. ///退回工单列表
  731. /// </summary>
  732. public string GetBackid(Model.T_Sys_UserAccount ua)
  733. {
  734. string str = string.Empty;
  735. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_ItemType in(" + (int)EnumItemType.deal + "," + (int)EnumItemType.audit + ")"
  736. + " and "
  737. + "F_OptType in(" + (int)EnumItemOpt.abreback + "," + (int)EnumItemOpt.reback + ") and F_NextUser='" + ua.F_UserCode + "'"
  738. + ""
  739. + " and isnull(F_IsUsed,'0')='0' ";
  740. return str;
  741. }
  742. /// <summary>
  743. ///工单列表
  744. /// </summary>
  745. ///
  746. 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,
  747. 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)
  748. {
  749. // int userId = CurrentUser.UserData.F_UserId;
  750. if (!string.IsNullOrEmpty(OpenId))
  751. {
  752. // Model.T_Sys_UserAccount ua = userAccountBLL.GetModel(userId);
  753. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  754. // if (source != 3)
  755. // {
  756. // if (ua == null)
  757. // {
  758. // return Error("你的账号已在别处登录,你确定要再次登录吗?");
  759. // }
  760. // }
  761. // Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  762. string sql = $" and F_IsDelete=0";
  763. DataTable dt = new DataTable();
  764. #region 筛选条件
  765. if (type > 0 && type < 6)//工单类型
  766. sql += $" and F_Type=" + type;
  767. if (source > 0)//工单来源
  768. {
  769. if (source == 1)
  770. sql += $" and (F_Source in (1,'')or F_Source is null )";
  771. else
  772. sql += $" and F_Source='" + source + "'";
  773. }
  774. if (!string.IsNullOrWhiteSpace(description))//问题描述
  775. sql += $" and F_Description like '%" + description.Trim() + "%'";
  776. if (!string.IsNullOrWhiteSpace(touser))//参与人
  777. sql += $" and F_DealBy like '%" + touser.Trim() + "%'";
  778. if (!string.IsNullOrWhiteSpace(code))//工单编号
  779. sql += $" and F_WorkOrderCode like '%" + code.Trim() + "%'";
  780. if (!string.IsNullOrWhiteSpace(keywords))//关键字搜索
  781. sql += $" and (F_QuestionType like '%" + keywords.Trim()
  782. + "%' or F_ZX_Area like '%" + keywords.Trim() + "%' or F_ZX_Branch like '%" + keywords.Trim()
  783. + "%' or F_CusName like '%" + keywords.Trim() + "%' or F_WorkOrderCode like '%" + keywords.Trim() + "%'or F_CusPhone like '%" + keywords.Trim() + "%' ) ";
  784. if (!string.IsNullOrWhiteSpace(cusname))//客户姓名
  785. sql += $" and F_CusName like '%" + cusname.Trim() + "%'";
  786. if (!string.IsNullOrWhiteSpace(cusphone))//客户电话
  787. sql += $" and F_CusPhone like '%" + cusphone.Trim() + "%'";
  788. if (!string.IsNullOrWhiteSpace(companyname))//公司名称
  789. sql += $" and F_CompanyName like '%" + companyname.Trim() + "%'";
  790. if (!string.IsNullOrWhiteSpace(category))//产品名称
  791. sql += $" and F_TS_Category like '%" + category.Trim() + "%'";
  792. if (!string.IsNullOrWhiteSpace(salebase))//销售基地
  793. sql += $" and F_SalesBase like '%" + salebase.Trim() + "%'";
  794. if (!string.IsNullOrWhiteSpace(province))//省
  795. sql += $" and F_IncidentProvince like '%" + province.Trim() + "%'";
  796. if (!string.IsNullOrWhiteSpace(province))//市
  797. sql += $" and F_IncidentCity like '%" + city.Trim() + "%'";
  798. if (!string.IsNullOrWhiteSpace(province))//县
  799. sql += $" and F_IncidentCountry like '%" + country.Trim() + "%'";
  800. if (!string.IsNullOrWhiteSpace(province))//乡
  801. sql += $" and F_IncidentTownship like '%" + township.Trim() + "%'";
  802. if (condition>-1)
  803. {
  804. if (condition == 5)
  805. {
  806. sql += $" and F_State in (2,3,4,5)";
  807. }
  808. else if (condition == 6)
  809. {
  810. sql += $" and F_State in (11)";
  811. sql += $" and F_IsVisit=" + 1; ;
  812. sql += $"and F_DealType != '当即办理' and F_VisitBy != ''";
  813. }
  814. else if (condition == 10)
  815. {
  816. sql += $" and F_State in (10,11)";
  817. }
  818. else if (condition == 12)
  819. {
  820. sql += $" and F_State=" + (int)EnumWorkOrderState.finish + " and F_IsVisit = '" + "1" + "' ";
  821. }
  822. else
  823. {
  824. sql += $" and F_State=" + condition;
  825. }
  826. if (ua != null)
  827. {
  828. Model.T_Sys_RoleInfo re = rolebll.GetModel(ua.F_RoleId);
  829. if (re.F_RoleCode == "QTJS" || re.F_RoleCode == "YWY")
  830. sql += $" and F_CreateBy like '%" + ua.F_UserCode.Trim() + "%'";
  831. else if (re.F_RoleCode == "DQJL" || re.F_RoleCode == "FGSJL" || re.F_RoleCode == "BLRY" || re.F_RoleCode == "ZG")
  832. {
  833. string detpid = "" + ua.F_DeptId;
  834. var deparmentlist = new List<Model.T_Sys_Department>();
  835. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  836. if (dModel != null)
  837. {
  838. if (dModel.F_Layer == 1)
  839. {
  840. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  841. if (deparmentlist.Count > 0)
  842. {
  843. foreach (var it in deparmentlist)
  844. {
  845. if (detpid != "")
  846. {
  847. detpid += "," + it.F_DeptId;
  848. }
  849. else
  850. {
  851. detpid = "" + it.F_DeptId;
  852. }
  853. }
  854. }
  855. }
  856. else
  857. {
  858. detpid = ua.F_DeptId.ToString();
  859. }
  860. if (state >= 0)
  861. {
  862. if (GetDeptWorkOrderID(detpid) != "")
  863. {
  864. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid) + ") ";
  865. }
  866. else
  867. {
  868. return Success("暂无工单"); ;
  869. }
  870. }
  871. else
  872. {
  873. if (GetDeptWorkOrderID(detpid) != "")
  874. {
  875. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid) + ") ";
  876. }
  877. else
  878. {
  879. return Success("暂无工单"); ;
  880. }
  881. }
  882. }
  883. else
  884. {
  885. return Error("加载失败");
  886. }
  887. }
  888. }
  889. }
  890. if (!string.IsNullOrWhiteSpace(createby))//创建人
  891. {
  892. sql += $" and F_CustomerID in(select F_CustomerCode from T_Cus_CustomerBaseNew where F_Salesman like '%" +createby+ "%' and F_IsDelete =0) ";
  893. }
  894. if (!string.IsNullOrWhiteSpace(createtel))//创建人
  895. {
  896. sql += $" and F_CustomerID in(select F_CustomerCode from T_Cus_CustomerBaseNew where F_SalesPhone like '%" + createtel + "%' and F_IsDelete =0) ";
  897. }
  898. if (!string .IsNullOrEmpty (handler))
  899. {
  900. Model.T_Sys_UserAccount user = userAccountBLL .GetworkModel(handler);
  901. if (user != null)
  902. {
  903. if (GetParticipate(user.F_UserCode) != "")
  904. {
  905. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetParticipate(user.F_UserCode) + ") ";
  906. }
  907. }
  908. else
  909. {
  910. Model.T_Sys_UserAccount userer = userAccountBLL.GetName(handler);
  911. if (userer != null)
  912. {
  913. if (GetParticipate(userer.F_UserCode) != "")
  914. {
  915. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetParticipate(userer.F_UserCode) + ") ";
  916. }
  917. }
  918. }
  919. }
  920. // sql += " and (F_CreateBy= '" + ua.F_UserCode + "' or T_Wo_WorkOrder.F_ID in ( " + GetCYWorkOrderID(ua.F_UserCode) + ")) ";
  921. if (source == 3)
  922. {
  923. sql += $" and F_WxOpenId ='" + OpenId + "'";
  924. }
  925. else if (ua != null)
  926. {
  927. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  928. if (state >-1)
  929. {
  930. switch (state)
  931. {
  932. case 0://待审批
  933. string uwhere = "";
  934. if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL")
  935. {
  936. if (GetApprovalOrderID(ua, OpenId, ro.F_RoleCode) != "")
  937. {
  938. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetApprovalOrderID(ua, OpenId, ro.F_RoleCode) + ") ";
  939. }
  940. else
  941. {
  942. return Success("暂无工单");
  943. }
  944. }
  945. else
  946. {
  947. return Success("无操作权限");
  948. }
  949. break;
  950. case 11://已创单
  951. sql += $" and F_CreateBy ='" + ua.F_UserCode + "'";
  952. break;
  953. case 12://退单
  954. if (GetBackid(ua) != "")
  955. {
  956. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetBackid(ua) + ") ";
  957. }
  958. else
  959. {
  960. return Success("暂无工单");
  961. }
  962. break;
  963. case 1://已审核
  964. if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "GC")
  965. {
  966. if (GetApprovedOrderID(ua.F_UserCode) != "")
  967. {
  968. sql += $" and F_ID in ( " + GetApprovedOrderID(ua.F_UserCode) + ") "; ;
  969. }
  970. else
  971. {
  972. return Error("暂无工单");
  973. }
  974. }
  975. else
  976. {
  977. return Success("暂无工单");
  978. }
  979. break;
  980. case 2://待完成的(待接单)
  981. string strsql = GetDeptWorkOrderID(ua.F_DeptId, ua.F_UserCode);
  982. if (strsql != "")
  983. {
  984. sql += $" and (F_State in(" + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.assign + ") ";
  985. sql += $" or F_State2 in(" + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.assign + ")) ";
  986. sql += " and T_Wo_WorkOrder.F_ID in ( " + strsql + ")";
  987. }
  988. else
  989. {
  990. return Success("暂无工单"); ;
  991. }
  992. break;
  993. case 5://待审批
  994. if (ro.F_RoleCode == "GC")
  995. {
  996. if (GetHApproval(ua.F_UserCode) != "")
  997. {
  998. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetHApproval(ua.F_UserCode) + ") "; ;
  999. }
  1000. }
  1001. else
  1002. {
  1003. return Success("暂无工单"); ;
  1004. }
  1005. break;
  1006. case 4://待完成的(待处理)
  1007. string dealstr = GetDWCWorkOrderID(ua.F_UserCode, ua.F_DeptId);
  1008. if (!string.IsNullOrEmpty(dealstr))
  1009. {
  1010. sql += " and ((F_State in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.revoke + ")";
  1011. sql += " or F_State2 in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.revoke + "))";
  1012. sql += " and T_Wo_WorkOrder.F_ID in ( " + dealstr + ") ";
  1013. if (!string.IsNullOrEmpty(GetRevokeWo(ua.F_UserCode)))
  1014. {
  1015. sql += " or ((F_State=" + (int)EnumWorkOrderState.assign + " or F_State2=" + (int)EnumWorkOrderState.assign + ") and T_Wo_WorkOrder.F_ID in (" + GetRevokeWo(ua.F_UserCode) + ")))";
  1016. }
  1017. else
  1018. {
  1019. sql += $")";
  1020. }
  1021. }
  1022. else
  1023. {
  1024. return Success("暂无工单"); ;
  1025. }
  1026. break;
  1027. case 10://已完成的
  1028. if (GetDeptUserCode(ua.F_DeptId) != "")
  1029. {
  1030. //sql += " and (F_State in(10,11) or F_State2 in(10,11))";
  1031. 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))))";
  1032. sql += " and F_DealBy in(" + GetDeptUserCode(ua.F_DeptId) + ") ";
  1033. sql += " or T_Wo_WorkOrder.F_ID in (" + GetOverWo(ua.F_UserCode) + "))";
  1034. }
  1035. // sql += " and F_State in(10,11) and F_DealBy = '" + ua.F_UserCode + "' ";
  1036. break;
  1037. case 3://我参与的
  1038. if (GetParticipateID(ua.F_UserCode) != "")
  1039. {
  1040. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetParticipateID(ua.F_UserCode) + ") ";
  1041. }
  1042. else
  1043. {
  1044. return Error("暂无工单");
  1045. }
  1046. break;
  1047. case 6://待回访
  1048. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "JDYBZZX")
  1049. {
  1050. uwhere = $" and F_Type <> 3";
  1051. }
  1052. else
  1053. {
  1054. return Success("无操作权限"); ;
  1055. }
  1056. 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; ;
  1057. break;
  1058. case 7://已回访
  1059. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "JDYBZZX")
  1060. {
  1061. if (GetCYWorkOrderID(ua.F_UserCode) != "")
  1062. {
  1063. sql += " and (F_CreateBy= '" + ua.F_UserCode + "' or T_Wo_WorkOrder.F_ID in ( " + GetCYWorkOrderID(ua.F_UserCode) + ")) ";
  1064. }
  1065. else
  1066. {
  1067. return Success("暂无工单"); ;
  1068. }
  1069. sql += $" and F_State=" + (int)EnumWorkOrderState.evaluate;
  1070. }
  1071. else if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "ZG")
  1072. {
  1073. string detpid = "" + ua.F_DeptId;
  1074. var deparmentlist = new List<Model.T_Sys_Department>();
  1075. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  1076. if (dModel != null)
  1077. {
  1078. if (dModel.F_Layer == 1)
  1079. {
  1080. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  1081. if (deparmentlist.Count > 0)
  1082. {
  1083. foreach (var it in deparmentlist)
  1084. {
  1085. if (detpid != "")
  1086. {
  1087. detpid += "," + it.F_DeptId;
  1088. }
  1089. else
  1090. {
  1091. detpid = "" + it.F_DeptId; ;
  1092. }
  1093. }
  1094. }
  1095. }
  1096. else
  1097. {
  1098. detpid = ua.F_DeptId.ToString();
  1099. }
  1100. if (GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.evaluate + "") != "")
  1101. {
  1102. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.evaluate + "") + ") "; ;
  1103. }
  1104. else
  1105. {
  1106. return Success("暂无工单"); ;
  1107. }
  1108. }
  1109. else
  1110. {
  1111. return Error("加载失败");
  1112. }
  1113. }
  1114. else
  1115. {
  1116. return Success("无操作权限"); ;
  1117. }
  1118. sql += $" and F_State=" + (int)EnumWorkOrderState.evaluate;
  1119. break;
  1120. case 8://待完结
  1121. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "JDYBZZX")
  1122. {
  1123. uwhere = ""; ;
  1124. }
  1125. else
  1126. {
  1127. return Success("无操作权限"); ;
  1128. }
  1129. sql += $" and (F_State=" + (int)EnumWorkOrderState.finish + " or F_State2=" + (int)EnumWorkOrderState.finish + ") and ( F_IsVisit = '" + "0" + "' or F_Type = 3)"; ;
  1130. break;
  1131. case 9://待接单
  1132. string strsql2 = GetDeptWorkOrderID(ua.F_DeptId, ua.F_UserCode);
  1133. if (strsql2 != "")
  1134. {
  1135. sql += $" and (F_State in(" + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.assign + ") ";
  1136. sql += $" or F_State2 in(" + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.assign + ")) ";
  1137. sql += " and T_Wo_WorkOrder.F_ID in ( " + strsql2 + ")";
  1138. }
  1139. else
  1140. {
  1141. return Success("暂无工单"); ;
  1142. }
  1143. break;
  1144. case 20: //抄送工单列表
  1145. sql += $" and T_Wo_WorkOrder.F_ID in (select F_WorkOrderID from T_Wo_WorkCopy where F_SendCopyUser like '%{ua.F_UserCode}%'"
  1146. + $" or (F_Flag=1 and F_SendCopyDepts={ua.F_DeptId} )) ";
  1147. break;
  1148. }
  1149. }
  1150. else
  1151. {
  1152. if (ro.F_RoleCode == "QTJS" || ro.F_RoleCode == "YWY")
  1153. sql += $" and F_CreateBy like '%" + ua.F_UserCode.Trim() + "%'";
  1154. else if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "BLRY" || ro.F_RoleCode == "ZG")
  1155. {
  1156. string detpid = "" + ua.F_DeptId;
  1157. var deparmentlist = new List<Model.T_Sys_Department>();
  1158. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  1159. if (dModel != null)
  1160. {
  1161. if (dModel.F_Layer == 1)
  1162. {
  1163. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  1164. if (deparmentlist.Count > 0)
  1165. {
  1166. foreach (var it in deparmentlist)
  1167. {
  1168. if (detpid != "")
  1169. {
  1170. detpid += "," + it.F_DeptId;
  1171. }
  1172. else
  1173. {
  1174. detpid = "" + it.F_DeptId;
  1175. }
  1176. }
  1177. }
  1178. }
  1179. else
  1180. {
  1181. detpid = ua.F_DeptId.ToString();
  1182. }
  1183. if (state >= 0)
  1184. {
  1185. if (GetDeptWorkOrderID(detpid) != "")
  1186. {
  1187. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid) + ") ";
  1188. }
  1189. else
  1190. {
  1191. return Success("暂无工单"); ;
  1192. }
  1193. }
  1194. else
  1195. {
  1196. if (GetDeptWorkOrderID(detpid) != "")
  1197. {
  1198. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid) + ") ";
  1199. }
  1200. else
  1201. {
  1202. return Success("暂无工单"); ;
  1203. }
  1204. }
  1205. }
  1206. else
  1207. {
  1208. return Error("加载失败");
  1209. }
  1210. }
  1211. }
  1212. }
  1213. else
  1214. {
  1215. sql += $" and F_WxOpenId ='" + OpenId + "'";
  1216. }
  1217. #endregion
  1218. int recordCount = 0;
  1219. if (!string.IsNullOrWhiteSpace(sql))
  1220. {
  1221. dt = BLL.PagerBLL.GetListPager(
  1222. "T_Wo_WorkOrder",
  1223. "F_ID",
  1224. "*",
  1225. sql,
  1226. "ORDER BY T_Wo_WorkOrder.F_ID desc",
  1227. pagesize,
  1228. pageindex,
  1229. true,
  1230. out recordCount);
  1231. }
  1232. List<Model.T_Wo_WorkOrder> modlelist = new BLL.T_Wo_WorkOrder().DataTableToList(dt);
  1233. if (modlelist.Count > 0)
  1234. {
  1235. List<WorkOrderNewInput> Input = modeltooip(modlelist, ua,state);
  1236. var obj = new
  1237. {
  1238. state = "success",
  1239. message = "成功",
  1240. rows = Input,
  1241. total = recordCount
  1242. };
  1243. return Content(obj.ToJson()); ;
  1244. }
  1245. else
  1246. {
  1247. return Success("暂无工单"); ;
  1248. }
  1249. }
  1250. else
  1251. {
  1252. return Success("暂无工单"); ;
  1253. }
  1254. }
  1255. /// <summary>
  1256. /// 指派工单时撤回
  1257. /// </summary>
  1258. /// <param name="usercode"></param>
  1259. /// <returns></returns>
  1260. public string GetRevokeWo(string usercode, int flag = 0)
  1261. {
  1262. string str = string.Empty;
  1263. str = $"Select F_WoID from T_Wo_WorkOrderItem_New where F_IsUsed=0 and F_OptType=" + (int)EnumItemOpt.assign +
  1264. $" and F_CreateUser='{usercode}' group by F_WoID HAVING COUNT(*) >{flag}";
  1265. var modetab = DbHelperSQL.Query(str).Tables[0];
  1266. var modelarray = modetab.AsEnumerable().Select(c => c.Field<long>("F_WoID")).ToArray(); ;
  1267. str = string.Join(",", modelarray);
  1268. return str;
  1269. }
  1270. public string GetDeptUserCode(int deptid)
  1271. {
  1272. string deptuser = string.Empty;
  1273. var dept = userAccountBLL .GetModelList("F_DeptId=" + deptid);
  1274. if (dept != null)
  1275. {
  1276. foreach (var it in dept)
  1277. {
  1278. if (deptuser != "")
  1279. deptuser += "," + it.F_UserCode;
  1280. else
  1281. deptuser += it.F_UserCode;
  1282. }
  1283. }
  1284. return deptuser;
  1285. }
  1286. /// <summary>
  1287. /// 市场管理科 和质量管理科可以看到整个事业部的工单
  1288. /// </summary>
  1289. /// <param name="deptid"></param>
  1290. /// <param name="pdeptid"></param>
  1291. /// <returns></returns>
  1292. public string GetAllDepts(int deptid)
  1293. {
  1294. string sql = " F_State=1 ";
  1295. string dptcode = departmentBLL.GetModel(deptid).F_ParentCode;
  1296. string arrsql = " select F_DeptId from T_Sys_Department where F_DeptCode LIKE '" + dptcode + "%' ";
  1297. var deptlist = departmentBLL.GetModelList(sql).Select(p => p.F_DeptId).ToArray();
  1298. if (deptlist.Count() > 0)
  1299. return string.Join(",", deptlist);
  1300. else return "";
  1301. }
  1302. /// <summary>
  1303. /// 市场管理科 和质量管理科可以看到整个事业部的工单
  1304. /// </summary>
  1305. /// <param name="deptid"></param>
  1306. /// <returns></returns>
  1307. public string GetDeptAllWorkOrderID(int deptid)
  1308. {
  1309. string sql = " ";
  1310. string dptcode = departmentBLL.GetModel(deptid).F_ParentCode;
  1311. string arrsql = $"select F_DeptId from T_Sys_Department where F_DeptCode LIKE '" + dptcode + "%' ";
  1312. string ua = $"select F_UserCode from T_Sys_UserAccount where F_DeptId in ( " + arrsql + ") ";
  1313. sql = "select F_WoID from T_Wo_WorkOrderItem_New where (F_CreateUser in(" + ua + ") or F_NextDept in(" + arrsql + "))";
  1314. return sql;
  1315. }
  1316. /// <summary>
  1317. /// 高层可以看到本事业部的所有工单
  1318. /// </summary>
  1319. /// <param name="deptid"></param>
  1320. /// <returns></returns>
  1321. public string judgmentDept(int deptid)
  1322. {
  1323. string deptcode = "";
  1324. string sql = "";
  1325. if (CirculMarket(deptid, 11))
  1326. {
  1327. deptcode = "|0|1|11|";
  1328. }
  1329. else if (CirculMarket(deptid, 14))
  1330. {
  1331. deptcode = "|0|1|14|";
  1332. }
  1333. else if (CirculMarket(deptid, 15))
  1334. {
  1335. deptcode = "|0|1|15|";
  1336. }
  1337. else if (CirculMarket(deptid, 16))
  1338. {
  1339. deptcode = "|0|1|16|";
  1340. }
  1341. else if (CirculMarket(deptid, 18))
  1342. {
  1343. deptcode = "|0|1|18|";
  1344. }
  1345. else if (CirculMarket(deptid, 20))
  1346. {
  1347. deptcode = "|0|1|20|";
  1348. }
  1349. if (!string.IsNullOrEmpty(deptcode))
  1350. {
  1351. string arrsql = $"select F_DeptId from T_Sys_Department where F_DeptCode LIKE '" + deptcode + "%' ";
  1352. string ua = $"select F_UserCode from T_Sys_UserAccount where F_DeptId in ( " + arrsql + ") ";
  1353. sql = "select F_WoID from T_Wo_WorkOrderItem_New where (F_CreateUser in(" + ua + ") or F_NextDept in(" + arrsql + "))";
  1354. }
  1355. return sql;
  1356. }
  1357. /// <summary>
  1358. /// 找到事业部中的高层
  1359. /// </summary>
  1360. /// <param name="deptid"></param>
  1361. /// <returns></returns>
  1362. public int GetGCDept(int deptid)
  1363. {
  1364. string deptcode = "";
  1365. string namelike = "总经理";
  1366. int gcdeptid = 0;
  1367. if (CirculMarket(deptid, 11))
  1368. {
  1369. deptcode = "|0|1|11|";
  1370. }
  1371. else if (CirculMarket(deptid, 14))
  1372. {
  1373. deptcode = "|0|1|14|";
  1374. }
  1375. else if (CirculMarket(deptid, 15))
  1376. {
  1377. deptcode = "|0|1|15|";
  1378. }
  1379. else if (CirculMarket(deptid, 16))
  1380. {
  1381. deptcode = "|0|1|16|";
  1382. }
  1383. else if (CirculMarket(deptid, 18))
  1384. {
  1385. deptcode = "|0|1|18|";
  1386. }
  1387. else if (CirculMarket(deptid, 20))
  1388. {
  1389. deptcode = "|0|1|20|";
  1390. }
  1391. if (!string.IsNullOrEmpty(deptcode))
  1392. {
  1393. var deptmodel = departmentBLL.GetModel(deptid);
  1394. if (deptmodel != null)
  1395. {
  1396. if (deptmodel.F_DeptCode.Contains("|0|1|14|423|"))
  1397. {
  1398. deptcode = "|0|1|14|423|";
  1399. namelike = "高层";
  1400. }
  1401. }
  1402. var dept = departmentBLL.GetModelList($" F_DeptCode LIKE '" + deptcode + "%' and F_DeptName like '%" + namelike + "%'").FirstOrDefault();
  1403. if (dept != null)
  1404. gcdeptid = dept.F_DeptId;
  1405. }
  1406. return gcdeptid;
  1407. }
  1408. /// <summary>
  1409. ///综合查询列表
  1410. /// </summary>
  1411. 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,
  1412. string country, string township, string category, string salebase, string touser,string question,string question1,string question2, int source = 0, int state = -1, int type = 0, int pageindex = 1, int pagesize = 10)
  1413. {
  1414. if (!string.IsNullOrEmpty(OpenId))
  1415. {
  1416. // Model.T_Sys_UserAccount ua = userAccountBLL.GetModel(userId);
  1417. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  1418. // if (ua == null)
  1419. // {
  1420. // return Error("你的账号已在别处登录,你确定要再次登录吗?");
  1421. // }
  1422. string sql = $" and F_IsDelete=0";
  1423. DataTable dt = new DataTable();
  1424. #region 筛选条件
  1425. if (type > 0 && type < 6)//工单类型
  1426. sql += $" and F_Type=" + type;
  1427. if (state >= 0)//
  1428. {
  1429. if (state == 5)
  1430. {
  1431. sql += $" and F_State in (2,3,4,5)";
  1432. }
  1433. else if (state == 6)
  1434. {
  1435. sql += $" and F_State in (11)";
  1436. sql += $" and F_IsVisit=" + 1; ;
  1437. sql += $"and F_DealType != '当即办理' and F_VisitBy != ''";
  1438. }
  1439. else if (state == 10)
  1440. {
  1441. sql += $" and F_State in (10,11)";
  1442. }
  1443. else if (state == 12)
  1444. {
  1445. sql += $" and F_State=" + (int)EnumWorkOrderState.finish + " and F_IsVisit = '" + "1" + "' ";
  1446. }
  1447. else
  1448. {
  1449. sql += $" and F_State=" + state;
  1450. }
  1451. }
  1452. if (source > 0)//工单来源
  1453. {
  1454. if (source == 1)
  1455. sql += $" and F_Source in (1,'')";
  1456. else
  1457. sql += $" and F_Source='" + source + "'";
  1458. }
  1459. if (!string.IsNullOrWhiteSpace(createby))//创建人
  1460. {
  1461. sql += $" and F_CustomerID in(select F_CustomerCode from T_Cus_CustomerBaseNew where F_Salesman like '%" + createby + "%' and F_IsDelete =0) ";
  1462. }
  1463. if (!string.IsNullOrWhiteSpace(createtel))//创建人
  1464. {
  1465. sql += $" and F_CustomerID in(select F_CustomerCode from T_Cus_CustomerBaseNew where F_SalesPhone like '%" + createtel + "%' and F_IsDelete =0) ";
  1466. }
  1467. if (!string.IsNullOrWhiteSpace(description))//问题描述
  1468. sql += $" and F_Description like '%" + description.Trim() + "%'";
  1469. if (!string.IsNullOrWhiteSpace(createby))//创建人
  1470. sql += $" and F_CreateBy like '%" + createby.Trim() + "%'";
  1471. if (!string.IsNullOrWhiteSpace(touser))//参与人
  1472. sql += $" and F_DealBy like '%" + touser.Trim() + "%'";
  1473. if (!string.IsNullOrWhiteSpace(code))//工单编号
  1474. sql += $" and F_WorkOrderCode like '%" + code.Trim() + "%'";
  1475. if (!string.IsNullOrEmpty(question2))
  1476. {
  1477. string squsdf = string.Format("'{0}'", question2.Replace(",", "','"));
  1478. var QuestionManage = quesBLL.GetModelList("F_QuestionName in (" + squsdf + ")");
  1479. if (QuestionManage != null)
  1480. {
  1481. if (QuestionManage.FirstOrDefault().F_Type == EnumWOType.Complaint.ToString())
  1482. {
  1483. string queststrs = string.Format("'{0}'", string.Join(",", QuestionManage.Select(T => T.F_Id)).Replace(",", "','"));
  1484. sql += $" and T_Wo_WorkOrder.F_QuestionType in (" + queststrs + ")"; ;
  1485. }
  1486. }
  1487. //
  1488. }
  1489. else if (!string.IsNullOrEmpty(question1))
  1490. {
  1491. var QuestionManage = quesBLL.GetModelList("F_QuestionName='" + question1 + "'").FirstOrDefault();
  1492. if (QuestionManage != null)
  1493. {
  1494. if (QuestionManage.F_Type == EnumWOType.Complaint.ToString())
  1495. {
  1496. sql += $" and T_Wo_WorkOrder.F_QuestionType in ('" + GetComplaint("'" + question1 + "'", 1) + "')"; ;
  1497. }
  1498. }
  1499. }
  1500. else if (!string.IsNullOrEmpty(question))
  1501. {
  1502. var QuestionManage = quesBLL.GetModelList("F_QuestionName='" + question + "'").FirstOrDefault();
  1503. if (QuestionManage != null)
  1504. {
  1505. if (QuestionManage.F_Type == EnumWOType.Complaint.ToString())
  1506. {
  1507. sql += $" and T_Wo_WorkOrder.F_QuestionType in ('" + GetComplaint("'" + question + "'", 0) + "')"; ;
  1508. }
  1509. else
  1510. sql += $" and (T_Wo_WorkOrder.F_QuestionType ='{ QuestionManage.F_Id }' or T_Wo_WorkOrder.F_QuestionType='{question}')"; ;
  1511. }
  1512. }
  1513. if (!string.IsNullOrWhiteSpace(keywords))//关键字搜索
  1514. {
  1515. var QuestionManage = quesBLL.GetModelList("F_QuestionName like '%" + keywords + "%' and F_IsDelete=0");
  1516. if (QuestionManage != null)
  1517. {
  1518. if (QuestionManage.FirstOrDefault().F_Type == EnumWOType.Complaint.ToString())
  1519. {
  1520. if (QuestionManage.FirstOrDefault().F_Label == "3")
  1521. {
  1522. string queststrs = string.Format("'{0}'", string.Join(",", QuestionManage.Select(T => T.F_Id)).Replace(",", "','"));
  1523. sql += $" and T_Wo_WorkOrder.F_QuestionType in (" + queststrs + ")";
  1524. }
  1525. else if (QuestionManage.FirstOrDefault().F_Label == "2")
  1526. {
  1527. sql += $" and T_Wo_WorkOrder.F_QuestionType in ('" + GetComplaint(keywords, 1) + "')"; ;
  1528. }
  1529. else
  1530. {
  1531. sql += $" and T_Wo_WorkOrder.F_QuestionType in ('" + GetComplaint(keywords, 0) + "')"; ;
  1532. }
  1533. }
  1534. else
  1535. {
  1536. 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 + "%')";
  1537. }
  1538. }
  1539. }
  1540. //sql += $" and ( F_QuestionType like '%" + keywords.Trim()
  1541. // + "%' or F_ZX_Area like '%" + keywords.Trim() + "%' or F_ZX_Branch like '%" + keywords.Trim()
  1542. // + "%' or F_CusName like '%" + keywords.Trim() + "%'or F_CusPhone like '%" + keywords.Trim() + "%') ";
  1543. if (!string.IsNullOrWhiteSpace(cusname))//客户姓名
  1544. sql += $" and F_CusName like '%" + cusname.Trim() + "%'";
  1545. if (!string.IsNullOrWhiteSpace(cusphone))//客户电话
  1546. sql += $" and F_CusPhone like '%" + cusphone.Trim() + "%'";
  1547. if (!string.IsNullOrWhiteSpace(companyname))//公司名称
  1548. sql += $" and F_CompanyName like '%" + companyname.Trim() + "%'";
  1549. if (!string.IsNullOrWhiteSpace(category))//产品名称
  1550. sql += $" and F_TS_Category like '%" + category.Trim() + "%'";
  1551. if (!string.IsNullOrWhiteSpace(salebase))//销售基地
  1552. sql += $" and F_SalesBase like '%" + salebase.Trim() + "%'";
  1553. if (!string.IsNullOrWhiteSpace(province))//省
  1554. sql += $" and F_IncidentProvince like '%" + province.Trim() + "%'";
  1555. if (!string.IsNullOrWhiteSpace(city))//市
  1556. sql += $" and F_IncidentCity like '%" + city.Trim() + "%'";
  1557. if (!string.IsNullOrWhiteSpace(country))//县
  1558. sql += $" and F_IncidentCountry like '%" + country.Trim() + "%'";
  1559. if (!string.IsNullOrWhiteSpace(township))//乡
  1560. sql += $" and F_IncidentTownship like '%" + township.Trim() + "%'";
  1561. if (ua != null)
  1562. {
  1563. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  1564. if (ro.F_RoleCode == "QTJS" || ro.F_RoleCode == "YWY")
  1565. {
  1566. sql += $" and F_CreateBy like '%" + ua.F_UserCode.Trim() + "%'";
  1567. }
  1568. else if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "BLRY" || ro.F_RoleCode == "ZG" || ro.F_RoleCode == "GC")
  1569. {
  1570. string markdepts = "37,57,74,88,268,295,339,422,213,427,433,424";
  1571. string qualdepts = "12,36,295,245";
  1572. string detpid = "" + ua.F_DeptId;
  1573. var deparmentlist = new List<Model.T_Sys_Department>();
  1574. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  1575. if (dModel != null)
  1576. {
  1577. #region 工单查询- 综合查询模块,权限增加,市场部和质管部可以看到事业部所有的工单,包含未经办的 20220519
  1578. if (markdepts.Contains(ua.F_DeptId.ToString()) || qualdepts.Contains(ua.F_DeptId.ToString()))
  1579. {
  1580. //detpid += "," + GetAllDepts(ua.F_DeptId);
  1581. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptAllWorkOrderID(ua.F_DeptId) + ") ";
  1582. }
  1583. #endregion
  1584. #region 高层可以看到本事业部的所有工单
  1585. else if (ro.F_RoleCode == "GC")
  1586. {
  1587. string strsq = judgmentDept(ua.F_DeptId);
  1588. if (!string.IsNullOrEmpty(strsq))
  1589. {
  1590. sql += $" and T_Wo_WorkOrder.F_ID in ( " + strsq + ") ";
  1591. }
  1592. else
  1593. {
  1594. sql += $" and 1!=1";
  1595. }
  1596. }
  1597. #endregion
  1598. else
  1599. {
  1600. if (dModel.F_Layer == 1)
  1601. {
  1602. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  1603. if (deparmentlist.Count > 0)
  1604. {
  1605. foreach (var it in deparmentlist)
  1606. {
  1607. if (detpid != "")
  1608. {
  1609. detpid += "," + it.F_DeptId;
  1610. }
  1611. else
  1612. {
  1613. detpid = "" + it.F_DeptId;
  1614. }
  1615. }
  1616. }
  1617. }
  1618. else
  1619. {
  1620. detpid = ua.F_DeptId.ToString();
  1621. }
  1622. #region 人员更换部门后,仍然需要查看、处理自己原部门的历史工单 20220307
  1623. //if (!string.IsNullOrEmpty(ua.F_Origdepts))
  1624. //{
  1625. // detpid += "," + ua.F_Origdepts;
  1626. //}
  1627. #endregion
  1628. if (state >= 0)
  1629. {
  1630. if (GetDeptWorkOrderID(detpid, "" + state + "") != "")
  1631. {
  1632. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid, "" + state + "") + ") ";
  1633. }
  1634. else
  1635. {
  1636. return Success("暂无工单"); ;
  1637. }
  1638. }
  1639. else
  1640. {
  1641. if (GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.neworder + ", " + (int)EnumWorkOrderState.assign + "," +
  1642. (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.finish
  1643. + "," + (int)EnumWorkOrderState.evaluate + "") != "")
  1644. {
  1645. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.neworder + ", " + (int)EnumWorkOrderState.assign + "," +
  1646. (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.finish
  1647. + "," + (int)EnumWorkOrderState.evaluate + "") + ") ";
  1648. }
  1649. else
  1650. {
  1651. return Success("暂无工单"); ;
  1652. }
  1653. }
  1654. }
  1655. }
  1656. else
  1657. {
  1658. return Error("加载失败");
  1659. }
  1660. }
  1661. }
  1662. else
  1663. {
  1664. return Error("无操作权限");
  1665. }
  1666. #endregion
  1667. int recordCount = 0;
  1668. if (!string.IsNullOrWhiteSpace(sql))
  1669. {
  1670. dt = BLL.PagerBLL.GetListPager(
  1671. "T_Wo_WorkOrder",
  1672. "F_ID",
  1673. "*",
  1674. sql,
  1675. "ORDER BY T_Wo_WorkOrder.F_ID desc",
  1676. pagesize,
  1677. pageindex,
  1678. true,
  1679. out recordCount);
  1680. }
  1681. List<Model.T_Wo_WorkOrder> modlelist = new BLL.T_Wo_WorkOrder().DataTableToList(dt);
  1682. if (modlelist.Count > 0)
  1683. {
  1684. List<WorkOrderNewInput> Input =modeltooip(modlelist, ua);
  1685. var obj = new
  1686. {
  1687. state = "success",
  1688. message = "成功",
  1689. rows = Input,
  1690. total = recordCount
  1691. };
  1692. return Content(obj.ToJson()); ;
  1693. }
  1694. else
  1695. {
  1696. return Success("暂无工单"); ;
  1697. }
  1698. }
  1699. else
  1700. {
  1701. return Error("无操作权限!");
  1702. }
  1703. }
  1704. /// <summary>
  1705. /// 获取问题类别
  1706. /// </summary>
  1707. /// <returns></returns>
  1708. public string GetComplaint(string msg, int type = 0)
  1709. {
  1710. string str = "";
  1711. string str1 = "";
  1712. string str3 = "";
  1713. if (type == 0)
  1714. {
  1715. str1 = " select F_Id from T_Wo_QuestionManage where F_QuestionName like '%"+ msg +"%'";
  1716. str3 = " select F_Id from T_Wo_QuestionManage where F_ParentId in(" + str1 + ")";
  1717. }
  1718. else if (type == 1)
  1719. {
  1720. str3 = " select F_Id from T_Wo_QuestionManage where F_QuestionName like '%" + msg + "%'";
  1721. }
  1722. var dept = quesBLL.GetModelList("F_ParentId in(" + str3 + ")");
  1723. if (dept != null)
  1724. {
  1725. foreach (var it in dept)
  1726. {
  1727. if (str != "")
  1728. str += "','" + it.F_Id.ToString();
  1729. else
  1730. str += it.F_Id.ToString();
  1731. }
  1732. }
  1733. // string str4 = " select F_Id from T_Wo_QuestionManage where F_ParentId in(" + str3 + ")";
  1734. return str;
  1735. }
  1736. /// <summary>
  1737. /// 根据部门获取工单号
  1738. /// </summary>
  1739. /// <returns></returns>
  1740. public string GetDeptWorkOrderID(string user)
  1741. {
  1742. string sql = " ";
  1743. string ua = "";
  1744. DataTable dt = new DataTable();
  1745. if (user != "")
  1746. {
  1747. sql += " and F_DeptId in ( " + user + ") ";
  1748. }
  1749. int recordCount;
  1750. dt = BLL.PagerBLL.GetListPager(
  1751. "T_Sys_UserAccount",
  1752. "F_UserId",
  1753. "*",
  1754. sql,
  1755. "ORDER BY F_UserId desc",
  1756. 10000,
  1757. 1,
  1758. true,
  1759. out recordCount);
  1760. List<Model.UserAccount> modelList = new BLL.UserAccount().DataTableToList(dt);
  1761. if (modelList != null)
  1762. {
  1763. foreach (var it in modelList)
  1764. {
  1765. if (ua != "")
  1766. ua += "," + it.F_UserCode;
  1767. else
  1768. ua += it.F_UserCode;
  1769. }
  1770. }
  1771. string str = string.Empty;
  1772. str = "select F_WoID from T_Wo_WorkOrderItem_New where (F_CreateUser in(" + ua + ") or F_NextDept in(" + user + "))"
  1773. ;
  1774. return str;
  1775. }
  1776. /// <summary>
  1777. /// 根据部门获取工单号
  1778. /// </summary>
  1779. /// <returns></returns>
  1780. public string GetDeptWorkOrderID(string user, string F_ItemType)
  1781. {
  1782. string sql = " ";
  1783. string ua = "";
  1784. DataTable dt = new DataTable();
  1785. if (user != "")
  1786. {
  1787. sql += " and F_DeptId in ( " + user + ") ";
  1788. }
  1789. int recordCount;
  1790. dt = BLL.PagerBLL.GetListPager(
  1791. "T_Sys_UserAccount",
  1792. "F_UserId",
  1793. "*",
  1794. sql,
  1795. "ORDER BY F_UserId desc",
  1796. 10000,
  1797. 1,
  1798. true,
  1799. out recordCount);
  1800. List<Model.UserAccount> modelList = new BLL.UserAccount().DataTableToList(dt);
  1801. if (modelList != null)
  1802. {
  1803. foreach (var it in modelList)
  1804. {
  1805. if (ua != "")
  1806. ua += "," + it.F_UserCode;
  1807. else
  1808. ua += it.F_UserCode;
  1809. }
  1810. }
  1811. string str = string.Empty;
  1812. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_OptType in(" + F_ItemType + ")"
  1813. + " and "
  1814. + "F_CreateUser in(" + ua + ")"
  1815. ;
  1816. return str;
  1817. }
  1818. /// <summary>
  1819. /// 获取完结审批的工单
  1820. /// </summary>
  1821. /// <param name="usercode"></param>
  1822. /// <returns></returns>
  1823. public string GetOverWo(string usercode)
  1824. {
  1825. string str = "";
  1826. 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 in (" + (int)EnumItemOpt.end + "," + (int)EnumItemOpt.deal + ") and F_CreateUser='" + usercode + "'";
  1827. return str;
  1828. }
  1829. /// <summary>
  1830. /// 获取待完成的工单编号
  1831. /// </summary>
  1832. /// <returns></returns>
  1833. public string GetDWCWorkOrderID(string user, int deptid, int flag = 1)
  1834. {
  1835. string str = string.Empty;
  1836. string strsql = "";
  1837. if (flag == 1)
  1838. {
  1839. strsql = "and F_Type in(1,3)";
  1840. }
  1841. else if (flag == 2)
  1842. {
  1843. strsql = "and F_Type in(2,3)";
  1844. }
  1845. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_ItemType=" + (int)EnumItemType.deal
  1846. + " and "
  1847. + "F_WoState in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.revoke + ") and (F_NextUser like '%" + user + "%' or F_NextDept='" + deptid + "') "//办理中和接单状态的操作人,退回下一步操作人,撤回下一步操作人
  1848. + " and isnull(F_IsUsed,'0')='0'";
  1849. return str;
  1850. }
  1851. public string GetHApproval(string user)
  1852. {
  1853. string str = string.Empty;
  1854. 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";
  1855. return str;
  1856. }
  1857. /// <summary>
  1858. /// 获取部门待完成的工单编号
  1859. /// </summary>
  1860. /// <returns></returns>
  1861. public string GetDeptWorkOrderID(int deptid, string user, int flag = 1)
  1862. {
  1863. string str = string.Empty;
  1864. string deptuser = string.Empty;
  1865. var dept = userAccountBLL.GetModelList("F_DeptId=" + deptid);
  1866. if (dept != null)
  1867. {
  1868. foreach (var it in dept)
  1869. {
  1870. //if (it.F_UserCode != user)
  1871. //{
  1872. if (deptuser != "")
  1873. deptuser += "','" + it.F_UserCode;
  1874. else
  1875. deptuser += it.F_UserCode;
  1876. //}
  1877. }
  1878. }
  1879. if (!string.IsNullOrEmpty(deptuser))
  1880. {
  1881. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_ItemType=" + (int)EnumItemType.deal
  1882. + " and isnull(F_IsUsed,'0')='0'" + " and "
  1883. + " F_WoState in(" + (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.abreback + ") and (F_NextUser in('" + deptuser + "') or F_NextDept =" + deptid + ") ";//办理中和接单状态的操作人
  1884. }
  1885. else
  1886. {
  1887. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_ItemType=" + (int)EnumItemType.deal
  1888. + " and F_WoState in(" + (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.abreback + ") and F_NextDept =" + deptid + " "//办理中和接单状态的操作人
  1889. + " and isnull(F_IsUsed,'0')='0'";
  1890. }
  1891. return str;
  1892. }
  1893. /// <summary>
  1894. /// 获取工单数量
  1895. /// </summary>
  1896. /// <returns></returns>
  1897. public ActionResult GetWorkCount(string OpenId)
  1898. {
  1899. if (string .IsNullOrEmpty (OpenId) )
  1900. return Success ("你的账号已在别处登录,你确定要再次登录吗?");
  1901. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  1902. if (ua == null)
  1903. {
  1904. return Success("你的账号已在别处登录,你确定要再次登录吗?");
  1905. }
  1906. DataTable dt = new DataTable();
  1907. #region 筛选条件
  1908. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  1909. string uwhere = " ";
  1910. string sql = "";
  1911. //if (!Refresh())
  1912. //{
  1913. // return Error("查询失败");
  1914. //}
  1915. Task.Run(() => Refresh());
  1916. 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;
  1917. for (int i = 0; i <= 9; i++)
  1918. {
  1919. switch (i)
  1920. {
  1921. case 0://待接单的
  1922. sql = "";
  1923. sql += $" F_IsDelete=0";
  1924. string strsql = GetDeptWorkOrderID(ua.F_DeptId, ua.F_UserCode, ua.F_Flag);
  1925. if (strsql != "")
  1926. {
  1927. //if (ua.F_Flag == 1)
  1928. //{
  1929. sql += $" and (F_State in(" + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.assign + ") ";
  1930. //}
  1931. //else if (ua.F_Flag == 2)
  1932. //{
  1933. sql += $" or F_State2 in(" + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.assign + ")) ";
  1934. //}
  1935. sql += " and T_Wo_WorkOrder.F_ID in ( " + strsql + ")";
  1936. }
  1937. else
  1938. {
  1939. DJD = 0;
  1940. break;
  1941. }
  1942. DJD = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//接单
  1943. break;
  1944. case 1://待完成的(待处理)
  1945. sql = "";
  1946. sql += $" F_IsDelete=0";
  1947. string dealstr = GetDWCWorkOrderID(ua.F_UserCode, ua.F_DeptId);
  1948. if (!string.IsNullOrEmpty(dealstr))
  1949. {
  1950. //if (ua.F_Flag == 1)
  1951. //{
  1952. sql += " and ((F_State in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.revoke + ")";
  1953. //}
  1954. //else if (ua.F_Flag == 2)
  1955. //{
  1956. sql += " or F_State2 in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.revoke + "))";
  1957. //}
  1958. sql += " and T_Wo_WorkOrder.F_ID in ( " + dealstr + ") ";
  1959. if (!string.IsNullOrEmpty(GetRevokeWo(ua.F_UserCode)))
  1960. {
  1961. sql += " or ((F_State=" + (int)EnumWorkOrderState.assign + " or F_State2=" + (int)EnumWorkOrderState.assign + ") and T_Wo_WorkOrder.F_ID in (" + GetRevokeWo(ua.F_UserCode) + ")))";
  1962. }
  1963. else
  1964. {
  1965. sql += $")";
  1966. }
  1967. }
  1968. else
  1969. {
  1970. DCL = 0;
  1971. break;
  1972. }
  1973. DCL = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//已接单
  1974. break;
  1975. case 2://已完成的
  1976. sql = "";
  1977. sql += $" F_IsDelete=0";
  1978. //sql += " and (F_State in(10,11) or F_State2 in(10,11))";
  1979. 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))))";
  1980. sql += " and F_DealBy in(" + GetDeptUserCode(ua.F_DeptId) + ") ";
  1981. sql += " or T_Wo_WorkOrder.F_ID in (" + GetOverWo(ua.F_UserCode) + "))";
  1982. // sql += " and F_State in(10,11) and F_DealBy = '" + ua.F_UserCode + "' ";
  1983. YCL = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//已完成的
  1984. break;
  1985. case 3://待审批
  1986. sql = "";
  1987. sql += $" F_IsDelete=0";
  1988. if (ro.F_RoleCode == "GC")
  1989. {
  1990. if (GetHApproval(ua.F_UserCode) != "")
  1991. {
  1992. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetHApproval(ua.F_UserCode) + ") "; ;
  1993. }
  1994. }
  1995. else
  1996. {
  1997. GCDBL = 0;
  1998. break; ;
  1999. }
  2000. GCDBL = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//高层待审批
  2001. break;
  2002. case 4://已审批
  2003. sql = "";
  2004. sql += $" F_IsDelete=0";
  2005. if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "GC")
  2006. {
  2007. if (GetApprovedOrderID(ua.F_UserCode) != "")
  2008. {
  2009. sql += $" and F_ID in ( " + GetApprovedOrderID(ua.F_UserCode) + ") "; ;
  2010. }
  2011. else
  2012. {
  2013. YBL = 0;
  2014. break; ;
  2015. }
  2016. }
  2017. else
  2018. {
  2019. YBL = 0;
  2020. break; ;
  2021. }
  2022. YBL = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//已审批
  2023. break;
  2024. case 5://待审批
  2025. sql = "";
  2026. sql += $" F_IsDelete=0";
  2027. if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL")
  2028. {
  2029. if (GetApprovalOrderID(ua, OpenId, ro.F_RoleCode) != "")
  2030. {
  2031. sql += " and T_Wo_WorkOrder.F_ID in ( " + GetApprovalOrderID(ua, OpenId, ro.F_RoleCode) + ") ";
  2032. }
  2033. else
  2034. {
  2035. DSP = 0;
  2036. break; ;
  2037. }
  2038. }
  2039. else
  2040. {
  2041. DSP = 0;
  2042. break; ;
  2043. }
  2044. DSP = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//待审批
  2045. break;
  2046. case 6:
  2047. sql = "";
  2048. sql += $" F_IsDelete=0";
  2049. sql += $" and F_CreateBy ='" + ua.F_UserCode + "'";
  2050. YCD = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//业务员已创单
  2051. break;
  2052. case 7://超期
  2053. sql = "";
  2054. sql += $" F_IsDelete=0";
  2055. //sql += $" and (F_IsOver=1 or F_IsOver=2)";
  2056. //sql += $" and F_State !=" + 11;
  2057. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "JDYBZZX" || ro.F_RoleCode == "XTGLY")
  2058. {
  2059. sql += $" and((F_IsOver in(1,3) and F_State !=11) or ( F_IsOver in (2,3) and F_State2!=11))";
  2060. }
  2061. else if (ua.F_Flag == 1)
  2062. {
  2063. sql += $" and F_IsOver in (1,3)";
  2064. sql += $" and F_State !=" + 11;
  2065. }
  2066. else if (ua.F_Flag == 2)
  2067. {
  2068. sql += $" and F_IsOver in (2,3)";
  2069. sql += $" and F_State2 !=" + 11;
  2070. }
  2071. #region 退换货的工单按未超期处理 20220302
  2072. sql += $" and F_ID not in (select F_ID from T_Wo_WorkOrder where F_SC_PreliminaryOpinion='退换货')";
  2073. #endregion
  2074. if (ro.F_RoleCode == "YWY" || ro.F_RoleCode == "BLRY")
  2075. {
  2076. sql += $" and F_DealBy like '%" + ua.F_UserCode.Trim() + "%'";
  2077. }
  2078. else if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "ZG")
  2079. {
  2080. string detpid = "" + ua.F_DeptId;
  2081. var deparmentlist = new List<Model.T_Sys_Department>();
  2082. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  2083. if (dModel != null)
  2084. {
  2085. if (dModel.F_Layer == 1)
  2086. {
  2087. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  2088. if (deparmentlist.Count > 0)
  2089. {
  2090. foreach (var it in deparmentlist)
  2091. {
  2092. if (detpid != "")
  2093. {
  2094. detpid += "," + it.F_DeptId;
  2095. }
  2096. else
  2097. {
  2098. detpid = "" + it.F_DeptId; ;
  2099. }
  2100. }
  2101. }
  2102. }
  2103. else
  2104. {
  2105. detpid = ua.F_DeptId.ToString();
  2106. }
  2107. if (GetDeptWorkOrderID(detpid) != "")
  2108. {
  2109. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid) + ") "; ;
  2110. }
  2111. else
  2112. {
  2113. CQGD = 0;
  2114. break; ;
  2115. }
  2116. }
  2117. else
  2118. {
  2119. CQGD = 0;
  2120. break; ;
  2121. }
  2122. }
  2123. else if (ro.F_RoleCode == "QTJS")
  2124. {
  2125. CQGD = 0;
  2126. break; ;
  2127. }
  2128. CQGD = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//超期
  2129. break;
  2130. case 8://综合查询
  2131. sql = "";
  2132. sql += $" F_IsDelete=0";
  2133. if (ro.F_RoleCode == "QTJS" || ro.F_RoleCode == "YWY")
  2134. sql += $" and F_CreateBy like '%" + ua.F_UserCode.Trim() + "%'";
  2135. else if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "BLRY" || ro.F_RoleCode == "ZG" || ro.F_RoleCode == "GC")
  2136. {
  2137. string markdepts = "37,57,74,88,268,295,339,422,213,427,433,424";
  2138. string qualdepts = "12,36,295,245";
  2139. string detpid = "" + ua.F_DeptId;
  2140. var deparmentlist = new List<Model.T_Sys_Department>();
  2141. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  2142. if (dModel != null)
  2143. {
  2144. #region 工单查询- 综合查询模块,权限增加,市场部和质管部可以看到事业部所有的工单,包含未经办的 20220519
  2145. if (markdepts.Contains(ua.F_DeptId.ToString()) || qualdepts.Contains(ua.F_DeptId.ToString()))
  2146. {
  2147. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptAllWorkOrderID(ua.F_DeptId) + ") ";
  2148. }
  2149. #endregion
  2150. #region 高层可以看到本事业部的所有工单
  2151. else if (ro.F_RoleCode == "GC")
  2152. {
  2153. string strsq = judgmentDept(ua.F_DeptId);
  2154. if (!string.IsNullOrEmpty(strsq))
  2155. {
  2156. sql += $" and T_Wo_WorkOrder.F_ID in ( " + strsq + ") ";
  2157. }
  2158. else
  2159. {
  2160. sql += $" and 1!=1";
  2161. }
  2162. }
  2163. #endregion
  2164. else
  2165. {
  2166. if (dModel.F_Layer == 1)
  2167. {
  2168. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  2169. if (deparmentlist.Count > 0)
  2170. {
  2171. foreach (var it in deparmentlist)
  2172. {
  2173. if (detpid != "")
  2174. {
  2175. detpid += "," + it.F_DeptId;
  2176. }
  2177. else
  2178. {
  2179. detpid = "" + it.F_DeptId;
  2180. }
  2181. }
  2182. }
  2183. }
  2184. else
  2185. {
  2186. detpid = ua.F_DeptId.ToString();
  2187. }
  2188. #region 人员更换部门后,仍然需要查看、处理自己原部门的历史工单 20220307
  2189. //if (!string.IsNullOrEmpty(ua.F_Origdepts))
  2190. //{
  2191. // detpid += "," + ua.F_Origdepts;
  2192. //}
  2193. #endregion
  2194. if (GetDeptWorkOrderID(detpid) != "")
  2195. {
  2196. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid) + ") ";
  2197. }
  2198. else
  2199. {
  2200. ZHCX = 0;
  2201. break;
  2202. }
  2203. }
  2204. }
  2205. else
  2206. {
  2207. ZHCX = 0;
  2208. break;
  2209. }
  2210. }
  2211. ZHCX = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;//综合查询
  2212. break;
  2213. case 9: //抄送工单列表
  2214. sql = "";
  2215. sql += $" F_IsDelete=0";
  2216. sql += $" and T_Wo_WorkOrder.F_ID in (select F_WorkOrderID from T_Wo_WorkCopy where F_SendCopyUser like '%{ua.F_UserCode}%'"
  2217. +$" or (F_Flag=1 and F_SendCopyDepts={ua.F_DeptId} )) ";
  2218. CSGD = new BLL.T_Wo_WorkOrder().GetModelList(sql).Count;
  2219. break;
  2220. }
  2221. }
  2222. #endregion
  2223. var obj = new
  2224. {
  2225. state = "success",
  2226. message = "成功",
  2227. DJD = DJD,//待接单
  2228. DCL = DCL,//已接单(待处理)
  2229. YCL = YCL,//已完成的
  2230. GCDBL = GCDBL,//高层待审批
  2231. YBL = YBL,//已审批
  2232. DSP = DSP,//待审批
  2233. YCD = YCD,//业务员已创单
  2234. TD = TD,//退单
  2235. CQGD = CQGD,//超期
  2236. YFP= YFP,
  2237. ZHCX= ZHCX , //综合查询
  2238. CSGD= CSGD
  2239. };
  2240. return Content(obj.ToJson()); ;
  2241. }
  2242. /// <summary>
  2243. /// 注解
  2244. /// </summary>
  2245. /// <param name="orderid"></param>
  2246. /// <param name="cont"></param>
  2247. /// <returns></returns>
  2248. public ActionResult Annotation(string OpenId, int orderid, string cont, int flag = 0)
  2249. {
  2250. //注解给超级管理员开通编辑删除修改权限 20220221
  2251. if (!string.IsNullOrEmpty(OpenId))
  2252. {
  2253. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  2254. if (ua != null)
  2255. {
  2256. string Annotationstr = "";
  2257. Model.T_Wo_WorkOrder model = woBLL .GetModel(orderid);
  2258. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  2259. //验证信息
  2260. if (model != null)
  2261. {
  2262. #region 添加注解表
  2263. //Model.T_Wo_AnnotationTab annotab = new T_Wo_AnnotationTab();
  2264. //annotab.F_Contents = cont;
  2265. //annotab.F_AnnotationPerson = ua.F_UserCode;
  2266. //annotab.F_CreateTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  2267. //annotab.F_Wocode = model.F_ID;
  2268. //new BLL.T_Wo_AnnotationTab().Add(annotab);
  2269. #endregion
  2270. //Annotationstr = cont + "-" + ua.F_UserName + "(" + ua.F_WorkNumber + ")" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2271. Annotationstr = ua.F_UserName + DateTime.Now.ToString("yyyy-MM-dd") + " " + cont + ";";
  2272. if (flag == 1)
  2273. {
  2274. model.F_Annotation = Annotationstr;
  2275. }
  2276. else
  2277. {
  2278. if (string.IsNullOrEmpty(model.F_Annotation))
  2279. {
  2280. model.F_Annotation = Annotationstr;
  2281. }
  2282. else
  2283. {
  2284. model.F_Annotation = model.F_Annotation + "\n" + Annotationstr;
  2285. }
  2286. }
  2287. var res = woBLL.Update(model);
  2288. if (res)
  2289. #region 增加注解通知市场部功能 20220216
  2290. {
  2291. string touser = "";
  2292. string strwhere = "";
  2293. string contens = "";
  2294. 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,424) order by F_CreateTime desc)";
  2295. var deptmodel = departmentBLL.GetModelList(strwhere).FirstOrDefault();
  2296. if (deptmodel != null)
  2297. {
  2298. var userlist = userAccountBLL.GetModelList("F_DeptId=" + deptmodel.F_DeptId);
  2299. if (userlist.Count > 0)
  2300. {
  2301. if (flag == 1)
  2302. contens = $" 修改注解,工单编号:" + model.F_WorkOrderCode + "";
  2303. //< span class="top_notices_con">系统维护管理员 修改注解, 工单编号 20220527152927398</span>
  2304. else
  2305. contens = $" 附加注解,工单编号:" + model.F_WorkOrderCode + "";
  2306. foreach (var item in userlist)
  2307. {
  2308. touser = item.F_UserCode; ;
  2309. Model.T_Msg_List msg = new Model.T_Msg_List();
  2310. msg.Type = (int)Model.MSGType.Annotation;
  2311. msg.ToUser = touser;
  2312. msg.ToID = (int)model.F_ID;
  2313. msg.Detail = $"<span class='top_notices_con'> " + ua.F_UserName + contens + "</span>" + "," + model.F_ID + "";
  2314. msg.State = 0;
  2315. msg.IsDel = 0;
  2316. msg.CreateDate = DateTime.Now;
  2317. msg.ReadDate = DateTime.Now;
  2318. new BLL.T_Msg_List().Add(msg);
  2319. //sendsysmsg(model, ua, touser, (int)model.F_ID, "增加注解");
  2320. }
  2321. }
  2322. }
  2323. return Success("注解成功");
  2324. }
  2325. #endregion
  2326. else
  2327. return Error("注解失败!");
  2328. }
  2329. return Error("工单不存在");
  2330. }
  2331. }
  2332. return Error("无操作权限");
  2333. }
  2334. /// <summary>
  2335. /// 抄送工单
  2336. /// </summary>
  2337. /// <param name="id"></param>
  2338. /// <param name="content"></param>
  2339. /// <param name="user"></param>
  2340. /// <returns></returns>
  2341. [WechatActionFilter]
  2342. public ActionResult SendCopy(string OpenId, int id = 0, string content = "", string users = "")
  2343. {
  2344. if (!string.IsNullOrEmpty(OpenId))
  2345. {
  2346. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  2347. if (id <= 0)
  2348. return Error("请选择工单");
  2349. var model = woBLL.GetModel(id);
  2350. if (string.IsNullOrEmpty(users))
  2351. return Error("请选择抄送部门");
  2352. JavaScriptSerializer Serializer = new JavaScriptSerializer(); //实例化⼀个能够序列化数据的类
  2353. List<CopyMessage> list = Serializer.Deserialize<List<CopyMessage>>(users);
  2354. if (model != null)
  2355. {
  2356. string userstr = "";
  2357. string deptmessage = "", deptname1 = "";
  2358. var dept1 = new BLL.T_Sys_Department().GetModel(ua.F_DeptId);
  2359. if (dept1 != null)
  2360. deptname1 = dept1.F_DeptName;
  2361. if (list != null && list.Count > 0)
  2362. {
  2363. foreach (var item in list)
  2364. {
  2365. string username = string.Empty;
  2366. var deptmodel = new BLL.T_Sys_Department().GetModel(Convert.ToInt32(item.deptid));
  2367. if (deptmodel == null)
  2368. return Error("抄送部门不存在!");
  2369. var clus = item.ucodelist;
  2370. Model.T_Wo_WorkCopy t_Wo_WorkCopy = new Model.T_Wo_WorkCopy();
  2371. if (clus.Count > 0)
  2372. {
  2373. t_Wo_WorkCopy.F_Flag = 0;
  2374. t_Wo_WorkCopy.F_SendCopyUser = string.Join(",", clus.ToArray());
  2375. }
  2376. else
  2377. {
  2378. t_Wo_WorkCopy.F_Flag = 1;
  2379. t_Wo_WorkCopy.F_SendCopyUser = "";
  2380. }
  2381. t_Wo_WorkCopy.F_WorkOrderID = model.F_ID;
  2382. t_Wo_WorkCopy.F_CreateOn = DateTime.Now;
  2383. t_Wo_WorkCopy.F_Content = content;
  2384. t_Wo_WorkCopy.F_CreateBy = ua.F_UserId.ToString();
  2385. t_Wo_WorkCopy.F_SendCopyOn = DateTime.Now;
  2386. t_Wo_WorkCopy.F_State = model.F_State;
  2387. t_Wo_WorkCopy.F_SendCopyDepts = Convert.ToInt32(item.deptid);
  2388. if (new BLL.T_Wo_WorkCopy().Add(t_Wo_WorkCopy) > 0)
  2389. {
  2390. #region 发送短信
  2391. int sms = 0;
  2392. if (clus.Count > 0)
  2393. {
  2394. foreach (var noticlus in clus)
  2395. {
  2396. var usermodel = new BLL.T_Sys_UserAccount().GetModel(noticlus);
  2397. username = string.IsNullOrEmpty(username) ? usermodel.F_UserName : username + "," + usermodel.F_UserName;
  2398. string[] mag = { };
  2399. if (!string.IsNullOrEmpty(usermodel.F_Mobile))
  2400. {
  2401. //SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, noticlus.F_Mobile.Trim());
  2402. //bool n = new SMSController().AddSmS(noticlus.F_Mobile.Trim(), "抄送工单", ua.F_UserId);
  2403. }
  2404. }
  2405. }
  2406. else
  2407. {
  2408. var usermodel = new BLL.T_Sys_UserAccount().GetModelList($"F_DeptId={Convert.ToInt32(item.deptid)}");
  2409. if (usermodel.Count > 0)
  2410. {
  2411. foreach (var user in usermodel)
  2412. {
  2413. username = string.IsNullOrEmpty(username) ? user.F_UserName : username + "," + user.F_UserName;
  2414. string[] mag = { };
  2415. if (!string.IsNullOrEmpty(user.F_Mobile))
  2416. {
  2417. //SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, noticlus.F_Mobile.Trim());
  2418. //bool n = new SMSController().AddSmS(noticlus.F_Mobile.Trim(), "抄送工单", ua.F_UserId);
  2419. }
  2420. }
  2421. }
  2422. }
  2423. #endregion
  2424. }
  2425. deptmessage = string.IsNullOrEmpty(deptmessage) ? deptmodel.F_DeptName + "-" + username : deptmessage + ";" + deptmodel.F_DeptName + "-" + username;
  2426. }
  2427. string message = "抄送工单给" + deptmessage;
  2428. if (!string.IsNullOrEmpty(content))
  2429. message += ",抄送内容:" + content;
  2430. 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);
  2431. return Success("抄送成功");
  2432. }
  2433. }
  2434. else
  2435. return Error("工单不存在");
  2436. }
  2437. return Error("无操作权限!");
  2438. }
  2439. /// <summary>
  2440. /// 审核工单
  2441. /// </summary>
  2442. public ActionResult GetApproval(string OpenId, long orderid, string AuditCont, int IsAudit = 0, int AuditState = 0, float overtime = 0, int sms = 0)
  2443. {
  2444. if (!string.IsNullOrEmpty(OpenId))
  2445. {
  2446. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  2447. if (ua != null)
  2448. {
  2449. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  2450. if (model != null)
  2451. {
  2452. //var itemlast = itembll.GetModelList(" F_WoID='" + model.F_ID + "' order by F_ID desc").FirstOrDefault();
  2453. //if (itemlast!=null )
  2454. // sms = (int)itemlast.F_IsSMS;
  2455. var res = Approval(OpenId, orderid, AuditCont, ua, model, overtime, sms, IsAudit, AuditState);
  2456. if (res)
  2457. return Success("审核成功");
  2458. else
  2459. return Error("审核失败");
  2460. }
  2461. else
  2462. return Error("工单不存在");
  2463. }
  2464. }
  2465. return Error("OpenId不能为空");
  2466. }
  2467. /// <summary>
  2468. /// 填写超时原因
  2469. /// </summary>
  2470. /// <param name="input"></param>
  2471. /// <returns></returns>
  2472. [WechatActionFilter]
  2473. public ActionResult Reasontimeout(string OpenId, long orderid, string cont)
  2474. {
  2475. if (!string.IsNullOrEmpty(OpenId))
  2476. {
  2477. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  2478. if (ua != null)
  2479. {
  2480. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  2481. //验证信息
  2482. if (model != null)
  2483. {
  2484. model.F_Reasontimeout = cont;
  2485. bool n = woBLL.Update(model);
  2486. if (n)
  2487. return Success("填写成功");
  2488. else
  2489. return Error("填写失败!");
  2490. }
  2491. return Error("工单不存在");
  2492. }
  2493. }
  2494. return Error("无操作权限");
  2495. }
  2496. /// <summary>
  2497. /// 审核工单
  2498. /// </summary>
  2499. [WechatActionFilter]
  2500. 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)
  2501. {
  2502. int res = 1;
  2503. string touser = ""; string tousername = "";
  2504. string opt = "审核";
  2505. #region 获取接收人
  2506. string deptname = "";
  2507. string deptmodelsname = "";
  2508. int wostate = 0;
  2509. var toussers = "";
  2510. int woflag = 0;
  2511. #region 上报
  2512. if (IsAudit != 0)
  2513. {
  2514. if (GetUser(OpenId) != null)
  2515. {
  2516. var user = GetUser(OpenId);
  2517. var deptmodel = departmentBLL.GetModel(user.F_DeptId);
  2518. var deptmodels = departmentBLL.GetModel(nowUser.F_DeptId);
  2519. if (deptmodel != null)
  2520. {
  2521. deptname = deptmodel.F_DeptName + "-";
  2522. }
  2523. if (deptmodels != null)
  2524. {
  2525. deptmodelsname = deptmodels.F_DeptName + "-";
  2526. }
  2527. 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();
  2528. if (itemlast != null)
  2529. {
  2530. toussers = itemlast.F_CreateUser;
  2531. if (sms == -1)
  2532. {
  2533. sms = (int)itemlast.F_IsSMS;
  2534. }
  2535. }
  2536. else
  2537. {
  2538. if (sms == -1)
  2539. {
  2540. sms = 0;
  2541. }
  2542. }
  2543. wostate = 16;
  2544. if (AuditState == 0)
  2545. {
  2546. opt = "同意上报";
  2547. 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);
  2548. 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);
  2549. if (userid <= 0 || uaid <= 0)
  2550. res = 0;
  2551. else
  2552. {
  2553. if (sms ==1&& !string .IsNullOrEmpty(user .F_Mobile ))
  2554. {
  2555. SendSms(model.F_Type, user.F_Mobile, nowUser.F_UserId);
  2556. }
  2557. }
  2558. }
  2559. else if (AuditState == 1)
  2560. {
  2561. opt = "驳回修订";
  2562. 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);
  2563. if (userid <= 0)
  2564. res = 0;
  2565. }
  2566. else
  2567. {
  2568. opt = "强制结案";
  2569. wostate = 11;
  2570. 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);
  2571. if (userid <= 0)
  2572. res = 0;
  2573. }
  2574. }
  2575. else
  2576. {
  2577. Model.T_Sys_RoleInfo ro = rolebll.GetModel(nowUser.F_RoleId);
  2578. if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL")
  2579. {
  2580. 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();
  2581. if (itemlast != null)
  2582. {
  2583. toussers = itemlast.F_CreateUser;
  2584. if (sms == -1)
  2585. {
  2586. sms = (int)itemlast.F_IsSMS;
  2587. }
  2588. }
  2589. else
  2590. {
  2591. if (sms == -1)
  2592. {
  2593. sms = 0;
  2594. }
  2595. }
  2596. if (AuditState == 0)
  2597. {
  2598. opt = "同意上报";
  2599. 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);
  2600. res = GetDaQucirCulation(AuditCont, nowUser, DateTime.Now.ToString(), model.F_ID, true);
  2601. if (userid <= 0 || res==0)
  2602. res = 0;
  2603. wostate = 1;
  2604. woflag = 9;
  2605. }
  2606. else if (AuditState == 1)
  2607. {
  2608. opt = "驳回修订";
  2609. 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);
  2610. if (userid <= 0)
  2611. res = 0;
  2612. wostate = 16;
  2613. }
  2614. else
  2615. {
  2616. opt = "强制结案";
  2617. 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);
  2618. if (userid <= 0)
  2619. res = 0;
  2620. wostate = 11;
  2621. }
  2622. }
  2623. else
  2624. {
  2625. res = 0;
  2626. }
  2627. }
  2628. }
  2629. #endregion
  2630. #endregion
  2631. if (res>0)
  2632. {
  2633. if (res == 1)
  2634. {
  2635. model.F_State = wostate;
  2636. //if (woflag == 9)
  2637. //{
  2638. // model.F_State2 = 0;
  2639. //}
  2640. //else
  2641. //{
  2642. // model.F_State2 = wostate;
  2643. //}
  2644. model.F_State2 = wostate;
  2645. model.F_Flag = woflag;
  2646. }
  2647. else if (res == 2)
  2648. {
  2649. model.F_State = wostate;
  2650. model.F_State2 = wostate;
  2651. model.F_Flag = 3;
  2652. }
  2653. //处理内容
  2654. if (!string.IsNullOrEmpty(AuditCont))
  2655. model.F_AuditCont += AuditCont + ";";
  2656. model.F_IsAudit = IsAudit;
  2657. model.F_AuditState = AuditState;
  2658. model.F_AuditBy = nowUser.F_UserCode;
  2659. model.F_AuditOn = DateTime.Now;
  2660. woBLL.Update(model);
  2661. if (nowUser.F_UserCode != model.F_CreateBy)
  2662. {
  2663. sendsysmsg(model, nowUser, model.F_CreateBy, (int)model.F_ID, opt);//
  2664. }
  2665. #region 向下一级操作人员推送消息
  2666. if (!string.IsNullOrWhiteSpace(touser))
  2667. {
  2668. sendsysmsg(model, nowUser, touser, (int)model.F_ID, opt);//
  2669. }
  2670. #endregion 向下一级操作人员推送消息
  2671. }
  2672. else
  2673. return false;
  2674. return true;
  2675. }
  2676. public bool SendSms(string type,string F_Mobile,int userid)
  2677. {
  2678. string smscont = "";
  2679. if (type == "1")
  2680. {
  2681. smscont = "咨询";
  2682. }
  2683. else if (type == "2")
  2684. {
  2685. smscont = "投诉";
  2686. }
  2687. else if (type == "3")
  2688. {
  2689. smscont = "抽检";
  2690. }
  2691. else if (type == "5")
  2692. {
  2693. smscont = "业务协办";
  2694. }
  2695. else
  2696. {
  2697. smscont = "建议";
  2698. }
  2699. string[] mag = { smscont };
  2700. string smsmsg = "您好,您有一条新的" + smscont + "工单,请及时接单处理!";
  2701. SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, F_Mobile.Trim());
  2702. bool n = new SMSController().AddSmS(F_Mobile.Trim(), smsmsg, userid);
  2703. return n;
  2704. }
  2705. /// <summary>
  2706. /// 大区经理未审批流转市场管理科
  2707. /// </summary>
  2708. /// <param name="ua"></param>
  2709. /// <param name="time"></param>
  2710. /// <param name="id"></param>
  2711. public int GetDaQucirCulation(string AuditCont, Model.T_Sys_UserAccount ua, string time, long id, bool istrue)
  2712. {
  2713. DateTime times = DateTime.Parse(time).AddHours(24);
  2714. Model.T_Wo_WorkOrder model = woBLL.GetModel(id);
  2715. List<Model.T_Wo_WorkOrder> modeLlist = new List<Model.T_Wo_WorkOrder>();
  2716. modeLlist.Add(model);
  2717. List<WorkOrderNewInput> Input = modeltooip(modeLlist, ua);
  2718. string cont = "";
  2719. int dapt = 0, nextda = 0; string opt = ""; int nextda2 = 0; string opt2 = ""; string cont2 = "";
  2720. var itemlast = itembll.GetModelList(" F_WoID='" + model.F_ID + "' order by F_ID desc").FirstOrDefault();
  2721. int sms = (int)itemlast.F_IsSMS;
  2722. var deptmodel1 = departmentBLL.GetModel(ua.F_DeptId);
  2723. string deptname = "";
  2724. if (deptmodel1 != null)
  2725. {
  2726. dapt = deptmodel1.F_ParentId;
  2727. deptname = deptmodel1.F_DeptName;
  2728. }
  2729. int isbl = 0;
  2730. int flag = 9;
  2731. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  2732. //if (dapt != 0)
  2733. //{
  2734. if (CirculMarket(ua.F_DeptId, 11))
  2735. {
  2736. isbl = 1;
  2737. nextda = 427;
  2738. opt = "流转运营中心";
  2739. //nextda2 = 36;
  2740. //opt2 = "流转质量管理科";
  2741. //flag = 3;
  2742. }
  2743. else if (CirculMarket(ua.F_DeptId, 14))
  2744. {
  2745. isbl = 1;
  2746. nextda = 57;
  2747. opt = "流转营销管理处";
  2748. }
  2749. else if (CirculMarket(ua.F_DeptId, 15))
  2750. {
  2751. isbl = 1;
  2752. nextda = 74;
  2753. opt = "流转策划推广";
  2754. //nextda2 = 245;
  2755. //opt2 = "流转质量督察处";
  2756. //flag = 3;
  2757. }
  2758. else if (CirculMarket(ua.F_DeptId, 16))
  2759. {
  2760. isbl = 1;
  2761. nextda = 88;
  2762. opt = "流转销售部";
  2763. }
  2764. else if (CirculMarket(ua.F_DeptId, 18))
  2765. {
  2766. nextda = 268;
  2767. opt = "流转车用尿素";
  2768. }
  2769. else if (CirculMarket(ua.F_DeptId, 20))
  2770. {
  2771. nextda = 422;
  2772. opt = "流转营销中心市场科";
  2773. nextda2 = 295;
  2774. opt2 = "流转新乡黑科质检";
  2775. }
  2776. else if (CirculMarket(ua.F_DeptId, 332))
  2777. {
  2778. nextda = 339;
  2779. opt = "流转营销管理处";
  2780. }
  2781. else if (ua.F_DeptId == 17 || ua.F_DeptId == 19 || ua.F_DeptId == 20 || ua.F_DeptId == 21)
  2782. {
  2783. isbl = 1;
  2784. nextda = ua.F_DeptId;
  2785. opt = "流转" + deptname;
  2786. }
  2787. //}
  2788. if (istrue)
  2789. {
  2790. if (ro.F_RoleCode == "DQJL")
  2791. {
  2792. cont = "大区经理已审批:" + AuditCont + "," + opt;
  2793. if (!string.IsNullOrEmpty(opt2))
  2794. {
  2795. cont2 = "大区经理已审批: " + AuditCont + "," + opt2;
  2796. }
  2797. }
  2798. else
  2799. {
  2800. cont = "分公司经理已审批:" + AuditCont + "," + opt;
  2801. if (!string.IsNullOrEmpty(opt2))
  2802. {
  2803. cont2 = "分公司经理已审批: " + AuditCont + "," + opt2;
  2804. }
  2805. }
  2806. }
  2807. else
  2808. {
  2809. if (ro.F_RoleCode == "DQJL")
  2810. {
  2811. cont = "大区经理未审批" + opt;
  2812. if (!string.IsNullOrEmpty(opt2))
  2813. {
  2814. cont2 = "大区经理未审批" + opt2;
  2815. }
  2816. }
  2817. else
  2818. {
  2819. cont = "分公司经理未审批" + opt;
  2820. if (!string.IsNullOrEmpty(opt2))
  2821. {
  2822. cont2 = "分公司经理未审批" + opt2;
  2823. }
  2824. }
  2825. }
  2826. if (nextda != 0)
  2827. {
  2828. if (nextda2 != 0)
  2829. {
  2830. model.F_Flag = 3;
  2831. var res = AssignWO(ua, model, Input[0], cont, "", nextda, 0, model.F_limit, sms, 0, 0, 0, time.ToString(), isbl, 1, 3);
  2832. var res2 = AssignWO(ua, model, Input[0], cont2, "", nextda2, 0, model.F_limit, sms, 0, 0, 0, time.ToString(), isbl, 2);
  2833. return 2;
  2834. }
  2835. else
  2836. {
  2837. model.F_Flag = 9;
  2838. var res = AssignWO(ua, model, Input[0], cont, "", nextda, 0, model.F_limit, sms, 0, 0, 0, time.ToString(), isbl, 3, 9);
  2839. return 1;
  2840. }
  2841. }
  2842. else
  2843. {
  2844. return 0;
  2845. }
  2846. }
  2847. /// <summary>
  2848. /// 判断市场管理科
  2849. /// </summary>
  2850. /// <param name="deptid"></param>
  2851. /// <param name="pdeptid"></param>
  2852. /// <returns></returns>
  2853. public bool CirculMarket(int deptid, int pdeptid)
  2854. {
  2855. string sql = " F_State=1 ";
  2856. string dptcode = departmentBLL.GetModel(pdeptid).F_DeptCode;
  2857. string arrsql = " select F_DeptCode from T_Sys_Department where F_DeptCode LIKE '" + dptcode + "%' ";
  2858. sql += $" and F_DeptCode in ({arrsql}) and F_DeptId=" + deptid;
  2859. var modellist = departmentBLL.GetModelList(sql);
  2860. if (modellist.Count > 0)
  2861. return true;
  2862. else return false;
  2863. }
  2864. /// <summary>
  2865. /// 查询工单详情
  2866. /// </summary>
  2867. [WechatActionFilter]
  2868. public ActionResult GetCustomDetails(string OpenId, int id)
  2869. {
  2870. if (!string.IsNullOrEmpty(OpenId))
  2871. {
  2872. int woflag = 0;
  2873. string markdepts = "37,57,74,88,268,295,339,213,427,433,424";
  2874. string sqlstr = "";
  2875. if (id <= 0)
  2876. {
  2877. return Error("请输入正确的id");
  2878. }
  2879. DataTable FileUrl = new DataTable();
  2880. var list = new List<Model.T_Wo_WorkOrder>();
  2881. var model = woBLL.GetModel(id);
  2882. if (model != null)
  2883. list.Add(model);
  2884. var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  2885. if (!string.IsNullOrEmpty(model.F_Files))
  2886. {
  2887. FileUrl = GetFileData(model.F_Files, configfj.F_ParamValue);
  2888. }
  2889. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  2890. var itemlasts = itembll.GetModelList(" F_WoID=" + id + "");
  2891. 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");
  2892. if (itemlast != null && itemlast.Count > 0)
  2893. {
  2894. if (markdepts.Contains(ua.F_DeptId.ToString()))
  2895. {
  2896. 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();
  2897. if (itemlast.Count == 2 || itemnext.F_Flag == 9)
  2898. {
  2899. woflag = 9;
  2900. }
  2901. }
  2902. }
  2903. int n = DbHelperSQL.ExecuteSql(" update T_Msg_List set State=1 where Detail like '%," + model.F_ID + "%' and IsDel=0 and State=0");
  2904. //var itemlasts = itembll.GetModelList(" F_WoID=" + +id + " ");
  2905. if (list.Count > 0)
  2906. {
  2907. List<WorkOrderNewInput> Input = modeltooip(list, ua);
  2908. if (Input != null)
  2909. {
  2910. var obj = new
  2911. {
  2912. state = "success",
  2913. message = "成功",
  2914. rows = Input,
  2915. FileUrl,
  2916. total = itemlasts,
  2917. woflag = woflag
  2918. };
  2919. return Content(obj.ToJson());
  2920. }
  2921. else
  2922. {
  2923. return Error("没有查询到此工单");
  2924. }
  2925. }
  2926. else
  2927. return Error("没有查询到此工单");
  2928. }
  2929. else
  2930. {
  2931. return Error("无操作权限!");
  2932. }
  2933. }
  2934. /// <summary>
  2935. /// 查询工单详情
  2936. /// </summary>
  2937. [WechatActionFilter]
  2938. public ActionResult GetDetails(string OpenId, int id,int flag=1,int state=0)
  2939. {
  2940. if (!string.IsNullOrEmpty(OpenId))
  2941. {
  2942. if (id <= 0)
  2943. {
  2944. return Error("请输入正确的id");
  2945. }
  2946. DataTable FileUrl = new DataTable();
  2947. var list = new List<Model.T_Wo_WorkOrder>();
  2948. var model = woBLL.GetModel(id);
  2949. if (model != null)
  2950. {
  2951. //if (model.F_SC_PreliminaryOpinion == "退换货")
  2952. //{
  2953. List<T_Wo_MaterialItems> materlist = new BLL.T_Wo_MaterialItems().GetModelList($" F_WoID={model.F_ID}");
  2954. if (materlist != null)
  2955. {
  2956. model.MaterialItems = materlist;
  2957. }
  2958. //}
  2959. list.Add(model);
  2960. }
  2961. var itemlasts = itembll.GetModelList(" F_WoID=" + id + " ");
  2962. var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  2963. if (!string.IsNullOrEmpty(model.F_Files))
  2964. {
  2965. FileUrl = GetFileData(model.F_Files, configfj.F_ParamValue);
  2966. }
  2967. //if (!string.IsNullOrEmpty(model.F_Files))
  2968. //{
  2969. // var configfj = "http://192.168.8.9:1005/Upload/APP/2022/06/22/";
  2970. // FileUrl = GetFileData(model.F_Files, configfj);
  2971. //}
  2972. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  2973. if (model.F_Source != "3")
  2974. {
  2975. if (ua == null)
  2976. {
  2977. return Success("你的账号已在别处登录,你确定要再次登录吗?");
  2978. }
  2979. }
  2980. if (list.Count > 0)
  2981. {
  2982. List<WorkOrderNewInput> Input = modeltooip(list, ua,state);
  2983. if (Input != null)
  2984. {
  2985. var obj = new
  2986. {
  2987. state = "success",
  2988. message = "成功",
  2989. rows = Input,
  2990. FileUrl,
  2991. total = itemlasts,
  2992. };
  2993. return Content(obj.ToJson());
  2994. }
  2995. else
  2996. {
  2997. return Error("没有查询到此工单");
  2998. }
  2999. }
  3000. else
  3001. return Error("没有查询到此工单");
  3002. }
  3003. else
  3004. {
  3005. return Error("无操作权限!");
  3006. }
  3007. }
  3008. /// <summary>
  3009. /// 获取当前节点内外线状态
  3010. /// </summary>
  3011. /// <param name="fid"></param>
  3012. /// <returns></returns>
  3013. public int? GetNodeState(int fid, string usercode, int state = 0)
  3014. {
  3015. int? flag = 0;
  3016. string markdepts = "37,57,74,88,268,295,339,213,427,433,424";
  3017. if (!string.IsNullOrEmpty(usercode))
  3018. {
  3019. Model.T_Sys_UserAccount ua = userAccountBLL.GetModel(usercode);
  3020. 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();
  3021. if (itemlast != null)
  3022. {
  3023. int? wostate1 = 0, wostate2 = 0; int i = 0;
  3024. //if (!markdepts.Contains(ua.F_DeptId.ToString()))
  3025. //{
  3026. if (state == 2)
  3027. state = 1;
  3028. else if (state == 4)
  3029. state = 2;
  3030. else
  3031. state = 0;
  3032. if (itemlast.F_Flag != 9)
  3033. {
  3034. 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");
  3035. if (itemnext.Count > 0 && itemnext.Count == 2)
  3036. {
  3037. foreach (var item in itemnext)
  3038. {
  3039. if (i == 0)
  3040. {
  3041. wostate1 = item.F_WoState;
  3042. }
  3043. else
  3044. {
  3045. wostate2 = item.F_WoState;
  3046. }
  3047. i++;
  3048. }
  3049. if (wostate1 == wostate2 || (wostate2 == 2 && wostate1 == 17) || (wostate1 == 2 && wostate2 == 17))
  3050. {
  3051. flag = 3;//需要判断处理内线还是外线
  3052. }
  3053. else if (state > 0 && state<=2)
  3054. {
  3055. flag = itemnext.Where(t => t.F_WoState == state || t.F_WoState == 17 || t.F_WoState == 4 || t.F_WoState == 3).FirstOrDefault()?.F_Type??0;
  3056. }
  3057. }
  3058. else if (itemnext.Count > 0)
  3059. {
  3060. flag = itemnext.FirstOrDefault().F_Type;
  3061. }
  3062. else
  3063. {
  3064. 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");
  3065. if (itemnext2.Count > 0 && itemnext2.Count == 2)
  3066. {
  3067. flag = 3;
  3068. }
  3069. else if (itemnext2.Count > 0)
  3070. {
  3071. flag = itemnext2.FirstOrDefault().F_Type;
  3072. }
  3073. else
  3074. {
  3075. flag = itemlast.F_Type;
  3076. }
  3077. }
  3078. }
  3079. //}
  3080. else if (itemlast.F_Flag == 9)
  3081. {
  3082. 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();
  3083. if (itemlest.F_IsUsed == 0)
  3084. {
  3085. if (itemlest.F_Flag == 9)
  3086. flag = 9;
  3087. else
  3088. flag = itemlest.F_Type;
  3089. }
  3090. else
  3091. {
  3092. 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");
  3093. if (itemnext.Count > 0 && itemnext.Count == 2)
  3094. {
  3095. foreach (var item in itemnext)
  3096. {
  3097. if (i == 0)
  3098. {
  3099. wostate1 = item.F_WoState;
  3100. }
  3101. else
  3102. {
  3103. wostate2 = item.F_WoState;
  3104. }
  3105. i++;
  3106. }
  3107. if (wostate1 == wostate2 || (wostate2 == 2 && wostate1 == 17) || (wostate1 == 2 && wostate2 == 17))
  3108. {
  3109. flag = 3;//需要判断处理内线还是外线
  3110. }
  3111. else if (state > 0 && state<=2)
  3112. {
  3113. flag = itemnext.Where(t => t.F_WoState == state || t.F_WoState == 17 || t.F_WoState == 4 || t.F_WoState == 3).FirstOrDefault()?.F_Type??0;
  3114. }
  3115. }
  3116. else if(itemnext.Count > 0)
  3117. {
  3118. flag = itemnext.FirstOrDefault().F_Type;
  3119. }
  3120. else
  3121. {
  3122. 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");
  3123. if (itemnext2.Count > 0)
  3124. {
  3125. foreach (var item in itemnext2)
  3126. {
  3127. if (item.F_WoState != 11 && item.F_WoState != 10)
  3128. flag = item.F_Type;
  3129. }
  3130. }
  3131. }
  3132. }
  3133. }
  3134. }
  3135. }
  3136. return flag;
  3137. }
  3138. public string GetID(string str, long id)
  3139. {
  3140. if (str != "")
  3141. {
  3142. str += "," + id;
  3143. }
  3144. else
  3145. {
  3146. str += id;
  3147. }
  3148. return str;
  3149. }
  3150. public string GetDeptment(Model.T_Sys_UserAccount ua)
  3151. {
  3152. string detpid = "" + ua.F_DeptId;
  3153. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  3154. var deparmentlist = new List<Model.T_Sys_Department>();
  3155. if (dModel != null)
  3156. {
  3157. if (dModel.F_Layer == 1)
  3158. {
  3159. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  3160. if (deparmentlist.Count > 0)
  3161. {
  3162. foreach (var it in deparmentlist)
  3163. {
  3164. if (detpid != "")
  3165. {
  3166. detpid += "," + it.F_DeptId;
  3167. }
  3168. else
  3169. {
  3170. detpid = "" + it.F_DeptId;
  3171. }
  3172. }
  3173. }
  3174. }
  3175. else
  3176. {
  3177. detpid = ua.F_DeptId.ToString();
  3178. }
  3179. }
  3180. return detpid;
  3181. }
  3182. /// <summary>
  3183. /// 获取待审批的工单
  3184. /// </summary>
  3185. /// <param name="user"></param>
  3186. /// <returns></returns>
  3187. public string GetApprovalOrderID(Model.T_Sys_UserAccount ua, string OpenId, string F_RoleCode)
  3188. {
  3189. string str = string.Empty;
  3190. #region 查询自己名下未审批的工单列表
  3191. var itemlast = itembll.GetModelList(" isnull(F_IsUsed,'0')='0' and F_OptType in(" + (int)EnumItemOpt.audit + ")" + " and "
  3192. + "F_WoState in(" + (int)EnumWorkOrderState.audit + ") and F_NextUser='" + ua.F_UserCode + "' "
  3193. + "" + " ");
  3194. foreach (var it in itemlast)
  3195. {
  3196. float hours = (DateTime.Now - DateTime.Parse(it.F_CreateTime.ToString())).Hours;
  3197. int overtime = 0;
  3198. if (!string .IsNullOrEmpty (it.F_LimitTime))
  3199. {
  3200. overtime = int.Parse(it.F_LimitTime);
  3201. }
  3202. int sms = int.Parse (it.F_IsSMS.ToString ());
  3203. if (F_RoleCode == "DQJL" || F_RoleCode == "FGSJL")
  3204. {
  3205. if (hours >= 24)
  3206. {
  3207. GetDaQucirCulation("", ua, it.F_CreateTime.ToString(), it.F_WoID, false);
  3208. }
  3209. else
  3210. {
  3211. str = GetID(str, it.F_WoID);
  3212. }
  3213. }
  3214. else
  3215. {
  3216. //var user = GetUser(OpenId);
  3217. //string deptname = "";
  3218. //string deptmodelsname = "";
  3219. //var deptmodel = departmentBLL.GetModel(user.F_DeptId);
  3220. //var deptmodels = departmentBLL.GetModel(ua.F_DeptId);
  3221. //if (deptmodel != null)
  3222. //{
  3223. // deptname = deptmodel.F_DeptName + "-";
  3224. //}
  3225. //if (deptmodels != null)
  3226. //{
  3227. // deptmodelsname = deptmodels.F_DeptName + "-";
  3228. //}
  3229. if (hours >= 24)
  3230. {
  3231. var user = GetUser(OpenId);
  3232. string deptname = "";
  3233. string deptmodelsname = "";
  3234. string namestr = "";
  3235. Model.T_Sys_RoleInfo ro = rolebll.GetModel(user.F_RoleId);
  3236. if (ro.F_RoleCode == "DQJL")
  3237. {
  3238. namestr = "大区经理";
  3239. }
  3240. else
  3241. {
  3242. namestr = "分公司经理";
  3243. }
  3244. var deptmodel = departmentBLL.GetModel(user.F_DeptId);
  3245. var deptmodels = departmentBLL.GetModel(ua.F_DeptId);
  3246. if (deptmodel != null)
  3247. {
  3248. deptname = deptmodel.F_DeptName + "-";
  3249. }
  3250. if (deptmodels != null)
  3251. {
  3252. deptmodelsname = deptmodels.F_DeptName + "-";
  3253. }
  3254. DateTime time = DateTime.Parse(it.F_CreateTime.ToString()).AddHours(24);
  3255. Model.T_Wo_WorkOrder model = woBLL.GetModel(it.F_WoID);
  3256. 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);
  3257. 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);
  3258. }
  3259. else if (hours >= 48)
  3260. {
  3261. var user = GetUser(OpenId);
  3262. GetDaQucirCulation("", user, it.F_CreateTime.ToString(), it.F_WoID, false);
  3263. }
  3264. else
  3265. {
  3266. str = GetID(str, it.F_WoID);
  3267. }
  3268. }
  3269. }
  3270. #endregion
  3271. if (F_RoleCode == "DQJL")
  3272. {
  3273. if (!string.IsNullOrEmpty(GetDeptment(ua)))
  3274. {
  3275. var itemlasts = itembll.GetModelList(" isnull(F_IsUsed,'0')='0' and F_OptType in(" + (int)EnumItemOpt.audit + ")" + " and "
  3276. + "F_WoState in(" + (int)EnumWorkOrderState.audit + ") and F_NextUser in ( " + GetDeptment(ua) + ") ");
  3277. foreach (var it in itemlasts)
  3278. {
  3279. int overtime = 0;
  3280. if (!string.IsNullOrEmpty(it.F_LimitTime))
  3281. {
  3282. overtime = int.Parse(it.F_LimitTime);
  3283. }
  3284. int sms = int.Parse(it.F_IsSMS.ToString());
  3285. float hours = (DateTime.Now - DateTime.Parse(it.F_CreateTime.ToString())).Hours;
  3286. if (F_RoleCode == "DQJL")
  3287. {
  3288. if (hours >= 24)
  3289. {
  3290. Model.T_Sys_UserAccount user = userAccountBLL.GetModel(it.F_CreateUser);
  3291. DateTime time = DateTime.Parse(it.F_CreateTime.ToString()).AddHours(24);
  3292. Model.T_Wo_WorkOrder model = woBLL.GetModel(it.F_WoID);
  3293. string deptname = "";
  3294. string deptmodelsname = "";
  3295. var deptmodel = departmentBLL.GetModel(user.F_DeptId);
  3296. var deptmodels = departmentBLL.GetModel(ua.F_DeptId);
  3297. if (deptmodel != null)
  3298. {
  3299. deptname = deptmodel.F_DeptName + "-";
  3300. }
  3301. if (deptmodels != null)
  3302. {
  3303. deptmodelsname = deptmodels.F_DeptName + "-";
  3304. }
  3305. 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);
  3306. 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 );
  3307. if (hours < 48)
  3308. {
  3309. str = GetID(str, it.F_WoID);
  3310. }
  3311. else
  3312. {
  3313. GetDaQucirCulation("", ua, time.ToString(), it.F_WoID, false);
  3314. }
  3315. }
  3316. }
  3317. }
  3318. }
  3319. }
  3320. return str;
  3321. }
  3322. /// <summary>
  3323. /// 获取已审批的工单列表
  3324. /// </summary>
  3325. /// <param name="user"></param>
  3326. /// <returns></returns>
  3327. public string GetApprovedOrderID(string user)
  3328. {
  3329. string str = string.Empty;
  3330. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_OptType=" + (int)EnumItemOpt.reaudit
  3331. + " and F_CreateUser=" + user + " "//
  3332. ;
  3333. return str;
  3334. }
  3335. /// <summary>
  3336. /// 获取已审批的工单列表
  3337. /// </summary>
  3338. /// <param name="user"></param>
  3339. /// <returns></returns>
  3340. public string GetApprovedOrderID()
  3341. {
  3342. string str = string.Empty;
  3343. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_OptType=" + (int)EnumItemOpt.reaudit
  3344. //
  3345. ;
  3346. return str;
  3347. }
  3348. /// <summary>
  3349. /// 根据model返回CustomerBaseNewInput对象
  3350. /// </summary>
  3351. private List<WorkOrderNewInput> modeltooip(List<Model.T_Wo_WorkOrder> model1, Model.T_Sys_UserAccount ua,int state=0)
  3352. {
  3353. if (model1 != null && model1.Count > 0)
  3354. {
  3355. List<WorkOrderNewInput> Input = new List<WorkOrderNewInput>(model1.Count);
  3356. for (int i = 0; i < model1.Count; i++)
  3357. {
  3358. WorkOrderNewInput model = new WorkOrderNewInput();
  3359. Model.T_Cus_CustomerBaseNew cuModel = new Model.T_Cus_CustomerBaseNew();
  3360. if (!string.IsNullOrEmpty(model1[i].F_CustomerID))
  3361. {
  3362. cuModel = customerBaseBLL.GetModel(model1[i].F_CustomerID.ToString());//通过客户编号获取客户资料
  3363. }
  3364. else
  3365. {
  3366. var sql = $" and F_LegalPhone ='" + model1[i].F_CusPhone.Trim() + "'";
  3367. cuModel = new BLL.T_Cus_CustomerBaseNew().GetModelList(" F_IsDelete = 0 " + sql).FirstOrDefault();
  3368. }
  3369. if (cuModel != null)
  3370. {
  3371. if (!string.IsNullOrEmpty(cuModel.F_AreaID))
  3372. {
  3373. Model.T_Sys_Department pdModel = new Model.T_Sys_Department();
  3374. try
  3375. {
  3376. pdModel = departmentBLL.GetModel(int.Parse(cuModel.F_AreaID));//通过公司id获取部门
  3377. }
  3378. catch
  3379. {
  3380. pdModel = departmentBLL.GetModel(cuModel.F_AreaID);//通过公司id获取部门
  3381. }
  3382. if (pdModel != null)
  3383. {
  3384. model.F_AreaName = pdModel.F_DeptName;
  3385. }
  3386. }
  3387. if (!string.IsNullOrEmpty(cuModel.F_BranchID))
  3388. {
  3389. Model.T_Sys_Department pdModel1 = new Model.T_Sys_Department();
  3390. try
  3391. {
  3392. pdModel1 = departmentBLL.GetModel(int.Parse(cuModel.F_BranchID));//通过公司id获取部门
  3393. }
  3394. catch
  3395. {
  3396. pdModel1 = departmentBLL.GetModel(cuModel.F_BranchID);//通过公司id获取部门
  3397. }
  3398. if (pdModel1 != null)
  3399. {
  3400. model.F_BranchName = pdModel1.F_DeptName;
  3401. }
  3402. }
  3403. model.F_CompanyName = cuModel.F_CompanyName;//公司名称
  3404. model.F_CustomerID = cuModel.F_CustomerCode;//客户编码
  3405. model.F_Salesman = cuModel.F_Salesman;
  3406. if (string.IsNullOrEmpty(cuModel.F_SalesPhone) && !string.IsNullOrEmpty(cuModel.F_Salesman))
  3407. {
  3408. var modellist = new BLL.T_Sys_UserAccount().
  3409. GetModelList("F_UserName ='" + cuModel.F_Salesman + "' and F_DeleteFlag =0");
  3410. if (modellist != null && modellist.Count > 0)
  3411. {
  3412. model.F_SalesPhone = modellist.FirstOrDefault().F_Mobile;
  3413. }
  3414. }
  3415. else
  3416. model.F_SalesPhone = cuModel.F_SalesPhone;
  3417. model.F_Legal = cuModel.F_Legal;
  3418. model.F_LegalPhone = cuModel.F_LegalPhone;
  3419. model.F_AddressProvince = cuModel.F_AddressProvince;
  3420. model.F_AddressCity = cuModel.F_AddressCity;
  3421. model.F_AddressCountry = cuModel.F_AddressCountry;
  3422. model.F_AddressTownship = cuModel.F_AddressTownship;
  3423. model.F_AddressFull = cuModel.F_AddressFull;
  3424. model.F_Brands = cuModel.F_Brands;
  3425. model.F_Channel = cuModel.F_Channel;
  3426. model.F_IsRunXLX = cuModel.F_IsRunXLX;
  3427. model.F_AnnualSales = cuModel.F_AnnualSales;
  3428. model.F_Formula = cuModel.F_Formula;
  3429. model.F_RaiseCrops = cuModel.F_RaiseCrops;
  3430. model.F_PlantingArea = cuModel.F_PlantingArea;
  3431. model.F_FertilizerBrand = cuModel.F_FertilizerBrand;
  3432. }
  3433. if (valcode(model1[i].F_MaterialID.ToString(), 11))
  3434. {
  3435. model.F_MaterialID = model1[i].F_MaterialID;//验证物料编码为11位纯数字
  3436. Model.T_Wo_MaterialManage maModel = mmBLL.GetModel(model1[i].F_MaterialID.ToString());//通过物料编码获取物料信息
  3437. if (maModel != null)
  3438. {
  3439. model.F_MaterialName = maModel.F_MaterialName;
  3440. model.F_Model = maModel.F_Model;
  3441. model.F_Specs = maModel.F_Specs;
  3442. model.F_Level1 = maModel.F_Level1;
  3443. model.F_Level2 = maModel.F_Level2;
  3444. model.F_Level3 = maModel.F_Level3;
  3445. model.F_Brand = maModel.F_Brand;
  3446. model.F_MaterialEffect = maModel.F_MaterialEffect;
  3447. model.F_Pipeline = maModel.F_Pipeline;
  3448. model.F_Craft = maModel.F_Craft;
  3449. }
  3450. }
  3451. #region 基本字段
  3452. model.F_ID = model1[i].F_ID;//
  3453. model.F_WorkOrderCode = model1[i].F_WorkOrderCode;//工单编号
  3454. #region
  3455. if (!string.IsNullOrEmpty(model1[i].F_Source))
  3456. {
  3457. model.F_Source = int.Parse(model1[i].F_Source);//工单来源
  3458. }
  3459. if (model1[i].F_Source == "1")
  3460. {
  3461. model.F_SourceName = "电话";
  3462. }
  3463. else if (model1[i].F_Source == "2")
  3464. {
  3465. model.F_SourceName = "微信业务员";
  3466. }
  3467. else if (model1[i].F_Source == "3")
  3468. {
  3469. model.F_SourceName = "微信客户";
  3470. }
  3471. else
  3472. {
  3473. model.F_SourceName = "官网";
  3474. }
  3475. model.F_Type = int.Parse(model1[i].F_Type);//工单来源
  3476. if (model1[i].F_Type == "1")
  3477. {
  3478. model.F_TypeName = "咨询";//工单类型:咨询及需求、投诉、抽检、其他(其它手动输入别的点选)
  3479. }
  3480. else if (model1[i].F_Type == "2")
  3481. {
  3482. model.F_TypeName = "投诉";//工单类型:咨询及需求、投诉、抽检、其他(其它手动输入别的点选)
  3483. }
  3484. else if (model1[i].F_Type == "3")
  3485. {
  3486. model.F_TypeName = "抽检";//工单类型:咨询及需求、投诉、抽检、其他(其它手动输入别的点选)
  3487. }
  3488. else if (model1[i].F_Type == "5")
  3489. {
  3490. model.F_TypeName = "业务协办";//工单类型:咨询及需求、投诉、抽检、其他(其它手动输入别的点选)
  3491. }
  3492. else
  3493. {
  3494. model.F_TypeName = "建议及其他";//工单类型:咨询及需求、投诉、抽检、其他(其它手动输入别的点选)
  3495. }
  3496. model.F_State = model1[i].F_State;
  3497. if (model1[i].F_State == 0)//工单状态
  3498. {
  3499. model.F_StateName = "待指派";
  3500. }
  3501. else if (model1[i].F_State == 1)
  3502. {
  3503. model.F_StateName = "待接单";
  3504. }
  3505. else if (model1[i].F_State == 2)
  3506. {
  3507. model.F_StateName = "待处理";
  3508. }
  3509. else if (model1[i].F_State == 3)
  3510. {
  3511. model.F_StateName = "已退回";
  3512. }
  3513. else if (model1[i].F_State == 4)
  3514. {
  3515. model.F_StateName = "异常退回";
  3516. }
  3517. else if (model1[i].F_State == 5)
  3518. {
  3519. model.F_StateName = "处理中";
  3520. }
  3521. else if (model1[i].F_State == 6)
  3522. {
  3523. model.F_StateName = "待回访";
  3524. }
  3525. else if (model1[i].F_State == 7)
  3526. {
  3527. model.F_StateName = "待完结";
  3528. }
  3529. else if (model1[i].F_State == 10)
  3530. {
  3531. model.F_StateName = "已处理";
  3532. }
  3533. else if (model1[i].F_State == 11)
  3534. {
  3535. model.F_StateName = "已评价";
  3536. }
  3537. else if (model1[i].F_State == 12)
  3538. {
  3539. model.F_StateName = "已退回";
  3540. }
  3541. else if (model1[i].F_State == 14)
  3542. {
  3543. model.F_StateName = "待办理";
  3544. }
  3545. else if (model1[i].F_State == 15)
  3546. {
  3547. model.F_StateName = "微信未通过";
  3548. }
  3549. else if (model1[i].F_State == 16)
  3550. {
  3551. model.F_StateName = "待审批";
  3552. }
  3553. else if (model1[i].F_State == 17)
  3554. {
  3555. model.F_StateName = "已撤回待指派";
  3556. }
  3557. #region 内线工单状态
  3558. model.F_State2 = model1[i].F_State2;
  3559. if (model1[i].F_State2 == 0)//工单状态
  3560. {
  3561. model.F_StateName2 = "待指派";
  3562. }
  3563. else if (model1[i].F_State2 == 1)
  3564. {
  3565. model.F_StateName2 = "待接单";
  3566. }
  3567. else if (model1[i].F_State2 == 2)
  3568. {
  3569. model.F_StateName2 = "待处理";
  3570. }
  3571. else if (model1[i].F_State2 == 3)
  3572. {
  3573. model.F_StateName2 = "已退回";
  3574. }
  3575. else if (model1[i].F_State2 == 4)
  3576. {
  3577. model.F_StateName2 = "异常退回";
  3578. }
  3579. else if (model1[i].F_State2 == 5)
  3580. {
  3581. model.F_StateName2 = "处理中";
  3582. }
  3583. else if (model1[i].F_State2 == 6)
  3584. {
  3585. model.F_StateName2 = "待回访";
  3586. }
  3587. else if (model1[i].F_State2 == 7)
  3588. {
  3589. model.F_StateName2 = "待完结";
  3590. }
  3591. else if (model1[i].F_State2 == 10)
  3592. {
  3593. model.F_StateName2 = "已处理";
  3594. }
  3595. else if (model1[i].F_State2 == 11)
  3596. {
  3597. model.F_StateName2 = "已回访";
  3598. }
  3599. else if (model1[i].F_State2 == 12)
  3600. {
  3601. model.F_StateName2 = "已退回";
  3602. }
  3603. else if (model1[i].F_State2 == 13)
  3604. {
  3605. model.F_StateName2 = "导入工单";
  3606. }
  3607. else if (model1[i].F_State2 == 14)
  3608. {
  3609. model.F_StateName2 = "待办理";
  3610. }
  3611. else if (model1[i].F_State2 == 15)
  3612. {
  3613. model.F_StateName2 = "微信未通过";
  3614. }
  3615. else if (model1[i].F_State2 == 16)
  3616. {
  3617. model.F_StateName2 = "待审批";
  3618. }
  3619. else if (model1[i].F_State2 == 17)
  3620. {
  3621. model.F_StateName2 = "已撤回待指派";
  3622. }
  3623. #endregion 内线工单状态
  3624. #endregion
  3625. model.F_CusName = model1[i].F_CusName;//客户姓名
  3626. model.F_CusPhone = model1[i].F_CusPhone;//客户电话
  3627. model.F_Canal = model1[i].F_Canal;//
  3628. model.F_IncidentProvince = model1[i].F_IncidentProvince;//事发地-省
  3629. model.F_IncidentCity = model1[i].F_IncidentCity;//事发地-市
  3630. model.F_IncidentCountry = model1[i].F_IncidentCountry;//事发地-县
  3631. model.F_IncidentTownship = model1[i].F_IncidentTownship;//事发地-乡
  3632. model.F_IncidentDetailed = model1[i].F_IncidentDetailed;//事发地-详细
  3633. model.F_SalesBase = model1[i].F_SalesBase;//销售基地:新乡、新疆、九江、东北、其他(其它手动输入别的点选)
  3634. model.F_Description = model1[i].F_Description;//问题描述
  3635. model.F_Files = "0";//附件上传ids
  3636. model.F_DealType = model1[i].F_DealType;//处理方式:当即办理、电话转接、网络转办(点选)
  3637. #endregion
  3638. if (!string.IsNullOrEmpty(model1[i].F_QuestionType))
  3639. {
  3640. try
  3641. {
  3642. int b = int.Parse(model1[i].F_QuestionType.Trim());
  3643. Model.T_Wo_QuestionManage manage = quesBLL.GetModel(b);
  3644. if (manage != null)
  3645. {
  3646. model.F_QuestionType = manage.F_QuestionName;//问题类别3
  3647. model.F_QuestionTypeid = manage.F_Id;
  3648. #region 20220304 修改 肥效类增加作物字段
  3649. var cropid = 0;
  3650. if (manage.F_Label == "3")
  3651. {
  3652. Model.T_Wo_QuestionManage Manage1 = quesBLL.GetModel(int.Parse(manage.F_ParentId.ToString()));//获取问题类别2
  3653. Model.T_Wo_QuestionManage Manage2 = quesBLL.GetModel(int.Parse(Manage1.F_ParentId.ToString()));//获取问题类别1
  3654. model.F_QuestionTypeone = Manage2.F_QuestionName;//问题类别1
  3655. model.F_QuestionTypeoneid = Manage2.F_Id;//问题类别1
  3656. model.F_QuestionTypetwo = Manage1.F_QuestionName;//问题类别2
  3657. model.F_QuestionTypetwoid = Manage1.F_Id;//问题类别2
  3658. }
  3659. if (int.TryParse(model1[i].F_Crops.Trim(), out cropid))
  3660. {
  3661. model.F_QuestionTypefour = new BLL.T_Sys_DictionaryValue().GetModel(cropid)?.F_Name ?? "";//作物名称
  3662. model.F_QuestionTypefourid = cropid;//作物
  3663. }
  3664. #endregion
  3665. #region 修改前
  3666. //if (manage.F_Label == "3")
  3667. // {
  3668. // Model.T_Wo_QuestionManage Manage1 = quesBLL.GetModel(int.Parse(manage.F_ParentId.ToString()));//获取问题类别
  3669. // Model.T_Wo_QuestionManage Manage2 = quesBLL.GetModel(int.Parse(Manage1.F_ParentId.ToString()));//获取问题类别
  3670. // model.F_QuestionTypeone = Manage2.F_QuestionName;//问题类别1
  3671. // model.F_QuestionTypeoneid = Manage2.F_Id ;//问题类别1
  3672. // model.F_QuestionTypetwo = Manage1.F_QuestionName;//问题类别2
  3673. // model.F_QuestionTypetwoid = Manage1.F_Id;//问题类别2
  3674. //}
  3675. #endregion
  3676. }
  3677. }
  3678. catch (Exception)
  3679. {
  3680. model.F_QuestionType = model1[i].F_QuestionType; //问题类别(投诉抽捡和咨询类别不一样)
  3681. }
  3682. }
  3683. model.F_Annotation = model1[i].F_Annotation; ;//注解
  3684. #region 投诉类
  3685. model.F_BatchNumber = model1[i].F_BatchNumber;//生产批次号
  3686. model.F_TS_Formula = model1[i].F_TS_Formula;// 投诉-配方
  3687. model.F_TS_Category = model1[i].F_TS_Category;//投诉-产品种类:化肥、化工、其他
  3688. if (!string.IsNullOrEmpty(model1[i].F_TS_Quantity))
  3689. {
  3690. model.F_TS_Quantity = model1[i].F_TS_Quantity ;//投诉-问题数量(吨)
  3691. }
  3692. else
  3693. model.F_TS_Quantity = "";
  3694. model.F_TS_Level = model1[i].F_TS_Level;//投诉-重要级别:轻微、一般、较大、重大
  3695. List<T_Wo_MaterialItems> materlist = new BLL.T_Wo_MaterialItems().GetModelList($" F_WoID={model.F_ID}");
  3696. if (materlist != null)
  3697. {
  3698. model.MaterialItems = materlist;
  3699. model.F_ZL_Fquantity = materlist.Sum(x => x.F_ReturnQuantity).ToString();
  3700. }
  3701. model.F_CarNumber = model1[i].F_CarNumber;
  3702. model.F_LoadingFee = model1[i].F_LoadingFee;
  3703. model.F_UnLoadingFee = model1[i].F_UnLoadingFee;
  3704. model.F_MaterialFee = model1[i].F_MaterialFee;
  3705. model.F_EventReason = model1[i].F_EventReason;
  3706. model.F_EventReason2 = model1[i].F_EventReason2;
  3707. #endregion
  3708. #region 咨询类
  3709. // model.F_ZX_ProName = model1[i].F_ZX_ProName;//咨询-产品名称:三聚氰胺、甲醇、液氨、二甲醚、糠醇、其他
  3710. model.F_ZX_Quantity = model1[i].F_ZX_Quantity;// 咨询-问题数量(吨)
  3711. model.F_ZX_Area = model1[i].F_ZX_Area;// 咨询-大区
  3712. model.F_ZX_Branch = model1[i].F_ZX_Branch;// 咨询-分公司
  3713. #endregion
  3714. #region 抽检类
  3715. model.F_CJ_Time = model1[i].F_CJ_Time;// 抽检-抽检时间
  3716. model.F_CJ_Level = model1[i].F_CJ_Level;// 抽检-抽检级别:乡镇级、县级、市级、省级及以上、个人送检
  3717. model.F_CJ_Unit = model1[i].F_CJ_Unit;// 抽检-抽检单位:市场监督、农业部、土肥站、工商、联合执法、其他
  3718. model.F_CJ_TestUnit = model1[i].F_CJ_TestUnit;//抽检-化验单位
  3719. model.F_CJ_Tonnage = model1[i].F_CJ_Tonnage;//抽检-抽检吨数
  3720. model.F_CJ_BagNo = model1[i].F_CJ_BagNo;//抽检-抽检袋数
  3721. model.F_CJ_Outlay = model1[i].F_CJ_Outlay;//抽检-公关费用金额:单位元
  3722. model.F_Production = model1[i].F_Production;
  3723. model.F_WorkerBrand = model1[i].F_Brand;//工单品牌
  3724. model.F_DealBy = model1[i].F_DealBy;//处理人
  3725. model.F_DealTime = model1[i].F_DealTime;//处理时间
  3726. model.F_DealContent = model1[i].F_DealContent;//处理内容---外线
  3727. model.F_DealContent2 = model1[i].F_DealContent2;//处理内容---内线
  3728. model.F_DealResult = model1[i].F_DealResult;//处理结果
  3729. model.F_DealReasons = model1[i].F_DealReasons;//未处理原因
  3730. model.F_SC_ProductBase = model1[i].F_SC_ProductBase;//市场管理科-生产基地(新乡、新疆、九江、东北、贴牌、无法确定)
  3731. model.F_SC_PreliminaryOpinion = model1[i].F_SC_PreliminaryOpinion;// 市场管理科-初审意见:退货、换货、补偿、自行处理
  3732. model.F_SC_QualityMonth = model1[i].F_SC_QualityMonth;//市场管理科-超出质保期限(算法:工单创建日期-生产日期,生产日期根据生产批次号获取,单位:月)
  3733. model.F_SC_CJ_SpotResult = model1[i].F_SC_CJ_SpotResult;/// 市场管理科-抽检-抽检结果(视同合格、合格、不合格、复检后合格、未送检)
  3734. model.F_SC_CJ_SelfResult = model1[i].F_SC_CJ_SelfResult;//市场管理科-抽检-自检结果
  3735. model.F_SC_CJ_ApprovalNo = model1[i].F_SC_CJ_ApprovalNo;// 市场管理科-抽检-对应审批工作流单号
  3736. model.F_SC_CJ_ReturnAccount = model1[i].F_SC_CJ_ReturnAccount;//市场管理科-抽检-确认返账金额(元)
  3737. model.F_ZL_QualityEventLevel = model1[i].F_ZL_QualityEventLevel;// 质量管理科-质量事件等级(未遂、一般、较大、重大)
  3738. model.F_ZL_ClaimAmount = model1[i].F_ZL_ClaimAmount;//质量管理科-索赔金额(单位元,对应责任单位)
  3739. model.F_ZL_ResponsibleUnit = model1[i].F_ZL_ResponsibleUnit;//质量管理科-责任单位(需列出,可选多个)
  3740. model.F_ZL_ApprovalOpinions = model1[i].F_ZL_ApprovalOpinions;// 质量管理科-审批意见(同意、不同意,若选择不同意,增加输入框输入补充内容)
  3741. model.F_ZL_ApprovalDisagree = model1[i].F_ZL_ApprovalDisagree;// 质量管理科-审批不同意意见
  3742. model.F_ZL_CompensationMethod = model1[i].F_ZL_CompensationMethod;//质量管理科-补偿方式(实物、钱款【单位元】,若选择钱款,增加输入框输入补充内容)
  3743. model.F_ZL_CompensationMoney = model1[i].F_ZL_CompensationMoney;// 质量管理科-补偿钱款
  3744. model.F_ZL_CResponsibleUnits = model1[i].F_ZL_CResponsibleUnits;//质量管理科-对应责任单位(生产、研发、农化、物流、质量管理科,销售内勤)
  3745. //model.F_ZL_Fquantity = model1[i].F_ZL_Fquantity;// 质量管理科-确认实收数量(吨)
  3746. model.F_ZL_ImprovementRequirements = model1[i].F_ZL_ImprovementRequirements;//质量管理科-改进要求
  3747. model.F_ZL_CApprovalNo = model1[i].F_ZL_CApprovalNo;//质量管理科-对应审批工作流单号
  3748. model.F_ZL_CJ_IsRecord = model1[i].F_ZL_CJ_IsRecord;//质量管理科-抽检-未备案、已备案
  3749. model.F_VisitRemarks = model1[i].F_VisitRemarks;//回访备注
  3750. //model.SuperiorOpinion = AssCont(model1[i].F_ID);//上级处理意见
  3751. model.SuperiorOpinion = model1[i].F_SuperiorOpinion;//处理结果--外线
  3752. model.SuperiorOpinion2 = model1[i].F_SuperiorOpinion2;//处理结果--内线
  3753. model.F_Reasontimeout= model1[i].F_Reasontimeout;//超期原因
  3754. if (model1[i].F_SMSReply == 1)
  3755. {
  3756. model.F_SMSReply = "满意";//短信回访结果
  3757. }
  3758. else if (model1[i].F_SMSReply == 2)
  3759. {
  3760. model.F_SMSReply = "一般";//短信回访结果
  3761. }
  3762. else if (model1[i].F_SMSReply == 3)
  3763. {
  3764. model.F_SMSReply = "不满意";//短信回访结果
  3765. }
  3766. else
  3767. {
  3768. model.F_SMSReply = "";//短信回访结果
  3769. }
  3770. if (model1[i].F_IsVisit != 0)
  3771. {
  3772. model.F_IsVisit = "是";//是否回访
  3773. }
  3774. else
  3775. {
  3776. model.F_IsVisit = "否";//是否回访
  3777. }
  3778. model.F_IsAudit = model1[i].F_IsAudit;//是否审核
  3779. model.F_Highopinions = model1[i].F_Highopinions;//高层处理意见
  3780. model.F_CreateOn = model1[i].F_CreateOn; ;//添加时间
  3781. // model.F_CreateBy = model1[i].F_CreateBy; ;//添加人
  3782. if (!string.IsNullOrEmpty(model1[i].F_CreateBy))
  3783. {
  3784. Model.T_Sys_UserAccount creatname = userAccountBLL.GetModel(model1[i].F_CreateBy);
  3785. if (creatname != null)
  3786. {
  3787. model.F_CreateBy = creatname.F_WorkNumber; ;//添加人
  3788. model.F_CreateName = creatname.F_UserName; ;//添加人
  3789. model.F_CreatePhone = creatname.F_Mobile;
  3790. model.CreateName = creatname.F_UserName + "(" + creatname.F_WorkNumber + ")";
  3791. }
  3792. }
  3793. model.F_UpdateBy = model1[i].F_UpdateBy;//修改人工号
  3794. model.F_UpdateOn = model1[i].F_UpdateOn; ;//修改人工号
  3795. if (model1[i].F_IsAudit != 0 && model1[i].F_IsAudit != null)
  3796. {
  3797. if (model1[i].F_AuditState == 0)
  3798. {
  3799. model.F_AuditState = "同意上报";
  3800. }
  3801. else if (model1[i].F_AuditState == 1)
  3802. {
  3803. model.F_AuditState = "驳回修订";
  3804. }
  3805. else
  3806. {
  3807. model.F_AuditState = "强制结案";
  3808. }
  3809. }
  3810. else
  3811. {
  3812. model.F_AuditState = "";
  3813. }
  3814. model.F_AuditBy = model1[i].F_AuditBy;//审核人
  3815. model.F_AuditOn = model1[i].F_AuditOn;//审核时间
  3816. model.F_AuditCont = model1[i].F_AuditCont;//审核内容
  3817. // model.RemainingTime = float.Parse(string.Format("{0:f2}", TimeToOver(model1[i].F_ID, model1[i].F_limit)));
  3818. float c = TimeToOver(model1[i].F_ID, model1[i].F_limit);
  3819. float a = Math.Abs(c);
  3820. int days = (int)Math.Floor(Convert.ToDouble(a / 24));
  3821. int hours = days > 0
  3822. ? (int)Math.Floor(Convert.ToDouble((a - days * 24)))
  3823. : (int)Math.Floor(Convert.ToDouble(a));
  3824. float minutes = hours > 0
  3825. ? a * 60 - days * 1440 - hours * 60
  3826. : 0;
  3827. if (c > 0)
  3828. model.RemainingTime = string.Format("剩余{0:f0}天{1:f0}时{2:f0}分", days, hours, minutes);
  3829. else
  3830. model.RemainingTime = string.Format("超时{0:f0}天{1:f0}时{2:f0}分", days, hours, minutes);
  3831. #region 内线超时时间计算
  3832. //float c2 = TimeToOver(model1[i].F_ID, model1[i].F_limit, 2);
  3833. //float a2 = Math.Abs(c2);
  3834. //int days2 = (int)Math.Floor(Convert.ToDouble(a2 / 24));
  3835. //int hours2 = days2 > 0
  3836. // ? (int)Math.Floor(Convert.ToDouble((a2 - days2 * 24)))
  3837. // : (int)Math.Floor(Convert.ToDouble(a2));
  3838. //float minutes2 = hours2 > 0
  3839. // ? a2 * 60 - days2 * 1440 - hours2 * 60
  3840. // : 0;
  3841. //if (c2 > 0)
  3842. // model.RemainingTime2 = string.Format("剩余{0:f0}天{1:f0}时{2:f0}分", days2, hours2, minutes2);
  3843. //else
  3844. // model.RemainingTime2 = string.Format("超时{0:f0}天{1:f0}时{2:f0}分", days2, hours2, minutes2);
  3845. #endregion
  3846. if (ua != null)
  3847. {
  3848. var itemlast = itembll.GetModelList(" F_WoID='" + model.F_ID + "' order by F_ID desc").FirstOrDefault();
  3849. if (itemlast != null)
  3850. model.F_UserCode = itemlast.F_CreateUser;
  3851. if (!string.IsNullOrEmpty(model.F_UserCode))
  3852. {
  3853. Model.T_Sys_UserAccount user = userAccountBLL.GetModel(model.F_UserCode);
  3854. if (user != null)
  3855. {
  3856. model.F_UserName = user?.F_UserName?? "";
  3857. Model.T_Sys_Department dept = departmentBLL.GetModel(user.F_DeptId);
  3858. if (dept != null)
  3859. {
  3860. model.F_NextDeptName = dept.F_DeptName;
  3861. }
  3862. }
  3863. }
  3864. }
  3865. model.F_limit = model1[i].F_limit;
  3866. int day = (int)Math.Floor(Convert.ToDouble(model.F_limit / 24));
  3867. int hour = day > 0
  3868. ? (int)Math.Floor(Convert.ToDouble((model.F_limit - day * 24)))
  3869. : (int)Math.Floor(Convert.ToDouble(model.F_limit));
  3870. string time = "";
  3871. if (day > 0) time += day + "天";
  3872. if (hour > 0) time += hour + "小时";
  3873. model.F_limitTime = time;
  3874. //if (model1[i].F_Type !="3")
  3875. //{
  3876. // #region 判断外线是否超时
  3877. // if (TimeToOver(model1[i].F_ID, model1[i].F_limit) < 0)
  3878. // {
  3879. // model.F_IsOver = 1;
  3880. // }
  3881. // #endregion
  3882. // #region 判断内线是否超时
  3883. // else if (TimeToOver(model1[i].F_ID, model1[i].F_limit, 2) < 0)
  3884. // {
  3885. // model.F_IsOver = 2; //内线超时
  3886. // }
  3887. // #endregion
  3888. // else
  3889. // {
  3890. // model.F_IsOver = model1[i].F_IsOver;
  3891. // }
  3892. //}
  3893. model.F_IsOver = model1[i].F_IsOver;
  3894. model.F_VisitResultScore = model1[i].F_VisitResultScore;
  3895. model.F_EffectiveScore = model1[i].F_EffectiveScore;
  3896. model.F_ServiceAttitude = model1[i].F_ServiceAttitude;
  3897. model.F_ProductQuality = model1[i].F_ProductQuality;
  3898. model.F_NPS = model1[i].F_NPS;
  3899. model.F_EvaluationResult = model1[i].F_EvaluationResult;
  3900. model.F_MailingNumber = model1[i].F_MailingNumber;
  3901. model.F_ExpressName = model1[i].F_ExpressName;
  3902. model.F_WorkmanShip = model1[i].F_WorkmanShip;//质量管理科-工艺
  3903. model.F_Manufacturers = model1[i].F_Manufacturers;//质量管理科-原料及厂家
  3904. model.F_ProductionNum = model1[i].F_ProductionNum;//质量管理科-该批次生产数量
  3905. model.F_Flag = model1[i].F_Flag;//1单线外 2单线内 3双线 9市场科可以双线指派工单 0 未指派工单
  3906. if (!string.IsNullOrEmpty(model1[i].F_Material_CreateBy))
  3907. {
  3908. model.F_Material_CreateBy = userAccountBLL.GetModel(model1[i].F_Material_CreateBy).F_UserName;
  3909. model.F_Material_CreateTime = model1[i].F_Material_CreateTime?.ToString("yyyy-MM-dd HH:mm:ss") ?? "";
  3910. }
  3911. if (ua != null)
  3912. {
  3913. model.inout = GetNodeState(model1[i].F_ID, ua.F_UserCode, state);
  3914. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  3915. if (deptmodel != null)
  3916. {
  3917. model.F_Deptid = deptmodel.F_DeptId;
  3918. model.F_DeptName = deptmodel.F_DeptName;
  3919. }
  3920. }
  3921. #endregion
  3922. Input.Add(model);
  3923. }
  3924. return Input;
  3925. }
  3926. else
  3927. {
  3928. return null;
  3929. }
  3930. }
  3931. /// <summary>
  3932. /// 是否超时
  3933. /// </summary>
  3934. /// <param name="id"></param>
  3935. /// <returns></returns>
  3936. private float TimeToOver(int id, int limit, int flag = 1)
  3937. {
  3938. string strsql = "";
  3939. if (flag == 1)
  3940. {
  3941. strsql = " and F_Type in(1,3)";
  3942. }
  3943. else if (flag == 2)
  3944. {
  3945. strsql = " and F_Type in(2,3)";
  3946. }
  3947. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + "" + strsql + " and F_WoID=" + id);
  3948. string time1 = "", time2 = ""; int x = 0, y = 0;
  3949. if (itemlasts.Count > 0)
  3950. {
  3951. for (int z = 0; z < itemlasts.Count; z++)
  3952. {
  3953. if (itemlasts[z].F_WoState >= 1)
  3954. {
  3955. if (itemlasts[z].F_WoState == 1)
  3956. {
  3957. x = z;
  3958. time1 = itemlasts[z].F_CreateTime.ToString();
  3959. break;
  3960. }
  3961. }
  3962. }
  3963. for (int i = 0; i < itemlasts.Count; i++)
  3964. {
  3965. if (itemlasts[i].F_WoState >= 1)
  3966. {
  3967. if (itemlasts[i].F_WoState == 10 || itemlasts[i].F_WoState == 11)
  3968. {
  3969. y = i;
  3970. time2 = itemlasts[i].F_CreateTime.ToString();
  3971. }
  3972. }
  3973. }
  3974. if (time2 != "")
  3975. {
  3976. if (time1 != "")
  3977. {
  3978. if (y > x)
  3979. {
  3980. System.TimeSpan a = DateTime.Parse(time2) - DateTime.Parse(time1);
  3981. float b = limit - (float)a.TotalHours;
  3982. return b;
  3983. }
  3984. else
  3985. {
  3986. System.TimeSpan a = DateTime.Now - DateTime.Parse(time1);
  3987. float b = limit - (float)a.TotalHours;
  3988. return b;
  3989. }
  3990. }
  3991. else
  3992. {
  3993. return 0;
  3994. }
  3995. }
  3996. else if (time1 != "")
  3997. {
  3998. System.TimeSpan a = DateTime.Now - DateTime.Parse(time1);
  3999. float b = limit - (float)a.TotalHours;
  4000. return b;
  4001. }
  4002. else
  4003. {
  4004. return 0;
  4005. }
  4006. }
  4007. else
  4008. {
  4009. return 0;
  4010. }
  4011. }
  4012. private string AssCont(int id)
  4013. {
  4014. string cont = "";
  4015. var itemlist = itembll.GetModelList("F_WoID=" + id + "and F_IsUsed=0" + "order by F_ID desc");
  4016. if (itemlist.Count > 0)
  4017. {
  4018. cont = itemlist[0].F_OptContent;
  4019. }
  4020. return cont;
  4021. }
  4022. /// <summary>
  4023. /// 获取当前用户上一级的用户
  4024. /// </summary>
  4025. /// <param name="OpenId"></param>
  4026. /// <returns></returns>
  4027. public Model.T_Sys_UserAccount GetUser(string OpenId)
  4028. {
  4029. if (!string.IsNullOrEmpty(OpenId))
  4030. {
  4031. // int userId = CurrentUser.UserData.F_UserId;
  4032. // Model.T_Sys_UserAccount ua = userAccountBLL.GetModel(userId);
  4033. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  4034. if (ua != null)
  4035. {
  4036. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  4037. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  4038. // var dept = departmentBLL.GetModel(deptmodel.F_ParentId);
  4039. #region 业务员
  4040. if (ro.F_RoleCode == "YWY")
  4041. {
  4042. if (deptmodel != null)
  4043. {
  4044. Model.T_Sys_UserAccount userModel = userAccountBLL.GetModelList(" F_DeptId=" + deptmodel.F_DeptId + " and F_RoleId=60 ").FirstOrDefault();
  4045. if (userModel != null)
  4046. return userModel;
  4047. else
  4048. {
  4049. Model.T_Sys_UserAccount userModel1 = userAccountBLL.GetModelList(" F_DeptId=" + deptmodel.F_DeptId + " and F_RoleId=62 ").FirstOrDefault();
  4050. return userModel1;
  4051. }
  4052. //if (deptmodel.F_Layer == 2)
  4053. //{
  4054. // Model.T_Sys_UserAccount userModel = userAccountBLL.GetModelList(" F_DeptId=" + deptmodel.F_DeptId + " and F_RoleId=60 ").FirstOrDefault();
  4055. // if (userModel!=null )
  4056. // return userModel;
  4057. // else
  4058. // {
  4059. // var dept = departmentBLL.GetModel(deptmodel.F_ParentId);
  4060. // if (dept != null)
  4061. // {
  4062. // Model.T_Sys_UserAccount userModel1 = userAccountBLL.GetModelList(" F_DeptId=" + dept.F_DeptId + " and F_RoleId=62 ").FirstOrDefault();
  4063. // return userModel1;
  4064. // }
  4065. // }
  4066. //}
  4067. //if (deptmodel.F_Layer == 1)
  4068. //{
  4069. // Model.T_Sys_UserAccount userModel = userAccountBLL.GetModelList(" F_DeptId=" + deptmodel.F_DeptId + " and F_RoleId=62 ").FirstOrDefault();
  4070. // return userModel;
  4071. //}
  4072. }
  4073. else
  4074. {
  4075. return null;
  4076. }
  4077. }
  4078. #endregion
  4079. #region 大区经理
  4080. else if (ro.F_RoleCode == "DQJL")
  4081. {
  4082. return null;
  4083. }
  4084. #endregion
  4085. #region 分公司经理
  4086. else if (ro.F_RoleCode == "FGSJL")
  4087. {
  4088. if (deptmodel != null)
  4089. {
  4090. var dept = departmentBLL.GetModel(deptmodel.F_ParentId);
  4091. if (dept != null)
  4092. {
  4093. Model.T_Sys_UserAccount userModel = userAccountBLL.GetModelList(" F_DeptId=" + dept.F_DeptId + " and F_RoleId=62 ").FirstOrDefault();
  4094. if (userModel!=null )
  4095. return userModel;
  4096. }
  4097. else
  4098. {
  4099. return null;
  4100. }
  4101. }
  4102. else
  4103. {
  4104. return null;
  4105. }
  4106. }
  4107. #endregion
  4108. }
  4109. return null;
  4110. }
  4111. else
  4112. {
  4113. return null;
  4114. }
  4115. }
  4116. /// <summary>
  4117. /// 获取上一级管理员
  4118. /// </summary>
  4119. /// <param name="OpenId"></param>
  4120. /// <returns></returns>
  4121. [WechatActionFilter]
  4122. public ActionResult GetDpment(string OpenId)
  4123. {
  4124. if (!string.IsNullOrEmpty(OpenId))
  4125. {
  4126. if (GetUser(OpenId) != null)
  4127. {
  4128. return Success("获取成功!", GetUser(OpenId));
  4129. }
  4130. else
  4131. {
  4132. return Success("获取失败!", null);
  4133. }
  4134. }
  4135. else
  4136. {
  4137. return Error("OpenId不能为空!");
  4138. }
  4139. }
  4140. /// <summary>
  4141. /// 修改密码
  4142. /// </summary>
  4143. /// <returns></returns>
  4144. [WechatActionFilter]
  4145. public ActionResult UpdatePassWord()
  4146. {
  4147. string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  4148. //5--业主(客户档案会员)
  4149. int usertype = RequestString.GetInt("usertype", 0);
  4150. //原密码
  4151. string oldpwd = RequestString.GetFormString("oldpwd").Trim();
  4152. string pwd = RequestString.GetFormString("pwd").Trim();
  4153. string repeatpwd = RequestString.GetFormString("repeatpwd").Trim();
  4154. if (usertype == 0)
  4155. return Error("无权修改密码");
  4156. if (string.IsNullOrWhiteSpace(oldpwd))
  4157. return Error("请输入原密码");
  4158. if (string.IsNullOrWhiteSpace(pwd))
  4159. return Error("请输入新密码");
  4160. if (string.IsNullOrWhiteSpace(repeatpwd))
  4161. return Error("请再次输入新密码");
  4162. if (!pwd.Equals(repeatpwd))
  4163. return Error("两个新密码不同,请重新输入");
  4164. var model = new Model.T_Sys_UserAccount();
  4165. var modelCus = new Model.T_Cus_CustomerBaseNew();
  4166. //坐席表
  4167. if (usertype < 5)
  4168. {
  4169. model = userAccountBLL.GetModelByOpenid(stropenid);
  4170. if (model != null)
  4171. {
  4172. if (!model.F_Password.Equals(oldpwd)) return Error("原密码不正确");
  4173. model.F_Password = pwd;
  4174. if (userAccountBLL.Update(model))
  4175. return Success("重置密码成功");
  4176. }
  4177. return Error("重置密码失败");
  4178. }
  4179. //客户档案表
  4180. modelCus = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();//customerBaseBLL.GetModelByOpenid(stropenid);
  4181. if (modelCus != null)
  4182. {
  4183. if (!modelCus.F_WxPassword.Equals(oldpwd)) return Error("原密码不正确");
  4184. modelCus.F_WxPassword = pwd;
  4185. if (customerBaseBLL.Update(modelCus))
  4186. return Success("重置密码成功");
  4187. }
  4188. return Error("重置密码失败");
  4189. }
  4190. /// <summary>
  4191. /// 验证生产批次号为15位
  4192. /// </summary>
  4193. private bool vaBatchNumber(string code)
  4194. {
  4195. var res = false;
  4196. if (code.Length == 15)
  4197. {
  4198. char chr = code[12];
  4199. if (chr > 'A' && chr < 'Z')
  4200. {
  4201. string code1 = code.Substring(0, 12);
  4202. string code2 = code.Substring(15 - 2, 2);
  4203. if (Regex.IsMatch(code1, @"^\d{12}$") && Regex.IsMatch(code2, @"^\d{2}$"))
  4204. res = true;
  4205. }
  4206. else
  4207. {
  4208. res = false;
  4209. }
  4210. }
  4211. return res;
  4212. }
  4213. /// <summary>
  4214. /// 验证物料编码为10位纯数字
  4215. /// </summary>
  4216. private bool valcode(string code, int number)
  4217. {
  4218. var res = false;
  4219. //11位数字
  4220. if (code.Length == number && Regex.IsMatch(code, @"^\d{" + number + "}$"))
  4221. res = true;
  4222. return res;
  4223. }
  4224. /// <summary>
  4225. /// 验证物料编号是否唯一
  4226. /// </summary>
  4227. private bool gematerque(int id, string code)
  4228. {
  4229. var sql = " F_IsDelete=0 ";
  4230. sql += "and (F_MaterialCode='" + code + "')";
  4231. if (id > 0)
  4232. sql += " and F_Id<>" + id;
  4233. var count = mmBLL.GetModelList(sql).Count();
  4234. return count > 0;
  4235. }
  4236. /// <summary>
  4237. /// 验证客户编号是否唯一
  4238. /// </summary>
  4239. private bool getunique(int id, string code)
  4240. {
  4241. var sql = " F_IsDelete=0 ";
  4242. sql += "and (F_CustomerCode='" + code + "')";
  4243. if (id > 0)
  4244. sql += " and F_CustomerId<>" + id;
  4245. var count = customerBaseBLL.GetModelList(sql).Count();
  4246. return count > 0;
  4247. }
  4248. /// <summary>
  4249. /// 获取我参与的工单编号
  4250. /// </summary>
  4251. /// <param name="user"></param>
  4252. /// <returns></returns>
  4253. public string GetParticipateID(string user)
  4254. {
  4255. string str = string.Empty;
  4256. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_CreateUser in(" + user + ") and F_OptType in( 0,1,7 )";
  4257. ;
  4258. return str;
  4259. }
  4260. /// <summary>
  4261. /// 获取我参与的工单编号
  4262. /// </summary>
  4263. /// <param name="user"></param>
  4264. /// <returns></returns>
  4265. public string GetID(string user)
  4266. {
  4267. string str = string.Empty;
  4268. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_CreateUser in(" + user + ") ";
  4269. ;
  4270. return str;
  4271. }
  4272. /// <summary>
  4273. /// 获取我参与的工单编号
  4274. /// </summary>
  4275. /// <param name="user"></param>
  4276. /// <returns></returns>
  4277. public string GetParticipate(string user)
  4278. {
  4279. string str = string.Empty;
  4280. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_CreateUser in(" + user + ") ";
  4281. ;
  4282. return str;
  4283. }
  4284. private bool IsCustomerBaseNew(WorkOrderNewInput input)
  4285. {
  4286. bool n = false;
  4287. if (!string.IsNullOrEmpty(input.F_CustomerID) || !string.IsNullOrEmpty(input.F_CompanyName)
  4288. || !string.IsNullOrEmpty(input.F_AreaName) || !string.IsNullOrEmpty(input.F_BranchName)
  4289. || !string.IsNullOrEmpty(input.F_Salesman) || !string.IsNullOrEmpty(input.F_SalesPhone)
  4290. || !string.IsNullOrEmpty(input.F_Brands) )
  4291. {
  4292. n = true;
  4293. }
  4294. return n;
  4295. }
  4296. /// <summary>
  4297. /// 添加客户
  4298. /// </summary>
  4299. private Model.T_Cus_CustomerBaseNew inputtooCustomer(Model.T_Cus_CustomerBaseNew model, WorkOrderNewInput input)
  4300. {
  4301. var newmodel = model;
  4302. if (!string.IsNullOrWhiteSpace(input.F_CustomerID.ToString()))
  4303. model.F_CustomerCode = input.F_CustomerID.ToString();
  4304. else
  4305. model.F_CustomerCode = model.F_CustomerCode;
  4306. if (!string.IsNullOrWhiteSpace(input.F_CompanyName))
  4307. model.F_CompanyName = input.F_CompanyName;
  4308. #region 基本字段
  4309. if (!string.IsNullOrEmpty(input.F_AreaName))
  4310. {
  4311. Model.T_Sys_Department pdModel = new Model.T_Sys_Department();
  4312. try
  4313. {
  4314. pdModel = departmentBLL.GetModel(int.Parse(input.F_AreaName));
  4315. }
  4316. catch
  4317. {
  4318. pdModel = departmentBLL.GetModel(input.F_AreaName);
  4319. }
  4320. model.F_AreaID = pdModel.F_DeptId.ToString();
  4321. }
  4322. if (!string.IsNullOrEmpty(input.F_BranchName))
  4323. {
  4324. Model.T_Sys_Department pdModel = new Model.T_Sys_Department();
  4325. try
  4326. {
  4327. pdModel = departmentBLL.GetModel(int.Parse(input.F_BranchName));
  4328. }
  4329. catch
  4330. {
  4331. pdModel = departmentBLL.GetModel(input.F_BranchName);
  4332. }
  4333. model.F_BranchID = pdModel.F_DeptId.ToString();
  4334. }
  4335. model.F_Salesman = input.F_Salesman;//业务员
  4336. model.F_SalesPhone = input.F_SalesPhone;//业务员电话
  4337. model.F_Channel = input.F_Channel;// 渠道类型:总经销、二级商、种田大户、农户、化工客户、公司员工
  4338. model.F_Legal = input.F_CusName;//法人
  4339. model.F_LegalPhone = input.F_CusPhone;//法人电话
  4340. model.F_AddressProvince = input.F_AddressProvince;//省
  4341. model.F_AddressCity = input.F_AddressCity;//市
  4342. model.F_AddressCountry = input.F_AddressCountry;//县
  4343. model.F_AddressTownship = input.F_AddressTownship;//乡
  4344. model.F_AddressFull = input.F_AddressFull;//详细地址
  4345. model.F_Brands = input.F_Brands;// 经营品牌:心连心、手拉手、沃利沃、双心、空
  4346. model.F_IsRunXLX = input.F_IsRunXLX;// 是否经营心连心:是、否
  4347. model.F_AnnualSales = input.F_AnnualSales;//年销量
  4348. model.F_Formula = input.F_Formula;//配方
  4349. model.F_RaiseCrops = input.F_RaiseCrops;//种植作物
  4350. model.F_PlantingArea = input.F_PlantingArea;//种植面积
  4351. model.F_FertilizerBrand = input.F_FertilizerBrand;//用肥品牌
  4352. model.F_FileId = 0;
  4353. #endregion
  4354. return model;
  4355. }
  4356. private string GetCusCode(int i)
  4357. {
  4358. DateTime times = DateTime.Now.AddMinutes(i);
  4359. string time = times.ToString("yyMMddhhmm");
  4360. return time;
  4361. }
  4362. private string GetIntCode()
  4363. {
  4364. string time = DateTime.Now.ToString("hhmmss");
  4365. Random ran = new Random();
  4366. int RandKey = ran.Next(1000, 9999);
  4367. string timecode = 3 + "" + RandKey + "" + time;
  4368. return timecode;
  4369. }
  4370. private bool IsMaterial(WorkOrderNewInput input)
  4371. {
  4372. bool n = false;
  4373. if (!string.IsNullOrEmpty(input.F_MaterialID) || !string.IsNullOrEmpty(input.F_MaterialName)
  4374. || !string.IsNullOrEmpty(input.F_Model) || !string.IsNullOrEmpty(input.F_Specs)
  4375. || !string.IsNullOrEmpty(input.F_Level1) || !string.IsNullOrEmpty(input.F_Level2)
  4376. || !string.IsNullOrEmpty(input.F_Level3) || !string.IsNullOrEmpty(input.F_Brand)
  4377. || !string.IsNullOrEmpty(input.F_MaterialEffect) || !string.IsNullOrEmpty(input.F_Craft)
  4378. || !string.IsNullOrEmpty(input.F_Pipeline))
  4379. {
  4380. n = true;
  4381. }
  4382. return n;
  4383. }
  4384. private void AddMait(WorkOrderNewInput input, string usercode)
  4385. {
  4386. Model.T_Wo_MaterialManage dModel = new Model.T_Wo_MaterialManage();
  4387. dModel.F_MaterialCode = input.F_MaterialID.ToString();//物料编号
  4388. dModel.F_MaterialName = input.F_MaterialName;//物料名称
  4389. dModel.F_Model = input.F_Model;//型号
  4390. dModel.F_Specs = input.F_Specs;//规格
  4391. dModel.F_Level1 = input.F_Level1;//一级分类
  4392. dModel.F_Level2 = input.F_Level2;//二级分类
  4393. dModel.F_Level3 = input.F_Level3;//三级分类
  4394. dModel.F_Brand = input.F_Brand;//品牌
  4395. dModel.F_MaterialEffect = input.F_MaterialEffect;//复合肥肥效
  4396. dModel.F_Craft = input.F_Craft;//工艺
  4397. dModel.F_Pipeline = input.F_Pipeline;//产品线
  4398. dModel.F_IsDelete = 0;
  4399. dModel.F_CreateOn = DateTime.Now;
  4400. dModel.F_CreateBy = usercode;
  4401. int f = mmBLL.Add(dModel);
  4402. }
  4403. /// <summary>
  4404. /// 根据传入的对象和input的内容返回对象(添加修改使用)
  4405. /// </summary>
  4406. private Model.T_Wo_WorkOrder inputtoobj(Model.T_Sys_UserAccount ua, Model.T_Wo_WorkOrder model, WorkOrderNewInput input, int type)
  4407. {
  4408. string usercode = "";
  4409. if (ua != null)
  4410. {
  4411. usercode = ua.F_UserCode;
  4412. }
  4413. var newmodel = model;
  4414. if (input.F_ID != 0)
  4415. {
  4416. model.F_ID = input.F_ID;
  4417. }
  4418. else
  4419. {
  4420. model.F_ID = model.F_ID;//工单ID
  4421. }
  4422. if (type == 2)
  4423. {
  4424. model.F_WorkOrderCode = DateTime.Now.ToString("yyyyMMddHHmmssfff"); //工单编号
  4425. model.F_Source = model.F_Source;
  4426. }
  4427. else
  4428. {
  4429. model.F_WorkOrderCode = model.F_WorkOrderCode;//工单编号
  4430. model.F_Source = model.F_Source.ToString();//工单来源
  4431. }
  4432. if (input.F_Type == 2 || input.F_Type == 3)
  4433. {
  4434. if (string.IsNullOrEmpty(input.F_CustomerID))
  4435. {
  4436. var sql = $" and F_LegalPhone = '" + input.F_CusPhone.Trim() + "'";
  4437. var Customer = new BLL.T_Cus_CustomerBaseNew().GetModelList(" F_IsDelete = 0 " + sql).FirstOrDefault(); ;
  4438. if (Customer != null)
  4439. {
  4440. model.F_CustomerID = Customer.F_CustomerCode;
  4441. if (!string.IsNullOrEmpty(input.F_Salesman))
  4442. Customer.F_Salesman = input.F_Salesman;
  4443. if (!string.IsNullOrEmpty(input.F_SalesPhone))
  4444. Customer.F_SalesPhone = input.F_SalesPhone;
  4445. if (!string.IsNullOrEmpty(input.F_Channel))
  4446. Customer.F_Channel = input.F_Channel;
  4447. if (!string.IsNullOrEmpty(input.F_Brands))
  4448. Customer.F_Brands = input.F_Brands;
  4449. if (!string.IsNullOrEmpty(input.F_AreaName))
  4450. {
  4451. Model.T_Sys_Department pdModel = new Model.T_Sys_Department();
  4452. try
  4453. {
  4454. pdModel = departmentBLL.GetModel(int.Parse(input.F_AreaName));
  4455. }
  4456. catch
  4457. {
  4458. pdModel = departmentBLL.GetModel(input.F_AreaName);
  4459. }
  4460. Customer.F_AreaID = pdModel.F_DeptId.ToString();
  4461. }
  4462. else
  4463. {
  4464. Customer.F_AreaID = "";
  4465. }
  4466. if (!string.IsNullOrEmpty(input.F_BranchName))
  4467. {
  4468. Model.T_Sys_Department pdModel = new Model.T_Sys_Department();
  4469. try
  4470. {
  4471. pdModel = departmentBLL.GetModel(int.Parse(input.F_BranchName));
  4472. }
  4473. catch
  4474. {
  4475. pdModel = departmentBLL.GetModel(input.F_BranchName);
  4476. }
  4477. Customer.F_BranchID = pdModel.F_DeptId.ToString();
  4478. }
  4479. else
  4480. {
  4481. Customer.F_BranchID = "";
  4482. }
  4483. if (!string.IsNullOrEmpty(input.F_CompanyName ))
  4484. Customer.F_CompanyName = input.F_CompanyName;
  4485. customerBaseBLL.Update(Customer);
  4486. }
  4487. else
  4488. {
  4489. if (IsCustomerBaseNew(input))
  4490. {
  4491. if (string.IsNullOrEmpty(input.F_CustomerID))
  4492. {
  4493. int i = 0;
  4494. while (true)
  4495. {
  4496. if (!getunique(0, GetCusCode(i)))
  4497. {
  4498. input.F_CustomerID = GetCusCode(i);
  4499. break;
  4500. }
  4501. else
  4502. {
  4503. i++;
  4504. }
  4505. }
  4506. }
  4507. var CustomerBaseNewmodel = new Model.T_Cus_CustomerBaseNew();
  4508. CustomerBaseNewmodel.F_CustomerCode = input.F_CustomerID;
  4509. CustomerBaseNewmodel.F_CreateBy = usercode;
  4510. CustomerBaseNewmodel.F_CreateOn = DateTime.Now;
  4511. CustomerBaseNewmodel.F_IsDelete = 0;
  4512. customerBaseBLL.Add(inputtooCustomer(CustomerBaseNewmodel, input));
  4513. }
  4514. }
  4515. }
  4516. else
  4517. {
  4518. var Customer = customerBaseBLL.GetModel(input.F_CustomerID.Trim());
  4519. if (Customer != null)
  4520. {
  4521. if (!string.IsNullOrEmpty(input.F_Salesman))
  4522. Customer.F_Salesman = input.F_Salesman;
  4523. if (!string.IsNullOrEmpty(input.F_SalesPhone))
  4524. Customer.F_SalesPhone = input.F_SalesPhone;
  4525. if (!string.IsNullOrEmpty(input.F_Brands))
  4526. Customer.F_Brands = input.F_Brands;
  4527. if (!string.IsNullOrEmpty(input.F_CompanyName))
  4528. Customer.F_CompanyName = input.F_CompanyName.Trim();
  4529. if (!string.IsNullOrEmpty(input.F_Channel))
  4530. Customer.F_Channel = input.F_Channel;
  4531. if (!string.IsNullOrEmpty(input.F_AreaName))
  4532. {
  4533. Model.T_Sys_Department pdModel = new Model.T_Sys_Department();
  4534. try
  4535. {
  4536. pdModel = departmentBLL.GetModel(int.Parse(input.F_AreaName));
  4537. }
  4538. catch
  4539. {
  4540. pdModel = departmentBLL.GetModel(input.F_AreaName);
  4541. }
  4542. Customer.F_AreaID = pdModel.F_DeptId.ToString();
  4543. }
  4544. else
  4545. {
  4546. Customer.F_AreaID = "";
  4547. }
  4548. if (!string.IsNullOrEmpty(input.F_BranchName))
  4549. {
  4550. {
  4551. Model.T_Sys_Department pdModel = new Model.T_Sys_Department();
  4552. try
  4553. {
  4554. pdModel = departmentBLL.GetModel(int.Parse(input.F_BranchName));
  4555. }
  4556. catch
  4557. {
  4558. pdModel = departmentBLL.GetModel(input.F_BranchName);
  4559. }
  4560. Customer.F_BranchID = pdModel.F_DeptId.ToString();
  4561. }
  4562. }
  4563. else
  4564. {
  4565. Customer.F_BranchID = "";
  4566. }
  4567. if (!string.IsNullOrEmpty(input.F_CompanyName))
  4568. Customer.F_CompanyName = input.F_CompanyName;
  4569. customerBaseBLL .Update(Customer);
  4570. }
  4571. }
  4572. }
  4573. #region 基本字段
  4574. if (!string.IsNullOrEmpty(input.F_MaterialID))
  4575. {
  4576. model.F_MaterialID = input.F_MaterialID.ToString();//物料编码为11为纯数字
  4577. }
  4578. model.F_Source = input.F_Source.ToString();//工单来源
  4579. model.F_Type = input.F_Type.ToString();//工单类型:咨询及需求、投诉、抽检、其他(其它手动输入别的点选)
  4580. model.F_Production = input.F_Production;//生产单位
  4581. LogFactory.GetLogger("123").Debug(input.F_Production);
  4582. model.F_CusName = input.F_CusName;//客户姓名
  4583. model.F_CusPhone = input.F_CusPhone;//客户电话
  4584. model.F_CompanyName = input.F_CompanyName;//公司名称
  4585. model.F_IncidentProvince = input.F_IncidentProvince;//事发地-省
  4586. model.F_IncidentCity = input.F_IncidentCity;//事发地-市
  4587. model.F_IncidentCountry = input.F_IncidentCountry;//事发地-县
  4588. model.F_IncidentTownship = input.F_IncidentTownship;//事发地-乡
  4589. model.F_IncidentDetailed = input.F_IncidentDetailed;//事发地-详细
  4590. model.F_SalesBase = input.F_SalesBase;//销售基地:新乡、新疆、九江、东北、其他(其它手动输入别的点选)
  4591. model.F_Description = input.F_Description;//问题描述
  4592. model.F_ZX_Area = input.F_ZX_Area;// 大区
  4593. model.F_ZX_Branch = input.F_ZX_Branch;//分公司
  4594. if (!string.IsNullOrEmpty(input.F_Files))
  4595. model.F_Files = input.F_Files;//附件上传ids
  4596. else
  4597. model.F_Files = model.F_Files;//附件上传ids
  4598. model.F_Brand = input.F_WorkerBrand;//
  4599. model.F_DealType = model.F_DealType;//处理方式:当即办理、电话转接、网络转办(点选)
  4600. model.F_Canal = input.F_Canal;//处理方式:当即办理、电话转接、网络转办(点选)
  4601. #endregion
  4602. model.F_QuestionType = input.F_QuestionType;//问题类别(投诉抽捡和咨询类别不一样)
  4603. model.F_CustomerID = input.F_CustomerID;//客户编号为10为纯数字
  4604. model.F_MaterialID = input.F_MaterialID;//物料编码为11为纯数字
  4605. #region 投诉类
  4606. model.F_BatchNumber = input.F_BatchNumber;//生产批次号
  4607. model.F_TS_Formula = input.F_TS_Formula;// 投诉-配方
  4608. model.F_TS_Category = input.F_TS_Category;//投诉-产品种类:化肥、化工、其他
  4609. model.F_TS_Quantity = input.F_TS_Quantity;//投诉-问题数量(吨)
  4610. model.F_TS_Level = input.F_TS_Level;//投诉-重要级别:轻微、一般、较大、重大
  4611. #region 肥效类增加作物字段 20220307
  4612. if (!string.IsNullOrEmpty(input.F_Crops))
  4613. {
  4614. model.F_Crops = input.F_Crops;
  4615. }
  4616. #endregion
  4617. #endregion
  4618. #region 咨询类
  4619. // model.F_ZX_ProName = input.F_ZX_ProName;//咨询-产品名称:三聚氰胺、甲醇、液氨、二甲醚、糠醇、其他
  4620. model.F_ZX_Quantity = input.F_ZX_Quantity;// 咨询-问题数量(吨)
  4621. #endregion
  4622. #region 抽检类
  4623. model.F_CJ_Time = input.F_CJ_Time;// 抽检-抽检时间
  4624. model.F_CJ_Level = input.F_CJ_Level;// 抽检-抽检级别:乡镇级、县级、市级、省级及以上、个人送检
  4625. model.F_CJ_Unit = input.F_CJ_Unit;// 抽检-抽检单位:市场监督、农业部、土肥站、工商、联合执法、其他
  4626. model.F_CJ_TestUnit = input.F_CJ_TestUnit;//抽检-化验单位
  4627. model.F_CJ_Tonnage = input.F_CJ_Tonnage;//抽检-抽检吨数
  4628. model.F_CJ_BagNo = input.F_CJ_BagNo;//抽检-抽检袋数
  4629. model.F_CJ_Outlay = input.F_CJ_Outlay;//抽检-公关费用金额:单位元】
  4630. model.F_WxOpenId = input.F_WxOpenId;
  4631. // model.F_VisitRemarks = input.F_VisitRemarks;//回访备注
  4632. //if (!string.IsNullOrEmpty(input.F_BatchNumber))
  4633. //{
  4634. // if (type == 1)
  4635. // {
  4636. // model.F_SC_QualityMonth = new WorkOrderController().GetProTime(input.F_BatchNumber, DateTime.Parse(model.F_CreateOn.ToString())).ToString();
  4637. // }
  4638. // else
  4639. // {
  4640. // model.F_SC_QualityMonth = new WorkOrderController().GetProTime(input.F_BatchNumber, DateTime.Now).ToString();
  4641. // }
  4642. //}
  4643. if (type == 1)
  4644. {
  4645. model.F_State = model.F_State;//工单状态
  4646. model.F_CreateOn = model.F_CreateOn;//添加时间
  4647. model.F_CreateBy = model.F_CreateBy;//添加人
  4648. model.F_UpdateBy = usercode;//修改人工号
  4649. model.F_UpdateOn = DateTime.Now;//修改人工号
  4650. if (input.F_UpdateCount != null)
  4651. {
  4652. model.F_UpdateCount = model.F_UpdateCount + 1;//修改次数
  4653. }
  4654. else
  4655. {
  4656. model.F_UpdateCount = 1;//修改次数
  4657. }
  4658. model.F_limit = model.F_limit;
  4659. }
  4660. else
  4661. {
  4662. model.F_limit = 0;
  4663. model.F_State = (int)EnumWorkOrderState.neworder;
  4664. model.F_State2= (int)EnumWorkOrderState.neworder;
  4665. model.F_CreateBy = usercode;
  4666. model.F_CreateOn = DateTime.Now;
  4667. }
  4668. model.F_IsVisit = 1;
  4669. model.F_IsDelete = 0;
  4670. model.F_IsOver = 0;
  4671. #endregion
  4672. return model;
  4673. }
  4674. /// <summary>
  4675. /// 获取我参与的工单编号
  4676. /// </summary>
  4677. /// <param name="user"></param>
  4678. /// <returns></returns>
  4679. public string GetCYWorkOrderID(string user)
  4680. {
  4681. string str = string.Empty;
  4682. str = "select F_WoID from T_Wo_WorkOrderItem_New where F_CreateUser in(" + user + ") and F_OptType in( 1,3,13 )";
  4683. return str;
  4684. }
  4685. /// <summary>
  4686. /// 获取高层
  4687. /// </summary>
  4688. /// <param name="deptId"></param>
  4689. /// <returns></returns>
  4690. public ActionResult GetHighlevel()
  4691. {
  4692. var user = userAccountBLL.GetModelList(" F_RoleId=61");
  4693. if (user != null)
  4694. return Success("获取高层信息成功", new
  4695. {
  4696. user
  4697. });
  4698. return Error("获取高层信息失败");
  4699. }
  4700. /// <summary>
  4701. /// 验证客户电话是否唯一
  4702. /// </summary>
  4703. private bool getunphone(int id, string phone)
  4704. {
  4705. var sql = " F_IsDelete=0 ";
  4706. sql += "and (F_LegalPhone='" + phone + "')";
  4707. if (id > 0)
  4708. sql += " and F_CustomerId<>" + id;
  4709. var count = customerBaseBLL.GetModelList(sql).Count();
  4710. return count > 0;
  4711. }
  4712. /// <summary>
  4713. /// 添加工单
  4714. /// </summary>
  4715. /// <returns></returns>
  4716. public ActionResult CustomAdd(WorkOrderNewInput input, int overtime = 0, int sms = 0)
  4717. {
  4718. if (string.IsNullOrEmpty(input.F_CusName))
  4719. return Error("请输入客户姓名!");
  4720. if (string.IsNullOrEmpty(input.F_CusPhone))
  4721. return Error("请输入客户电话!");
  4722. if (input.F_Type == 3)
  4723. {
  4724. if (string.IsNullOrEmpty(input.F_Files))
  4725. return Error("请上传抽检单");
  4726. if (string.IsNullOrEmpty(input.F_CJ_Time.ToString()))
  4727. return Error("请选择抽检时间");
  4728. }
  4729. if (!string.IsNullOrEmpty(input.F_SalesPhone))
  4730. {
  4731. if (!IsNumeric(input.F_SalesPhone))
  4732. return Error("请输入正确的业务员电话");
  4733. }
  4734. var model = new Model.T_Wo_WorkOrder();
  4735. #region 保存客户基本信息
  4736. model = inputtoobj(null , model, input, 2);
  4737. model.F_State = (int)EnumWorkOrderState.customers;
  4738. model.F_limit = overtime;
  4739. #endregion
  4740. long n = woBLL.Add(model);
  4741. if (n > 0)
  4742. {
  4743. #region 流转上一级领导审批
  4744. Model.T_Wo_WorkOrder modlelist = new BLL.T_Wo_WorkOrder().GetModel(n);
  4745. if (modlelist != null)
  4746. {
  4747. AddLog(modlelist.F_ID, 0, "客户" + "创建工单", (int)EnumItemType.deal, (int)EnumItemOpt.create, "", 0, null, overtime, sms);
  4748. return Success("添加成功");
  4749. }
  4750. #endregion
  4751. return Success("添加成功!");
  4752. }
  4753. else
  4754. return Error("添加失败!");
  4755. }
  4756. /// <summary>
  4757. /// 添加工单
  4758. /// </summary>
  4759. /// <returns></returns>
  4760. public ActionResult Add(WorkOrderNewInput input, int overtime = 0, int sms = 0, int tempid = 0)
  4761. {
  4762. if (!string.IsNullOrEmpty(input.F_WxOpenId))
  4763. {
  4764. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + input.F_WxOpenId + "'").FirstOrDefault();
  4765. // string usercode = CurrentUser.UserData.F_UserCode;
  4766. // Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModel(userId);
  4767. if (ua == null && input.F_Source != 3)
  4768. {
  4769. return Error("无操作权限!");
  4770. }
  4771. if (input .F_Source !=3& input.F_Type == 2 || input.F_Type == 5)
  4772. {
  4773. if (string.IsNullOrEmpty(input.F_SalesBase))
  4774. return Error("请输入基地!");
  4775. if (string.IsNullOrEmpty(input.F_QuestionType))
  4776. return Error("请选择问题类别!");
  4777. }
  4778. //if (!string.IsNullOrEmpty(input.F_BatchNumber) && !vaBatchNumber(input.F_BatchNumber))
  4779. //{
  4780. // return Error("请输入正确的生产批次号!");
  4781. //}
  4782. //else
  4783. //{
  4784. // if (!string.IsNullOrEmpty(input.F_BatchNumber))
  4785. // {
  4786. // var prono = input.F_BatchNumber.Substring(0, 6);
  4787. // try
  4788. // {
  4789. // var pronos = DateTime.ParseExact(prono, "yyMMdd", null).ToString("yyyy-MM-dd");
  4790. // var protime = Convert.ToDateTime(pronos);
  4791. // if (DateTime.Parse(pronos) > DateTime.Now)
  4792. // {
  4793. // return Error("生产批次号错误,生产日期不能大于当前时间!");
  4794. // }
  4795. // }
  4796. // catch
  4797. // {
  4798. // return Error("生产批次号错误,日期格式错误!");
  4799. // }
  4800. // }
  4801. //}
  4802. if (!string.IsNullOrEmpty(input.F_CustomerID) && !valcode(input.F_CustomerID.ToString(), 10))
  4803. return Error("客户编号为10为纯数字!");
  4804. if (!string.IsNullOrEmpty(input.F_MaterialID) && !valcode(input.F_MaterialID.ToString(), 11))
  4805. return Error("物料编码为11为纯数字!");
  4806. if (string.IsNullOrEmpty(input.F_CusName))
  4807. return Error("请输入客户姓名!");
  4808. if (string.IsNullOrEmpty(input.F_CusPhone))
  4809. return Error("请输入客户电话!");
  4810. if (!string.IsNullOrEmpty(input.F_CustomerID))
  4811. {
  4812. var Customer = customerBaseBLL.GetModel(input.F_CustomerID.Trim());
  4813. if (Customer == null)
  4814. return Error("无此客户编码!");
  4815. }
  4816. if (!string.IsNullOrWhiteSpace(input.F_MaterialID))
  4817. {
  4818. var Customer = mmBLL.GetModel(input.F_MaterialID.Trim());
  4819. if (Customer == null)
  4820. return Error("无此物料编码!");
  4821. }
  4822. if (input.F_Type == 3)
  4823. {
  4824. if (string.IsNullOrEmpty(input.F_Files))
  4825. return Error("请上传抽检单");
  4826. if (string.IsNullOrEmpty(input.F_CJ_Time.ToString()))
  4827. return Error("请选择抽检时间");
  4828. if (overtime==0)
  4829. {
  4830. overtime = 2160;
  4831. }
  4832. }
  4833. if (!string.IsNullOrEmpty(input.F_SalesPhone))
  4834. {
  4835. if (!IsNumeric(input.F_SalesPhone))
  4836. return Error("请输入正确的业务员电话");
  4837. }
  4838. #region 暂存数据删除
  4839. new BLL.T_Wo_TempStorage().DelteByWhere($"F_CreateBy={ua.F_UserCode}");
  4840. //if (tempid > 0)
  4841. //{
  4842. // var tempmodel = new BLL.T_Wo_TempStorage().GetModel(tempid);
  4843. // if (tempmodel != null)
  4844. // new BLL.T_Wo_TempStorage().DelteByWhere($"F_CreateBy={ua.F_UserCode}");
  4845. //}
  4846. #endregion
  4847. var model = new Model.T_Wo_WorkOrder();
  4848. #region 保存客户基本信息
  4849. model = inputtoobj(ua, model, input, 2);
  4850. LogFactory.GetLogger("635").Debug("添加中。。。。");
  4851. if (model.F_Source == "3")
  4852. {
  4853. model.F_State = (int)EnumWorkOrderState.customers;
  4854. model.F_State2 = (int)EnumWorkOrderState.customers;
  4855. }
  4856. else
  4857. {
  4858. model.F_State = (int)EnumWorkOrderState.audit;
  4859. model.F_State2 = (int)EnumWorkOrderState.audit;
  4860. }
  4861. model.F_limit = overtime;
  4862. #endregion
  4863. long n = woBLL.Add(model);
  4864. if (n > 0)
  4865. {
  4866. #region 流转上一级领导审批
  4867. Model.T_Wo_WorkOrder modlelist = new BLL.T_Wo_WorkOrder().GetModel(n);
  4868. if (modlelist != null)
  4869. {
  4870. if (ua != null && model.F_Source != "3")
  4871. {
  4872. if (GetUser(input.F_WxOpenId) != null)
  4873. {
  4874. var user = GetUser(input.F_WxOpenId);
  4875. string deptname = "", deptname1 = "";
  4876. var deptmodel = departmentBLL.GetModel(user.F_DeptId);
  4877. if (deptmodel != null)
  4878. {
  4879. deptname = deptmodel.F_DeptName + "-";
  4880. }
  4881. var deptmodel1 = departmentBLL.GetModel(ua.F_DeptId);
  4882. if (deptmodel1 != null)
  4883. {
  4884. deptname1 = deptmodel1.F_DeptName + "-";
  4885. }
  4886. 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);
  4887. 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);
  4888. if (sms == 1 && !string.IsNullOrEmpty(user.F_Mobile))
  4889. {
  4890. SendSms(model.F_Type, user.F_Mobile, ua.F_UserId);
  4891. }
  4892. }
  4893. else
  4894. {
  4895. string deptname1 = "";
  4896. int dapt = 0, nextda = 0, nextda2 = 0;
  4897. string deptment = "";
  4898. var deptmodel1 = departmentBLL.GetModel(ua.F_DeptId);
  4899. if (deptmodel1 != null)
  4900. {
  4901. deptname1 = deptmodel1.F_DeptName + "-";
  4902. dapt = deptmodel1.F_ParentId;
  4903. deptment = deptmodel1.F_DeptName;
  4904. }
  4905. AddLog(modlelist.F_ID, 0, deptname1 + ua.F_UserName + "(" + ua.F_WorkNumber + ")" + "创建工单", (int)EnumWorkOrderState.neworder, (int)EnumItemOpt.create, "", 0, ua, overtime, sms);
  4906. string opt = "", opt2 = "";
  4907. //if (dapt != 0)
  4908. //{
  4909. if (CirculMarket(ua.F_DeptId, 11))
  4910. {
  4911. nextda = 427;
  4912. opt = "流转运营中心";
  4913. }
  4914. else if (CirculMarket(ua.F_DeptId, 14))
  4915. {
  4916. nextda = 57;
  4917. opt = "流转营销管理处";
  4918. }
  4919. else if (CirculMarket(ua.F_DeptId, 15))
  4920. {
  4921. nextda = 74;
  4922. opt = "流转策划推广";
  4923. }
  4924. else if (CirculMarket(ua.F_DeptId, 16))
  4925. {
  4926. nextda = 88;
  4927. opt = "流转销售部";
  4928. }
  4929. else if (CirculMarket(ua.F_DeptId, 18))
  4930. {
  4931. nextda = 268;
  4932. opt = "流转车用尿素";
  4933. }
  4934. else if (CirculMarket(ua.F_DeptId, 20))
  4935. {
  4936. nextda = 422;
  4937. opt = "流转营销中心市场科";
  4938. nextda2 = 295;
  4939. opt2 = "流转新乡黑科质检";
  4940. }
  4941. else if (CirculMarket(ua.F_DeptId, 332))
  4942. {
  4943. nextda = 339;
  4944. opt = "流转营销管理处";
  4945. }
  4946. else if (ua.F_DeptId == 17 || ua.F_DeptId == 19 || ua.F_DeptId == 20 || ua.F_DeptId == 21)
  4947. {
  4948. nextda = ua.F_DeptId;
  4949. opt = "流转" + deptment;
  4950. }
  4951. //}
  4952. if (nextda != 0)
  4953. {
  4954. if (nextda2 != 0)
  4955. {
  4956. modlelist.F_Flag = 3;
  4957. AssignWO(ua, modlelist, input, opt, "", nextda, 0, 0, 0, 0, 0, 0, "", 1, 1, 3);
  4958. var res2 = AssignWO(ua, modlelist, input, opt2, "", nextda2, 0, 0, 0, 0, 0, 0, "", 1, 2, 3);
  4959. }
  4960. else
  4961. {
  4962. modlelist.F_State = 1;
  4963. modlelist.F_State2 = 1;
  4964. modlelist.F_Flag = 9;
  4965. var res = AssignWO(ua, modlelist, input, opt, "", nextda, 0, overtime, sms, 0, 0, 0, "", 1, 3, 9);
  4966. }
  4967. return Success("添加成功");
  4968. }
  4969. else
  4970. {
  4971. return Error("流转失败!");
  4972. }
  4973. }
  4974. }
  4975. else
  4976. {
  4977. AddLog(modlelist.F_ID, 0, "客户" + "创建工单", (int)EnumItemType.deal, (int)EnumItemOpt.create, "", 0, null, overtime, sms);
  4978. LogFactory.GetLogger("456").Debug("添加成功");
  4979. return Success("添加成功");
  4980. }
  4981. }
  4982. #endregion
  4983. return Success("添加成功!");
  4984. }
  4985. else
  4986. return Error("添加失败!");
  4987. }
  4988. else
  4989. {
  4990. return Error("OpenId不能为空!");
  4991. }
  4992. }
  4993. /// <summary>
  4994. /// 工单暂存
  4995. /// </summary>
  4996. /// <param name="contents"></param>
  4997. /// <param name="type"></param>
  4998. /// <param name="title"></param>
  4999. /// <param name="fid"></param>
  5000. /// <returns></returns>
  5001. public ActionResult TempStorageWo(string OpenId,string contents, string type, string title, int tid = 0)
  5002. {
  5003. if (!string.IsNullOrEmpty(OpenId))
  5004. {
  5005. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  5006. Model.T_Wo_TempStorage temp = new T_Wo_TempStorage();
  5007. if (tid > 0)
  5008. {
  5009. temp = new BLL.T_Wo_TempStorage().GetModel(tid);
  5010. }
  5011. temp.F_Contents = contents;
  5012. temp.F_Title = title;
  5013. temp.F_Type = Convert.ToInt32(type);
  5014. temp.F_CreateTime = DateTime.Now;
  5015. temp.F_CreateBy = ua.F_UserCode;
  5016. if (tid > 0)
  5017. new BLL.T_Wo_TempStorage().Update(temp);
  5018. else
  5019. new BLL.T_Wo_TempStorage().Add(temp);
  5020. return Success("暂存成功!");
  5021. }
  5022. else
  5023. {
  5024. return Error("无操作权限!");
  5025. }
  5026. }
  5027. /// <summary>
  5028. /// 获取最新暂存数据 一个用户只能暂存一次
  5029. /// </summary>
  5030. /// <returns></returns>
  5031. public ActionResult GetStorageWo(string OpenId)
  5032. {
  5033. if (!string.IsNullOrEmpty(OpenId))
  5034. {
  5035. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  5036. string strsql = $" F_CreateBy={ua.F_UserCode} order by F_CreateTime desc";
  5037. var temp = new BLL.T_Wo_TempStorage().GetModelList(strsql).FirstOrDefault();
  5038. return Success(temp.ToJson());
  5039. }
  5040. else
  5041. {
  5042. return Error("无操作权限!");
  5043. }
  5044. }
  5045. /// <summary>
  5046. /// 更新市场管理科,质量管理科
  5047. /// </summary>
  5048. /// <param name="model"></param>
  5049. /// <param name="input"></param>
  5050. /// <returns></returns>
  5051. private Model.T_Wo_WorkOrder InToworkModel(Model.T_Wo_WorkOrder model, WorkOrderNewInput input,Model.T_Sys_UserAccount ua)
  5052. {
  5053. string str = ua.F_UserName + "(" + ua.F_WorkNumber + ")" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ";
  5054. if (!string.IsNullOrEmpty(input.F_SC_ProductBase))
  5055. model.F_SC_ProductBase = input.F_SC_ProductBase;//市场管理科-生产基地(新乡、新疆、九江、东北、贴牌、无法确定)
  5056. if (!string.IsNullOrEmpty(input.F_SC_PreliminaryOpinion))
  5057. model.F_SC_PreliminaryOpinion = input.F_SC_PreliminaryOpinion;// 市场管理科-初审意见:退货、换货、补偿、自行处理
  5058. if (!string.IsNullOrEmpty(input.F_SC_QualityMonth))
  5059. model.F_SC_QualityMonth = input.F_SC_QualityMonth;//市场管理科-超出质保期限(算法:工单创建日期-生产日期,生产日期根据生产批次号获取,单位:月)
  5060. if (!string.IsNullOrEmpty(input.F_SC_CJ_SpotResult))
  5061. model.F_SC_CJ_SpotResult = input.F_SC_CJ_SpotResult;/// 市场管理科-抽检-抽检结果(视同合格、合格、不合格、复检后合格、未送检)
  5062. if (!string.IsNullOrEmpty(input.F_SC_CJ_SelfResult))
  5063. model.F_SC_CJ_SelfResult = input.F_SC_CJ_SelfResult;//市场管理科-抽检-自检结果
  5064. if (!string.IsNullOrEmpty(input.F_SC_CJ_ApprovalNo))
  5065. model.F_SC_CJ_ApprovalNo = input.F_SC_CJ_ApprovalNo;// 市场管理科-抽检-对应审批工作流单号
  5066. if (!string.IsNullOrEmpty(input.F_SC_CJ_ReturnAccount))
  5067. model.F_SC_CJ_ReturnAccount = input.F_SC_CJ_ReturnAccount;//市场管理科-抽检-确认返账金额(元)
  5068. if (!string.IsNullOrEmpty(input.F_ZL_QualityEventLevel))
  5069. model.F_ZL_QualityEventLevel = input.F_ZL_QualityEventLevel;// 质量管理科-质量事件等级(未遂、一般、较大、重大)
  5070. if (!string.IsNullOrEmpty(input.F_ZL_ClaimAmount))
  5071. model.F_ZL_ClaimAmount = input.F_ZL_ClaimAmount;//质量管理科-索赔金额(单位元,对应责任单位)
  5072. if (!string.IsNullOrEmpty(input.F_ZL_ResponsibleUnit))
  5073. model.F_ZL_ResponsibleUnit = input.F_ZL_ResponsibleUnit;//质量管理科-责任单位(需列出,可选多个)
  5074. if (!string.IsNullOrEmpty(input.F_ZL_ApprovalOpinions))
  5075. model.F_ZL_ApprovalOpinions = input.F_ZL_ApprovalOpinions;// 质量管理科-审批意见(同意、不同意,若选择不同意,增加输入框输入补充内容)
  5076. if (!string.IsNullOrEmpty(input.F_ZL_ApprovalDisagree))
  5077. model.F_ZL_ApprovalDisagree = input.F_ZL_ApprovalDisagree;// 质量管理科-审批不同意意见
  5078. if (!string.IsNullOrEmpty(input.F_ZL_CompensationMethod))
  5079. model.F_ZL_CompensationMethod = input.F_ZL_CompensationMethod;//质量管理科-补偿方式(实物、钱款【单位元】,若选择钱款,增加输入框输入补充内容)
  5080. if (!string.IsNullOrEmpty(input.F_ZL_CompensationMoney))
  5081. model.F_ZL_CompensationMoney = input.F_ZL_CompensationMoney;// 质量管理科-补偿钱款
  5082. if (!string.IsNullOrEmpty(input.F_ZL_CResponsibleUnits))
  5083. model.F_ZL_CResponsibleUnits = input.F_ZL_CResponsibleUnits;//质量管理科-对应责任单位(生产、研发、农化、物流、质量管理科,销售内勤)
  5084. if (!string.IsNullOrEmpty(input.F_ZL_Fquantity))
  5085. model.F_ZL_Fquantity = input.F_ZL_Fquantity;// 质量管理科-确认实收数量(吨)
  5086. if (!string.IsNullOrEmpty(input.F_ZL_ImprovementRequirements) && !model.F_ZL_ImprovementRequirements.Contains(input.F_ZL_ImprovementRequirements))
  5087. {
  5088. string strimprovement = str + input.F_ZL_ImprovementRequirements + ";@# ";
  5089. //model.F_ZL_ImprovementRequirements = string.IsNullOrEmpty(model.F_ZL_ImprovementRequirements) ? strimprovement : model.F_ZL_ImprovementRequirements + strimprovement; //质量管理科-改进要求
  5090. model.F_ZL_ImprovementRequirements = input.F_ZL_ImprovementRequirements; //质量管理科-改进要求
  5091. }
  5092. if (!string.IsNullOrEmpty(input.F_ZL_CApprovalNo))
  5093. model.F_ZL_CApprovalNo = input.F_ZL_CApprovalNo;//质量管理科-对应审批工作流单号
  5094. if (!string.IsNullOrEmpty(input.F_ZL_CJ_IsRecord))
  5095. model.F_ZL_CJ_IsRecord = input.F_ZL_CJ_IsRecord;//质量管理科-抽检-未备案、已备案
  5096. if (input.F_IsVisit != null)
  5097. {
  5098. try
  5099. {
  5100. model.F_IsVisit = int.Parse(input.F_IsVisit);
  5101. }
  5102. catch
  5103. {
  5104. model.F_IsVisit = 1;
  5105. }
  5106. }
  5107. if (!string.IsNullOrEmpty(input.F_CarNumber))//返厂车牌号
  5108. model.F_CarNumber = input.F_CarNumber;
  5109. if (input.F_LoadingFee > 0)//装车费
  5110. model.F_LoadingFee = input.F_LoadingFee;
  5111. if (input.F_UnLoadingFee > 0) //卸车费
  5112. model.F_UnLoadingFee = input.F_UnLoadingFee;
  5113. if (input.F_MaterialFee > 0) //返料费
  5114. model.F_MaterialFee = input.F_MaterialFee;
  5115. if (!string.IsNullOrEmpty(input.F_EventReason) && !model.F_EventReason.Contains(input.F_EventReason))
  5116. {
  5117. string strevent = str + input.F_EventReason + ";@# ";
  5118. //model.F_EventReason = string.IsNullOrEmpty(model.F_EventReason) ? strevent : model.F_EventReason + strevent; //质量管理科-事件原因
  5119. model.F_EventReason = input.F_EventReason; //质量管理科-事件原因
  5120. }
  5121. if (!string.IsNullOrEmpty(input.F_DrivePhone))
  5122. model.F_DrivePhone = input.F_DrivePhone;//电话号码
  5123. if (!string.IsNullOrEmpty(input.F_WorkmanShip))
  5124. model.F_WorkmanShip = input.F_WorkmanShip;//质量管理科-工艺
  5125. if (!string.IsNullOrEmpty(input.F_Manufacturers))
  5126. model.F_Manufacturers = input.F_Manufacturers;//质量管理科-原料及厂家
  5127. if (input.F_ProductionNum > 0)
  5128. model.F_ProductionNum = input.F_ProductionNum;//质量管理科-该批次生产数量
  5129. if (!string.IsNullOrEmpty(input.F_TS_Level))
  5130. model.F_TS_Level = input.F_TS_Level;//投诉-重要级别:轻微、一般、较大、重大
  5131. return model;
  5132. }
  5133. /// <summary>
  5134. /// 指派/转派工单
  5135. /// <param name="orderid">工单id</param>
  5136. /// <param name="cont">指派说明</param>
  5137. /// <param name="clbm">指派部门</param>
  5138. /// <param name="clid">指派人</param>
  5139. /// </summary>
  5140. /// <returns></returns>
  5141. [WechatActionFilter]
  5142. public ActionResult AssignWorkOrder(string OpenId, long orderid, string cont, WorkOrdeDeptment deptment, string F_Files, int isvisit = 1,
  5143. 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 = "")
  5144. {
  5145. if (!string.IsNullOrEmpty(OpenId))
  5146. {
  5147. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  5148. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  5149. if (model == null)
  5150. {
  5151. return Error("工单不存在!");
  5152. }
  5153. if (model.F_State == 1 && model.F_CreateBy == ua.F_UserCode)
  5154. {
  5155. return Error("工单已转派请勿重复操作!");
  5156. }
  5157. if (model.F_State != 0)
  5158. {
  5159. //string strsql = " and F_Type in(3,"+ua.F_Flag+")";
  5160. 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 ");
  5161. if (modellist.Count<=0)
  5162. {
  5163. //if (modellist.F_NextUser != ua.F_UserCode)
  5164. return Error("非接单人不可操作工单");
  5165. }
  5166. if (modellist.Count > 1 && model.F_Flag == 9)
  5167. {
  5168. foreach (var item in modellist)
  5169. {
  5170. if (item.F_WoState != 2)
  5171. return Error("操作失败!");
  5172. }
  5173. }
  5174. }
  5175. if (sms ==-1)
  5176. {
  5177. var itemlast = itembll.GetModelList(" F_WoID='" + model.F_ID + "' order by F_ID desc").FirstOrDefault();
  5178. sms = (int)itemlast.F_IsSMS;
  5179. }
  5180. WorkOrderNewInput input = new WorkOrderNewInput();
  5181. string markdepts = "37,57,74,88,268,295,339,422,213,427,433,424";
  5182. string qualdepts = "12,36,295,245";
  5183. if (ua != null)
  5184. {
  5185. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  5186. if (clid != 0)
  5187. {
  5188. Model.T_Sys_UserAccount clus = userAccountBLL .GetModel(clid);
  5189. if (clus != null)
  5190. {
  5191. if (clus.F_WorkNumber == "7000")
  5192. return Error("不能转派到市场管理员");
  5193. else if (clus.F_RoleId == 1 || clus.F_RoleId == 4)
  5194. return Error("不能转派到话务人员");
  5195. else if (clus.F_RoleId == 58)
  5196. return Error("不能转派到业务员");
  5197. else if (clus.F_RoleId == 60)
  5198. return Error("不能转派到分公司经理");
  5199. else if (clus.F_RoleId == 62)
  5200. return Error("不能转派到大区经理");
  5201. }
  5202. }
  5203. //if (hclid == 0 && hclbm == 0 && isApprovalp != 0)
  5204. //{
  5205. // return Error("请选择接收部门");
  5206. //}
  5207. #region 五要素
  5208. input.F_ZL_ResponsibleUnit = deptment.ResponsibleUnit;// 责任单位
  5209. input.F_EventReason = deptment.EventReason;// 事件原因
  5210. input.F_ZL_ImprovementRequirements = deptment.ImprovementRequirements;// 改进要求
  5211. input.F_TS_Level = deptment.TS_Level;//投诉-重要级别:轻微、一般、较大、重大
  5212. #endregion
  5213. if (markdepts.Contains(ua.F_DeptId.ToString()) && model.F_Flag == 9)
  5214. {
  5215. if (markdepts.Contains(ua.F_DeptId.ToString()))
  5216. {
  5217. if (model.F_Type == "2" || model.F_Type == "5")
  5218. {
  5219. input.F_SC_PreliminaryOpinion = deptment.PreliminaryOpinion;//市场管理科-初审意见:退货、换货、补偿、自行处理
  5220. input.F_ZL_ClaimAmount = deptment.ClaimAmount;// 质量管理科-索赔金额(单位元,对应责任单位)
  5221. }
  5222. else if (model.F_Type == "3")
  5223. {
  5224. input.F_SC_CJ_SpotResult = deptment.SpotResult;//市场管理科-抽检-抽检结果(视同合格、合格、不合格、复检后合格、未送检)
  5225. input.F_SC_CJ_SelfResult = deptment.SelfResult;//市场管理科-抽检-自检结果
  5226. input.F_SC_CJ_ApprovalNo = deptment.ApprovalNo;//市场管理科-抽检-对应审批工作流单号
  5227. input.F_SC_CJ_ReturnAccount = deptment.ReturnAccount;//市场管理科-抽检-确认返账金额
  5228. }
  5229. }
  5230. model.F_Flag = flag;
  5231. 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();
  5232. #region 咨询、建议、抽检类工单变更为单线流转
  5233. if (model.F_Type == "1" || model.F_Type == "3" || model.F_Type == "4")
  5234. {
  5235. if (clbm == 0 && clid == 0)
  5236. {
  5237. return Error("请选择接收部门");
  5238. }
  5239. Overorder(ua, model, 2);
  5240. model.F_Flag = 1;
  5241. AssignWO(ua, model, input, cont, F_Files, clbm, clid, overtime, sms, isApprovalp, hclbm, hclid, "", 0, 1, 1, Supercont);
  5242. }
  5243. #endregion
  5244. else
  5245. {
  5246. if (flag == 3)
  5247. {
  5248. if ((clbm == 0 && clid == 0) || (clbm2 == 0 && clid2 == 0))
  5249. {
  5250. return Error("请选择接收部门");
  5251. }
  5252. var res = AssignWO(ua, model, input, cont, F_Files, clbm, clid, overtime, sms, isApprovalp, hclbm, hclid, "", 0, 1, flag, Supercont);
  5253. var res1 = AssignWO(ua, model, input, cont, F_Files, clbm2, clid2, overtime, sms, isApprovalp, hclbm, hclid, "", 0, 2, flag);
  5254. }
  5255. else if (flag == 2)
  5256. {
  5257. if (clbm2 == 0 && clid2 == 0)
  5258. {
  5259. return Error("请选择接收部门");
  5260. }
  5261. if (opttype == 2) //填写处理结果
  5262. {
  5263. flag = 3;
  5264. DealWO(ua, model, "", input, cont2, 1, "", 1, "", flag, isApprovalp);
  5265. }
  5266. else if (opttype == 3) // 待处理状态
  5267. {
  5268. flag = 3;
  5269. modellast.F_Type = 1;
  5270. modellast.F_Flag = flag;
  5271. modellast.F_NextDept = 0;
  5272. itembll.Update(modellast);
  5273. }
  5274. else //完结工单
  5275. {
  5276. Overorder(ua, model, 1);
  5277. }
  5278. model.F_Flag = flag;
  5279. var res1 = AssignWO(ua, model, input, cont, F_Files, clbm2, clid2, overtime, sms, isApprovalp, hclbm, hclid, "", 0, 2, flag, Supercont);
  5280. }
  5281. else
  5282. {
  5283. if (clbm == 0 && clid == 0)
  5284. {
  5285. return Error("请选择接收部门");
  5286. }
  5287. if (opttype == 2) //填写处理结果
  5288. {
  5289. flag = 3;
  5290. DealWO(ua, model, "", input, cont2, 1, "", 2, "", flag, isApprovalp);
  5291. }
  5292. else if (opttype == 3) // 待处理状态
  5293. {
  5294. flag = 3;
  5295. modellast.F_Type = 2;
  5296. modellast.F_Flag = flag;
  5297. modellast.F_NextDept = 0;
  5298. itembll.Update(modellast);
  5299. }
  5300. else //完结工单
  5301. {
  5302. Overorder(ua, model, 2);
  5303. }
  5304. model.F_Flag = flag;
  5305. var res = AssignWO(ua, model, input, cont, F_Files, clbm, clid, overtime, sms, isApprovalp, hclbm, hclid, "", 0, 1, flag, Supercont);
  5306. }
  5307. }
  5308. return Success("转派成功");
  5309. }
  5310. else
  5311. {
  5312. if (clbm == 0 && clid == 0)
  5313. {
  5314. return Error("请选择接收部门");
  5315. }
  5316. else
  5317. {
  5318. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  5319. if (deptmodel != null)
  5320. {
  5321. if (model != null)
  5322. {
  5323. if (deptmodel.F_DeptId == 12 || deptmodel.F_DeptId == 36)
  5324. {
  5325. input.F_WorkmanShip = deptment.WorkmanShip;//质量管理科-工艺
  5326. input.F_Manufacturers = deptment.Manufacturers;//质量管理科-原料及厂家
  5327. input.F_ProductionNum = deptment.ProductionNum;//质量管理科-该批次生产数量
  5328. }
  5329. if (model.F_Type == "2" || model.F_Type == "5")
  5330. {
  5331. if (deptmodel.F_DeptId == 37)
  5332. {
  5333. // input. F_SC_QualityMonth = QualityMonth;//市场管理科-超出质保期限
  5334. input.F_SC_PreliminaryOpinion = deptment.PreliminaryOpinion;//市场管理科-初审意见:退货、换货、补偿、自行处理
  5335. }
  5336. else if (deptmodel.F_DeptId == 12 || deptmodel.F_DeptId == 36)
  5337. {
  5338. input.F_IsVisit = isvisit.ToString();
  5339. input.F_ZL_QualityEventLevel = deptment.QualityEventLevel;//质量管理科-质量事件等级(未遂、一般、较大、重大)
  5340. input.F_ZL_ClaimAmount = deptment.ClaimAmount;// 质量管理科-索赔金额(单位元,对应责任单位)
  5341. input.F_ZL_ApprovalOpinions = deptment.ApprovalOpinions;// 质量管理科-审批意见(同意、不同意,若选择不同意,增加输入框输入补充内容)
  5342. input.F_ZL_ApprovalDisagree = deptment.ApprovalDisagree;// 质量管理科-审批不同意意见
  5343. input.F_ZL_CompensationMethod = deptment.CompensationMethod;// 质量管理科-补偿方式(实物、钱款【单位元】,若选择钱款,增加输入框输入补充内容)
  5344. input.F_ZL_CompensationMoney = deptment.CompensationMoney;// 质量管理科-补偿钱款
  5345. input.F_ZL_CResponsibleUnits = deptment.CResponsibleUnits;//质量管理科-对应责任单位(生产、研发、农化、物流、质量管理科,销售内勤)
  5346. //input.F_ZL_Fquantity = deptment.Fquantity;//质量管理科-确认实收数量(吨)
  5347. //input.F_ZL_ImprovementRequirements = deptment.ImprovementRequirements;// 质量管理科-改进要求
  5348. input.F_ZL_CApprovalNo = deptment.CApprovalNo;// 质量管理科-对应审批工作流单号
  5349. //if (string.IsNullOrEmpty(deptment.EventReason))
  5350. // return Error("请填写事件原因!");
  5351. //if (string.IsNullOrEmpty(deptment.ResponsibleUnit))
  5352. // return Error("请填写责任单位!");
  5353. //input.F_EventReason = deptment.EventReason;// 质量管理科-事件原因
  5354. input.F_ZL_ResponsibleUnit = deptment.ResponsibleUnit;// 质量管理科-责任单位(需列出,可选多个)
  5355. }
  5356. //else if (deptmodel.F_DeptName == "成品库" && model.F_SC_PreliminaryOpinion == "退换货" ) //退换货成品库录入物料信息
  5357. //{
  5358. // if (!string.IsNullOrEmpty(jsonstr))
  5359. // {
  5360. // JavaScriptSerializer Serializer = new JavaScriptSerializer(); //实例化⼀个能够序列化数据的类
  5361. // List<Material> list = Serializer.Deserialize<List<Material>>(jsonstr);
  5362. // List<T_Wo_MaterialItems> itemlist = new List<T_Wo_MaterialItems>();
  5363. // if (list != null && list.Count > 0)
  5364. // {
  5365. // foreach (var item in list)
  5366. // {
  5367. // T_Wo_MaterialItems itemodel = new T_Wo_MaterialItems();
  5368. // itemodel.F_MaterialCode = item.materialcode;
  5369. // itemodel.F_MaterialName = item.materialname;
  5370. // itemodel.F_Formula = item.formula;
  5371. // itemodel.F_ReturnQuantity = item.returnum??0;
  5372. // itemodel.F_WoID = model.F_ID;//工单id
  5373. // itemodel.F_CreateOn = DateTime.Now;
  5374. // itemodel.F_Remark = item.specs;//规格
  5375. // itemlist.Add(itemodel);
  5376. // }
  5377. // model.MaterialItems = itemlist;
  5378. // }
  5379. // }
  5380. //}
  5381. else if (deptmodel.F_DeptName == "计划调度科")
  5382. {
  5383. input.F_CarNumber = deptment.CarNumber;
  5384. input.F_UnLoadingFee = deptment.UnLoadingFee;//卸车费
  5385. input.F_MaterialFee = deptment.MaterialFee;//返料费
  5386. input.F_DrivePhone = deptment.DrivePhone;//电话号码nt.CarNumber;//返厂车牌号
  5387. input.F_LoadingFee = deptment.LoadingFee;//装车费
  5388. if (!string.IsNullOrEmpty(jsonstr))
  5389. {
  5390. JavaScriptSerializer Serializer = new JavaScriptSerializer(); //实例化⼀个能够序列化数据的类
  5391. List<Material> list = Serializer.Deserialize<List<Material>>(jsonstr);
  5392. List<T_Wo_MaterialItems> itemlist = new List<T_Wo_MaterialItems>();
  5393. if (list != null && list.Count > 0)
  5394. {
  5395. foreach (var item in list)
  5396. {
  5397. T_Wo_MaterialItems itemodel = new T_Wo_MaterialItems();
  5398. if (!string.IsNullOrEmpty(item.fid))
  5399. {
  5400. itemodel.F_Id = Convert.ToInt32(item.fid);
  5401. }
  5402. itemodel.F_MaterialCode = item.materialcode;
  5403. itemodel.F_MaterialName = item.materialname;
  5404. itemodel.F_Formula = item.formula;
  5405. itemodel.F_ReturnQuantity = item.returnum ?? 0;
  5406. itemodel.F_WoID = model.F_ID;//工单id
  5407. itemodel.F_CreateOn = DateTime.Now;
  5408. itemodel.F_Remark = item.specs;//规格
  5409. itemlist.Add(itemodel);
  5410. }
  5411. model.MaterialItems = itemlist;
  5412. model.F_SC_PreliminaryOpinion = "退换货";
  5413. model.F_Material_CreateBy = ua.F_UserCode;
  5414. model.F_Material_CreateTime = DateTime.Now;
  5415. }
  5416. }
  5417. }
  5418. //else if (deptmodel.F_DeptName == "销售内勤" && (model.F_SC_PreliminaryOpinion == "退货" || model.F_SC_PreliminaryOpinion == "换货"))//部门id=193
  5419. //{
  5420. // model.F_SC_CJ_ReturnAccount = deptment.ReturnAccount;//销售内勤-确认返账金额
  5421. //}
  5422. }
  5423. else if (model.F_Type == "3")
  5424. {
  5425. if (deptmodel.F_DeptId == 37)
  5426. {
  5427. input.F_SC_CJ_SpotResult = deptment.SpotResult;//市场管理科-抽检-抽检结果(视同合格、合格、不合格、复检后合格、未送检)
  5428. input.F_SC_CJ_SelfResult = deptment.SelfResult;//市场管理科-抽检-自检结果
  5429. input.F_SC_CJ_ApprovalNo = deptment.ApprovalNo;//市场管理科-抽检-对应审批工作流单号
  5430. input.F_SC_CJ_ReturnAccount = deptment.ReturnAccount;//市场管理科-抽检-确认返账金额
  5431. }
  5432. else if (deptmodel.F_DeptId == 12)
  5433. {
  5434. input.F_IsVisit = isvisit.ToString();
  5435. input.F_ZL_CJ_IsRecord = deptment.IsRecord;//质量管理科-抽检-未备案、已备案
  5436. input.F_ZL_ClaimAmount = deptment.ClaimAmount;// 质量管理科-索赔金额(单位元,对应责任单位)
  5437. }
  5438. }
  5439. if (deptmodel.F_DeptName == "销售内勤")//部门id=193
  5440. {
  5441. input.F_SC_CJ_ReturnAccount = deptment.ReturnAccount2;//销售内勤-确认返账金额
  5442. }
  5443. if (deptmodel.F_DeptId == 260)//销售财务
  5444. {
  5445. input.F_SC_CJ_ReturnAccount = deptment.ReturnAccount3;//销售内勤-确认返账金额
  5446. }
  5447. if (deptmodel.F_DeptId == 36)
  5448. {
  5449. input.F_ZL_Fquantity = deptment.Fquantity;//质量管理科-确认实收数量(吨)
  5450. }
  5451. }
  5452. else
  5453. return Error("工单不存在!");
  5454. }
  5455. else
  5456. {
  5457. return Error("请选择接收部门");
  5458. }
  5459. }
  5460. 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 ");
  5461. int? zflag = 0;
  5462. if (inoutflag != 0)
  5463. {
  5464. zflag = inoutflag;
  5465. }
  5466. else if (modellist.Count > 0)
  5467. {
  5468. zflag = modellist.FirstOrDefault().F_Type;
  5469. }
  5470. if (zflag != 3)
  5471. {
  5472. 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();
  5473. if (modeldpts != null)
  5474. return Error("不允许同一个部门出现在两条线内,请重新指派!");
  5475. }
  5476. var res = AssignWO(ua, model, input, cont, F_Files, clbm, clid, overtime, sms, isApprovalp, hclbm, hclid, "", 0, Convert.ToInt32(zflag),0, Supercont);
  5477. if (res)
  5478. {
  5479. return Success("转派成功");
  5480. }
  5481. else
  5482. return Error("转派失败!");
  5483. }
  5484. }
  5485. }
  5486. return Error("无操作权限!");
  5487. }
  5488. /// <summary>
  5489. /// 完结工单
  5490. /// </summary>
  5491. /// <param name="nowUser"></param>
  5492. /// <param name="model"></param>
  5493. /// <param name="isOver"></param>
  5494. /// <param name="flag"></param>
  5495. /// <returns></returns>
  5496. public bool Overorder(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, int isOver = 0)
  5497. {
  5498. #region 工单处理
  5499. int sms = 0;
  5500. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.visit + " and F_WoID=" + model.F_ID + " ");
  5501. if (itemlasts.Count > 0)
  5502. {
  5503. foreach (var it in itemlasts)
  5504. {
  5505. if (it.F_WoState == 1)
  5506. {
  5507. sms = int.Parse(it.F_IsSMS.ToString());
  5508. }
  5509. }
  5510. }
  5511. int optbut = (int)EnumItemOpt.end;
  5512. int wostate = (int)EnumWorkOrderState.evaluate;
  5513. #region 读取当前登录人部门
  5514. string deptname = "";
  5515. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  5516. if (deptmodel != null)
  5517. {
  5518. deptname = deptmodel.F_DeptName + "-";
  5519. }
  5520. #endregion
  5521. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ") 自动关闭工单";
  5522. //var itemid = AddLog((int)model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, touser, 0, nowUser, model.F_limit, sms);
  5523. if (isOver >= 1)
  5524. {
  5525. #region 处理工单
  5526. //model.F_VisitOn = DateTime.Now;
  5527. if (isOver == 1)
  5528. {
  5529. AddLog((int)model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, "", 0, nowUser, model.F_limit, sms, "", 0, 1);
  5530. model.F_State = wostate; //外线关闭
  5531. }
  5532. else if (isOver == 2)
  5533. {
  5534. AddLog((int)model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, "", 0, nowUser, model.F_limit, sms, "", 0, 2);
  5535. model.F_State2 = wostate; //内线关闭
  5536. }
  5537. woBLL.Update(model);
  5538. #endregion
  5539. return true;
  5540. }
  5541. else
  5542. return false;
  5543. #endregion
  5544. }
  5545. /// <summary>
  5546. /// 转派工单
  5547. /// </summary>
  5548. 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 = "")
  5549. {
  5550. if (model.F_limit > 0)
  5551. overtime = model.F_limit;
  5552. string smscont = "";
  5553. if (model.F_Type == "1")
  5554. {
  5555. smscont = "咨询";
  5556. }
  5557. else if (model.F_Type == "2")
  5558. {
  5559. smscont = "投诉";
  5560. }
  5561. else if (model.F_Type == "3")
  5562. {
  5563. smscont = "抽检";
  5564. }
  5565. else if (model.F_Type == "5")
  5566. {
  5567. smscont = "业务协办";
  5568. }
  5569. else
  5570. {
  5571. smscont = "建议";
  5572. }
  5573. string[] mag = { smscont };
  5574. string smsmsg = "您好,您有一条新的" + smscont + "工单,请及时接单处理!";
  5575. string touser = ""; string tousername = "";
  5576. #region 获取接收人
  5577. int deptid = 0;
  5578. if (clid != 0)
  5579. {
  5580. Model.T_Sys_UserAccount clus = userAccountBLL.GetModel(clid);
  5581. deptid = clus.F_DeptId;
  5582. clbm = clus.F_DeptId;
  5583. if (clus != null)
  5584. {
  5585. touser = clus.F_UserCode;
  5586. tousername = clus.F_UserName + "(" + clus.F_WorkNumber + ")";
  5587. }
  5588. if (sms != 0)
  5589. {
  5590. if (!string.IsNullOrEmpty(clus.F_Mobile))
  5591. {
  5592. SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, clus.F_Mobile);
  5593. bool n = new SMSController().AddSmS(clus.F_Mobile, smsmsg, nowUser.F_UserId);
  5594. }
  5595. }
  5596. }
  5597. else
  5598. {
  5599. string users = string.Empty;
  5600. deptid = clbm;
  5601. string sql = "";
  5602. if (isbl>0)
  5603. {
  5604. sql = " and F_RoleId in(select F_RoleId from T_Sys_RoleInfo where F_RoleCode='BLRY')";
  5605. }
  5606. var list = userAccountBLL.GetModelList(" F_DeptId='" + clbm + "'and F_DeleteFlag=0" + sql);
  5607. foreach (var l in list)
  5608. {
  5609. if (string.IsNullOrEmpty(users))
  5610. {
  5611. users = l.F_UserCode;
  5612. tousername = l.F_UserName + "(" + l.F_WorkNumber + ")";
  5613. }
  5614. else
  5615. {
  5616. users = users + "," + l.F_UserCode;
  5617. tousername = tousername + "," + l.F_UserName + "(" + l.F_WorkNumber + ")";
  5618. }
  5619. if (sms != 0)
  5620. {
  5621. if (!string.IsNullOrEmpty(l.F_Mobile))
  5622. {
  5623. SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, l.F_Mobile);
  5624. bool n = new SMSController().AddSmS(l.F_Mobile, smsmsg, nowUser.F_UserId);
  5625. }
  5626. }
  5627. }
  5628. touser = users;
  5629. }
  5630. string htouser = "", htousername = "";
  5631. //if (isApprovalp != 0 && nowUser.F_DeptId == 37)
  5632. //{
  5633. // if (hclid != 0)
  5634. // {
  5635. // Model.T_Sys_UserAccount clus = userAccountBLL.GetModel(hclid);
  5636. // if (clus != null)
  5637. // {
  5638. // if (string.IsNullOrEmpty(htouser))
  5639. // {
  5640. // htouser = clus.F_UserCode;
  5641. // htousername = clus.F_UserName + "(" + clus.F_WorkNumber + ")";
  5642. // }
  5643. // }
  5644. // }
  5645. // else
  5646. // {
  5647. // var list = userAccountBLL.GetModelList(" F_DeptId='" + hclbm + "'");
  5648. // foreach (var l in list)
  5649. // {
  5650. // if (string.IsNullOrEmpty(htouser))
  5651. // {
  5652. // htouser = l.F_UserCode;
  5653. // htousername = l.F_UserName + "(" + l.F_UserCode + ")";
  5654. // }
  5655. // else
  5656. // {
  5657. // htouser = htouser + "," + l.F_UserCode;
  5658. // htousername = htousername + "," + l.F_UserName + "(" + l.F_WorkNumber + ")";
  5659. // }
  5660. // }
  5661. // }
  5662. // AddLog(model.F_ID, (int)EnumWorkOrderState.assign, htousername + "高层待审批", (int)EnumItemType.audit, (int)EnumItemOpt.audit, htouser, hclbm, nowUser, overtime, sms, creat, 2);
  5663. //}
  5664. #region 财务审核后,填单人员可以收到到账提醒(短信到账提醒)20220217
  5665. if (nowUser.F_DeptId == 260)
  5666. {
  5667. var noticlus = userAccountBLL.GetModel(model.F_CreateBy);
  5668. if (!string.IsNullOrEmpty(noticlus.F_Mobile))
  5669. {
  5670. //SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, noticlus.F_Mobile.Trim());
  5671. //bool n = new SMSController().AddSmS(noticlus.F_Mobile.Trim(), "返款已到账", nowUser.F_UserId);
  5672. }
  5673. }
  5674. #endregion
  5675. #endregion
  5676. #region 工单处理
  5677. var opt = "指派";
  5678. int optbut = (int)EnumItemOpt.assign;
  5679. int wostate = (int)EnumWorkOrderState.assign;//已指派待接单
  5680. #region 读取当前登录人部门
  5681. string deptname = "";
  5682. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  5683. if (deptmodel != null)
  5684. {
  5685. deptname = deptmodel.F_DeptName + "-";
  5686. }
  5687. #endregion
  5688. var optcont = "";
  5689. if (!string.IsNullOrEmpty(cont))
  5690. optcont = ",说明:" + cont;
  5691. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + opt + "工单给 " + tousername + optcont;
  5692. var itemid = AddLog(model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, touser, clbm, nowUser, overtime, sms, creat,0,flag,flagstate);
  5693. if (itemid > 0)
  5694. {
  5695. #region 处理工单
  5696. //工单完结要更新工单的状态
  5697. // model.F_DealBy = touser;
  5698. if (flag == 1 || ((model.F_Flag == null || model.F_Flag == 0) && flag == 3))
  5699. {
  5700. model.F_State = wostate;
  5701. }
  5702. else if (flag == 2)
  5703. {
  5704. model.F_State2 = wostate;
  5705. }
  5706. if (model.F_limit == 0)
  5707. model.F_limit = overtime;
  5708. //处理内容
  5709. if (!string.IsNullOrEmpty(cont))
  5710. if (flag == 2)
  5711. {
  5712. model.F_DealContent2 += cont + ";";
  5713. }
  5714. else
  5715. {
  5716. model.F_DealContent += cont + ";";
  5717. }
  5718. if (!string.IsNullOrEmpty(Supercont))
  5719. {
  5720. string strcont = nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ") " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  5721. string strconts1 = strcont + " " + Supercont + ";@# ";
  5722. if (flag == 1 || ((model.F_Flag == null || model.F_Flag == 0) && flag == 3))
  5723. {
  5724. if (!model.F_SuperiorOpinion.Trim().Contains(Supercont.Trim()))
  5725. {
  5726. //model.F_SuperiorOpinion = string.IsNullOrEmpty(model.F_SuperiorOpinion) ? strconts1 : model.F_SuperiorOpinion + strconts1;
  5727. model.F_SuperiorOpinion = Supercont.Trim();
  5728. }
  5729. }
  5730. else if (flag == 2)
  5731. {
  5732. if (!model.F_SuperiorOpinion2.Trim().Contains(Supercont.Trim()))
  5733. {
  5734. model.F_SuperiorOpinion2 = Supercont.Trim();
  5735. }
  5736. }
  5737. }
  5738. InToworkModel(model, input, nowUser);
  5739. if (!string.IsNullOrEmpty(F_Files))
  5740. {
  5741. if (!string.IsNullOrEmpty(model.F_Files))
  5742. model.F_Files = model.F_Files + "," + F_Files;
  5743. else
  5744. model.F_Files = F_Files;
  5745. }
  5746. woBLL.Update(model);
  5747. #region 添加物料信息
  5748. if (model.MaterialItems != null && model.MaterialItems.Count > 0)
  5749. {
  5750. //var delmodels = new BLL.T_Wo_MaterialItems().GetModelList($" F_WoID ={ model.F_ID}");
  5751. //if (delmodels != null && delmodels.Count > 0)
  5752. //{
  5753. // string delids = string.Join(",", delmodels.Select(p => p.F_Id).ToArray());
  5754. // new BLL.T_Wo_MaterialItems().DeleteList(delids);
  5755. //}
  5756. foreach (var item in model.MaterialItems)
  5757. {
  5758. if (item.F_Id > 0)
  5759. {
  5760. new BLL.T_Wo_MaterialItems().Update(item);
  5761. }
  5762. else
  5763. {
  5764. new BLL.T_Wo_MaterialItems().Add(item);
  5765. }
  5766. }
  5767. }
  5768. #endregion
  5769. #endregion
  5770. #region 推送消息
  5771. #region 推送消息给添加的坐席 -转派和处理
  5772. if (nowUser.F_UserCode != model.F_CreateBy)
  5773. {
  5774. sendsysmsg(model, nowUser, model.F_CreateBy, (int)model.F_ID, opt);//推送系统消息
  5775. // var createmodel = userAccountBLL.GetModel(model.F_CreateBy); //被指派人
  5776. // if (createmodel != null)
  5777. // {
  5778. // if (!string.IsNullOrEmpty(createmodel.F_WxOpenId))
  5779. // {
  5780. // sendwxmsg(model, createmodel.F_WxOpenId, nowUser, opt);
  5781. // }
  5782. // }
  5783. }
  5784. #endregion
  5785. #region 向下一级操作人员推送消息
  5786. if (!string.IsNullOrWhiteSpace(touser))
  5787. {
  5788. sendsysmsg(model, nowUser, touser, (int)model.F_ID, opt);//推送系统消息
  5789. // var modelUser2 = userAccountBLL.GetModel(touser); //被指派人
  5790. // if (modelUser2 != null)
  5791. // {
  5792. // if (!string.IsNullOrEmpty(modelUser2.F_WxOpenId))
  5793. // {
  5794. // sendwxmsg(model, modelUser2.F_WxOpenId, nowUser, "指派");
  5795. // }
  5796. //}
  5797. }
  5798. #endregion
  5799. #endregion
  5800. return true;
  5801. }
  5802. else
  5803. return false;
  5804. #endregion
  5805. }
  5806. /// <summary>
  5807. /// 查询超时工单列表
  5808. /// </summary>
  5809. [WechatActionFilter]
  5810. public ActionResult GetOvertime(string OpenId, string code, string keywords, string cusname, string cusphone, string companyname, string province, string city,
  5811. string country, string township, string touser, int source = 0, int type = 0, int pageindex = 1, int pagesize = 10, int state = 0)
  5812. {
  5813. if (!string.IsNullOrEmpty(OpenId))
  5814. {
  5815. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  5816. if (ua == null)
  5817. {
  5818. return Success("你的账号已在别处登录,你确定要再次登录吗?");
  5819. }
  5820. //if (!Refresh())
  5821. //{
  5822. // return Error("查询失败");
  5823. //}
  5824. Task.Run(() => Refresh());
  5825. string sql = $" and F_IsDelete=0";
  5826. // sql += "and F_Type !=3";
  5827. DataTable dt = new DataTable();
  5828. #region 筛选条件
  5829. if (type > 0 && type < 6)//工单类型
  5830. sql += $" and F_Type=" + type;
  5831. if (source > 0)//工单来源
  5832. {
  5833. if (source == 1)
  5834. sql += $" and F_Source in (1,'')";
  5835. else
  5836. sql += $" and F_Source='" + source + "'";
  5837. }
  5838. if (!string.IsNullOrWhiteSpace(touser))//参与人
  5839. sql += $" and F_DealBy like '%" + touser.Trim() + "%'";
  5840. if (!string.IsNullOrWhiteSpace(code))//工单编号
  5841. sql += $" and F_WorkOrderCode like '%" + code.Trim() + "%'";
  5842. if (!string.IsNullOrWhiteSpace(keywords))//关键字搜索
  5843. sql += $" and (F_WorkOrderCode like '%" + keywords.Trim() + "%' or F_CusName like '%" + keywords.Trim() + "%'or F_CusPhone like '%" + keywords.Trim() + "%' )";
  5844. if (!string.IsNullOrWhiteSpace(cusname))//客户姓名
  5845. sql += $" and F_CusName like '%" + cusname.Trim() + "%'";
  5846. if (!string.IsNullOrWhiteSpace(cusphone))//客户电话
  5847. sql += $" and F_CusPhone like '%" + cusphone.Trim() + "%'";
  5848. if (!string.IsNullOrWhiteSpace(companyname))//公司名称
  5849. sql += $" and F_CompanyName like '%" + companyname.Trim() + "%'";
  5850. if (!string.IsNullOrWhiteSpace(province))//省
  5851. sql += $" and F_IncidentProvince like '%" + province.Trim() + "%'";
  5852. if (!string.IsNullOrWhiteSpace(province))//市
  5853. sql += $" and F_IncidentCity like '%" + city.Trim() + "%'";
  5854. if (!string.IsNullOrWhiteSpace(province))//县
  5855. sql += $" and F_IncidentCountry like '%" + country.Trim() + "%'";
  5856. if (!string.IsNullOrWhiteSpace(province))//乡
  5857. sql += $" and F_IncidentTownship like '%" + township.Trim() + "%'";
  5858. //sql += $" and F_State in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," +
  5859. //(int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + ")";
  5860. sql += $" and F_IsOver=" + 1;
  5861. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  5862. if (state > 0)
  5863. {
  5864. sql += $" and F_State =" + state;
  5865. }
  5866. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "JDYBZZX" || ro.F_RoleCode == "XTGLY")
  5867. {
  5868. sql += $" and((F_IsOver in(1,3) and F_State !=11) or ( F_IsOver in (2,3) and F_State2!=11))";
  5869. }
  5870. else if (ua.F_Flag == 1)
  5871. {
  5872. sql += $" and F_IsOver in (1,3)";
  5873. sql += $" and F_State !=" + 11;
  5874. }
  5875. else if (ua.F_Flag == 2)
  5876. {
  5877. sql += $" and F_IsOver in (2,3)";
  5878. sql += $" and F_State2 !=" + 11;
  5879. }
  5880. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "YWY" || ro.F_RoleCode == "BLRY")
  5881. {
  5882. sql += $" and F_DealBy like '%" + ua.F_UserCode.Trim() + "%'";
  5883. }
  5884. else if (ro.F_RoleCode == "DQJL" || ro.F_RoleCode == "FGSJL" || ro.F_RoleCode == "ZG")
  5885. {
  5886. string detpid = "" + ua.F_DeptId;
  5887. var deparmentlist = new List<Model.T_Sys_Department>();
  5888. Model.T_Sys_Department dModel = departmentBLL.GetModel(ua.F_DeptId);
  5889. if (dModel != null)
  5890. {
  5891. if (dModel.F_Layer == 1)
  5892. {
  5893. deparmentlist = new BLL.T_Sys_Department().GetModelList(" F_State=1 and F_Layer=" + 2 + " and F_ParentId=" + dModel.F_DeptId);
  5894. if (deparmentlist.Count > 0)
  5895. {
  5896. foreach (var it in deparmentlist)
  5897. {
  5898. if (detpid != "")
  5899. {
  5900. detpid += "," + it.F_DeptId;
  5901. }
  5902. else
  5903. {
  5904. detpid = "" + it.F_DeptId; ;
  5905. }
  5906. }
  5907. }
  5908. }
  5909. else
  5910. {
  5911. detpid = ua.F_DeptId.ToString();
  5912. }
  5913. if (GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.dealing + ", " + (int)EnumWorkOrderState.receive + "," +
  5914. (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "") != "")
  5915. {
  5916. sql += $" and T_Wo_WorkOrder.F_ID in ( " + GetDeptWorkOrderID(detpid, "" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," +
  5917. (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "") + ") "; ;
  5918. }
  5919. else
  5920. {
  5921. return Success("暂无工单"); ;
  5922. }
  5923. }
  5924. else
  5925. {
  5926. return Error("加载失败");
  5927. }
  5928. }
  5929. else if (ro.F_RoleCode == "JDYBZZX")
  5930. {
  5931. sql += $" and F_CreateBy like '%" + ua.F_UserCode.Trim() + "%'";
  5932. }
  5933. else if (ro.F_RoleCode == "QTJS")
  5934. {
  5935. return Error("无操作权限!");
  5936. }
  5937. #endregion
  5938. #region 退换货的工单按未超期处理 20220302
  5939. sql += $" and F_ID not in (select F_ID from T_Wo_WorkOrder where F_SC_PreliminaryOpinion='退换货')";
  5940. #endregion
  5941. int recordCount = 0;
  5942. if (!string.IsNullOrWhiteSpace(sql))
  5943. {
  5944. dt = BLL.PagerBLL.GetListPager(
  5945. "T_Wo_WorkOrder",
  5946. "F_ID",
  5947. "*",
  5948. sql,
  5949. "ORDER BY T_Wo_WorkOrder.F_ID desc",
  5950. pagesize,
  5951. pageindex,
  5952. true,
  5953. out recordCount);
  5954. }
  5955. List<long> woid = new List<long>();
  5956. List<Model.T_Wo_WorkOrder> modlelist = new BLL.T_Wo_WorkOrder().DataTableToList(dt);
  5957. List<WorkOrderNewInput> Input = modeltooip(modlelist, ua);
  5958. var obj = new
  5959. {
  5960. state = "success",
  5961. message = "成功",
  5962. rows = Input,
  5963. total = recordCount
  5964. };
  5965. return Content(obj.ToJson()); ;
  5966. }
  5967. else
  5968. {
  5969. return Error("无操作权限!");
  5970. }
  5971. }
  5972. /// 是否超时
  5973. /// </summary>
  5974. /// <param name="id"></param>
  5975. /// <returns></returns>
  5976. private bool TimeforOver(int id, int flag = 1)
  5977. {
  5978. string strsql = "";
  5979. if (flag == 1)
  5980. {
  5981. strsql = " and F_Type in(1,3)";
  5982. }
  5983. else if (flag == 2)
  5984. {
  5985. strsql = " and F_Type in(2,3)";
  5986. }
  5987. var itemlasts = itembll.GetModelList(" F_WoID=" + id + strsql + "");
  5988. string time1 = "", time2 = ""; int x = 0, y = 0;
  5989. float time = 0;
  5990. if (itemlasts.Count > 0)
  5991. {
  5992. for (int z = 0; z < itemlasts.Count; z++)
  5993. {
  5994. if (itemlasts[z].F_WoState >= 1)
  5995. {
  5996. if (itemlasts[z].F_WoState == 1)
  5997. {
  5998. x = z;
  5999. time1 = itemlasts[z].F_CreateTime.ToString();
  6000. time = float.Parse(itemlasts[z].F_LimitTime);
  6001. break; ;
  6002. }
  6003. }
  6004. }
  6005. for (int i = 0; i < itemlasts.Count; i++)
  6006. {
  6007. if (itemlasts[i].F_WoState >= 1)
  6008. {
  6009. if (itemlasts[i].F_WoState == 10)
  6010. {
  6011. y = i;
  6012. time2 = itemlasts[i].F_CreateTime.ToString();
  6013. }
  6014. }
  6015. }
  6016. if (time2 != "")
  6017. {
  6018. if (time1 != "")
  6019. {
  6020. if (y > x )
  6021. {
  6022. System.TimeSpan a = DateTime.Parse(time2) - DateTime.Parse(time1);
  6023. if ((float)a.TotalHours > time)
  6024. {
  6025. return false;
  6026. }
  6027. }
  6028. else
  6029. {
  6030. System.TimeSpan a = DateTime.Now - DateTime.Parse(time1);
  6031. if ((float)a.TotalHours > time)
  6032. {
  6033. return false;
  6034. }
  6035. }
  6036. }
  6037. else
  6038. {
  6039. return true;
  6040. }
  6041. }
  6042. else if (time1 != "")
  6043. {
  6044. System.TimeSpan a = DateTime.Now - DateTime.Parse(time1);
  6045. if ((float)a.TotalHours > time)
  6046. {
  6047. return false;
  6048. }
  6049. }
  6050. else
  6051. {
  6052. return true;
  6053. }
  6054. }
  6055. else
  6056. {
  6057. return true;
  6058. }
  6059. return true;
  6060. }
  6061. /// <summary>
  6062. /// 接单 - 确认工单
  6063. /// </summary>
  6064. /// <returns></returns>
  6065. [WechatActionFilter]
  6066. public ActionResult SureWorkOrder(long orderid, string OpenId,int inoutflag=0)
  6067. {
  6068. if (!string.IsNullOrEmpty(OpenId))
  6069. {
  6070. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  6071. if (ua != null)
  6072. {
  6073. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  6074. if (model != null)
  6075. {
  6076. int? zflag = 0;
  6077. //string strsql = "";
  6078. //if (ua.F_Flag == 1)
  6079. //{
  6080. // strsql = " and F_Type in(1,3)";
  6081. //}
  6082. //else if (ua.F_Flag == 2)
  6083. //{
  6084. // strsql = " and F_Type in(2,3)";
  6085. //}
  6086. 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();
  6087. if (modellist == null)
  6088. {
  6089. return Error("非接单人不可操作工单");
  6090. }
  6091. 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 ");
  6092. if (modellast.Count > 0)
  6093. {
  6094. int isused = modellast.Select(p => p.F_IsUsed == 0).Count();
  6095. if (isused <= 0)
  6096. return Error("工单已接单无需重新接单");
  6097. }
  6098. if (inoutflag != 0)
  6099. {
  6100. zflag = inoutflag;
  6101. }
  6102. else
  6103. {
  6104. zflag = modellist.F_Type;
  6105. }
  6106. var res = SureWO(ua, model, Convert.ToInt32(zflag));
  6107. if (res)
  6108. return Success("接单成功");
  6109. else
  6110. return Error("接单失败");
  6111. }
  6112. else
  6113. return Error("工单不存在");
  6114. }
  6115. return Error("OpenId不能为空");
  6116. }
  6117. return Error("无操作权限");
  6118. }
  6119. /// <summary>
  6120. /// 高层审批
  6121. /// </summary>
  6122. /// <param name="input"></param>
  6123. /// <returns></returns>
  6124. [WechatActionFilter]
  6125. public ActionResult HigApprovalOrder(string OpenId, long orderid, string cont, int isApproval = 0)
  6126. {
  6127. if (!string.IsNullOrEmpty(OpenId))
  6128. {
  6129. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  6130. if (ua != null)
  6131. {
  6132. string isagreestr = "";
  6133. string touser = "";
  6134. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  6135. //验证信息
  6136. if (model != null)
  6137. {
  6138. 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);
  6139. if (itemlast.Count > 0)
  6140. {
  6141. foreach (var it in itemlast)
  6142. {
  6143. it.F_IsUsed = 1;
  6144. itembll.Update(it);
  6145. }
  6146. }
  6147. model.F_Highopinions = cont;
  6148. if (isApproval == 1)
  6149. isagreestr = " 通过 " + cont;
  6150. else
  6151. isagreestr = " 未通过 " + cont;
  6152. string deptname = "";
  6153. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  6154. if (deptmodel != null)
  6155. {
  6156. deptname = deptmodel.F_DeptName + "-";
  6157. }
  6158. if (itemlast.Count > 0)
  6159. {
  6160. foreach (var item in itemlast)
  6161. {
  6162. int type = Convert.ToInt32(item.F_Type);
  6163. if (isApproval == 1)
  6164. {
  6165. if (type == 1 || type == 3)
  6166. {
  6167. model.F_State = (int)EnumWorkOrderState.finish;
  6168. }
  6169. else if (type == 2)
  6170. {
  6171. model.F_State2 = (int)EnumWorkOrderState.finish;
  6172. }
  6173. 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);
  6174. }
  6175. else
  6176. {
  6177. string[] mag = { model.F_WorkOrderCode };
  6178. string smsmsg = $"你好,投诉工单 {model.F_WorkOrderCode} 高层审批未通过,已驳回至你的待处理工单,请及时办理!";
  6179. touser = item.F_CreateUser;
  6180. if (type == 1 || type == 3)
  6181. {
  6182. model.F_State = (int)EnumWorkOrderState.receive;
  6183. }
  6184. else if (type == 2)
  6185. {
  6186. model.F_State2 = (int)EnumWorkOrderState.receive;
  6187. }
  6188. 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);
  6189. var tosermodel = userAccountBLL.GetModel(touser);
  6190. #region 审批未通过发送短信
  6191. if (tosermodel != null && !string.IsNullOrEmpty(tosermodel.F_Mobile))
  6192. {
  6193. SmsSingleSenderResult result = new SMSController().SMSSingleshot(1498743, mag, tosermodel.F_Mobile.Trim());
  6194. bool nn = new SMSController().AddSmS(tosermodel.F_Mobile.Trim(), smsmsg, model.F_ID);
  6195. }
  6196. #endregion
  6197. }
  6198. }
  6199. }
  6200. else
  6201. return Error("无操作权限!");
  6202. //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);
  6203. bool n = woBLL.Update(model);
  6204. if (n)
  6205. return Success("审批成功");
  6206. else
  6207. return Error("审批失败!");
  6208. }
  6209. return Error("工单不存在");
  6210. }
  6211. }
  6212. return Error("无操作权限");
  6213. }
  6214. /// <summary>
  6215. /// 接单
  6216. /// </summary>
  6217. public bool SureWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, int flag = 3)
  6218. {
  6219. int overtime = 0, sms = 0;
  6220. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID=" + model.F_ID + " ");
  6221. if (itemlasts.Count > 0)
  6222. {
  6223. foreach (var it in itemlasts)
  6224. {
  6225. if (it.F_WoState == 1)
  6226. {
  6227. overtime = int.Parse(it.F_LimitTime);
  6228. sms = int.Parse(it.F_IsSMS.ToString());
  6229. }
  6230. }
  6231. }
  6232. #region 工单处理
  6233. var opt = "处理接单";
  6234. int optbut = (int)EnumItemOpt.receive;
  6235. int wostate = (int)EnumWorkOrderState.receive;
  6236. #region 读取当前登录人部门
  6237. string deptname = "";
  6238. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  6239. if (deptmodel != null)
  6240. {
  6241. deptname = deptmodel.F_DeptName + "-";
  6242. }
  6243. #endregion
  6244. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + opt;
  6245. var itemid = AddLog((int)model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, nowUser.F_UserCode, nowUser.F_DeptId, nowUser, overtime, sms,"",0,flag);
  6246. if (itemid > 0)
  6247. {
  6248. #region 处理工单
  6249. if (flag == 1 || ((model.F_Flag == null || model.F_Flag == 0) && flag == 3))
  6250. {
  6251. model.F_State = wostate;//已接单待处理
  6252. }
  6253. else if (flag == 2)
  6254. {
  6255. model.F_State2 = wostate;//已接单待处理
  6256. }
  6257. else
  6258. {
  6259. model.F_State = wostate;//已接单待处理
  6260. model.F_State2 = wostate;//已接单待处理
  6261. }
  6262. //model.F_DealBy = nowUser.F_UserCode;//已接单待处理
  6263. woBLL.Update(model);
  6264. #endregion
  6265. #region 推送消息
  6266. //读取上一级指派人员以及添加坐席并推送系统消息和微信消息
  6267. #region 给添加坐席推送系统消息和微信消息
  6268. sendsysmsg(model, nowUser, model.F_CreateBy, (int)itemid, "处理接单");
  6269. // var createUser = userAccountBLL.GetModel(model.F_CreateBy);
  6270. // if (createUser != null && !string.IsNullOrEmpty(createUser.F_WxOpenId))
  6271. // sendwxmsg(model, createUser.F_WxOpenId, nowUser, "接单");
  6272. #endregion
  6273. #region 读取上一级指派人员推送系统消息和微信消息
  6274. 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();
  6275. if (itemlast != null)
  6276. {
  6277. if (itemlast.F_CreateUser != model.F_CreateBy)
  6278. {
  6279. sendsysmsg(model, nowUser, itemlast.F_CreateUser, (int)itemid, "处理接单");
  6280. // var lastUser = userAccountBLL.GetModel(itemlast.F_CreateUser);
  6281. // if (lastUser != null && !string.IsNullOrEmpty(lastUser.F_WxOpenId))
  6282. // sendwxmsg(model, lastUser.F_WxOpenId, nowUser, "接单");
  6283. }
  6284. }
  6285. #endregion
  6286. #endregion
  6287. return true;
  6288. }
  6289. else
  6290. return false;
  6291. #endregion
  6292. }
  6293. /// <summary>
  6294. /// 工单处理
  6295. /// </summary>
  6296. /// <returns></returns>
  6297. [WechatActionFilter]
  6298. public ActionResult DealWorkOrder(string OpenId, long orderid, string F_Files, string cont, WorkOrdeDeptment deptment,
  6299. string uncont = "",
  6300. int isvisit = 1, int isover = 0, int inoutflag = 0, int isApprovalp = 0)
  6301. {
  6302. string markdepts = "37,57,74,88,268,295,339,422,213,427,433,424";
  6303. string qualdepts = "12,36,295,245";
  6304. if (!string.IsNullOrEmpty(OpenId))
  6305. {
  6306. if (string.IsNullOrEmpty(cont))
  6307. return Error("请输入处理内容");
  6308. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  6309. WorkOrderNewInput input = new WorkOrderNewInput();
  6310. if (ua != null)
  6311. {
  6312. if (!markdepts.Contains(ua.F_DeptId.ToString()) && !qualdepts.Contains(ua.F_DeptId.ToString()))
  6313. return Error("权限不足");
  6314. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  6315. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  6316. if (deptmodel != null)
  6317. {
  6318. if (model != null)
  6319. {
  6320. //string strsql = "";
  6321. //if (ua.F_Flag == 1)
  6322. //{
  6323. // strsql = " and F_Type in(1,3)";
  6324. //}
  6325. //else if (ua.F_Flag == 2)
  6326. //{
  6327. // strsql = " and F_Type in(2,3)";
  6328. //}
  6329. 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();
  6330. //int? zflag = 0;
  6331. //if (inoutflag != 0)
  6332. //{
  6333. // zflag = inoutflag;
  6334. //}
  6335. //else
  6336. //{
  6337. // zflag = modellist.F_Type;
  6338. //}
  6339. if (modellist == null)
  6340. {
  6341. //if (modellist.F_NextUser != ua.F_UserCode)
  6342. return Error("非接单人不可操作工单");
  6343. }
  6344. //if (model.F_Flag == 9)
  6345. //{
  6346. // return Error("操作失败!");
  6347. //}
  6348. if (markdepts.Contains(ua.F_DeptId.ToString()) || qualdepts.Contains(ua.F_DeptId.ToString()))
  6349. {
  6350. input.F_ZL_ResponsibleUnit = deptment.ResponsibleUnit;// 责任单位
  6351. input.F_EventReason = deptment.EventReason;// 事件原因
  6352. input.F_ZL_ImprovementRequirements = deptment.ImprovementRequirements;// 改进要求
  6353. input.F_IsVisit = isvisit.ToString();
  6354. input.F_WorkmanShip = deptment.WorkmanShip;//质量管理科-工艺
  6355. input.F_Manufacturers = deptment.Manufacturers;//质量管理科-原料及厂家
  6356. input.F_ProductionNum = deptment.ProductionNum;//质量管理科-该批次生产数量
  6357. input.F_TS_Level = deptment.TS_Level;//投诉-重要级别:轻微、一般、较大、重大
  6358. }
  6359. int? zflag = 0;
  6360. if (model.F_Flag == 9)
  6361. {
  6362. model.F_Flag = 1;//默认外线操作
  6363. zflag = 1;
  6364. Overorder(ua, model, 2);
  6365. }
  6366. else
  6367. {
  6368. if (inoutflag != 0)
  6369. {
  6370. zflag = inoutflag;
  6371. }
  6372. else
  6373. {
  6374. zflag = modellist.F_Type;
  6375. }
  6376. }
  6377. var modellast = new BLL.T_Wo_WorkOrderItem_New().GetModelList("F_WoID=" + model.F_ID + "and F_IsUsed=0 order by F_ID desc ").FirstOrDefault();
  6378. if (model.F_State == 10 && model.F_State2 == 10)
  6379. return Error("工单已处理请勿重复操作!");
  6380. else
  6381. {
  6382. var res = DealWO(ua, model, F_Files, input, cont, isover, uncont, Convert.ToInt32(zflag),"", 0, isApprovalp);
  6383. if (res)
  6384. return Success("处理成功");
  6385. else
  6386. return Error("处理失败!");
  6387. }
  6388. }
  6389. else
  6390. return Error("工单不存在!");
  6391. }
  6392. else
  6393. {
  6394. return Error("请选择接收部门");
  6395. }
  6396. }
  6397. }
  6398. return Error("无操作权限!");
  6399. }
  6400. /// <summary>
  6401. /// 更新工单
  6402. /// </summary>
  6403. private bool Refresh()
  6404. {
  6405. int type = 0;
  6406. var modlelist = woBLL.GetModelList(" F_IsDelete=0" + "and F_IsOver=0" + " and F_State in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," +
  6407. (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.finish + ")");
  6408. if (modlelist.Count > 0)
  6409. {
  6410. foreach (var it in modlelist)
  6411. {
  6412. if (TimeforOver(it.F_ID))
  6413. {
  6414. type = 0;
  6415. }
  6416. else
  6417. {
  6418. type = 1;
  6419. }
  6420. if (type != it.F_IsOver)
  6421. {
  6422. it.F_IsOver = type;
  6423. bool n = woBLL.Update(it);
  6424. if (!n)
  6425. {
  6426. return false;
  6427. }
  6428. }
  6429. }
  6430. }
  6431. return true;
  6432. }
  6433. /// <summary>
  6434. /// 更新工单---判断内线超时工单
  6435. /// </summary>
  6436. private bool Refresh2()
  6437. {
  6438. int type = 0;
  6439. var modlelist = woBLL.GetModelList(" F_IsDelete=0" + "and F_IsOver in(0,1)" + " and F_State2 in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," +
  6440. (int)EnumWorkOrderState.assign + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + "," + (int)EnumWorkOrderState.finish + ")");
  6441. if (modlelist.Count > 0)
  6442. {
  6443. foreach (var it in modlelist)
  6444. {
  6445. if (TimeforOver(it.F_ID, 2))
  6446. {
  6447. type = 0;
  6448. }
  6449. else
  6450. {
  6451. type = 2;
  6452. }
  6453. if (type != it.F_IsOver)
  6454. {
  6455. if (it.F_IsOver == 1)
  6456. {
  6457. if (type == 2)
  6458. {
  6459. it.F_IsOver = 3;
  6460. }
  6461. else
  6462. {
  6463. it.F_IsOver = 1;
  6464. }
  6465. }
  6466. else
  6467. {
  6468. it.F_IsOver = type;
  6469. }
  6470. bool n = woBLL.Update(it);
  6471. if (!n)
  6472. {
  6473. return false;
  6474. }
  6475. }
  6476. }
  6477. }
  6478. return true;
  6479. }
  6480. /// <summary>
  6481. /// 退回工单
  6482. /// </summary>
  6483. /// <param name="input"></param>
  6484. /// <returns></returns>
  6485. [WechatActionFilter]
  6486. public ActionResult BackWorkOrder(string OpenId, long orderid, string cont, int type = 0, int inoutflag = 0)
  6487. {//办理人员和监管可以退回工单
  6488. if (!string.IsNullOrEmpty(OpenId))
  6489. {
  6490. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  6491. //河南心连心化学工业集团股份有限公司-系统维护管理员(8000)指派工单给 李波(80324),张绍申(80325),杜爱国(80326),说明:无
  6492. if (ua != null)
  6493. {
  6494. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  6495. //验证信息
  6496. if (model != null)
  6497. {
  6498. int flag = 0;
  6499. string markdepts = "37,57,74,88,268,295,339,422,213,427,433,424";
  6500. 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 ");
  6501. 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();
  6502. if (modellist.Count <= 0)
  6503. {
  6504. return Error("非接单人不可操作工单");
  6505. }
  6506. if (markdepts.Contains(ua.F_DeptId.ToString()) && itemnext.F_Flag == 9)
  6507. {
  6508. if (modellist.Count >= 2)
  6509. {
  6510. flag = 3;
  6511. }
  6512. else
  6513. return Error("异常退回工单失败!");
  6514. }
  6515. else
  6516. {
  6517. if (inoutflag != 0)
  6518. {
  6519. flag = inoutflag;
  6520. }
  6521. else
  6522. {
  6523. flag = Convert.ToInt32(modellist.FirstOrDefault().F_Type);
  6524. }
  6525. }
  6526. var res = BackWO(ua, model, cont, type, flag);
  6527. if (res)
  6528. return Success("退回成功");
  6529. else
  6530. return Error("退回失败!");
  6531. }
  6532. return Error("工单不存在");
  6533. }
  6534. }
  6535. return Error("无操作权限");
  6536. }
  6537. /// <summary>
  6538. /// 撤回工单
  6539. /// </summary>
  6540. /// <param name="orderid"></param>
  6541. /// <param name="cont"></param>
  6542. /// <returns></returns>
  6543. [WechatActionFilter]
  6544. public ActionResult RevokeWo(string OpenId, long orderid, string cont, int inoutflag = 0)
  6545. {
  6546. if (!string.IsNullOrEmpty(OpenId))
  6547. {
  6548. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  6549. //增加撤回功能
  6550. if (ua != null)
  6551. {
  6552. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  6553. //验证信息
  6554. if (model != null)
  6555. {
  6556. int flag = 0;
  6557. string markdepts = "37,57,74,88,268,295,339,422,213,427,433,424";
  6558. Model.T_Sys_RoleInfo ro = rolebll.GetModel(ua.F_RoleId);
  6559. 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 ");
  6560. if (modelnext != null)
  6561. {
  6562. if (inoutflag != 0)
  6563. {
  6564. flag = inoutflag;
  6565. }
  6566. else
  6567. {
  6568. var modellist = itembll.GetModelList($"F_WoID={model.F_ID} and F_IsUsed=0 and F_CreateUser={ua.F_UserCode} order by F_ID desc ");
  6569. if (modellist.Count <= 0)
  6570. return Error("撤回失败,无法撤回!");
  6571. if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "JDYBZZX" || ro.F_RoleCode == "XTGLY")
  6572. {
  6573. if (modellist != null && modellist.Count < 2)
  6574. return Error("撤回失败,无法撤回!");
  6575. flag = 3;
  6576. }
  6577. else if (modellist != null && modellist.Count > 0)
  6578. {
  6579. if (markdepts.Contains(ua.F_DeptId.ToString()))
  6580. {
  6581. 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();
  6582. if (modellist.Count == 2)
  6583. {
  6584. flag = 3;
  6585. model.F_Flag = 9;
  6586. }
  6587. else if (itemnext != null && itemnext.F_Flag == 9)
  6588. {
  6589. if (modellist != null && modellist.Count < 2)
  6590. return Error("撤回失败,无法撤回!");
  6591. flag = 3;
  6592. model.F_Flag = 9;
  6593. }
  6594. }
  6595. if (flag == 0)
  6596. {
  6597. flag = Convert.ToInt32(modellist.FirstOrDefault().F_Type);
  6598. }
  6599. }
  6600. else
  6601. {
  6602. return Error("无操作权限");
  6603. }
  6604. }
  6605. var res = RevWO(ua, model, cont, flag);
  6606. if (res)
  6607. return Success("撤回成功");
  6608. //}
  6609. //else
  6610. // return Error("撤回失败!");
  6611. }
  6612. return Error("操作失败!");
  6613. }
  6614. return Error("工单不存在");
  6615. }
  6616. }
  6617. return Error("无操作权限");
  6618. }
  6619. /// <summary>
  6620. ///申请延期
  6621. /// </summary>
  6622. /// <returns></returns>
  6623. [WechatActionFilter]
  6624. public ActionResult DelayWorkOrder(string OpenId, long orderid, string cont, float limit = 0)
  6625. {
  6626. if (!string.IsNullOrEmpty(OpenId))
  6627. {
  6628. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  6629. if (ua != null)
  6630. {
  6631. Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  6632. //验证信息
  6633. if (model != null)
  6634. {
  6635. var res = DeWO(ua, model, cont, limit);
  6636. if (res)
  6637. return Success("延期成功");
  6638. else
  6639. return Error("延期失败!");
  6640. }
  6641. return Error("工单不存在");
  6642. }
  6643. }
  6644. return Error("无操作权限");
  6645. }
  6646. /// <summary>
  6647. /// 申请延期
  6648. /// </summary>
  6649. public bool DeWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, string cont, float limit)
  6650. {
  6651. #region 工单处理
  6652. int sms = 0; int wostate = 0;
  6653. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID=" + model.F_ID + " ");
  6654. if (itemlasts.Count > 0)
  6655. {
  6656. foreach (var it in itemlasts)
  6657. {
  6658. if (it.F_WoState == 1)
  6659. {
  6660. sms = int.Parse(it.F_IsSMS.ToString());
  6661. }
  6662. itembll.Update(it);
  6663. wostate = int.Parse(it.F_WoState.ToString());
  6664. }
  6665. }
  6666. int optbut = (int)EnumItemOpt.Delay;
  6667. #region 读取当前登录人部门
  6668. string deptname = "";
  6669. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  6670. if (deptmodel != null)
  6671. {
  6672. deptname = deptmodel.F_DeptName + "-";
  6673. }
  6674. #endregion
  6675. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + "延期工单,延期说明:" + cont;
  6676. //获取上一级处理人员
  6677. var touser = "";
  6678. 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();
  6679. if (itemlast != null)
  6680. touser = itemlast.F_CreateUser;
  6681. var itemid = AddLog((int)model.F_ID, wostate, content, (int)EnumItemType.Delay, optbut, touser, 0, nowUser, limit + model.F_limit, sms, "", 1);
  6682. #endregion
  6683. return true;
  6684. }
  6685. /// <summary>
  6686. /// 退回工单
  6687. /// </summary>
  6688. public bool BackWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, string cont, int type, int flag = 1)
  6689. {
  6690. #region 工单处理
  6691. int sms = 0;
  6692. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID=" + model.F_ID + " ");
  6693. if (itemlasts.Count > 0)
  6694. {
  6695. foreach (var it in itemlasts)
  6696. {
  6697. if (it.F_WoState == 1)
  6698. {
  6699. sms = int.Parse(it.F_IsSMS.ToString());
  6700. }
  6701. }
  6702. }
  6703. var opt = "退回";
  6704. int F_OptType = 1;
  6705. int optbut = (int)EnumItemOpt.reback;
  6706. int wostate = (int)EnumWorkOrderState.reback;
  6707. if (type == 1)
  6708. {
  6709. opt = "异常退回";
  6710. optbut = (int)EnumItemOpt.abreback;
  6711. wostate = (int)EnumWorkOrderState.abreback;
  6712. F_OptType = 2;
  6713. }
  6714. #region 读取当前登录人部门
  6715. string deptname = "";
  6716. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  6717. if (deptmodel != null)
  6718. {
  6719. deptname = deptmodel.F_DeptName + "-";
  6720. }
  6721. #endregion
  6722. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + opt + "工单,退回说明:" + cont;
  6723. //获取上一级处理人员
  6724. var touser = ""; var deptid = 0;
  6725. string strsql = "";
  6726. if (flag == 1)
  6727. {
  6728. strsql = $" and F_Type in(1,3)";
  6729. }
  6730. else if (flag == 2)
  6731. {
  6732. strsql = $" and F_Type in(2,3)";
  6733. }
  6734. 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();
  6735. if (itemlast != null)
  6736. {
  6737. touser = itemlast.F_CreateUser;
  6738. if (!string.IsNullOrEmpty(touser))
  6739. {
  6740. var ua = userAccountBLL.GetModel(touser);
  6741. if (ua != null)
  6742. {
  6743. deptid = ua.F_DeptId;
  6744. }
  6745. }
  6746. }
  6747. var itemid = AddLog((int)model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, touser, deptid, nowUser, model.F_limit, sms, "", 0, flag);
  6748. if (itemid > 0)
  6749. {
  6750. string smscont = "";
  6751. if (model.F_Type == "1")
  6752. {
  6753. smscont = "咨询";
  6754. }
  6755. else if (model.F_Type == "2")
  6756. {
  6757. smscont = "投诉";
  6758. }
  6759. else if (model.F_Type == "3")
  6760. {
  6761. smscont = "抽检";
  6762. }
  6763. else if (model.F_Type == "5")
  6764. {
  6765. smscont = "业务协办";
  6766. }
  6767. else
  6768. {
  6769. smscont = "建议";
  6770. }
  6771. string[] mag = { smscont };
  6772. string smsmsg = "您好,您有一条新的" + smscont + "工单,请及时接单处理!";
  6773. var tousermodel = new BLL.T_Sys_UserAccount().GetModel(touser);
  6774. if (tousermodel != null)
  6775. {
  6776. if (!string.IsNullOrEmpty(tousermodel.F_Mobile))
  6777. {
  6778. SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, tousermodel.F_Mobile.Trim());
  6779. bool n = new SMSController().AddSmS(tousermodel.F_Mobile.Trim(), smsmsg, nowUser.F_UserId);
  6780. }
  6781. }
  6782. #region 处理工单
  6783. if (deptid == 2)
  6784. {
  6785. if (flag == 1 || ((model.F_Flag == null || model.F_Flag == 0) && flag == 3))
  6786. {
  6787. model.F_State = (int)EnumWorkOrderState.reassign;
  6788. }
  6789. else if (flag == 2)
  6790. {
  6791. model.F_State2 = (int)EnumWorkOrderState.reassign;
  6792. }
  6793. else
  6794. {
  6795. model.F_State = (int)EnumWorkOrderState.reassign;
  6796. model.F_State2 = (int)EnumWorkOrderState.reassign;
  6797. }
  6798. }
  6799. else
  6800. {
  6801. if (flag == 1 || ((model.F_Flag == null || model.F_Flag == 0) && flag == 3))
  6802. {
  6803. model.F_State = wostate;
  6804. }
  6805. else if (flag == 2)
  6806. {
  6807. model.F_State2 = wostate;
  6808. }
  6809. else
  6810. {
  6811. model.F_Flag = 9;
  6812. model.F_State = wostate;
  6813. model.F_State2 = wostate;
  6814. }
  6815. }
  6816. woBLL.Update(model);
  6817. #endregion
  6818. #region 推送消息
  6819. #region 向上一级操作人员推送消息
  6820. if (!string.IsNullOrWhiteSpace(touser) && touser != nowUser.F_UserCode)
  6821. {//排除上一级指派人是自己
  6822. sendsysmsg(model, nowUser, touser, (int)itemid, opt);
  6823. // var lastUser = userAccountBLL.GetModel(touser);
  6824. // if (lastUser != null && !string.IsNullOrEmpty(lastUser.F_WxOpenId))
  6825. // sendwxmsg(model, lastUser.F_WxOpenId, nowUser, opt);
  6826. }
  6827. #endregion
  6828. #endregion
  6829. return true;
  6830. }
  6831. else
  6832. return false;
  6833. #endregion
  6834. }
  6835. /// <summary>
  6836. /// 撤回工单
  6837. /// </summary>
  6838. public bool RevWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, string cont,int flag=1)
  6839. {
  6840. #region 工单处理
  6841. int sms = 0;
  6842. string markdepts = "37,57,74,88,268,295,339,422,213,427,433,424";
  6843. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID=" + model.F_ID + " ");
  6844. if (itemlasts.Count > 0)
  6845. {
  6846. foreach (var it in itemlasts)
  6847. {
  6848. if (it.F_WoState == 1)
  6849. {
  6850. sms = int.Parse(it.F_IsSMS.ToString());
  6851. }
  6852. }
  6853. }
  6854. var opt = "撤回";
  6855. int F_OptType = 1;
  6856. int optbut = (int)EnumItemOpt.revoke;
  6857. int wostate = (int)EnumWorkOrderState.revoke;
  6858. #region 读取当前登录人部门
  6859. string deptname = "";
  6860. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  6861. if (deptmodel != null)
  6862. {
  6863. deptname = deptmodel.F_DeptName + "-";
  6864. }
  6865. #endregion
  6866. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + opt + "工单,撤回说明:" + cont;
  6867. //获取上一级处理人员
  6868. var touser = ""; var deptid = 0;
  6869. string strsql = "";
  6870. if (flag == 1)
  6871. {
  6872. strsql = " and F_Type in(1,3)";
  6873. }
  6874. else if (flag == 2)
  6875. {
  6876. strsql = " and F_Type in(2,3)";
  6877. }
  6878. else
  6879. {
  6880. strsql = "";
  6881. }
  6882. 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");
  6883. if (itemlast != null && itemlast.Count > 0)
  6884. {
  6885. //if (markdepts.Contains(nowUser.F_DeptId.ToString()))
  6886. //{
  6887. // 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();
  6888. // if (itemlast.Count == 2 || itemnext.F_Flag == 9)
  6889. // {
  6890. // flag = 3;
  6891. // model.F_Flag = 9;
  6892. // }
  6893. //}
  6894. foreach (var item in itemlast)
  6895. {
  6896. touser = item.F_NextUser;
  6897. if (!string.IsNullOrEmpty(touser))
  6898. {
  6899. var ua = userAccountBLL.GetModel(touser);
  6900. if (ua != null)
  6901. {
  6902. deptid = ua.F_DeptId;
  6903. }
  6904. }
  6905. }
  6906. }
  6907. 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);
  6908. if (itemid > 0)
  6909. {
  6910. #region 发短信
  6911. //string smscont = "";
  6912. //if (model.F_Type == "1")
  6913. //{
  6914. // smscont = "咨询";
  6915. //}
  6916. //else if (model.F_Type == "2")
  6917. //{
  6918. // smscont = "投诉";
  6919. //}
  6920. //else if (model.F_Type == "3")
  6921. //{
  6922. // smscont = "抽检";
  6923. //}
  6924. //else
  6925. //{
  6926. // smscont = "建议";
  6927. //}
  6928. //string[] mag = { smscont };
  6929. //string smsmsg = "您好,您有一条待处理的工单已被撤回,请留意!";
  6930. //var tousermodel = new BLL.T_Sys_UserAccount().GetModel(touser);
  6931. //if (tousermodel != null)
  6932. //{
  6933. // if (!string.IsNullOrEmpty(tousermodel.F_Mobile))
  6934. // {
  6935. // SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, tousermodel.F_Mobile.Trim());
  6936. // //SmsSingleSenderResult result = new SMSController().SMSSingleshot(445305, mag, "15225066843");
  6937. // bool n = new SMSController().AddSmS(tousermodel.F_Mobile.Trim(), smsmsg, nowUser.F_UserId);
  6938. // }
  6939. //}
  6940. #endregion
  6941. #region 处理工单
  6942. if (flag == 1 || ((model.F_Flag == null || model.F_Flag == 0) && flag == 3))
  6943. {
  6944. model.F_State = wostate;
  6945. }
  6946. else if (flag == 2)
  6947. {
  6948. model.F_State2 = wostate;
  6949. }
  6950. else
  6951. {
  6952. model.F_State = wostate;
  6953. model.F_State2 = wostate;
  6954. }
  6955. woBLL.Update(model);
  6956. #endregion
  6957. #region 推送消息
  6958. #region 向上一级操作人员推送消息
  6959. //if (!string.IsNullOrWhiteSpace(touser) && touser != nowUser.F_UserCode)
  6960. //{//排除上一级指派人是自己
  6961. // sendsysmsg(model, nowUser, touser, (int)itemid, opt);
  6962. //}
  6963. #endregion
  6964. #endregion
  6965. return true;
  6966. }
  6967. else
  6968. return false;
  6969. #endregion
  6970. }
  6971. /// <summary>
  6972. /// 处理工单
  6973. /// </summary>
  6974. 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)
  6975. {
  6976. #region 工单处理
  6977. int sms = 0;
  6978. var itemlasts = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and F_WoID=" + model.F_ID + " ");
  6979. if (itemlasts.Count > 0)
  6980. {
  6981. foreach (var it in itemlasts)
  6982. {
  6983. if (it.F_WoState == 1)
  6984. {
  6985. sms = int.Parse(it.F_IsSMS.ToString());
  6986. }
  6987. }
  6988. }
  6989. var opt = "处理";
  6990. int optbut = (int)EnumItemOpt.deal;
  6991. int wostate = (int)EnumWorkOrderState.receive;
  6992. string nextuser = "";
  6993. int nextdept = 0;
  6994. if (isover == 1)
  6995. {
  6996. model.F_DealResult = "已处理";//处理结果
  6997. opt = "处理完结";
  6998. optbut = (int)EnumItemOpt.end;
  6999. wostate = (int)EnumWorkOrderState.finish;
  7000. model.F_DealBy = nowUser.F_UserCode;
  7001. model.F_DealTime = DateTime.Now;
  7002. }
  7003. else
  7004. {
  7005. model.F_DealResult = "未处理";//处理结果
  7006. model.F_DealReasons = uncont;//未处理原因
  7007. nextuser = nowUser.F_UserCode;
  7008. nextdept = nowUser.F_DeptId;
  7009. }
  7010. #region 高层审批
  7011. string htouser = "", htousername = ""; int hclbm = 0;
  7012. if (isApprovalp != 0)
  7013. {
  7014. hclbm = GetGCDept(nowUser.F_DeptId);
  7015. if (hclbm != 0)
  7016. {
  7017. var cluslist = userAccountBLL.GetModelList($"F_DeptId = {hclbm}");
  7018. if (cluslist.Count > 0)
  7019. {
  7020. foreach (var l in cluslist)
  7021. {
  7022. if (string.IsNullOrEmpty(htouser))
  7023. {
  7024. htouser = string.IsNullOrEmpty(htouser) ? l.F_UserCode : htouser + "," + l.F_UserCode;
  7025. htousername = string.IsNullOrEmpty(htousername) ? l.F_UserName + "(" + l.F_WorkNumber + ")" : htousername + "," + l.F_UserName + "(" + l.F_WorkNumber + ")";
  7026. }
  7027. }
  7028. }
  7029. wostate = (int)EnumWorkOrderState.audit;
  7030. }
  7031. }
  7032. #endregion
  7033. #region 读取当前登录人部门
  7034. string deptname = "";
  7035. var deptmodel = departmentBLL.GetModel(nowUser.F_DeptId);
  7036. if (deptmodel != null)
  7037. {
  7038. deptname = deptmodel.F_DeptName + "-";
  7039. }
  7040. #endregion
  7041. var optcont = "";
  7042. if (!string.IsNullOrEmpty(cont))
  7043. optcont = ",处理内容:" + cont;
  7044. var content = deptname + nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ")" + opt + "工单" + optcont;
  7045. var itemid = AddLog(model.F_ID, wostate, content, (int)EnumItemType.deal, optbut, nextuser, nextdept, nowUser, model.F_limit, sms, "", 0, flag, flagstate);
  7046. if (hclbm>0)
  7047. AddLog(model.F_ID, (int)EnumWorkOrderState.audit, htousername + "高层待审批", (int)EnumItemType.audit, (int)EnumItemOpt.audit, htouser, hclbm, nowUser, model.F_limit, sms, "", 2, flag);
  7048. if (itemid > 0)
  7049. {
  7050. #region 处理工单
  7051. if (flag == 1 || ((model.F_Flag == null || model.F_Flag == 0) && flag == 3))
  7052. {
  7053. model.F_State = wostate;
  7054. }
  7055. else if (flag == 2)
  7056. {
  7057. model.F_State2 = wostate;
  7058. }
  7059. //处理内容
  7060. if (!string.IsNullOrEmpty(F_Files))
  7061. {
  7062. if (!string.IsNullOrEmpty(model.F_Files))
  7063. model.F_Files = model.F_Files + "," + F_Files;
  7064. else
  7065. model.F_Files = F_Files;
  7066. }
  7067. if (!string.IsNullOrEmpty(cont))
  7068. {
  7069. string strcont = nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ") " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  7070. string strconts1 = strcont + " " + cont + ";@# ";
  7071. if (model.F_Source == "3")
  7072. {
  7073. if (flag == 2)
  7074. {
  7075. model.F_DealContent2 = cont;
  7076. }
  7077. else
  7078. {
  7079. model.F_DealContent = cont;
  7080. }
  7081. }
  7082. else
  7083. {
  7084. if (flag == 2)
  7085. {
  7086. model.F_DealContent2 += cont + ";";
  7087. }
  7088. else
  7089. {
  7090. model.F_DealContent += cont + ";";
  7091. }
  7092. }
  7093. if (flag == 1 || ((model.F_Flag == null || model.F_Flag == 0) && flag == 3))
  7094. {
  7095. if (!model.F_SuperiorOpinion.Trim().Contains(cont.Trim()))
  7096. {
  7097. //model.F_SuperiorOpinion = nowUser.F_UserName + "(" + nowUser.F_WorkNumber + ") " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + cont;
  7098. model.F_SuperiorOpinion = cont;
  7099. }
  7100. }
  7101. else if (flag == 2)
  7102. {
  7103. if (!model.F_SuperiorOpinion2.Trim().Contains(cont.Trim()))
  7104. {
  7105. //model.F_SuperiorOpinion2 = string.IsNullOrEmpty(model.F_SuperiorOpinion2) ? strconts1 : model.F_SuperiorOpinion2 + strconts1;
  7106. model.F_SuperiorOpinion2 = cont;
  7107. }
  7108. }
  7109. //model.F_SuperiorOpinion = string.IsNullOrEmpty(model.F_SuperiorOpinion) ? cont : model.F_SuperiorOpinion + "; " + cont;
  7110. }
  7111. //if (!string.IsNullOrEmpty(eventreason))
  7112. //{
  7113. // if (flag == 1)
  7114. // {
  7115. // model.F_EventReason = eventreason;
  7116. // }
  7117. // else if (flag == 2)
  7118. // {
  7119. // model.F_EventReason2 = eventreason;
  7120. // }
  7121. //}
  7122. model.F_DealTime = DateTime.Now;
  7123. InToworkModel(model, input,nowUser);
  7124. woBLL.Update(model);
  7125. #endregion
  7126. #region 推送消息
  7127. #region 推送消息给添加的坐席 -处理情况
  7128. if (nowUser.F_UserCode != model.F_CreateBy)
  7129. {
  7130. sendsysmsg(model, nowUser, model.F_CreateBy, (int)model.F_ID, opt);//推送系统消息
  7131. if (model.F_State == (int)EnumWorkOrderState.finish)
  7132. {
  7133. var createmodel = userAccountBLL.GetModel(model.F_CreateBy); //被指派人
  7134. if (createmodel != null)
  7135. {
  7136. if (!string.IsNullOrEmpty(createmodel.F_WxOpenId))
  7137. {
  7138. sendwxmsg(model, createmodel.F_WxOpenId, nowUser, "工单完结");
  7139. }
  7140. }
  7141. }
  7142. }
  7143. #endregion
  7144. #region 向上一级操作人员推送消息
  7145. 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();
  7146. if (itemlast != null)
  7147. {
  7148. if (itemlast.F_CreateUser != model.F_CreateBy)
  7149. {
  7150. sendsysmsg(model, nowUser, itemlast.F_CreateUser, (int)itemid, opt);
  7151. // var lastUser = userAccountBLL.GetModel(itemlast.F_CreateUser);
  7152. // if (lastUser != null && !string.IsNullOrEmpty(lastUser.F_WxOpenId))
  7153. // sendwxmsg(model, lastUser.F_WxOpenId, nowUser, opt);
  7154. }
  7155. }
  7156. #endregion
  7157. #region 办理完结向客户发送消息
  7158. //if (model.F_State == (int)EnumWorkOrderState.finish)
  7159. //{
  7160. // if (!string.IsNullOrEmpty(model.F_CustomerID))
  7161. // {
  7162. // var cusmodel = customerBaseBLL.GetModel(model.F_CustomerID.Trim());
  7163. // if (cusmodel != null && !string.IsNullOrEmpty(cusmodel.F_WxOpenId))
  7164. // {
  7165. // sendwxmsg(model, cusmodel.F_WxOpenId, nowUser, opt);
  7166. // }
  7167. // }
  7168. //}
  7169. if (isover == 1)
  7170. {
  7171. // if (!string.IsNullOrEmpty(model.F_WxOpenId))
  7172. //sendwxmsg(model, model.F_WxOpenId, nowUser, model.F_DealContent);
  7173. }
  7174. #endregion
  7175. #endregion
  7176. return true;
  7177. }
  7178. else
  7179. return false;
  7180. #endregion
  7181. }
  7182. //推送系统提醒
  7183. public void sendsysmsg(Model.T_Wo_WorkOrder womodel, Model.T_Sys_UserAccount nowUser, string touser, int toid, string opt)
  7184. {
  7185. #region 消息提醒
  7186. string strmsg = string.Empty;
  7187. strmsg = nowUser.F_UserName + "(" + nowUser.F_UserCode + ")" + "操作" + opt + "工单, " + womodel.F_WorkOrderCode + "," + womodel.F_ID + "";
  7188. Model.T_Msg_List msg = new Model.T_Msg_List();
  7189. msg.Type = (int)Model.MSGType.workorder;//处理
  7190. msg.ToUser = touser;
  7191. msg.ToID = toid;
  7192. msg.Detail = strmsg;
  7193. msg.State = 0;
  7194. msg.IsDel = 0;
  7195. msg.CreateUser = nowUser.F_UserCode;
  7196. msg.CreateDate = DateTime.Now;
  7197. new BLL.T_Msg_List().Add(msg);
  7198. #endregion
  7199. }
  7200. //推送微信消息
  7201. public void sendwxmsg(Model.T_Wo_WorkOrder womodel, string openid, Model.T_Sys_UserAccount nowUser, string opt)
  7202. {
  7203. #region 推送微信
  7204. try
  7205. {
  7206. if (!string.IsNullOrEmpty(openid))
  7207. {
  7208. var dicv = dicvalueBll.GetModel(int.Parse(womodel.F_Type));
  7209. string content = string.Empty;
  7210. var wotype = "";
  7211. if (dicv != null)
  7212. {
  7213. wotype = dicv.F_Name;
  7214. }
  7215. content = opt;
  7216. var msg = WxHelper.SendWechatMsg1(DateTime .Now .ToString ("yyyy-MM-dd HH:mm:ss"), "你的工单已处理", wotype, womodel.F_State.ToString(), content, womodel.F_ID.ToString(), openid, "");
  7217. Error("推送微信::::::" + msg.ToString());
  7218. }
  7219. }
  7220. catch { }
  7221. #endregion
  7222. }
  7223. public static bool IsNumeric(string value)
  7224. {
  7225. return Regex.IsMatch(value, @"^[+-]?\d*[.]?\d*$");
  7226. }
  7227. /// <summary>
  7228. /// 修改工单
  7229. /// </summary>
  7230. /// <returns></returns>
  7231. [WechatActionFilter]
  7232. public ActionResult Update(WorkOrderNewInput input )
  7233. {
  7234. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + input.F_WxOpenId + "'").FirstOrDefault();
  7235. if (ua != null)
  7236. {
  7237. #region 添加验证判断
  7238. if (input.F_ID <= 0)
  7239. return Error("参数错误!");
  7240. if (!(input.F_Type > 0 && input.F_Type < 6))
  7241. return Error("工单类型错误!");
  7242. if (string.IsNullOrEmpty(input.F_CusName))
  7243. return Error("请输入客户姓名!");
  7244. if (string.IsNullOrEmpty(input.F_CusPhone))
  7245. return Error("请输入客户电话!");
  7246. if(input.F_Type == 2 || input.F_Type == 5)
  7247. {
  7248. if (string.IsNullOrEmpty(input.F_SalesBase))
  7249. return Error("请输入基地!");
  7250. if (string.IsNullOrEmpty(input.F_QuestionType))
  7251. return Error("请选择问题类别!");
  7252. }
  7253. //if (!string.IsNullOrEmpty(input.F_BatchNumber) && !vaBatchNumber(input.F_BatchNumber))
  7254. //{
  7255. // return Error("请输入正确的生产批次号!");
  7256. //}
  7257. if (!string.IsNullOrEmpty(input.F_CustomerID))
  7258. {
  7259. var Customer = customerBaseBLL.GetModel(input.F_CustomerID.Trim());
  7260. if (Customer == null)
  7261. return Error("无此客户编码!");
  7262. }
  7263. if (!string.IsNullOrWhiteSpace(input.F_MaterialID))
  7264. {
  7265. var Customer = mmBLL.GetModel(input.F_MaterialID.Trim());
  7266. if (Customer == null)
  7267. return Error("无此物料编码!");
  7268. }
  7269. //if (!string.IsNullOrEmpty(input.F_BatchNumber))
  7270. //{
  7271. // var prono = input.F_BatchNumber.Substring(0, 6);
  7272. // try
  7273. // {
  7274. // var pronos = DateTime.ParseExact(prono, "yyMMdd", null).ToString("yyyy-MM-dd");
  7275. // var protime = Convert.ToDateTime(pronos);
  7276. // if (DateTime.Parse(pronos) > DateTime.Now)
  7277. // {
  7278. // return Error("生产批次号错误,生产日期不能大于当前时间!");
  7279. // }
  7280. // }
  7281. // catch
  7282. // {
  7283. // return Error("生产批次号错误,日期格式错误!");
  7284. // }
  7285. //}
  7286. if (!string.IsNullOrEmpty(input.F_CustomerID) && !valcode(input.F_CustomerID.ToString(), 10))
  7287. return Error("客户编号为10为纯数字!");
  7288. if (!string.IsNullOrEmpty(input.F_MaterialID) && !valcode(input.F_MaterialID.ToString(), 11))
  7289. return Error("物料编码为11为纯数字!");
  7290. #endregion
  7291. var model = woBLL.GetModel(input.F_ID);
  7292. if (model == null)
  7293. return Error("查询不到此工单!");
  7294. if (model.F_State == 2)
  7295. {
  7296. return Error("此工单已接单不能修改!");
  7297. }
  7298. else if (model.F_State == 11 || model.F_State == 10)
  7299. {
  7300. return Error("此工单已处理不能修改!");
  7301. }
  7302. if (!string.IsNullOrEmpty(input.F_SalesPhone))
  7303. {
  7304. if (!IsNumeric(input.F_SalesPhone))
  7305. return Error("请输入正确的业务员电话");
  7306. }
  7307. var itemlasts = itembll.GetModelList(" F_WoID=" + model.F_ID + "order by F_ID desc ").FirstOrDefault ();
  7308. int overtime = 0, sms = 0;
  7309. if (itemlasts!=null )
  7310. {
  7311. if (itemlasts.F_LimitTime != "")
  7312. overtime = int.Parse(itemlasts.F_LimitTime);
  7313. sms = int.Parse(itemlasts.F_IsSMS.ToString());
  7314. }
  7315. #region 保存客户基本信息
  7316. model = inputtoobj(ua, model, input, 1);
  7317. #endregion
  7318. bool n = woBLL.Update(model);
  7319. if (n)
  7320. {
  7321. WriteWorkOrderLog(model.F_WorkOrderCode, ua.F_UserCode, 0, "", 1, "修改工单");
  7322. #region 读取当前登录人的部门
  7323. string deptname = "";
  7324. var deptmodel = departmentBLL.GetModel(ua.F_DeptId);
  7325. if (deptmodel != null)
  7326. {
  7327. deptname = deptmodel.F_DeptName + "-";
  7328. }
  7329. #endregion
  7330. 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);
  7331. if (GetUser(input.F_WxOpenId) != null)
  7332. {
  7333. var user = GetUser(input.F_WxOpenId);
  7334. string deptname1 = "";
  7335. var deptmode = departmentBLL.GetModel(user.F_DeptId);
  7336. if (deptmode != null)
  7337. {
  7338. deptname1 = deptmode.F_DeptName + "-";
  7339. }
  7340. var deptmodel1 = departmentBLL.GetModel(ua.F_DeptId);
  7341. 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);
  7342. if (sms == 1 && !string.IsNullOrEmpty(user.F_Mobile))
  7343. {
  7344. SendSms(model.F_Type, user.F_Mobile, ua.F_UserId);
  7345. }
  7346. }
  7347. else
  7348. {
  7349. string deptname1 = "";
  7350. int dapt = 0, nextda = 0, nextda2 = 0; string opt = "", opt2 = "";
  7351. var deptmodel1 = departmentBLL.GetModel(ua.F_DeptId);
  7352. if (deptmodel1 != null)
  7353. {
  7354. deptname1 = deptmodel1.F_DeptName;
  7355. dapt = deptmodel1.F_ParentId;
  7356. }
  7357. //if (dapt != 0)
  7358. //{
  7359. if (CirculMarket(ua.F_DeptId, 11))
  7360. {
  7361. nextda = 427;
  7362. opt = "流转运营中心";
  7363. }
  7364. else if (CirculMarket(ua.F_DeptId, 14))
  7365. {
  7366. nextda = 57;
  7367. opt = "流转营销管理处";
  7368. }
  7369. else if (CirculMarket(ua.F_DeptId, 15))
  7370. {
  7371. nextda = 74;
  7372. opt = "流转策划推广";
  7373. }
  7374. else if (CirculMarket(ua.F_DeptId, 16))
  7375. {
  7376. nextda = 88;
  7377. opt = "流转销售部";
  7378. }
  7379. else if (CirculMarket(ua.F_DeptId, 18))
  7380. {
  7381. nextda = 268;
  7382. opt = "流转车用尿素";
  7383. }
  7384. else if (CirculMarket(ua.F_DeptId, 20))
  7385. {
  7386. nextda = 422;
  7387. opt = "流转营销中心市场科";
  7388. nextda2 = 295;
  7389. opt2 = "流转新乡黑科质检";
  7390. }
  7391. else if (CirculMarket(ua.F_DeptId, 332))
  7392. {
  7393. nextda = 339;
  7394. opt = "流转营销管理处";
  7395. }
  7396. else if (ua.F_DeptId == 17 || ua.F_DeptId == 19 || ua.F_DeptId == 20 || ua.F_DeptId == 21)
  7397. {
  7398. nextda = ua.F_DeptId;
  7399. opt = "流转" + deptname1;
  7400. }
  7401. //}
  7402. if (nextda != 0)
  7403. {
  7404. if (nextda2 != 0)
  7405. {
  7406. model.F_Flag = 3;
  7407. AssignWO(ua, model, input, opt, "", nextda, 0, model.F_limit, sms, 0, 0, 0, "", 1, 1, 3);
  7408. var res2 = AssignWO(ua, model, input, opt2, "", nextda2, 0, model.F_limit, sms, 0, 0, 0, "", 1, 2, 3);
  7409. }
  7410. else
  7411. {
  7412. model.F_State = 1;
  7413. model.F_State2 = 1;
  7414. model.F_Flag = 9;
  7415. var res = AssignWO(ua, model, input, opt, "", nextda, 0, model.F_limit, sms, 0, 0, 0, "", 1, 3, 9);
  7416. }
  7417. return Success("保存成功");
  7418. }
  7419. else
  7420. {
  7421. return Error("流转失败!");
  7422. }
  7423. }
  7424. return Success("保存成功!");
  7425. }
  7426. else
  7427. return Error("保存失败!");
  7428. }
  7429. else
  7430. {
  7431. return Error("OpenId不能为空!!");
  7432. }
  7433. }
  7434. public void WriteWorkOrderLog(string WorkOrderID, string UserCode, int IsDelete, string DelUserCode, int TypeId, string Remark)
  7435. {
  7436. var model = new Model.T_Wo_WorkOrder_Logs();
  7437. model.WorkOrderID = WorkOrderID; //工单编号
  7438. model.UserCode = UserCode; //修改人code
  7439. model.AddTime = DateTime.Now; //添加时间
  7440. model.IsDelete = IsDelete; //是否删除(0正常1删除)
  7441. model.DelUserCode = DelUserCode; //删除人code
  7442. model.TypeId = TypeId; //类型(0添加,1修改)
  7443. model.Remark = Remark; //备注
  7444. blllogs.Add(model);
  7445. }
  7446. /// <summary>
  7447. /// 添加工单记录
  7448. /// </summary>
  7449. 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)
  7450. {
  7451. Model.T_Wo_WorkOrderItem_New itemModel = new Model.T_Wo_WorkOrderItem_New();
  7452. #region
  7453. string strsql = "";
  7454. if (nowUser != null)
  7455. {
  7456. string flagstr = "";
  7457. if (flag != 3)
  7458. flagstr = $" and F_Type in({ flag},3)";
  7459. Model.T_Sys_RoleInfo ro = rolebll.GetModel(nowUser.F_RoleId);
  7460. 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}";
  7461. //if (ro.F_RoleCode == "JDYPTZX" || ro.F_RoleCode == "JDYBZZX" || ro.F_RoleCode == "XTGLY")
  7462. //{
  7463. // 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}";
  7464. //}
  7465. //else
  7466. //{
  7467. // 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}";
  7468. //}
  7469. }
  7470. else
  7471. {
  7472. strsql = $" isnull(F_IsUsed,'0')='0' and F_ItemType={itemtype} and F_WoID={woid}";
  7473. }
  7474. //处理当前工单的记录之前的记录过期
  7475. //var itemlast = itembll.GetModelList(" isnull(F_IsUsed,'0')='0' and F_ItemType=" + itemtype + " and F_WoID=" + woid + " ");
  7476. var itemlast = itembll.GetModelList(strsql);
  7477. if (F_IsUsed == 0)
  7478. {
  7479. if (itemlast != null && itemlast.Count > 0)
  7480. {
  7481. foreach (var it in itemlast)
  7482. {
  7483. it.F_IsUsed = 1;
  7484. it.F_LimitTime = overtime.ToString();
  7485. itembll.Update(it);
  7486. }
  7487. itemModel.F_LastTime = itemlast.LastOrDefault().F_CreateTime;
  7488. }
  7489. }
  7490. #endregion
  7491. itemModel.F_WoID = woid;
  7492. itemModel.F_IsSMS = sms;
  7493. itemModel.F_WoState = wostate;
  7494. itemModel.F_ItemType = itemtype;
  7495. itemModel.F_OptType = opttype;
  7496. itemModel.F_OptContent = content;
  7497. itemModel.F_NextUser = nextuser;
  7498. itemModel.F_NextDept = nextdept;
  7499. itemModel.F_IsUsed = F_IsUsed;
  7500. itemModel.F_LimitTime = overtime.ToString();
  7501. itemModel.F_Type = flag;//区分内外线和公共部门
  7502. if (flagstate != 0)
  7503. itemModel.F_Flag = flagstate;
  7504. else
  7505. itemModel.F_Flag = new BLL.T_Wo_WorkOrder().GetModel(woid).F_Flag;
  7506. if (nowUser != null)
  7507. {
  7508. itemModel.F_CreateUser = nowUser.F_UserCode;
  7509. }
  7510. else
  7511. {
  7512. itemModel.F_CreateUser = "";
  7513. }
  7514. if (create != "")
  7515. {
  7516. itemModel.F_CreateTime = DateTime.Parse(create);
  7517. }
  7518. else
  7519. {
  7520. itemModel.F_CreateTime = DateTime.Now;
  7521. }
  7522. var res = itembll.Add(itemModel);
  7523. return res;
  7524. }
  7525. #region 客户来电
  7526. public ActionResult GetCallList(string phone,int pageindex = 1, int pagesize = 10)
  7527. {
  7528. DataTable dt = new DataTable();
  7529. string sql = " and DealType =3";
  7530. //sql+= " and datediff(Minute,BeginTime,'" + DateTime.Now.ToString() + "')<=5 ";
  7531. if (phone != null && phone.Trim() != "")
  7532. {
  7533. sql += " and CallNumber like '%" + phone + "%'";
  7534. }
  7535. int recordCount = 0;
  7536. dt = BLL.PagerBLL.GetListPager(
  7537. "T_Call_CallRecords left join T_Sys_UserAccount on UserCode=F_UserCode",
  7538. "CallRecordsId",
  7539. "T_Call_CallRecords.*,T_Sys_UserAccount.F_SeartGroup,(SELECT F_DeptName FROM dbo.T_Sys_Department WHERE F_DeptId = T_Sys_UserAccount.F_DeptId) AS DeptName",
  7540. sql,
  7541. "ORDER BY CallRecordsId desc",
  7542. pagesize,
  7543. pageindex,
  7544. true,
  7545. out recordCount);
  7546. dt.Columns.Add("CusName");
  7547. dt.Columns.Add("PhoneAddress",typeof(string));
  7548. var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
  7549. var users = new BLL.T_Sys_UserAccount().GetModelList("");
  7550. foreach (DataRow dr in dt.Rows)
  7551. {
  7552. string path = dr["FilePath"] != null ? dr["FilePath"].ToString() : "";
  7553. if (path != "" && config != null && !string.IsNullOrEmpty(config.F_ParamValue))
  7554. {
  7555. var ym = config.F_ParamValue;
  7556. if (ym.Substring(ym.Length - 1) == "/")
  7557. {
  7558. ym = ym.Substring(0, ym.Length - 1);
  7559. }
  7560. dr["FilePath"] = ym + path.Substring(path.IndexOf(':') + 1).Replace('\\', '/');
  7561. }
  7562. string ucode = dr["UserCode"] != null ? dr["UserCode"].ToString() : "";
  7563. string uname = dr["UserName"] != null ? dr["UserName"].ToString() : "";
  7564. string tephone = dr["CallNumber"] != null ? dr["CallNumber"].ToString() : "";
  7565. if (ucode != "")
  7566. {
  7567. if (uname == "")
  7568. {
  7569. var uu = users.Where(u => u.F_UserCode.Equals(ucode)).FirstOrDefault();
  7570. if (uu != null)
  7571. dr["UserName"] = uu.F_UserName;
  7572. }
  7573. }
  7574. if (!string.IsNullOrEmpty(tephone))
  7575. {
  7576. //12:08 2020/2/27 过滤字段F_LegalPhone字段中的空格
  7577. Model.T_Cus_CustomerBaseNew cus = new BLL.T_Cus_CustomerBaseNew().GetModelList(" REPLACE(F_LegalPhone,' ','') ='" + tephone + "' ").FirstOrDefault();
  7578. Model.T_Cus_CustomerBaseNew cusll = new BLL.T_Cus_CustomerBaseNew().GetModelList(" REPLACE(F_LegalPhone,' ','') ='0" + tephone + "' ").FirstOrDefault();
  7579. if (cus != null)
  7580. {
  7581. dr["CusName"] = new BLL.T_Cus_CustomerBaseNew().GetModelList(" REPLACE(F_LegalPhone,' ','') ='" + tephone + "' ").FirstOrDefault().F_Legal;
  7582. }
  7583. else if (cusll != null)
  7584. {
  7585. dr["CusName"] = new BLL.T_Cus_CustomerBaseNew().GetModelList(" REPLACE(F_LegalPhone,' ','') ='0" + tephone + "' ").FirstOrDefault().F_Legal;
  7586. }
  7587. var otherController = DependencyResolver.Current.GetService<CustomerNewController>();
  7588. var result = ((ContentResult)otherController.GetCustomerByTel(tephone)).Content.ToObject<AjaxResult>();
  7589. if (result.state.ToString() == "success")
  7590. {
  7591. dr["PhoneAddress"] = ((dynamic)result.data).CityaddressDes;
  7592. }
  7593. //object acre = JsonConvert.DeserializeObject<object>(GetActionResult(tephone).ToJson());
  7594. //dr["PhoneAddress"] = ((dynamic)acre).CityaddressDes;
  7595. }
  7596. }
  7597. var obj = new
  7598. {
  7599. state = "success",
  7600. message = "成功",
  7601. rows = dt,
  7602. total = recordCount
  7603. };
  7604. return Content(obj.ToJson());
  7605. }
  7606. public ActionResult GetActionResult(string tel)
  7607. {
  7608. var otherController = DependencyResolver.Current.GetService<CustomerNewController>();
  7609. var result = otherController.GetCustomerByTel(tel);
  7610. return result;
  7611. }
  7612. #endregion
  7613. /// <summary>
  7614. /// 获取记录详情
  7615. /// </summary>
  7616. /// <param name="callid"></param>
  7617. /// <returns></returns>
  7618. public ActionResult GetCallDetail(int callid)
  7619. {
  7620. if (callid != 0)
  7621. {
  7622. var model = new BLL.T_Call_CallRecords().GetModel(callid);
  7623. Model.T_Cus_CustomerBaseNew cusmodel = null;
  7624. if (model != null)
  7625. {
  7626. string CusName = "", PhoneAddress="";
  7627. string tephone = model.CallNumber!= null ? model.CallNumber.ToString() : "";
  7628. if (!string.IsNullOrEmpty(tephone))
  7629. {
  7630. //12:08 2020/2/27 过滤字段F_LegalPhone字段中的空格
  7631. Model.T_Cus_CustomerBaseNew cus = new BLL.T_Cus_CustomerBaseNew().GetModelList(" REPLACE(F_LegalPhone,' ','') ='" + tephone + "' ").FirstOrDefault();
  7632. Model.T_Cus_CustomerBaseNew cusll = new BLL.T_Cus_CustomerBaseNew().GetModelList(" REPLACE(F_LegalPhone,' ','') ='0" + tephone + "' ").FirstOrDefault();
  7633. if (cus != null)
  7634. {
  7635. cusmodel = cus;
  7636. CusName = new BLL.T_Cus_CustomerBaseNew().GetModelList(" REPLACE(F_LegalPhone,' ','') ='" + tephone + "' ").FirstOrDefault().F_Legal;
  7637. }
  7638. else if (cusll != null)
  7639. {
  7640. cusmodel = cusll;
  7641. CusName = new BLL.T_Cus_CustomerBaseNew().GetModelList(" REPLACE(F_LegalPhone,' ','') ='0" + tephone + "' ").FirstOrDefault().F_Legal;
  7642. }
  7643. var otherController = DependencyResolver.Current.GetService<CustomerNewController>();
  7644. var result = ((ContentResult)otherController.GetCustomerByTel(tephone)).Content.ToObject<AjaxResult>();
  7645. if (result.state.ToString() == "success")
  7646. {
  7647. PhoneAddress = ((dynamic)result.data).CityaddressDes;
  7648. }
  7649. }
  7650. var obj = new
  7651. {
  7652. tephone = tephone,
  7653. PhoneAddress= PhoneAddress,
  7654. CusId= cusmodel?.F_CustomerId??0,
  7655. CusName = CusName,
  7656. Province=cusmodel?.F_AddressProvince??"",
  7657. City = cusmodel?.F_AddressCity??"",
  7658. Country = cusmodel?.F_AddressCountry??"",
  7659. Township=cusmodel?.F_AddressTownship??""
  7660. };
  7661. return Content(obj.ToJson());
  7662. }
  7663. else return Error("获取失败!");
  7664. }
  7665. else
  7666. {
  7667. return Error("参数传输失败");
  7668. }
  7669. }
  7670. #region 客户信息添加
  7671. //public ActionResult CallAdd(CustomerBaseNewInput input,string OpenId)
  7672. //{
  7673. // if (!string.IsNullOrEmpty(OpenId))
  7674. // {
  7675. // var otherController = DependencyResolver.Current.GetService<CustomerNewController>();
  7676. // var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + OpenId + "'").FirstOrDefault();
  7677. // string usercode = ua.F_UserCode;
  7678. // if (string.IsNullOrEmpty(input.F_LegalPhone))
  7679. // return Error("请输入客户电话");
  7680. // var sql = $" and F_LegalPhone ='" + input.F_LegalPhone.Trim() + "'";
  7681. // var userModel = new BLL.T_Cus_CustomerBaseNew().GetModelList(" F_IsDelete = 0 " + sql);
  7682. // if (userModel.Count() > 0)
  7683. // {
  7684. // var model = new BLL.T_Cus_CustomerBaseNew().GetModel(userModel[0].F_CustomerId);
  7685. // #region 保存客户基本信息
  7686. // model = otherController.inputtoobj(model, input);
  7687. // #endregion
  7688. // bool n = new BLL.T_Cus_CustomerBaseNew().Update(model);
  7689. // if (n)
  7690. // {
  7691. // return Success("保存成功!", model.F_CustomerId);
  7692. // }
  7693. // else
  7694. // return Error("保存失败!");
  7695. // }
  7696. // else
  7697. // {
  7698. // int i = 0;
  7699. // if (string.IsNullOrEmpty(input.F_CustomerCode))
  7700. // {
  7701. // while (true)
  7702. // {
  7703. // if (!getunique(0, otherController.GetIntCode(i)))
  7704. // {
  7705. // input.F_CustomerCode = otherController.GetIntCode(i);
  7706. // break;
  7707. // }
  7708. // else
  7709. // {
  7710. // i++;
  7711. // }
  7712. // }
  7713. // }
  7714. // var model = new Model.T_Cus_CustomerBaseNew();
  7715. // #region 保存客户基本信息
  7716. // model = otherController.inputtoobj(model, input);
  7717. // model.F_CreateBy = usercode;
  7718. // model.F_CreateOn = DateTime.Now;
  7719. // model.F_IsDelete = 0;
  7720. // #endregion
  7721. // int n = new BLL.T_Cus_CustomerBaseNew().Add(model);
  7722. // if (n > 0)
  7723. // {
  7724. // return Success("新增成功!", n);
  7725. // }
  7726. // else
  7727. // return Error("新增失败!");
  7728. // }
  7729. // }
  7730. // else
  7731. // {
  7732. // return Error("");
  7733. // }
  7734. //}
  7735. #endregion
  7736. #region
  7737. //workorder.WoBillController blcon = new WoBillController();
  7738. ///// <summary>
  7739. ///// 获取所有业务
  7740. ///// </summary>
  7741. ///// <returns></returns>
  7742. //[WechatActionFilter]
  7743. //public ActionResult GetBusList()
  7744. //{
  7745. // var list = blcon.GetBusAllList();
  7746. // return Success("获取信息列表成功", list);
  7747. //}
  7748. ///// <summary>
  7749. ///// 获取业务内容
  7750. ///// </summary>
  7751. ///// <returns></returns>
  7752. //[WechatActionFilter]
  7753. //public ActionResult GetBusInfo()
  7754. //{
  7755. // string strbusid = HttpUtility.UrlDecode(RequestString.GetQueryString("busid"));
  7756. // if (string.IsNullOrEmpty(strbusid))
  7757. // return Error("参数错误");
  7758. // var model = blcon.GetBusInfo(strbusid);
  7759. // if (model != null)
  7760. // return Success("获取信息成功", model);
  7761. // else
  7762. // return Error("获取信息失败");
  7763. //}
  7764. ///// <summary>
  7765. ///// 获取开票列表
  7766. ///// </summary>
  7767. ///// <returns></returns>
  7768. //[WechatActionFilter]
  7769. //public ActionResult GetBillList()
  7770. //{
  7771. // DataTable dt = new DataTable();
  7772. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  7773. // string strbtime = HttpUtility.UrlDecode(RequestString.GetQueryString("btime"));
  7774. // string stretime = HttpUtility.UrlDecode(RequestString.GetQueryString("etime"));
  7775. // string strpageindex = RequestString.GetQueryString("pageindex");
  7776. // int pageindex = 1;
  7777. // string strpagesize = RequestString.GetQueryString("pagesize");
  7778. // int pagesize = 10;
  7779. // if (strpageindex.Trim() != "")
  7780. // {
  7781. // pageindex = Convert.ToInt32(strpageindex);
  7782. // }
  7783. // if (strpagesize.Trim() != "")
  7784. // {
  7785. // pagesize = Convert.ToInt32(strpagesize);
  7786. // }
  7787. // var obj=blcon.GetLists(stropenid, strbtime, stretime, pageindex, pagesize);
  7788. // return Content(obj.ToJson());
  7789. //}
  7790. ///// <summary>
  7791. ///// 获取开票详情
  7792. ///// </summary>
  7793. ///// <returns></returns>
  7794. //[WechatActionFilter]
  7795. //public ActionResult GetBillInfo()
  7796. //{
  7797. // string strbillid = HttpUtility.UrlDecode(RequestString.GetQueryString("billid"));
  7798. // if (string.IsNullOrEmpty(strbillid))
  7799. // return Error("参数错误");
  7800. // var model = blcon.GetBillInfo(strbillid);
  7801. // if (model != null)
  7802. // return Success("获取信息成功", model);
  7803. // else
  7804. // return Error("获取信息失败");
  7805. //}
  7806. ///// <summary>
  7807. ///// 开票
  7808. ///// </summary>
  7809. ///// <returns></returns>
  7810. //[WechatActionFilter]
  7811. //public ActionResult AddBill()
  7812. //{
  7813. // string billtype = RequestString.GetFormString("billtype");//发票类型
  7814. // string cusname = RequestString.GetFormString("cusname");//客户名称
  7815. // string taxidnum = RequestString.GetFormString("taxidnum");//纳税人识别号
  7816. // string address = RequestString.GetFormString("address");//地址
  7817. // string phone = RequestString.GetFormString("phone");//电话
  7818. // string bank = RequestString.GetFormString("bank");//开户行
  7819. // string bankaccount = RequestString.GetFormString("bankaccount");//开户行账号
  7820. // string proname = RequestString.GetFormString("proname");//项目名称
  7821. // string models = RequestString.GetFormString("models");//型号
  7822. // string unit = RequestString.GetFormString("unit");//单位
  7823. // string amount = RequestString.GetFormString("amount");//数量
  7824. // string unitprice = RequestString.GetFormString("unitprice");//单价
  7825. // string sumprice = RequestString.GetFormString("sumprice");//金额
  7826. // string taxrate = RequestString.GetFormString("taxrate");//税率
  7827. // string taxamount = RequestString.GetFormString("taxamount");//税额
  7828. // string billingMethod = RequestString.GetFormString("billingmethod");//开票方式:快递/自取
  7829. // string billingTime = RequestString.GetFormString("billingtime");//开票时间
  7830. // string remark = RequestString.GetFormString("remark");//备注
  7831. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  7832. // Model.T_Wo_Bill dModel = new Model.T_Wo_Bill();
  7833. // #region 保存基本信息
  7834. // dModel.F_BillType = billtype;
  7835. // dModel.F_CusName = cusname;
  7836. // dModel.F_TaxIDNum = taxidnum;
  7837. // dModel.F_Address = address;
  7838. // dModel.F_Phone = phone;
  7839. // dModel.F_Bank = bank;
  7840. // dModel.F_BankAccount = bankaccount;
  7841. // dModel.F_ProName = proname;
  7842. // dModel.F_Models = models;
  7843. // dModel.F_Unit = unit;
  7844. // dModel.F_Amount = amount;
  7845. // dModel.F_UnitPrice = unitprice;
  7846. // dModel.F_SumPrice = sumprice;
  7847. // dModel.F_TaxRate = taxrate;
  7848. // dModel.F_TaxAmount = taxamount;
  7849. // dModel.F_BillingMethod = billingMethod;
  7850. // dModel.F_BillingTime = billingTime;
  7851. // dModel.F_Remark = remark;
  7852. // dModel.F_Openid = stropenid;
  7853. // dModel.F_CreateOn = DateTime.Now;
  7854. // dModel.F_State = 0;
  7855. // #endregion
  7856. // var res=blcon.addbills(dModel);
  7857. // if (res)
  7858. // return Success("保存成功");
  7859. // else
  7860. // return Error("保存失败");
  7861. //}
  7862. #endregion
  7863. #region 获取公司详情
  7864. ////获取公司信息
  7865. //[WechatActionFilter]
  7866. //public ActionResult GetInfo()
  7867. //{
  7868. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  7869. // if (string.IsNullOrEmpty(stropenid))
  7870. // return Error("参数错误!");
  7871. // var model=customerBaseBLL.GetModelByOpenid(stropenid);
  7872. // if (model != null)
  7873. // {
  7874. // var sqlwo = " IsDel=0 and State <>2 "; var sqlno = " F_isDel=0 ";
  7875. // var nowUser = userAccountBLL.GetModelByOpenid(stropenid);
  7876. // var nowCus = customerBaseBLL.GetModelByOpenid(stropenid);
  7877. // if (nowUser != null)
  7878. // {
  7879. // workorder.WorkOrderController wo = new workorder.WorkOrderController();
  7880. // sqlwo += " and State =1 and WorkOrderID in ( '" + wo.GetDWCWorkOrderID(nowUser.F_UserCode) + "') ";
  7881. // sqlno += " and (ISNULL(F_UserId,'') = '' or ISNULL(F_UserId,'') like '%," + nowUser.F_UserId + ",%')";
  7882. // }
  7883. // else if (nowCus != null)
  7884. // {
  7885. // sqlwo += " and ( CustomerID=" + model.F_CustomerId + " or County like '%" + model.F_CompanyName + "%' )";
  7886. // 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)";
  7887. // }
  7888. // var ordercount = woBLL.GetRecordCount(sqlwo);
  7889. // var noticecount = new BLL.T_Msg_NoticeInfo().GetRecordCount(sqlno);
  7890. // var obj = new
  7891. // {
  7892. // model.F_CompanyName,//公司名称
  7893. // model.F_CompanyLogo,//logo
  7894. // model.F_CustomerCode,//编号
  7895. // model.F_CycleStart,//服务周期-开始时间
  7896. // model.F_CycleEnd,//服务周期-结束时间
  7897. // model.F_ChargeType,//收费类型:1月度,2季度,3年度
  7898. // model.F_Charges,//收费
  7899. // model.F_TaxNumber,//公司税号
  7900. // model.F_CompanyAddress,//公司地址
  7901. // ordercount,//待处理工单数量
  7902. // noticecount,//未读公告数量
  7903. // };
  7904. // return Success("获取成功", obj);
  7905. // }
  7906. // return Error("获取失败");
  7907. //}
  7908. ////获取财税信息
  7909. ////[WechatActionFilter]
  7910. //public ActionResult GetFinc()
  7911. //{
  7912. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  7913. // var model = customerBaseBLL.GetModelByOpenid(stropenid);
  7914. // if (model != null)
  7915. // {
  7916. // var finmodel = finbll.GetModelList(" F_CustomerId=" + model.F_CustomerId).FirstOrDefault();
  7917. // if (finmodel != null)
  7918. // {
  7919. // var obj = new
  7920. // {
  7921. // model.F_CompanyName,//公司名称
  7922. // model.F_CompanyLogo,//logo
  7923. // model.F_CustomerCode,//编号
  7924. // finmodel.F_CusFinId,
  7925. // finmodel.F_CustomerId,
  7926. // finmodel.F_MonthState,
  7927. // finmodel.F_AnnualIncome,
  7928. // finmodel.F_AnnualProfit,
  7929. // finmodel.F_AnnualCost,
  7930. // finmodel.F_AnnualPersonCount,
  7931. // finmodel.F_AnnualWages,
  7932. // finmodel.F_QuarterlyCost,
  7933. // finmodel.F_QuarterlyPersonCount,
  7934. // finmodel.F_QuarterlyWages,
  7935. // finmodel.F_QuarterlyIncome,
  7936. // finmodel.F_QPVAT,
  7937. // finmodel.F_QPSurtax,
  7938. // finmodel.F_QPTaxes,
  7939. // finmodel.F_QPConTax,
  7940. // finmodel.F_QPPerinTax,
  7941. // finmodel.F_QPStampTax,
  7942. // finmodel.F_QPOtherTax
  7943. // };
  7944. // return Success("获取成功", obj);
  7945. // }
  7946. // }
  7947. // return Error("获取失败");
  7948. //}
  7949. #endregion
  7950. #region 工单
  7951. /// <summary>
  7952. /// 工单列表
  7953. /// </summary>
  7954. [WechatActionFilter]
  7955. public ActionResult GetWoList()
  7956. {
  7957. workorder.WorkOrderController wo = new workorder.WorkOrderController();
  7958. var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='TimeLimitDays' ").FirstOrDefault();
  7959. int days = config != null ? Convert.ToInt32(config.F_ParamValue) : 60; //默认60天
  7960. DataTable dt = new DataTable();
  7961. int recordCount = 0;
  7962. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  7963. //客户姓名,电话,工单号
  7964. string keyword = HttpUtility.UrlDecode(RequestString.GetQueryString("keyword"));
  7965. //工单状态
  7966. int states = RequestString.GetInt("states", -1);
  7967. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  7968. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  7969. string strpageindex = RequestString.GetQueryString("page");
  7970. int pageindex = 1;
  7971. string strpagesize = RequestString.GetQueryString("pagesize");
  7972. int pagesize = 10;
  7973. //#region sql 语句相关处理
  7974. string sql = " ";
  7975. //获取坐席表信息
  7976. var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  7977. //获取客户档案(业主)表信息
  7978. var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  7979. if (!string.IsNullOrEmpty(sql))
  7980. {
  7981. //sql += " and IsDel=0 ";
  7982. ////客户姓名,电话,房间号,工单号,接待描述
  7983. //if (!string.IsNullOrEmpty(keyword))
  7984. //{
  7985. // sql += " and (CustomerTel like '%" + keyword + "%' or Customer like '%" + keyword + "%' or WorkOrderID like '%" + keyword + "%' or Detail like '%" + keyword + "%' or County like '%" + keyword + "%' ) ";
  7986. //}
  7987. //if (states >= 0)
  7988. //{
  7989. // #region 权限限制
  7990. // if (ua != null)
  7991. // {
  7992. // string uwhere = " ";
  7993. // switch (states)
  7994. // {
  7995. // case 0://待指派的
  7996. // //sql += " and State ='0' and CreateUser= '" + ua.F_UserCode + "' ";
  7997. // //3区域客服可以看到区域待指派工单
  7998. // if (ua.F_RoleId != 17)
  7999. // {
  8000. // uwhere += " and CreateUser='" + ua.F_UserCode + "' ";
  8001. // }
  8002. // sql += " and State =0 " + uwhere;
  8003. // break;
  8004. // case 1://待接单的
  8005. // sql += " and State =" + (int)EnumWorkOrderState.assign + " and T_Wo_WorkOrder.ID in ( " + wo.GetDJDWorkOrderID(ua.F_UserCode) + ") ";
  8006. // break;
  8007. // case 2://待完成的(待处理)
  8008. // 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) + ") ";
  8009. // break;
  8010. // case 3://已完成的
  8011. // sql += " and State =" + (int)EnumWorkOrderState.finish + " and LastDealUser = '" + ua.F_UserCode + "' ";
  8012. // break;
  8013. // case 4://我参与的
  8014. // sql += " and (CreateUser= '" + ua.F_UserCode + "' or T_Wo_WorkOrder.ID in ( " + wo.GetCYWorkOrderID(ua.F_UserCode) + ")) ";
  8015. // break;
  8016. // case 5://超期工单 - 设置两个月的处理时效,两个月内未解决的工单都直接汇总到这里
  8017. // sql += $" and DATEADD(DAY,{days},CreateTime) < GETDATE() AND State < " + (int)EnumWorkOrderState.finish + " ";
  8018. // break;
  8019. // }
  8020. // }
  8021. // else if (modelCustomer != null)
  8022. // {
  8023. // sql += " and ( CustomerID=" + modelCustomer.F_CustomerId + " or County like '%"+modelCustomer.F_CompanyName+"%' )";
  8024. // }
  8025. // else
  8026. // {
  8027. // sql = "";
  8028. // }
  8029. // #endregion
  8030. //}
  8031. //if (strstarttime.Trim() != "" && strstarttime != "undefined")
  8032. //{
  8033. // sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
  8034. //}
  8035. //if (strendtime.Trim() != "" && strendtime != "undefined")
  8036. //{
  8037. // sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0 ";
  8038. //}
  8039. //#endregion
  8040. //if (strpageindex.Trim() != "")
  8041. //{
  8042. // pageindex = Convert.ToInt32(strpageindex);
  8043. //}
  8044. //if (strpagesize.Trim() != "")
  8045. //{
  8046. // pagesize = Convert.ToInt32(strpagesize);
  8047. //}
  8048. //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";
  8049. //dt = BLL.PagerBLL.GetListPager(
  8050. // "T_Wo_WorkOrder (NOLOCK)",
  8051. // "WorkOrderID",
  8052. // cols,
  8053. // sql,
  8054. // "ORDER BY CreateTime DESC,State asc",
  8055. // pagesize,
  8056. // pageindex,
  8057. // true,
  8058. // out recordCount);
  8059. }
  8060. var obj = new
  8061. {
  8062. state = "success",
  8063. message = "成功",
  8064. rows = dt,
  8065. total = recordCount
  8066. };
  8067. return Content(obj.ToJson());
  8068. }
  8069. /// <summary>
  8070. /// 工单详情
  8071. /// </summary>
  8072. [WechatActionFilter]
  8073. public ActionResult GetWoInfo()
  8074. {
  8075. string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
  8076. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  8077. if (string.IsNullOrEmpty(strworkorderid))
  8078. return Error("参数错误");
  8079. if (string.IsNullOrEmpty(stropenid))
  8080. return Error("参数错误!");
  8081. //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 "
  8082. // + " from T_Wo_WorkOrder where T_Wo_WorkOrder.ID ='" + strworkorderid + "' ";
  8083. //var dt = DbHelperSQL.Query(sql).Tables[0];
  8084. //if (dt.Rows.Count > 0)
  8085. //{
  8086. // var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
  8087. // var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  8088. // if (configfj != null)
  8089. // {
  8090. // dt = BindFileData(dt, configfj.F_ParamValue);
  8091. // }
  8092. // string gcsql = "select *,dbo.GetUserName(F_NextUser) as F_NextUserName, dbo.GetDeptName(F_NextDept) as F_NextDeptName,dbo.GetUserName(F_CreateUser) as F_CreateUserName "
  8093. // + "from T_Wo_WorkOrderItem_New where F_WoID ='" + strworkorderid + "'";
  8094. // var gcdt = DbHelperSQL.Query(gcsql).Tables[0];
  8095. // dt.Columns.Add("FilePath", typeof(string));
  8096. // if (configfj != null || config != null)
  8097. // {
  8098. // foreach (DataRow bldr in dt.Rows)
  8099. // {
  8100. // if (bldr["CallID"] != null && config != null)
  8101. // {
  8102. // bldr["FilePath"] = GetCallPath(bldr["CallID"].ToString(), config.F_ParamValue);
  8103. // }
  8104. // }
  8105. // }
  8106. // var obj = new
  8107. // {
  8108. // data = dt,
  8109. // item = gcdt
  8110. // };
  8111. // return Success("查询成功", obj);
  8112. //}
  8113. return Error("查询失败");
  8114. }
  8115. #region 在用工单操作
  8116. ///// <summary>
  8117. ///// 处理工单
  8118. ///// </summary>
  8119. ///// <returns></returns>
  8120. //[WechatActionFilter]
  8121. //public ActionResult DealWorkOrder(long orderid, string cont, int isover = 0)
  8122. //{
  8123. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  8124. // if (!string.IsNullOrEmpty(stropenid))
  8125. // {
  8126. // Model.T_Sys_UserAccount ua = userAccountBLL.GetModelByOpenid(stropenid);
  8127. // if (ua != null)
  8128. // {
  8129. // Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  8130. // if (model != null)
  8131. // {
  8132. // bool res = new workorder.WorkOrderController().DealWO(ua, model, cont, isover);
  8133. // if (res)
  8134. // return Success("处理成功");
  8135. // else
  8136. // return Error("操作失败");
  8137. // }
  8138. // else
  8139. // return Error("工单不存在");
  8140. // }
  8141. // else
  8142. // return Error("无操作权限");
  8143. // }
  8144. // else
  8145. // return Error("参数错误");
  8146. //}
  8147. ///// <summary>
  8148. ///// 接单 - 确认工单
  8149. ///// </summary>
  8150. ///// <returns></returns>
  8151. //[WechatActionFilter]
  8152. //public ActionResult SureWorkOrder(long orderid)
  8153. //{
  8154. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  8155. // if (!string.IsNullOrEmpty(stropenid))
  8156. // {
  8157. // var ua = userAccountBLL.GetModelByOpenid(stropenid);
  8158. // if (ua != null)
  8159. // {
  8160. // Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  8161. // if (model != null)
  8162. // {
  8163. // bool res = new workorder.WorkOrderController().SureWO(ua, model);
  8164. // if (res)
  8165. // return Success("接单成功");
  8166. // else
  8167. // return Error("操作失败");
  8168. // }
  8169. // else
  8170. // return Error("工单不存在");
  8171. // }
  8172. // else
  8173. // return Error("无操作权限");
  8174. // }
  8175. // else
  8176. // return Error("参数错误");
  8177. //}
  8178. ///// <summary>
  8179. ///// 指派/转派工单
  8180. ///// </summary>
  8181. ///// <returns></returns>
  8182. //[WechatActionFilter]
  8183. //public ActionResult AssignWorkOrder(long orderid, string cont, int clbm = 0, int clid = 0)
  8184. //{
  8185. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  8186. // if (!string.IsNullOrEmpty(stropenid))
  8187. // {
  8188. // var ua = userAccountBLL.GetModelByOpenid(stropenid);
  8189. // if (ua != null)
  8190. // {
  8191. // if (clbm != 0 && clid == 0)
  8192. // return Error("请选择接收人");
  8193. // Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  8194. // if (model != null)
  8195. // {
  8196. // var res = new workorder.WorkOrderController().AssignWO(ua, model, cont, clbm, clid);
  8197. // if (res)
  8198. // return Success("转派成功");
  8199. // else
  8200. // return Error("转派失败!");
  8201. // }
  8202. // else
  8203. // return Error("工单不存在!");
  8204. // }
  8205. // }
  8206. // return Error("无操作权限!");
  8207. //}
  8208. ///// <summary>
  8209. ///// 退回工单
  8210. ///// </summary>
  8211. ///// <param name="input"></param>
  8212. ///// <returns></returns>
  8213. //[WechatActionFilter]
  8214. //public ActionResult BackWorkOrder(long orderid, string cont,int type=0)
  8215. //{//办理人员和监管可以退回工单
  8216. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  8217. // if (!string.IsNullOrEmpty(stropenid))
  8218. // {
  8219. // var ua = userAccountBLL.GetModelByOpenid(stropenid);
  8220. // if (ua != null)
  8221. // {
  8222. // Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  8223. // //验证信息
  8224. // if (model != null)
  8225. // {
  8226. // var res = new workorder.WorkOrderController().BackWO(ua, model, cont, type);
  8227. // if (res)
  8228. // return Success("处理成功");
  8229. // else
  8230. // return Error("处理失败!");
  8231. // }
  8232. // return Error("工单不存在");
  8233. // }
  8234. // }
  8235. // return Error("无操作权限");
  8236. //}
  8237. ///// <summary>
  8238. ///// 催办工单
  8239. ///// </summary>
  8240. ///// <returns></returns>
  8241. //[WechatActionFilter]
  8242. //public ActionResult AddWorkOrderRemind(long orderid, string cont)
  8243. //{
  8244. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  8245. // if (!string.IsNullOrEmpty(stropenid))
  8246. // {
  8247. // var ua = userAccountBLL.GetModelByOpenid(stropenid);
  8248. // if (ua != null)
  8249. // {
  8250. // Model.T_Wo_WorkOrder model = woBLL.GetModel(orderid);
  8251. // if (model != null)
  8252. // {
  8253. // var res = new workorder.WorkOrderController().RemindWO(ua, model, cont);
  8254. // if (res)
  8255. // Success("催办成功!");
  8256. // else
  8257. // Success("操作失败!");
  8258. // }
  8259. // return Error("工单不存在!");
  8260. // }
  8261. // }
  8262. // return Error("无操作权限!");
  8263. //}
  8264. #endregion
  8265. #endregion
  8266. #region 公告通知
  8267. /// <summary>
  8268. /// 获取公告列表
  8269. /// </summary>
  8270. /// <returns></returns>
  8271. //[WechatActionFilter]
  8272. public ActionResult GetNoticeList()
  8273. {
  8274. DataTable dt = new DataTable(); int recordCount = 0;
  8275. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  8276. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  8277. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  8278. string strpageindex = RequestString.GetQueryString("page");
  8279. int pageindex = 1;
  8280. string strpagesize = RequestString.GetQueryString("pagesize");
  8281. int pagesize = 10;
  8282. #region sql 语句相关处理
  8283. string sql = " and F_isDel=0 ";
  8284. //获取坐席表信息
  8285. var ua = userAccountBLL.GetModelByOpenid(stropenid);
  8286. //获取客户档案(业主)表信息
  8287. var modelCustomer = customerBaseBLL.GetModelByOpenid(stropenid);
  8288. if (ua != null)
  8289. {
  8290. sql += " and (ISNULL(F_UserId,'') = '' or ISNULL(F_UserId,'') like '%," + ua.F_UserId + ",%')";
  8291. }
  8292. else if (modelCustomer != null) {
  8293. sql += " and F_isCus=1";
  8294. }
  8295. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  8296. {
  8297. sql += " and datediff(day,F_CreateOn,'" + strstarttime + "')<=0 ";
  8298. }
  8299. if (strendtime.Trim() != "" && strendtime != "undefined")
  8300. {
  8301. sql += " and datediff(day,F_CreateOn,'" + strendtime + "')>=0 ";
  8302. }
  8303. #endregion
  8304. if (strpageindex.Trim() != "")
  8305. {
  8306. pageindex = Convert.ToInt32(strpageindex);
  8307. }
  8308. if (strpagesize.Trim() != "")
  8309. {
  8310. pagesize = Convert.ToInt32(strpagesize);
  8311. }
  8312. dt = BLL.PagerBLL.GetListPager(
  8313. "T_Msg_NoticeInfo",
  8314. "F_NoticeId",
  8315. "*",
  8316. sql,
  8317. "ORDER BY F_NoticeId desc",
  8318. pagesize,
  8319. pageindex,
  8320. true,
  8321. out recordCount);
  8322. List<Model.T_Msg_NoticeInfo> msgList = new BLL.T_Msg_NoticeInfo().DataTableToList(dt);
  8323. List<Model.T_Sys_UserAccount> userList = new BLL.T_Sys_UserAccount().GetModelList("");
  8324. var obj = new
  8325. {
  8326. rows = msgList.Select(m =>
  8327. {
  8328. Model.T_Sys_UserAccount usermodel = userList.Where(u => u.F_UserId == m.F_CreateBy.Value).FirstOrDefault();
  8329. var uname = "";
  8330. if (usermodel != null)
  8331. uname = usermodel.F_UserName;
  8332. return new
  8333. {
  8334. F_NoticeId = m.F_NoticeId,
  8335. F_Title = m.F_Title,
  8336. F_Content = m.F_Content,
  8337. F_isCus = m.F_isCus,
  8338. F_CreateOn = m.F_CreateOn,
  8339. F_CreateBy = m.F_CreateBy,
  8340. F_CreateByName = uname
  8341. };
  8342. }),
  8343. total = recordCount
  8344. };
  8345. return Content(obj.ToJson());
  8346. }
  8347. /// <summary>
  8348. /// 获取公告详情
  8349. /// </summary>
  8350. /// <returns></returns>
  8351. //[WechatActionFilter]
  8352. public ActionResult GetNoticeInfo()
  8353. {
  8354. string strnoticeid = HttpUtility.UrlDecode(RequestString.GetQueryString("noticeid"));
  8355. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  8356. if (string.IsNullOrEmpty(strnoticeid))
  8357. return Error("参数错误");
  8358. if (string.IsNullOrEmpty(stropenid))
  8359. return Error("参数错误!");
  8360. var dModel = new BLL.T_Msg_NoticeInfo().GetModel(int.Parse(strnoticeid.Trim()));
  8361. Model.T_Sys_UserAccount userModel = new Model.T_Sys_UserAccount();
  8362. if (dModel != null)
  8363. {
  8364. if (dModel.F_CreateBy != null)
  8365. userModel = userAccountBLL.GetModel(dModel.F_CreateBy.Value);
  8366. var uname = "";
  8367. if (userModel != null)
  8368. uname = userModel.F_UserName;
  8369. #region 标记为已读
  8370. var nowUser = userAccountBLL.GetModelByOpenid(stropenid);
  8371. var nowCus = customerBaseBLL.GetModelByOpenid(stropenid);
  8372. var usercode = "";
  8373. if (nowUser != null)
  8374. {
  8375. usercode = nowUser.F_UserCode;
  8376. var msglist = new BLL.T_Msg_List().GetModelList(" State=0 and ToUser='" + usercode + "' and Type=5 and ToID=" + dModel.F_NoticeId);
  8377. foreach (var item in msglist)
  8378. {
  8379. item.State = 1;
  8380. item.ReadDate = DateTime.Now;
  8381. new BLL.T_Msg_List().Update(item);
  8382. }
  8383. }
  8384. else if (nowCus != null)
  8385. {
  8386. usercode = nowCus.F_CustomerCode;
  8387. Model.T_Msg_List msg = new Model.T_Msg_List();
  8388. msg.Type = (int)Model.MSGType.cusnotice;
  8389. msg.ToUser = usercode;
  8390. msg.ToID = dModel.F_NoticeId;
  8391. msg.Detail = "客户" + usercode + "查看了公告《" + dModel.F_Title + "》";
  8392. msg.State = 1;
  8393. msg.IsDel = 0;
  8394. msg.CreateDate = DateTime.Now;
  8395. msg.ReadDate = DateTime.Now;
  8396. new BLL.T_Msg_List().Add(msg);
  8397. }
  8398. #endregion
  8399. var obj = new
  8400. {
  8401. F_NoticeId = dModel.F_NoticeId,
  8402. F_Title = dModel.F_Title,
  8403. F_Content = dModel.F_Content,
  8404. F_isCus = dModel.F_isCus,
  8405. F_CreateOn = dModel.F_CreateOn,
  8406. F_CreateBy = dModel.F_CreateBy,
  8407. F_CreateByName = uname,
  8408. F_UserId = dModel.F_UserId,
  8409. F_RoleId = dModel.F_RoleId,
  8410. };
  8411. return Success("获取公告详情成功", dModel);
  8412. }
  8413. else
  8414. return Error("获取公告详情失败");
  8415. }
  8416. #endregion
  8417. #region 微信工单
  8418. ///// <summary>
  8419. ///// 获取工单列表
  8420. ///// </summary>
  8421. ///// <returns></returns>
  8422. //[WechatActionFilter]
  8423. //public ActionResult GetList()
  8424. //{
  8425. // workorder.WorkOrderController wo = new workorder.WorkOrderController();
  8426. // var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='TimeLimitDays' ").FirstOrDefault();
  8427. // int days = config != null ? Convert.ToInt32(config.F_ParamValue) : 60; //默认60天
  8428. // DataTable dt = new DataTable();
  8429. // int recordCount = 0;
  8430. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  8431. // //客户姓名,电话,房间号,工单号
  8432. // string keyword = HttpUtility.UrlDecode(RequestString.GetQueryString("keyword"));
  8433. // //工单状态(ltype:)
  8434. // string strltype = HttpUtility.UrlDecode(RequestString.GetQueryString("ltype"));
  8435. // //工单状态
  8436. // int states = RequestString.GetInt("states", -1);
  8437. // //工单来源
  8438. // int strtype = RequestString.GetInt("type", 0);
  8439. // //工单类型
  8440. // int strtypeclass = RequestString.GetInt("typeclass", 0);
  8441. // //工单起止时间
  8442. // string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  8443. // string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  8444. // //来电单位
  8445. // string lddep = HttpUtility.UrlDecode(RequestString.GetQueryString("lddep"));
  8446. // //20180329 来电弹屏工单记录根据反馈单位获取列表 可以看到同一坐席组的所有人的工单记录
  8447. // string fkdep = HttpUtility.UrlDecode(RequestString.GetQueryString("fkdep"));
  8448. // int isldtp = RequestString.GetQueryInt("isldtp", 0);
  8449. // //微信列表(0未审核微信列表,1已审核微信列表)
  8450. // int isaudit = RequestString.GetInt("isaudit", -1);
  8451. // string strpageindex = RequestString.GetQueryString("page");
  8452. // int pageindex = 1;
  8453. // string strpagesize = RequestString.GetQueryString("pagesize");
  8454. // int pagesize = 10;
  8455. // #region sql 语句相关处理
  8456. // string sql = " ";
  8457. // //获取坐席表信息
  8458. // var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  8459. // //获取客户档案(业主)表信息
  8460. // var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  8461. // #region 权限限制
  8462. // string mobile = "", roomno = "";
  8463. // int customerid = 0, areaid = 0, proid = 0, buildingid = 0;
  8464. // if (ua != null)
  8465. // {
  8466. // int deptid = ua.F_DeptId; //部门id
  8467. // string deptCode = ua.F_DeptCode; //部门code
  8468. // int userRegionId = ua.RegionId; //项目id
  8469. // //部门信息
  8470. // var modelDep = new BLL.T_Sys_Department().GetModel(deptid);
  8471. // int depType = 0, depRegion = 0;
  8472. // if (modelDep != null)
  8473. // {
  8474. // depType = modelDep.F_Type ?? 0; //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  8475. // depRegion = modelDep.F_Header ?? 0; //部门权限范围:9全部,1区域,2项目,3期
  8476. // }
  8477. // if (ua.F_RoleId != 17)
  8478. // {
  8479. // if (depType == 2)
  8480. // {
  8481. // if (depRegion == 1)
  8482. // {
  8483. // // 查看该区域工单
  8484. // //sql += $" and IsUserSend = (SELECT TOP 1 F_ParentId FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = {userRegionId}) ";
  8485. // sql += $" and IsUserSend = {userRegionId} ";
  8486. // }
  8487. // else if (depRegion == 2)
  8488. // {
  8489. // // 查看该项目工单
  8490. // sql += $" and IsAdminSend = {userRegionId} ";
  8491. // }
  8492. // }
  8493. // else if (depType == 3)
  8494. // {
  8495. // if (depRegion == 1)
  8496. // {
  8497. // // 查看该区域工单
  8498. // //sql += $" and IsUserSend = (SELECT TOP 1 F_ParentId FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = {userRegionId}) ";
  8499. // sql += $" and IsUserSend = {userRegionId} ";
  8500. // }
  8501. // }
  8502. // else if (depType == 4)
  8503. // {
  8504. // if (depRegion == 2)
  8505. // {
  8506. // // 查看该项目工单
  8507. // sql += $" and IsAdminSend = {userRegionId} ";
  8508. // }
  8509. // else if (depRegion == 9)
  8510. // {
  8511. // // 查看该部门工单(包括一级,二级)
  8512. // string deptCodeNew = String.Empty;
  8513. // int deptCodeIndex = 0; //变量声明
  8514. // string deptCodeN = deptCode.TrimEnd('|'); //去掉最后一个|
  8515. // deptCodeIndex = deptCodeN.LastIndexOf("|"); //获得|的索引
  8516. // deptCodeNew = deptCodeN.Substring(0, deptCodeIndex + 1); //获得目标字符串(//去掉最后一个|后面的字符串)
  8517. // //============== 部门权限条件 - 部门 ================
  8518. // string arrUser = " select F_UserCode from T_Sys_UserAccount where F_DeptCode LIKE '" + deptCodeNew + "%' ";
  8519. // sql += $" and WorkOrderID in (SELECT DISTINCT WorkOrderID FROM dbo.T_Wo_WorkOrderItem WHERE ToUser IN ({arrUser})) ";
  8520. // }
  8521. // }
  8522. // }
  8523. // string uwhere = " ";
  8524. // switch (strltype)
  8525. // {
  8526. // case "0"://待指派的
  8527. // //sql += " and State ='0' and CreateUser= '" + ua.F_UserCode + "' ";
  8528. // if (ua.F_RoleId != 17 && depType != 1 && depType != 3)
  8529. // {
  8530. // uwhere += " and CreateUser='" + ua.F_UserCode + "' ";
  8531. // }
  8532. // sql += " and State ='0' " + uwhere;
  8533. // break;
  8534. // case "1"://待接单的
  8535. // sql += " and State ='1' and WorkOrderID in ( '" + wo.GetDJDWorkOrderID(ua.F_UserCode) + "') ";
  8536. // break;
  8537. // case "2"://待完成的
  8538. // sql += " and State ='1' and WorkOrderID in ( '" + wo.GetDWCWorkOrderID(ua.F_UserCode) + "') ";
  8539. // break;
  8540. // case "3"://已完成的
  8541. // sql += " and State ='2' and LastDealUser = '" + ua.F_UserCode + "' ";
  8542. // break;
  8543. // case "4"://我参与的
  8544. // sql += " and (CreateUser= '" + ua.F_UserCode + "' or WorkOrderID in ( '" + wo.GetCYWorkOrderID(ua.F_UserCode) + "')) ";
  8545. // break;
  8546. // case "5"://超期工单 - 设置两个月的处理时效,两个月内未解决的工单都直接汇总到这里
  8547. // sql += $" and DATEADD(DAY,{days},CreateTime) < GETDATE() AND State < 2 ";
  8548. // break;
  8549. // }
  8550. // }
  8551. // else if (modelCustomer != null)
  8552. // {
  8553. // #region 根据openid获取所有工单号
  8554. // //var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  8555. // //if (wxuser != null)
  8556. // //{
  8557. // // sql += " and id in (select distinct F_WorkOrderID from T_WO_UserWorkOrder where F_UserId='" + wxuser.F_Id + "') ";
  8558. // //}
  8559. // #endregion
  8560. // // ============== 项目权限 - 项目 ============== 不通过项目查询,因为客户可能有多个项目的房产
  8561. // // ============== 电话,区域,项目,楼号,房间号权限条件 - 电话 ================
  8562. // //通过相关电话,区域,项目,楼号,房间号(CustomerTel,IsUserSend,IsAdminSend,IsTimeOut,Address)查询该用户查看的工单
  8563. // //mobile = modelCustomer.F_LegalTel;
  8564. // customerid = modelCustomer.F_CustomerId;
  8565. // //int CustomerClassID = modelCustomer.F_CustomerClassID ?? 0;
  8566. // ////F_Layer区域id F_CategoryId所购项目id F_CustomerType楼号 F_BusinessLicenseID房间号
  8567. // //areaid = modelCustomer.F_Layer ?? 0;
  8568. // //proid = modelCustomer.F_CategoryId ?? 0;
  8569. // //buildingid = modelCustomer.F_CustomerType ?? 0;
  8570. // //roomno = modelCustomer.F_BusinessLicenseID;
  8571. // ////查询业主和相关的亲属租户名下工单
  8572. // //sql += $" and CustomerTel IN (SELECT DISTINCT F_Mobile FROM dbo.T_Cus_CustomerBase WHERE F_CustomerClassID = {customerid} OR F_CustomerId = {customerid}) ";
  8573. // //if (CustomerClassID == 0)
  8574. // //{
  8575. // // //业主查看房屋所有工单
  8576. // // sql += $" and CustomerID IN (SELECT DISTINCT F_CustomerId FROM dbo.T_Cus_CustomerBase WHERE F_CustomerClassID = {customerid} OR F_CustomerId = {customerid}) ";
  8577. // //}
  8578. // //else
  8579. // //{
  8580. // // //租户只可查看自己工单
  8581. // // sql += $" and CustomerID = {customerid} ";
  8582. // //}
  8583. // ////查询相关房间号下工单
  8584. // //if (areaid > 0 && proid > 0 && buildingid > 0 && !string.IsNullOrEmpty(roomno))
  8585. // //{
  8586. // // sql += $" and F_Layer = {areaid} and F_CategoryId = {proid} and F_CustomerType = {buildingid} and F_BusinessLicenseID = '{roomno}' ";
  8587. // //}
  8588. // }
  8589. // else
  8590. // {
  8591. // sql = "";
  8592. // }
  8593. // #endregion
  8594. // if (!string.IsNullOrEmpty(sql))
  8595. // {
  8596. // sql += " and IsDel=0 ";
  8597. // //客户姓名,电话,房间号,工单号,接待描述
  8598. // if (!string.IsNullOrEmpty(keyword))
  8599. // {
  8600. // sql += " and (CustomerTel like '%" + keyword + "%' or Customer like '%" + keyword + "%' or Address like '%" + keyword + "%' or WorkOrderID like '%" + keyword + "%' or Detail like '%" + keyword + "%' ) ";
  8601. // }
  8602. // if (isaudit >= 0)
  8603. // {
  8604. // sql += " and IsAudit = " + isaudit + " "; // ANd Type = (SELECT F_DictionaryValueId FROM dbo.T_Sys_DictionaryValue (NOLOCK) WHERE F_DictionaryFlag = 'GDLY' AND F_Name = '微信')
  8605. // }
  8606. // if (states >= 0)
  8607. // sql += " and State = " + states + " ";
  8608. // if (strtype > 0)
  8609. // {
  8610. // sql += " and Type = " + strtype + " ";
  8611. // }
  8612. // if (strtypeclass > 0)
  8613. // {
  8614. // sql += " and TypeClass = " + strtypeclass + " ";
  8615. // }
  8616. // if (lddep.Trim() != "" && lddep != "undefined")
  8617. // {
  8618. // sql += " and Address = '" + lddep.Trim() + "' ";
  8619. // }
  8620. // if (fkdep.Trim() != "" && fkdep != "undefined")
  8621. // {
  8622. // sql += " and Source = '" + fkdep.Trim() + "' ";
  8623. // }
  8624. // if (strstarttime.Trim() != "" && strstarttime != "undefined")
  8625. // {
  8626. // sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
  8627. // }
  8628. // if (strendtime.Trim() != "" && strendtime != "undefined")
  8629. // {
  8630. // sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0 ";
  8631. // }
  8632. // #endregion
  8633. // if (strpageindex.Trim() != "")
  8634. // {
  8635. // pageindex = Convert.ToInt32(strpageindex);
  8636. // }
  8637. // if (strpagesize.Trim() != "")
  8638. // {
  8639. // pagesize = Convert.ToInt32(strpagesize);
  8640. // }
  8641. // 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";
  8642. // dt = BLL.PagerBLL.GetListPager(
  8643. // "T_Wo_WorkOrder (NOLOCK)",
  8644. // "WorkOrderID",
  8645. // cols,
  8646. // sql,
  8647. // "ORDER BY CreateTime DESC",
  8648. // pagesize,
  8649. // pageindex,
  8650. // true,
  8651. // out recordCount);
  8652. // }
  8653. // var obj = new
  8654. // {
  8655. // state = "success",
  8656. // message = "成功",
  8657. // rows = dt,
  8658. // total = recordCount
  8659. // };
  8660. // return Content(obj.ToJson());
  8661. //}
  8662. ///// <summary>
  8663. ///// 获取可催办工单列表
  8664. ///// </summary>
  8665. ///// <returns></returns>
  8666. //[WechatActionFilter]
  8667. //public ActionResult GetNotDoneWorkList()
  8668. //{
  8669. // workorder.WorkOrderController wo = new workorder.WorkOrderController();
  8670. // DataTable dt = new DataTable();
  8671. // int recordCount = 0;
  8672. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  8673. // //客户姓名,电话,房间号,工单号
  8674. // string keyword = HttpUtility.UrlDecode(RequestString.GetQueryString("keyword"));
  8675. // //工单状态
  8676. // string strltype = HttpUtility.UrlDecode(RequestString.GetQueryString("ltype"));
  8677. // //工单状态
  8678. // int states = RequestString.GetInt("states", -1);
  8679. // //工单来源
  8680. // int strtype = RequestString.GetInt("type", 0);
  8681. // //工单类型
  8682. // int strtypeclass = RequestString.GetInt("typeclass", 0);
  8683. // //工单起止时间
  8684. // string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  8685. // string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  8686. // //区域id
  8687. // int areaid = RequestString.GetInt("areaid", 0);
  8688. // //项目id
  8689. // int regionid = RequestString.GetInt("regionid", 0);
  8690. // //期id
  8691. // int buldingid = RequestString.GetInt("buldingid", 0);
  8692. // string uid = HttpUtility.UrlDecode(RequestString.GetQueryString("userid") == "" ? "0" : HttpUtility.UrlDecode(RequestString.GetQueryString("userid")));
  8693. // string strpageindex = RequestString.GetQueryString("page");
  8694. // int pageindex = 1;
  8695. // string strpagesize = RequestString.GetQueryString("pagesize");
  8696. // int pagesize = 10;
  8697. // string sql = " and isdel=0 and State != 2 ";
  8698. // //获取坐席表信息
  8699. // var ua = userAccountBLL.GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  8700. // //获取客户档案(业主)表信息
  8701. // var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  8702. // if (ua != null)
  8703. // {
  8704. // #region 权限限制
  8705. // int deptid = ua.F_DeptId; //部门id
  8706. // string deptCode = ua.F_DeptCode; //部门code
  8707. // int userRegionId = ua.RegionId; //项目id
  8708. // //部门信息
  8709. // var modelDep = new BLL.T_Sys_Department().GetModel(deptid);
  8710. // int depType = 0, depRegion = 0;
  8711. // if (modelDep != null)
  8712. // {
  8713. // depType = modelDep.F_Type ?? 0; //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  8714. // depRegion = modelDep.F_Header ?? 0; //部门权限范围:9全部,1区域,2项目,3期
  8715. // }
  8716. // if (ua.F_RoleId != 17)
  8717. // {
  8718. // if (depType == 2)
  8719. // {
  8720. // if (depRegion == 1)
  8721. // {
  8722. // // 查看该区域工单
  8723. // //sql += $" and IsUserSend = (SELECT TOP 1 F_ParentId FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = {userRegionId}) ";
  8724. // sql += $" and IsUserSend = {userRegionId} ";
  8725. // }
  8726. // else if (depRegion == 2)
  8727. // {
  8728. // // 查看该项目工单
  8729. // sql += $" and IsAdminSend = {userRegionId} ";
  8730. // }
  8731. // }
  8732. // else if (depType == 3)
  8733. // {
  8734. // if (depRegion == 1)
  8735. // {
  8736. // // 查看该区域工单
  8737. // //sql += $" and IsUserSend = (SELECT TOP 1 F_ParentId FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = {userRegionId}) ";
  8738. // sql += $" and IsUserSend = {userRegionId} ";
  8739. // }
  8740. // }
  8741. // else if (depType == 4)
  8742. // {
  8743. // if (depRegion == 2)
  8744. // {
  8745. // // 查看该项目工单
  8746. // sql += $" and IsAdminSend = {userRegionId} ";
  8747. // }
  8748. // else if (depRegion == 9)
  8749. // {
  8750. // // 查看该部门工单(包括一级,二级)
  8751. // string deptCodeNew = String.Empty;
  8752. // int deptCodeIndex = 0; //变量声明
  8753. // string deptCodeN = deptCode.TrimEnd('|'); //去掉最后一个|
  8754. // deptCodeIndex = deptCodeN.LastIndexOf("|"); //获得|的索引
  8755. // deptCodeNew = deptCodeN.Substring(0, deptCodeIndex + 1); //获得目标字符串(//去掉最后一个|后面的字符串)
  8756. // //============== 部门权限条件 - 部门 ================
  8757. // string arrUser = " select F_UserCode from T_Sys_UserAccount where F_DeptCode LIKE '" + deptCodeNew + "%' ";
  8758. // sql += $" and WorkOrderID in (SELECT DISTINCT WorkOrderID FROM dbo.T_Wo_WorkOrderItem WHERE ToUser IN ({arrUser})) ";
  8759. // }
  8760. // }
  8761. // }
  8762. // #endregion
  8763. // //客户姓名,电话,房间号,工单号
  8764. // if (!string.IsNullOrEmpty(keyword))
  8765. // {
  8766. // sql += " and (CustomerTel like '%" + keyword + "%' or Customer like '%" + keyword + "%' or Address like '%" + keyword + "%' or WorkOrderID like '%" + keyword + "%' ) ";
  8767. // }
  8768. // if (states >= 0)
  8769. // sql += " and State = " + states + " ";
  8770. // if (areaid > 0)
  8771. // sql += " and IsUserSend = " + areaid + " ";
  8772. // if (regionid > 0)
  8773. // sql += " and IsAdminSend = " + regionid + " ";
  8774. // if (buldingid > 0)
  8775. // sql += " and IsTimeOut = " + buldingid + " ";
  8776. // //坐席工号
  8777. // if (uid.Trim() != "" && uid != "0")
  8778. // {
  8779. // sql += " and CreateUser = '" + uid + "' ";
  8780. // }
  8781. // if (strtype > 0)
  8782. // {
  8783. // sql += " and Type = " + strtype + " ";
  8784. // }
  8785. // if (strtypeclass > 0)
  8786. // {
  8787. // sql += " and TypeClass = " + strtype + " ";
  8788. // }
  8789. // if (strstarttime.Trim() != "" && strstarttime != "undefined")
  8790. // {
  8791. // sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
  8792. // }
  8793. // if (strendtime.Trim() != "" && strendtime != "undefined")
  8794. // {
  8795. // sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0 ";
  8796. // }
  8797. // if (strpageindex.Trim() != "")
  8798. // {
  8799. // pageindex = Convert.ToInt32(strpageindex);
  8800. // }
  8801. // if (strpagesize.Trim() != "")
  8802. // {
  8803. // pagesize = Convert.ToInt32(strpagesize);
  8804. // }
  8805. // dt = BLL.PagerBLL.GetListPager(
  8806. // "T_Wo_WorkOrder",
  8807. // "T_Wo_WorkOrder.ID",
  8808. // "*,(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",
  8809. // sql,
  8810. // "ORDER BY T_Wo_WorkOrder.ID desc",
  8811. // pagesize,
  8812. // pageindex,
  8813. // true,
  8814. // out recordCount);
  8815. // dt.Columns.Add("CBCount", typeof(int));
  8816. // foreach (DataRow dr in dt.Rows)
  8817. // {
  8818. // 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];
  8819. // dr["CBCount"] = list.Rows.Count;
  8820. // }
  8821. // }
  8822. // var obj = new
  8823. // {
  8824. // state = "success",
  8825. // message = "成功",
  8826. // rows = dt,
  8827. // total = recordCount
  8828. // };
  8829. // return Content(obj.ToJson());
  8830. //}
  8831. ///// <summary>
  8832. ///// 新增工单
  8833. ///// </summary>
  8834. ///// <returns></returns>
  8835. //[WechatActionFilter]
  8836. //public ActionResult AddWorkOrder()
  8837. //{
  8838. // DataTable dt = new DataTable();
  8839. // //工单来源
  8840. // int gdly = RequestString.GetFormInt("gdly", 0);
  8841. // //工单类型
  8842. // int gdlx = RequestString.GetFormInt("gdlx", 0);
  8843. // //客户id
  8844. // int customerid = RequestString.GetFormInt("customerid", 0);
  8845. // //客户姓名
  8846. // string callCustomer = RequestString.GetFormString("callCustomer");
  8847. // //联系电话
  8848. // string tel = RequestString.GetFormString("tel");
  8849. // //处理部门
  8850. // string fkdep = RequestString.GetFormString("fkdep");
  8851. // //客服类类型
  8852. // string kfdepid = RequestString.GetFormString("kfdepid");
  8853. // //受理人 - 审核人工号
  8854. // string auditusercode = RequestString.GetFormString("auditusercode");
  8855. // //工单状态
  8856. // int gdzt = RequestString.GetFormInt("gdzt", 0);
  8857. // //接待描述 - 反馈内容
  8858. // string fkcont = RequestString.GetFormString("fkcont");
  8859. // string callid = HttpUtility.UrlDecode(RequestString.GetFormString("callid"));
  8860. // string files = RequestString.GetFormString("files");
  8861. // //咨询类工单指派部门
  8862. // int clbm = RequestString.GetFormInt("clbm", 0);
  8863. // //备注
  8864. // string note = RequestString.GetFormString("note");
  8865. // #region 添加验证判断
  8866. // if (string.IsNullOrEmpty(callCustomer))
  8867. // return Error("姓名不能为空!");
  8868. // if (string.IsNullOrEmpty(tel))
  8869. // return Error("电话不能为空!");
  8870. // #endregion
  8871. // string workOrder = DateTime.Now.ToString("yyyyMMddHHmmssfff"); //工单编号
  8872. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  8873. // var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  8874. // var model = userAccountBLL.GetModelByOpenid(stropenid);
  8875. // var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault(); //customerBaseBLL.GetModelByOpenid(stropenid);
  8876. // string usercode = "";
  8877. // if (model != null)
  8878. // {
  8879. // usercode = model.F_UserCode;
  8880. // }
  8881. // else if (modelCustomer != null)
  8882. // {
  8883. // usercode = modelCustomer.F_CustomerCode;
  8884. // customerid = modelCustomer.F_CustomerId;
  8885. // }
  8886. // workorder.WorkOrderController wo = new workorder.WorkOrderController();
  8887. // string workorderid = wo.AddWXWorkOrder(workOrder, gdly, gdlx, customerid, callCustomer, tel, fkdep, kfdepid, auditusercode, fkcont, files, gdzt, note, usercode,-1);
  8888. // if (string.IsNullOrEmpty(workorderid))
  8889. // {
  8890. // return Error("新增失败");
  8891. // }
  8892. // else
  8893. // {
  8894. // #region 咨询类工单指派至部门
  8895. // //工单类型(107咨询,108投诉)
  8896. // if (gdlx == 107)
  8897. // {
  8898. // //需要审核后,再处理
  8899. // //bool b = wo.DealWXWorkOrder(workOrder, 0, 0, clbm, 0, "", fkcont, stropenid);
  8900. // }
  8901. // #endregion
  8902. // //暂时排除客户档案用户(F_UserId无法区分是住户添加 还是管理员添加) - 后期完善
  8903. // if (wxuser != null)
  8904. // {
  8905. // Model.T_WO_UserWorkOrder tbu = new Model.T_WO_UserWorkOrder();
  8906. // tbu.F_UserId = wxuser.F_Id;
  8907. // tbu.F_WorkOrderId = workorderid;
  8908. // new BLL.T_WO_UserWorkOrder().Add(tbu);
  8909. // }
  8910. // return Success("新增成功", workorderid);
  8911. // }
  8912. //}
  8913. ///// <summary>
  8914. ///// 修改工单
  8915. ///// </summary>
  8916. ///// <returns></returns>
  8917. //[WechatActionFilter]
  8918. //public ActionResult UpdateWorkOrder()
  8919. //{
  8920. // DataTable dt = new DataTable();
  8921. // //工单id
  8922. // string workorderid = RequestString.GetFormString("orderid");
  8923. // //工单来源
  8924. // int gdly = RequestString.GetFormInt("gdly", 0);
  8925. // //工单类型
  8926. // int gdlx = RequestString.GetFormInt("gdlx", 0);
  8927. // //客户id
  8928. // int customerid = RequestString.GetFormInt("customerid", 0);
  8929. // //客户姓名
  8930. // string callCustomer = RequestString.GetFormString("callCustomer");
  8931. // //联系电话
  8932. // string tel = RequestString.GetFormString("tel");
  8933. // //处理部门
  8934. // string fkdep = RequestString.GetFormString("fkdep");
  8935. // //客服类类型
  8936. // string kfdepid = RequestString.GetFormString("kfdepid");
  8937. // //受理人 - 审核人工号
  8938. // string auditusercode = RequestString.GetFormString("auditusercode");
  8939. // //接待描述 - 反馈内容
  8940. // string fkcont = RequestString.GetFormString("fkcont");
  8941. // string files = RequestString.GetFormString("files");
  8942. // //备注
  8943. // string note = RequestString.GetFormString("note");
  8944. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  8945. // //var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  8946. // if (!string.IsNullOrEmpty(stropenid))
  8947. // {
  8948. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  8949. // if (ua != null)
  8950. // {
  8951. // WorkOrderController wo = new WorkOrderController();
  8952. // if (!string.IsNullOrEmpty(workorderid))
  8953. // {
  8954. // var models = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + workorderid + "'");
  8955. // if (models.Count > 0)
  8956. // {
  8957. // var model = models.FirstOrDefault();
  8958. // string detail = model.Detail;
  8959. // model.Type = gdly; //工单来源
  8960. // model.TypeClass = gdlx; //投诉类型 -工单类型
  8961. // model.Customer = callCustomer; //客户姓名
  8962. // model.CustomerTel = tel; //联系电话
  8963. // //model.CustomerID = customerid; //用户档案Id
  8964. // model.Source = fkdep; //处理部门 反馈单位
  8965. // model.CreateUserID = kfdepid; //客服类类型
  8966. // model.AuditUser = auditusercode; //受理人 - 审核人工号
  8967. // //model.CreateUser = ua.F_UserCode; //接待人(工号)
  8968. // //model.State = 0; //工单状态
  8969. // //反馈内容
  8970. // var detailutf8 = System.Web.HttpUtility.UrlDecode(fkcont, System.Text.Encoding.UTF8);
  8971. // model.Detail = detailutf8;
  8972. // if (new BLL.T_Wo_WorkOrder().Update(model))
  8973. // {
  8974. // //添加工单修改操作日志
  8975. // wo.WriteWorkOrderLog(workorderid, detail, detailutf8, ua.F_UserCode, 0, "", 1, "修改工单(微信端)");
  8976. // return Success("修改成功!");
  8977. // }
  8978. // }
  8979. // }
  8980. // }
  8981. // }
  8982. // return Error("修改失败!");
  8983. //}
  8984. ///// <summary>
  8985. ///// 处理工单
  8986. ///// </summary>
  8987. ///// <returns></returns>
  8988. //[WechatActionFilter]
  8989. //public ActionResult DealWorkOrder()
  8990. //{
  8991. // DataTable dt = new DataTable();
  8992. // string orderid = RequestString.GetFormString("orderid");
  8993. // int isend = RequestString.GetInt("isend", 0); //0转派
  8994. // int ltype = RequestString.GetInt("ltype", 0); //处理方式 1结束 0转派
  8995. // int clbm = RequestString.GetInt("clbm", 0); //部门id
  8996. // int clid = RequestString.GetInt("clid", 0); //用户接收人id
  8997. // string cont = RequestString.GetFormString("cont"); //处理内容
  8998. // string detail = RequestString.GetFormString("detail");
  8999. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  9000. // workorder.WorkOrderController wo = new workorder.WorkOrderController();
  9001. // bool res = wo.DealWXWorkOrder(orderid, isend, ltype, clbm, clid, cont, detail, stropenid);
  9002. // if (res)
  9003. // {
  9004. // return Success("操作成功");
  9005. // }
  9006. // else
  9007. // {
  9008. // return Error("操作失败");
  9009. // }
  9010. //}
  9011. ///// <summary>
  9012. ///// 接单 - 确认工单
  9013. ///// </summary>
  9014. ///// <returns></returns>
  9015. //[WechatActionFilter]
  9016. //public ActionResult SureWorkOrder()
  9017. //{
  9018. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  9019. // string orderid = RequestString.GetFormString("orderid");
  9020. // if (!string.IsNullOrEmpty(stropenid))
  9021. // {
  9022. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  9023. // if (ua != null)
  9024. // {
  9025. // Model.T_Wo_WorkOrder model = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + orderid + "'").FirstOrDefault();
  9026. // if (model != null)
  9027. // {
  9028. // Model.T_Wo_WorkOrderItem item = new BLL.T_Wo_WorkOrderItem().GetModelList(" WorkOrderID='" + orderid + "' and isdel=0 and Type=1 ").OrderByDescending(p => p.CreateTime).FirstOrDefault();
  9029. // if (item != null && item.State == 0 && ("," + item.ToUser + ",").Contains("," + ua.F_UserCode + ","))
  9030. // {
  9031. // item.SureUser = ua.F_UserCode;
  9032. // item.State = 1;
  9033. // item.SureTime = DateTime.Now;
  9034. // if (new BLL.T_Wo_WorkOrderItem().Update(item))
  9035. // {
  9036. // return Success("接单成功!");
  9037. // }
  9038. // }
  9039. // return Error("操作失败,工单还没有派单!");
  9040. // }
  9041. // }
  9042. // return Error("操作失败");
  9043. // }
  9044. // return Error("参数错误");
  9045. //}
  9046. ///// <summary>
  9047. ///// 催办工单(管理员,业主)
  9048. ///// </summary>
  9049. ///// <returns></returns>
  9050. //[WechatActionFilter]
  9051. //public ActionResult RemindWorkOrder()
  9052. //{
  9053. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  9054. // if (!string.IsNullOrEmpty(stropenid))
  9055. // {
  9056. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  9057. // string usercode = string.Empty;
  9058. // string username = string.Empty;
  9059. // if (ua != null)
  9060. // {
  9061. // usercode = ua.F_UserCode;
  9062. // username = ua.F_UserName;
  9063. // }
  9064. // else
  9065. // {
  9066. // //获取客户档案(业主)表信息
  9067. // var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  9068. // if (modelCustomer != null)
  9069. // {
  9070. // usercode = modelCustomer.F_CustomerCode;
  9071. // username = modelCustomer.F_CompanyName;
  9072. // }
  9073. // }
  9074. // if (string.IsNullOrEmpty(usercode))
  9075. // return Error("参数错误!");
  9076. // string orderid = RequestString.GetFormString("orderid");
  9077. // string cont = RequestString.GetFormString("cont");
  9078. // string callid = RequestString.GetFormString("callid");
  9079. // Model.T_Wo_WorkOrder model = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + orderid + "'").FirstOrDefault();
  9080. // if (model != null)
  9081. // {
  9082. // 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();
  9083. // Model.T_Wo_WorkOrderItem item = new Model.T_Wo_WorkOrderItem();
  9084. // if (itemlast != null)
  9085. // {
  9086. // item.ToDept = itemlast.ToDept;
  9087. // item.ToUser = itemlast.ToUser;
  9088. // }
  9089. // else
  9090. // {
  9091. // var cu = new BLL.T_Sys_UserAccount().GetModel(model.CreateUser);
  9092. // if (cu != null)
  9093. // {
  9094. // item.ToDept = cu.F_DeptId;
  9095. // item.ToUser = cu.F_UserCode;
  9096. // }
  9097. // else {
  9098. // var modelCus = customerBaseBLL.GetModelList(" F_CustomerCode='" + model.CreateUser + "'").FirstOrDefault(); //customerBaseBLL.GetModel(model.CreateUser);
  9099. // if (modelCus != null)
  9100. // {
  9101. // item.ToDept = 0;
  9102. // item.ToUser = modelCus.F_LegalTel;
  9103. // }
  9104. // }
  9105. // }
  9106. // item.WorkOrderID = orderid;
  9107. // item.Type = 2;
  9108. // item.Detail = cont;
  9109. // item.CallID = callid;
  9110. // item.State = 0;
  9111. // item.IsDel = 0;
  9112. // item.IsLast = 0;
  9113. // item.IsStart = 0;
  9114. // item.IsTimeOut = 0;
  9115. // item.CreateUser = usercode; // ua.F_UserCode;
  9116. // item.CreateTime = DateTime.Now;
  9117. // long itemid = new BLL.T_Wo_WorkOrderItem().Add(item);
  9118. // if (itemid > 0 && !string.IsNullOrEmpty(item.ToUser))
  9119. // {
  9120. // foreach (string ur in item.ToUser.Split(','))
  9121. // {
  9122. // Model.T_Msg_List msg = new Model.T_Msg_List();
  9123. // msg.Type = 1;
  9124. // msg.ToUser = ur;
  9125. // msg.ToID = Int32.Parse(itemid.ToString());
  9126. // msg.Detail = username + "向你催办了工单,单号:" + model.WorkOrderID;
  9127. // msg.State = 0;
  9128. // msg.IsDel = 0;
  9129. // msg.CreateUser = usercode;
  9130. // msg.CreateDate = DateTime.Now;
  9131. // new BLL.T_Msg_List().Add(msg);
  9132. // }
  9133. // return Success("催办成功!");
  9134. // }
  9135. // }
  9136. // }
  9137. // return Error("参数错误");
  9138. //}
  9139. ///// <summary>
  9140. ///// 退回工单
  9141. ///// </summary>
  9142. ///// <param name="input"></param>
  9143. ///// <returns></returns>
  9144. //[WechatActionFilter]
  9145. //public ActionResult BackWorkOrder()
  9146. //{
  9147. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  9148. // if (!string.IsNullOrEmpty(stropenid))
  9149. // {
  9150. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  9151. // if (ua != null)
  9152. // {
  9153. // string orderid = RequestString.GetFormString("orderid");
  9154. // var model = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + orderid + "'").FirstOrDefault();
  9155. // //验证信息
  9156. // if (model == null)
  9157. // {
  9158. // return Error("工单不存在");
  9159. // }
  9160. // model.State = 0;
  9161. // if (new BLL.T_Wo_WorkOrder().Update(model))
  9162. // {
  9163. // 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();
  9164. // if (modelItem != null)
  9165. // {
  9166. // modelItem.State = 6;
  9167. // new BLL.T_Wo_WorkOrderItem().Update(modelItem);
  9168. // }
  9169. // return Success("操作成功");
  9170. // }
  9171. // return Error("操作失败");
  9172. // }
  9173. // }
  9174. // return Error("操作失败");
  9175. //}
  9176. ///// <summary>
  9177. ///// 评论工单(管理人员,业主)
  9178. ///// </summary>
  9179. ///// <returns></returns>
  9180. //[WechatActionFilter]
  9181. //public ActionResult CommentWorkOrder()
  9182. //{
  9183. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  9184. // if (!string.IsNullOrEmpty(stropenid))
  9185. // {
  9186. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  9187. // string usercode = string.Empty;
  9188. // string username = string.Empty;
  9189. // if (ua != null)
  9190. // {
  9191. // usercode = ua.F_UserCode;
  9192. // username = ua.F_UserName;
  9193. // }
  9194. // else
  9195. // {
  9196. // //获取客户档案(业主)表信息
  9197. // var modelCustomer = customerBaseBLL.GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  9198. // if (modelCustomer != null)
  9199. // {
  9200. // usercode = modelCustomer.F_CustomerCode;
  9201. // username = modelCustomer.F_CompanyName;
  9202. // }
  9203. // }
  9204. // if (string.IsNullOrEmpty(usercode))
  9205. // return Error("参数错误!");
  9206. // string orderid = RequestString.GetFormString("orderid");
  9207. // string cont = RequestString.GetFormString("cont");
  9208. // string file = RequestString.GetFormString("file");
  9209. // Model.T_Wo_WorkOrder model = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + orderid + "'").FirstOrDefault();
  9210. // if (model != null)
  9211. // {
  9212. // Model.T_Wo_WorkOrderItem item = new Model.T_Wo_WorkOrderItem();
  9213. // item.WorkOrderID = orderid;
  9214. // item.Type = 3; //评论
  9215. // item.Detail = cont;
  9216. // item.Files = file;
  9217. // item.State = 0;
  9218. // item.IsDel = 0;
  9219. // item.IsStart = 0;
  9220. // item.IsTimeOut = 0;
  9221. // item.IsLast = 0;
  9222. // item.CreateUser = usercode;
  9223. // item.CreateTime = DateTime.Now;
  9224. // if (new BLL.T_Wo_WorkOrderItem().Add(item) > 0)
  9225. // {
  9226. // return Success("评论成功!");
  9227. // }
  9228. // }
  9229. // }
  9230. // return Error("操作失败");
  9231. //}
  9232. ///// <summary>
  9233. ///// 刪除工单
  9234. ///// </summary>
  9235. ///// <returns></returns>
  9236. //[WechatActionFilter]
  9237. //public ActionResult DelWorkOrder(string[] ids)
  9238. //{
  9239. // string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  9240. // if (!string.IsNullOrEmpty(stropenid))
  9241. // {
  9242. // var ua = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  9243. // if (ua != null)
  9244. // {
  9245. // if (ids != null && ids.Length > 0)
  9246. // {
  9247. // string idd = " ";
  9248. // foreach (string str in ids)
  9249. // {
  9250. // idd += str + ",";
  9251. // }
  9252. // string sql = "update T_Wo_WorkOrder set IsDel=1,DelUser='" + ua.F_UserCode + "',DelTime=getdate() where ID in (" + idd.TrimEnd(',') + ")";
  9253. // if (!string.IsNullOrEmpty(idd.Trim()))
  9254. // {
  9255. // if (DbHelperSQL.ExecuteSql(sql) > 0)
  9256. // {
  9257. // return Success("删除成功");
  9258. // }
  9259. // }
  9260. // else
  9261. // {
  9262. // return Error("请选择记录");
  9263. // }
  9264. // }
  9265. // else
  9266. // {
  9267. // return Error("获取参数失败");
  9268. // }
  9269. // }
  9270. // }
  9271. // return Error("操作失败");
  9272. //}
  9273. ///// <summary>
  9274. ///// 获取工单详情
  9275. ///// </summary>
  9276. ///// <returns></returns>
  9277. //[WechatActionFilter]
  9278. //public ActionResult GetWorkOrder()
  9279. //{
  9280. // string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
  9281. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  9282. // if (string.IsNullOrEmpty(strworkorderid))
  9283. // return Error("参数错误");
  9284. // if (string.IsNullOrEmpty(stropenid))
  9285. // return Error("参数错误!");
  9286. // #region pc端工单也可以查看,所以注释(注释功能只能查看自己创建的工单)
  9287. // //var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  9288. // //if (wxuser != null)
  9289. // //{
  9290. // // var tbu = new BLL.T_WO_UserWorkOrder().GetList(" F_UserId='" + wxuser.F_Id + "' and F_WorkOrderId=" + strworkorderid + " ").Tables[0];
  9291. // // if (tbu.Rows.Count > 0)
  9292. // // {
  9293. // // }
  9294. // //}
  9295. // #endregion
  9296. // 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 "
  9297. // + " from T_Wo_WorkOrder where WorkOrderID ='" + strworkorderid + "' ";
  9298. // var dt = DbHelperSQL.Query(sql).Tables[0];
  9299. // if (dt.Rows.Count > 0)
  9300. // {
  9301. // var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
  9302. // var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  9303. // if (configfj != null)
  9304. // {
  9305. // dt = BindFileData(dt, configfj.F_ParamValue);
  9306. // }
  9307. // string gcsql = "select *,dbo.GetUserName(CreateUser) as UserName "
  9308. // + "from T_Wo_WorkOrderItem where IsDel=0 and WorkOrderID ='" + dt.Rows[0]["WorkOrderId"] + "'";
  9309. // var gcdt = DbHelperSQL.Query(gcsql).Tables[0];
  9310. // dt.Columns.Add("FilePath", typeof(string));
  9311. // if (configfj != null || config != null)
  9312. // {
  9313. // foreach (DataRow bldr in dt.Rows)
  9314. // {
  9315. // if (bldr["CallID"] != null && config != null)
  9316. // {
  9317. // bldr["FilePath"] = GetCallPath(bldr["CallID"].ToString(), config.F_ParamValue);
  9318. // }
  9319. // }
  9320. // }
  9321. // var obj = new
  9322. // {
  9323. // data = dt,
  9324. // item = gcdt
  9325. // };
  9326. // return Success("查询成功", obj);
  9327. // }
  9328. // return Error("查询失败");
  9329. //}
  9330. ///// <summary>
  9331. ///// 获取工单明细列表
  9332. ///// </summary>
  9333. ///// <returns></returns>
  9334. //[WechatActionFilter]
  9335. //public ActionResult GetItemList()
  9336. //{
  9337. // string sql = " and IsDel=0 ";
  9338. // DataTable dt = new DataTable();
  9339. // string strid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
  9340. // string strtype = HttpUtility.UrlDecode(RequestString.GetQueryString("type"));
  9341. // string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  9342. // string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  9343. // string strpageindex = RequestString.GetQueryString("page");
  9344. // int pageindex = 1;
  9345. // string strpagesize = RequestString.GetQueryString("pagesize");
  9346. // int pagesize = 10;
  9347. // if (strid.Trim() != "" && strid != "undefined")
  9348. // {
  9349. // sql += " and WorkOrderID = '" + strid.Trim() + "' ";
  9350. // }
  9351. // if (strtype.Trim() != "" && strtype != "undefined")
  9352. // {
  9353. // sql += " and Type = '" + strtype.Trim() + "' ";
  9354. // }
  9355. // if (strstarttime.Trim() != "" && strstarttime != "undefined")
  9356. // {
  9357. // sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
  9358. // }
  9359. // if (strendtime.Trim() != "" && strendtime != "undefined")
  9360. // {
  9361. // sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0 ";
  9362. // }
  9363. // if (strpageindex.Trim() != "")
  9364. // {
  9365. // pageindex = Convert.ToInt32(strpageindex);
  9366. // }
  9367. // if (strpagesize.Trim() != "")
  9368. // {
  9369. // pagesize = Convert.ToInt32(strpagesize);
  9370. // }
  9371. // int recordCount = 0;
  9372. // dt = BLL.PagerBLL.GetListPager(
  9373. // "T_Wo_WorkOrderItem",
  9374. // "T_Wo_WorkOrderItem.ID",
  9375. // "*,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",
  9376. // sql,
  9377. // "ORDER BY T_Wo_WorkOrderItem.ID desc",
  9378. // pagesize,
  9379. // pageindex,
  9380. // true,
  9381. // out recordCount);
  9382. // var obj = new
  9383. // {
  9384. // state = "success",
  9385. // message = "成功",
  9386. // rows = dt,
  9387. // total = recordCount
  9388. // };
  9389. // return Content(obj.ToJson());
  9390. //}
  9391. ///// <summary>
  9392. ///// 获取工作动态列表 - 工单明细动态列表 - 管理员功能
  9393. ///// </summary>
  9394. ///// <returns></returns>
  9395. //[WechatActionFilter]
  9396. //public ActionResult GetWorkOrderItemList()
  9397. //{
  9398. // DataTable dt = new DataTable();
  9399. // string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  9400. // //string stropenid = "oXF5e1mWpX5DajW5_yjNLPKb8ThE";
  9401. // //获取客户档案(业主)表信息
  9402. // var model = userAccountBLL.GetModelList(" F_WxOpenId='" + stropenid + "'").FirstOrDefault();
  9403. // string sql = " and IsDel=0 ";
  9404. // string daytype = HttpUtility.UrlDecode(RequestString.GetQueryString("daytype"));
  9405. // string strpageindex = RequestString.GetQueryString("page");
  9406. // int pageindex = 1;
  9407. // string strpagesize = RequestString.GetQueryString("pagesize");
  9408. // int pagesize = 10;
  9409. // #region 权限限制
  9410. // //if (model != null) {
  9411. // // var sqlUser = "";
  9412. // // //部门信息
  9413. // // var modelDep = new BLL.T_Sys_Department().GetModel(model.F_DeptId);
  9414. // // int depType = 0, depRegion = 0;
  9415. // // if (modelDep != null)
  9416. // // {
  9417. // // depType = modelDep.F_Type ?? 0; //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  9418. // // depRegion = modelDep.F_Header ?? 0; //部门权限范围:9全部,1区域,2项目,3期
  9419. // // }
  9420. // // //根据部门查询工单(可查看当前部门工单)
  9421. // // string deptCode = model.F_DeptCode; //部门code
  9422. // // int userRegionId = model.RegionId; //项目id
  9423. // // ////接待部(坐席)可以看到所有的工单
  9424. // // //if (model.F_RoleId != 17 && depType != 1)
  9425. // // //{
  9426. // // // //if (depType == 2 || depType == 3)
  9427. // // // //{
  9428. // // // // // ============== 项目权限 - 项目 ==============
  9429. // // // // sqlUser += $" and IsAdminSend = {userRegionId} ";
  9430. // // // //}
  9431. // // // //else if (depType == 4)
  9432. // // // //{
  9433. // // // // // 查看该部门工单(包括一级,二级)
  9434. // // // // string deptCodeNew = String.Empty;
  9435. // // // // int deptCodeIndex = 0; //变量声明
  9436. // // // // string deptCodeN = deptCode.TrimEnd('|'); //去掉最后一个|
  9437. // // // // deptCodeIndex = deptCodeN.LastIndexOf("|"); //获得|的索引
  9438. // // // // deptCodeNew = deptCodeN.Substring(0, deptCodeIndex + 1); //获得目标字符串(//去掉最后一个|后面的字符串)
  9439. // // // // // ============== 部门权限条件 - 部门 ================
  9440. // // // // string arrUser = " select F_UserCode from T_Sys_UserAccount where F_DeptCode LIKE '" + deptCodeNew + "%' ";
  9441. // // // // sql += $" and ToUser IN ({arrUser}) and WorkOrderID IN (SELECT WorkOrderID FROM dbo.T_Wo_WorkOrder WHERE 1=1 {sqlUser} ) ";
  9442. // // // //}
  9443. // // //}
  9444. // //}
  9445. // #endregion
  9446. // switch (daytype)
  9447. // {
  9448. // case "today":
  9449. // sql += " and DateDiff(dd,CreateTime,getdate())=0 ";
  9450. // break;
  9451. // case "yesterday":
  9452. // sql += " and DateDiff(dd,CreateTime,getdate())=1 ";
  9453. // break;
  9454. // case "month":
  9455. // sql += " and DateDiff(mm,CreateTime,getdate())=0 ";
  9456. // break;
  9457. // default:
  9458. // break;
  9459. // }
  9460. // if (strpageindex.Trim() != "")
  9461. // {
  9462. // pageindex = Convert.ToInt32(strpageindex);
  9463. // }
  9464. // if (strpagesize.Trim() != "")
  9465. // {
  9466. // pagesize = Convert.ToInt32(strpagesize);
  9467. // }
  9468. // int recordCount = 0;
  9469. // dt = BLL.PagerBLL.GetListPager(
  9470. // "T_Wo_WorkOrderItem",
  9471. // "T_Wo_WorkOrderItem.ID",
  9472. // "*,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",
  9473. // sql,
  9474. // "ORDER BY T_Wo_WorkOrderItem.ID desc",
  9475. // pagesize,
  9476. // pageindex,
  9477. // true,
  9478. // out recordCount);
  9479. // var obj = new
  9480. // {
  9481. // state = "success",
  9482. // message = "成功",
  9483. // rows = dt,
  9484. // total = recordCount
  9485. // };
  9486. // return Content(obj.ToJson());
  9487. //}
  9488. #endregion
  9489. #region 附件和语音文件
  9490. /// <summary>
  9491. /// 获取留言路径
  9492. /// </summary>
  9493. /// <param name="lid">留言id</param>
  9494. /// <param name="prefix">前缀</param>
  9495. /// <returns></returns>
  9496. public string GetLeavePath(string lid, string prefix)
  9497. {
  9498. string path = string.Empty;
  9499. var liuyan = new BLL.T_Call_LeaveRecord().GetModelList(" F_Id='" + lid + "' ").FirstOrDefault();
  9500. if (liuyan != null)
  9501. {
  9502. if (!string.IsNullOrEmpty(liuyan.F_RecFileUrl))
  9503. {
  9504. path = prefix + liuyan.F_RecFileUrl;
  9505. }
  9506. }
  9507. return path;
  9508. }
  9509. /// <summary>
  9510. /// 获取通话录音路径
  9511. /// </summary>
  9512. /// <param name="cid">通话id</param>
  9513. /// <param name="prefix">前缀</param>
  9514. /// <returns></returns>
  9515. public string GetCallPath(string cid, string prefix)
  9516. {
  9517. string path = string.Empty;
  9518. var luyin = new BLL.T_Call_CallRecords().GetModelList(" callid='" + cid + "' ").FirstOrDefault();
  9519. if (luyin != null)
  9520. {
  9521. if (!string.IsNullOrEmpty(luyin.FilePath))
  9522. {
  9523. var ym = prefix;
  9524. ym = ym.Substring(0, ym.Length - 1);
  9525. path = ym + luyin.FilePath.Substring(luyin.FilePath.IndexOf(':') + 1).Replace('\\', '/');
  9526. }
  9527. }
  9528. return path;
  9529. }
  9530. /// <summary>
  9531. /// 获取附件数据
  9532. /// </summary>
  9533. /// <param name="ids">附件id,多个用英文逗号,隔开</param>
  9534. /// <param name="prefix">前缀</param>
  9535. /// <returns></returns>
  9536. public DataTable GetFileData(string ids, string prefix)
  9537. {
  9538. DataTable dt = DbHelperSQL.Query("select * from T_Sys_Accessories where F_FileId in (" + ids + ")").Tables[0];
  9539. foreach (DataRow dr in dt.Rows)
  9540. {
  9541. dr["F_FileUrl"] = prefix + dr["F_FileUrl"].ToString();
  9542. }
  9543. return dt;
  9544. }
  9545. /// <summary>
  9546. /// 绑定附件信息
  9547. /// </summary>
  9548. /// <param name="dt"></param>
  9549. /// <param name="prefix"></param>
  9550. /// <returns></returns>
  9551. public DataTable BindFileData(DataTable dt, string prefix)
  9552. {
  9553. dt.Columns.Add("File", typeof(object));
  9554. foreach (DataRow dr in dt.Rows)
  9555. {
  9556. if (dr["Files"] != null && dr["Files"].ToString() != "")
  9557. {
  9558. dr["File"] = GetFileData(dr["Files"].ToString(), prefix);
  9559. }
  9560. }
  9561. return dt;
  9562. }
  9563. #endregion
  9564. #region 上传附件
  9565. /// <summary>
  9566. /// 上传附件
  9567. /// </summary>
  9568. /// <returns></returns>
  9569. public ActionResult UpLoadProcess(string id, string name, string type, string lastModifiedDate, int size, HttpPostedFileBase file)
  9570. {
  9571. try
  9572. {
  9573. string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  9574. string filePathName = string.Empty;
  9575. string path = "/Upload/Files/" + DateTime.Now.ToString("yyyy/MM/dd") + "/";
  9576. string localPath = Server.MapPath(Path.Combine(HttpRuntime.AppDomainAppPath, path));
  9577. if (Request.Files.Count == 0)
  9578. {
  9579. return Error("保存失败");
  9580. }
  9581. string ex = Path.GetExtension(file.FileName);
  9582. filePathName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + Guid.NewGuid().ToString("N") + ex;
  9583. if (!System.IO.Directory.Exists(localPath))
  9584. {
  9585. System.IO.Directory.CreateDirectory(localPath);
  9586. }
  9587. file.SaveAs(Path.Combine(localPath, filePathName));
  9588. #region 添加日志
  9589. Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
  9590. model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
  9591. model_T_Sys_Accessories.F_FileName = filePathName;//附件名称
  9592. model_T_Sys_Accessories.F_FileType = type;//附件类型
  9593. model_T_Sys_Accessories.F_FileUrl = path + filePathName;//附件地址
  9594. model_T_Sys_Accessories.F_Size = size;
  9595. model_T_Sys_Accessories.F_UserCode = stropenid;//上传人
  9596. int fid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
  9597. #endregion
  9598. if (fid > 0)
  9599. {//返回附件的ID
  9600. model_T_Sys_Accessories.F_FileId = fid;//修改为返回对象以便查看图片
  9601. return Success("文件日志都成功", model_T_Sys_Accessories);
  9602. }
  9603. else
  9604. return Success("文件成功");
  9605. }
  9606. catch (Exception ex)
  9607. {
  9608. return Error(ex.Message);
  9609. }
  9610. }
  9611. }
  9612. #endregion
  9613. }