No Description

WxLoginController.cs 275KB

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