MainController.php 265 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class MainController extends DooController {
  6. public $staff;
  7. public $nature = array (
  8. '1' => '设计',
  9. '2' => '造价管理',
  10. '3' => '业主',
  11. '4' => '交通局',
  12. '5' => '公路局',
  13. '6' => '审计',
  14. '7' => '财政',
  15. '8' => '审核',
  16. '9' => '施工',
  17. '10' => '咨询',
  18. '11' => '招标代理',
  19. '12' => '监理',
  20. '13' => '学校',
  21. '14' => '个人',
  22. '15' => '合作伙伴'
  23. );
  24. public $tooltip = array (
  25. '1' => array (
  26. 'L',
  27. '点击筛选标签'
  28. ),
  29. '2' => array (
  30. 'M',
  31. '点击筛选标签'
  32. ),
  33. '3' => array (
  34. 'N',
  35. '点击筛选标签'
  36. ),
  37. '4' => array (
  38. 'O',
  39. '点击筛选标签'
  40. ),
  41. '5' => array (
  42. 'P',
  43. '点击筛选标签'
  44. ),
  45. '6' => array (
  46. 'Q',
  47. '点击筛选标签'
  48. ),
  49. '7' => array (
  50. 'R',
  51. '点击筛选标签'
  52. )
  53. );
  54. public $webPath = "http://cld.smartcost.com.cn/upload/emailAnnex/";
  55. public function beforeRun($resource, $action) {
  56. // 主权限获得与判断
  57. Doo::loadModel ( 'staff' );
  58. $staff = new staff ();
  59. $detail = array ();
  60. if (isset ( $_COOKIE ["staff"] ))
  61. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  62. else
  63. $detail ['sid'] = 0;
  64. $flag = false;
  65. $accessModular = 'EMAIL';
  66. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  67. $flag = true;
  68. } else {
  69. $flag = false;
  70. }
  71. if ($flag === false) {
  72. $accessModular = 'INFORMATION';
  73. if (empty ( $detail ['cldAccessArray'] ))
  74. return '/settingEmployeeInfo';
  75. else {
  76. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  77. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  78. $flag = true;
  79. } else {
  80. $flag = false;
  81. }
  82. } else {
  83. $flag = false;
  84. }
  85. }
  86. }
  87. if ($flag === false) {
  88. $accessModular = 'DIRECTORIES';
  89. if (empty ( $detail ['cldAccessArray'] ))
  90. die ( 'illegal request' );
  91. else {
  92. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  93. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  94. $flag = true;
  95. } else {
  96. $flag = false;
  97. }
  98. } else {
  99. $flag = false;
  100. }
  101. }
  102. }
  103. if ($flag === false) {
  104. $accessModular = 'LOCK';
  105. if (empty ( $detail ['cldAccessArray'] ))
  106. die ( 'illegal request' );
  107. else {
  108. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  109. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  110. $flag = true;
  111. } else {
  112. $flag = false;
  113. }
  114. } else {
  115. $flag = false;
  116. }
  117. }
  118. }
  119. if ($detail ['sid'] == superHR && ! $flag)
  120. return '/settingEmployeeInfo';
  121. elseif (! $flag && $action == 'logStatistics')
  122. return '/settingEmployeeInfo';
  123. elseif (! $flag)
  124. die ( 'illegal request' );
  125. }
  126. function __construct() {
  127. // phpinfo();die;
  128. // include './protected/config/common.conf.php';
  129. // include $config['BASE_PATH'].'diagnostic/debug.php';
  130. if (isset ( $_COOKIE ["staff"] )) {
  131. if (! empty ( $_COOKIE ["staff"] )) {
  132. Doo::loadModel ( 'staff' );
  133. $staff = new staff ();
  134. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  135. return "";
  136. }
  137. }
  138. Doo::loadCore ( 'uri/DooUriRouter' );
  139. $router = new DooUriRouter ();
  140. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  141. if ($routeRs ['1'] != "login") {
  142. header ( 'Content-Type:text/html;charset=utf-8' );
  143. @header ( "Location: /login" );
  144. }
  145. }
  146. /**
  147. * 优化actionLog表
  148. */
  149. function backUpActionLog() {
  150. Doo::loadModel ( 'action_log' );
  151. $action_log = new action_log ();
  152. $date = date ( "Y" );
  153. $tableName = 'CLD_action_log' . $date;
  154. $action_log->copyActionLogToBakTable ( $tableName );
  155. $action_log = new action_log ();
  156. $aid = 0;
  157. $action_log->delActionLogByAid ( $aid );
  158. }
  159. function login() {
  160. $passwork = $this->get_args ( 'passwork' ) ? $this->get_args ( 'passwork' ) : 0;
  161. $uid = $this->get_args ( 'user' ) ? $this->get_args ( 'user' ) : 0;
  162. Doo::loadModel ( 'staff' );
  163. $staff = new staff ();
  164. Doo::loadClass ( 'XDeode' );
  165. $XDeode = new XDeode ( 5 );
  166. if (! empty ( $passwork )) {
  167. $userinfo = $staff->checkUser ( $uid, $passwork );
  168. if (! empty ( $userinfo )) {
  169. setcookie ( "staff", $XDeode->encode ( $userinfo [0] ['sid'] ), time () + 36000, "/" );
  170. // $text = 'CLDV2_CP';
  171. // $algorithm = 'aes192';
  172. // $password = '1234567890abcdef1234567890abcdef'; //node js required 32 byte length key
  173. // $iv = '1234567890abcdef'; //must be 16 byte length OPENSSL_RAW_DATA
  174. // $staffV2= bin2hex(openssl_encrypt($userinfo [0] ['sid'] , $algorithm, $text ));
  175. Doo::loadClass ( 'crypto' );
  176. $crypto = new crypto ( );
  177. $staffV2=$crypto->encrypt( $userinfo [0] ['sid'],'CLDV2_CP');
  178. setcookie ( "staffV2", $staffV2, time () + 36000, "/" );
  179. //工会动态密匙
  180. Doo::loadClass ( 'auth' );
  181. $auth = new auth ( );
  182. $staffGH=$auth->yundanran_auth($userinfo [0] ['sid'],'',"GH");
  183. setcookie ( "staffGH", $staffGH, time () + 36000, "/" );
  184. return "/";
  185. }
  186. }
  187. // 检测员工状态
  188. $data ['application'] = 0;
  189. $detail = $staff->getStaffByName ( $uid );
  190. if (! empty ( $detail )) {
  191. if ($detail ['pendStatus'] == 1) {
  192. $data ['application'] = 1;
  193. } elseif ($detail ['pendStatus'] == 2) {
  194. $data ['application'] = 2;
  195. }
  196. }
  197. $data ['staff'] = $detail; // $staff->getUser ();
  198. $data ['login'] = "";
  199. if (! empty ( $passwork ))
  200. $data ['login'] = "inputErrow";
  201. $this->render ( "/login", $data );
  202. }
  203. function out() {
  204. setcookie ( "staff", "", time () - 3600, "/" );
  205. setcookie ( "staffV2", "", time () - 3600, "/" );
  206. return "/";
  207. }
  208. function test() {
  209. // 实例化redis
  210. }
  211. function index2() {
  212. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  213. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  214. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  215. $page = $this->get_args ( 'page' ) ? $this->get_args ( 'page' ) : 1;
  216. Doo::loadModel ( 'action_log' );
  217. $action_log = new action_log ();
  218. Doo::loadModel ( 'staff' );
  219. $staff = new staff ();
  220. Doo::loadModel ( 'client_staff' );
  221. $client_staff = new client_staff ();
  222. Doo::loadModel ( 'longle' );
  223. $longle = new longle ();
  224. Doo::loadModel ( 'L_category' );
  225. $lcategory = new L_category ();
  226. $limit = 50;
  227. $p = $page;
  228. if ($page != 1)
  229. $page = $page * $limit - 1;
  230. else
  231. $page --;
  232. $condition = "";
  233. // if (!empty($cid) && $cid != 12) {
  234. // $condition = " and cid=" . $cid . " and sid=" . $sid;
  235. // }
  236. $staffCondition = "";
  237. $categorylist2 = array ();
  238. if ($this->staff [0] ['cid'] != 12) {
  239. $staffCondition = " and cid=" . $this->staff [0] ['cid'];
  240. array_push ( $categorylist2, array (
  241. 'cid' => $this->staff [0] ['cid'],
  242. 'title' => $this->staff [0] ['category']
  243. ) );
  244. if (! empty ( $sid ))
  245. $condition = " and cid=" . $this->staff [0] ['cid'] . " and sid=" . $sid;
  246. else
  247. $condition = " and cid=" . $this->staff [0] ['cid'];
  248. } else {
  249. $sql = 'SELECT `CLD_L_category`.cid,`CLD_L_category`.title,count(`CLD_staff`.sid) as count FROM `CLD_L_category` left join `CLD_staff` on `CLD_L_category`.cid=`CLD_staff`.cid group by `CLD_staff`.cid HAVING count(`CLD_staff`.sid)>0 order by count(`CLD_staff`.sid) desc';
  250. $query = Doo::db ()->query ( $sql );
  251. $result = $query->fetchAll ();
  252. $categorylist2 = $result;
  253. }
  254. // 有待优化
  255. Doo::loadModel ( 'department' );
  256. $department = new department ();
  257. $categorylist3 = $categorylist2;
  258. $bakCategory = array ();
  259. foreach ( $categorylist3 as $key => $value ) {
  260. $departList = $department->getDepartmentBycid ( $value ['cid'] );
  261. if (! empty ( $departList )) {
  262. // $bakCategory=$categorylist2[$key];
  263. array_unshift ( $bakCategory, $value );
  264. unset ( $categorylist2 [$key] );
  265. foreach ( $departList as $v ) {
  266. array_unshift ( $bakCategory, array (
  267. 'cid' => $v ['cid'],
  268. 'title' => $value ['title'],
  269. 'count' => $value ['count'],
  270. 'did' => $v ['did'],
  271. 'departmentName' => $v ['departmentName']
  272. ) );
  273. }
  274. }
  275. }
  276. foreach ( $bakCategory as $value ) {
  277. array_unshift ( $categorylist2, $value );
  278. }
  279. $data ['did'] = '';
  280. if (! empty ( $cid )) {
  281. $staffCondition = " and cid=" . $cid;
  282. if (! is_numeric ( $cid )) {
  283. $cdid = explode ( '-', $cid );
  284. $cid = $cdid [0];
  285. $data ['did'] = $cdid [1];
  286. $staffCondition = " and cid=" . $cid . " and departmentID=" . $cdid [1];
  287. }
  288. if (! empty ( $sid ))
  289. $condition = " and cid=" . $cid . " and sid=" . $sid;
  290. else
  291. $condition = " and cid=" . $cid;
  292. }
  293. /*
  294. * $itemCategoryList=$action_log->find(array('select'=>'updatetime,COUNT(*)', 'where'=>" Year(updatetime)=2014",'groupby'=>'Month(updatetime)','asArray'=>true)); print_r($itemCategoryList);die;
  295. */
  296. $staffList = $staff->find ( array (
  297. 'where' => ' username!="admin" ' . $staffCondition . $staffCondition . ' and nature!=4 and pendStatus!=4 and pendStatus!=1 and pendStatus!=2 ',
  298. 'asArray' => true
  299. ) );
  300. $alCondition = ' aid>' . REMIT . ' ';
  301. $actionLogList = $action_log->find ( array (
  302. 'where' => $alCondition . $condition,
  303. 'limit' => $page . ',' . $limit,
  304. 'desc' => 'aid',
  305. 'asArray' => true
  306. ) );
  307. // echo $condition;
  308. // 抽取日期 ,'groupby'=>'updatetime'
  309. $dateLog = $action_log->find ( array (
  310. 'select' => 'updatetime',
  311. 'where' => $alCondition . $condition,
  312. 'limit' => $limit,
  313. 'desc' => 'aid',
  314. 'asArray' => true
  315. ) );
  316. $dl = array ();
  317. foreach ( $dateLog as $value ) {
  318. array_push ( $dl, $value ['updatetime'] );
  319. }
  320. $dateLog = array_unique ( $dl );
  321. $log = array ();
  322. foreach ( $dateLog as $key => $value ) {
  323. $log [$value] = array ();
  324. foreach ( $actionLogList as $k => $v ) {
  325. if ($value == $v ['updatetime']) {
  326. array_push ( $log [$value], $v );
  327. unset ( $actionLogList [$k] );
  328. }
  329. }
  330. }
  331. $max = array ();
  332. foreach ( $staffList as $key => $value ) {
  333. $staffList [$key] ['count'] = $client_staff->count ( array (
  334. 'where' => 'sid=' . $value ['sid'],
  335. 'asArray' => true
  336. ) );
  337. array_push ( $max, $staffList [$key] ['count'] . ':' . $value ['username'] );
  338. }
  339. rsort ( $max, SORT_NUMERIC );
  340. $sum = 0;
  341. foreach ( $max as $key => $value ) {
  342. $max [$key] = explode ( ":", $value );
  343. $sum += $max [$key] [0];
  344. }
  345. $max2 = $max;
  346. array_shift ( $max2 );
  347. array_shift ( $max2 );
  348. array_shift ( $max2 );
  349. $lcategoryList = $lcategory->find ( array (
  350. 'asArray' => true
  351. ) );
  352. $useL = array ();
  353. $Rsum = $Ssum = 0;
  354. foreach ( $lcategoryList as $key => $value ) {
  355. $longleR = $longle->count ( array (
  356. 'where' => 'cid=' . $value ['cid'],
  357. 'asArray' => true
  358. ) );
  359. $longleS = $longle->count ( array (
  360. 'where' => 'cid=' . $value ['cid'] . ' and status!=1 and status!=2',
  361. 'asArray' => true
  362. ) );
  363. $Rsum += $longleR;
  364. $Ssum += $longleS;
  365. if (! empty ( $longleS ))
  366. array_push ( $useL, round ( ($longleS / $longleR) * 100 ) . '% :' . $value ['title'] );
  367. else
  368. array_push ( $useL, '0% :' . $value ['title'] );
  369. }
  370. rsort ( $useL, SORT_NUMERIC ); // $sum=0;
  371. foreach ( $useL as $key => $value ) {
  372. $useL [$key] = explode ( ":", $value );
  373. // $sum+=$max[$key][0];
  374. }
  375. $useL2 = $useL;
  376. array_shift ( $useL2 );
  377. array_shift ( $useL2 );
  378. array_shift ( $useL2 );
  379. $data ['Ssum'] = round ( ($Ssum / $Rsum) * 100 ) . '%';
  380. $data ['Rsum'] = $Rsum;
  381. $data ['useL2'] = $useL2;
  382. $data ['useL'] = $useL;
  383. $data ['sum'] = $sum;
  384. $data ['max'] = $max;
  385. $data ['max2'] = $max2;
  386. $data ['log'] = $log;
  387. $data ['page'] = $p;
  388. $data ['staffList'] = $staffList;
  389. $data ['categorylist2'] = $categorylist2;
  390. $data ['cid'] = $cid;
  391. $data ['sid'] = $sid;
  392. $data ['memu'] = "index";
  393. $data ['staff'] = $this->staff;
  394. $this->render ( "index2", $data );
  395. }
  396. function indexPage() {
  397. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  398. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  399. $page = $this->get_args ( 'page' ) ? $this->get_args ( 'page' ) : 1;
  400. Doo::loadModel ( 'action_log' );
  401. $action_log = new action_log ();
  402. $limit = 50;
  403. $p = $page;
  404. // if ($page!=1)
  405. // $page=$page*$limit-1;
  406. // else
  407. // $page--;
  408. $page = (-- $p) * $limit;
  409. /*
  410. * $condition=""; if (!empty($cid)&&$cid!=12){ $condition=" and cid=".$cid; } $staffCondition=""; if($this->staff[0]['cid']!=12){ $staffCondition=" and cid=".$this->staff[0]['cid']; $condition=" and cid=".$this->staff[0]['cid']; }
  411. */
  412. $condition = "";
  413. if (! empty ( $cid ) && $cid != 12) {
  414. $condition = " and cid=" . $cid . " and sid=" . $sid;
  415. }
  416. $staffCondition = "";
  417. if ($this->staff [0] ['cid'] != 12) {
  418. $staffCondition = " and cid=" . $this->staff [0] ['cid'];
  419. if (! empty ( $sid ))
  420. $condition = " and cid=" . $this->staff [0] ['cid'] . " and sid=" . $sid;
  421. else
  422. $condition = " and cid=" . $this->staff [0] ['cid'];
  423. }
  424. $actionLogList = $action_log->find ( array (
  425. 'where' => ' 1 ' . $condition,
  426. 'limit' => $page . ',' . $limit,
  427. 'desc' => 'aid',
  428. 'asArray' => true
  429. ) );
  430. // 抽取日期 ,'groupby'=>'updatetime'
  431. $dateLog = $action_log->find ( array (
  432. 'select' => 'updatetime',
  433. 'where' => ' 1 ' . $condition,
  434. 'limit' => $page . ',' . $limit,
  435. 'desc' => 'aid',
  436. 'asArray' => true
  437. ) );
  438. $dl = array ();
  439. foreach ( $dateLog as $value ) {
  440. array_push ( $dl, $value ['updatetime'] );
  441. }
  442. $dateLog = array_unique ( $dl );
  443. $log = array ();
  444. foreach ( $dateLog as $key => $value ) {
  445. $log [$value] = array ();
  446. foreach ( $actionLogList as $k => $v ) {
  447. if ($value == $v ['updatetime']) {
  448. array_push ( $log [$value], $v );
  449. unset ( $actionLogList [$k] );
  450. }
  451. }
  452. }
  453. $html = '';
  454. foreach ( $log as $key => $value ) {
  455. $html .= '<div class="item">
  456. <div class="date">' . $key . '</div>
  457. <dl class="recordList clearfix">';
  458. foreach ( $value as $k => $v ) {
  459. $html .= '<dd class="' . $v ['class'] . '"><span class="fR">' . $v ['time'] . '</span>' . $v ['action'] . '</dd>';
  460. }
  461. $html .= '</dl></div>';
  462. }
  463. echo $html;
  464. }
  465. function logStatistics() {
  466. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  467. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  468. Doo::loadModel ( 'action_log' );
  469. $action_log = new action_log ();
  470. Doo::loadModel ( 'staff' );
  471. $staff = new staff ();
  472. Doo::loadModel ( 'client_staff' );
  473. $client_staff = new client_staff ();
  474. Doo::loadModel ( 'longle' );
  475. $longle = new longle ();
  476. Doo::loadModel ( 'L_category' );
  477. $lcategory = new L_category ();
  478. Doo::loadModel ( 'department' );
  479. $department = new department ();
  480. $redis = new Redis ();
  481. $redis->connect ( '127.0.0.1', '6379' ); // 120.27.200.79
  482. $staffCondition = "";
  483. $categorylist2 = array ();
  484. if ($this->staff [0] ['cid'] != 12) {
  485. $staffCondition = " and cid=" . $this->staff [0] ['cid'];
  486. // array_push ( $categorylist2, array (
  487. // 'cid' => $this->staff [0] ['cid'],
  488. // 'title' => $this->staff [0] ['category']
  489. // ) );
  490. $otherC = $lcategory->getCategoryById ( $this->staff [0] ['cid'], $this->staff [0] ['othercid'] );
  491. foreach ( $otherC as $value ) {
  492. array_push ( $categorylist2, array (
  493. 'cid' => $value ['cid'],
  494. 'title' => $value ['title']
  495. ) );
  496. }
  497. } else {
  498. $sql = 'SELECT `CLD_L_category`.cid,`CLD_L_category`.title,count(`CLD_staff`.sid) as count FROM `CLD_L_category` left join `CLD_staff` on `CLD_L_category`.cid=`CLD_staff`.cid group by `CLD_staff`.cid HAVING count(`CLD_staff`.sid)>0 order by count(`CLD_staff`.sid) desc';
  499. $query = Doo::db ()->query ( $sql );
  500. $result = $query->fetchAll ();
  501. $categorylist2 = $result;
  502. // $otherC=$lcategory->getCategoryById($this->staff [0] ['cid'],$this->staff [0] ['othercid']);
  503. }
  504. // print_r($categorylist2);
  505. // 有待优化
  506. $categorylist3 = $categorylist2;
  507. $bakCategory = array ();
  508. foreach ( $categorylist3 as $key => $value ) {
  509. $departList = $department->getDepartmentBycid ( $value ['cid'] );
  510. if (! empty ( $departList )) {
  511. // $bakCategory=$categorylist2[$key];
  512. array_unshift ( $bakCategory, $value );
  513. unset ( $categorylist2 [$key] );
  514. foreach ( $departList as $v ) {
  515. array_unshift ( $bakCategory, array (
  516. 'cid' => $v ['cid'],
  517. 'title' => $value ['title'],
  518. 'count' => @$value ['count'],
  519. 'did' => $v ['did'],
  520. 'departmentName' => $v ['departmentName']
  521. ) );
  522. }
  523. }
  524. }
  525. foreach ( $bakCategory as $value ) {
  526. array_unshift ( $categorylist2, $value );
  527. }
  528. // array_unshift($categorylist2,$bakCategory);
  529. // print_r($categorylist2);
  530. $did = $data ['did'] = '';
  531. $othercateSql = '';
  532. if (! empty ( $this->staff [0] ['othercid'] ))
  533. $othercateSql = " or (othercid like '" . $this->staff [0] ['othercid'] . "')";
  534. if (! empty ( $cid )) { //
  535. if (is_numeric ( $cid ))
  536. $staffCondition = " and cid=" . $cid . $othercateSql;
  537. else {
  538. $cdid = explode ( '-', $cid );
  539. $cid = $cdid [0];
  540. $data ['did'] = $did = $cdid [1];
  541. $staffCondition = " and cid=" . $cdid [0] . " and departmentID=" . $cdid [1] . $othercateSql;
  542. }
  543. }
  544. // echo $staffCondition;
  545. // echo $staffCondition;
  546. // Doo::db()->beginTransaction();
  547. $staffList = $staff->find ( array (
  548. 'where' => ' username !="admin"' . $staffCondition . ' and nature!=4 and pendStatus!=4 and pendStatus!=1 and pendStatus!=2 ',
  549. 'asArray' => true
  550. ) );
  551. $max = array ();
  552. $sum = 0;
  553. // 客户总数
  554. $redisKey = date ( 'Y-m-d' ) . '_logStatisticsCSum_' . $this->staff [0] ['cid'];
  555. $redisValue = $redis->lrange ( $redisKey, 0, - 1 );
  556. if (empty ( $redisValue )) {
  557. $kkk = array ();
  558. foreach ( $staffList as $key => $value ) {
  559. $staffList [$key] ['count'] = $client_staff->count ( array (
  560. 'where' => 'sid=' . $value ['sid'],
  561. 'asArray' => true
  562. ) );
  563. array_push ( $max, $staffList [$key] ['count'] . ':' . $value ['username'] );
  564. if ($this->staff [0] ['cid'] == 12)
  565. array_push ( $kkk, $staffList [$key] ['count'] );
  566. if ($this->staff [0] ['cid'] == $value ['cid'] && $this->staff [0] ['cid'] != 12) {
  567. array_push ( $kkk, $staffList [$key] ['count'] );
  568. }
  569. }
  570. foreach ( $kkk as $key => $value ) {
  571. $sum += $value;
  572. }
  573. $sortMaxStr = json_encode ( $max );
  574. $redis->lpush ( $redisKey, $sum );
  575. $redis->lpush ( $redisKey, $sortMaxStr );
  576. } else {
  577. $sum = $redisValue [1];
  578. $max = json_decode ( $redisValue [0], true );
  579. }
  580. rsort ( $max, SORT_NUMERIC );
  581. foreach ( $max as $key => $value ) {
  582. $max [$key] = explode ( ":", $value );
  583. // $sum+=$max[$key][0];
  584. }
  585. $max2 = $max;
  586. array_shift ( $max2 );
  587. array_shift ( $max2 );
  588. array_shift ( $max2 );
  589. $lcategoryList = $lcategory->find ( array (
  590. 'asArray' => true
  591. ) );
  592. $useL = array ();
  593. $Rsum = $Ssum = 0;
  594. $redisKey = date ( 'Y-m-d' ) . '_logStatisticsLongle';
  595. $redisValue = $redis->lrange ( $redisKey, 0, - 1 );
  596. if (empty ( $redisValue )) {
  597. foreach ( $lcategoryList as $key => $value ) {
  598. $longleR = $longle->count ( array (
  599. 'where' => 'cid=' . $value ['cid'],
  600. 'asArray' => true
  601. ) );
  602. $longleS = $longle->count ( array (
  603. 'where' => 'cid=' . $value ['cid'] . ' and status!=1 and status!=2',
  604. 'asArray' => true
  605. ) );
  606. $Rsum += $longleR;
  607. $Ssum += $longleS;
  608. if (! empty ( $longleS ))
  609. array_push ( $useL, round ( ($longleS / $longleR) * 100 ) . '% :' . $value ['title'] );
  610. else
  611. array_push ( $useL, '0% :' . $value ['title'] );
  612. }
  613. $useLStr = json_encode ( $useL );
  614. $redis->lpush ( $redisKey, $Rsum );
  615. $redis->lpush ( $redisKey, $Ssum );
  616. $redis->lpush ( $redisKey, $useLStr );
  617. } else {
  618. $useL = $redisValue [0];
  619. $useL = json_decode ( $useL, true );
  620. $Ssum = $redisValue [1];
  621. $Rsum = $redisValue [2];
  622. }
  623. rsort ( $useL, SORT_NUMERIC );
  624. foreach ( $useL as $key => $value ) {
  625. $useL [$key] = explode ( ":", $value );
  626. }
  627. $useL2 = $useL;
  628. array_shift ( $useL2 );
  629. array_shift ( $useL2 );
  630. array_shift ( $useL2 );
  631. // statistics
  632. // 30天操作日志数
  633. $categoryCondition = " and cid=" . $this->staff [0] ['cid'];
  634. $redisCid = $this->staff [0] ['cid'];
  635. $sidCondition = $redisSid = "";
  636. if (! empty ( $cid )) {
  637. $categoryCondition = " and cid=" . $cid;
  638. $redisCid = $cid;
  639. }
  640. if (! empty ( $sid )) {
  641. $redisSid = $sid;
  642. $sidCondition = " and sid=" . $sid;
  643. }
  644. if ($this->staff [0] ['cid'] == 12 && empty ( $cid )) {
  645. $categoryCondition = "";
  646. $redisCid = '';
  647. }
  648. // if(!empty($did))
  649. // $categoryCondition=$categoryCondition.' and departmentID='.$did;
  650. $redisKey = date ( 'Y-m-d' ) . 'SL_' . $redisCid . '_' . $redisSid;
  651. $redisValue = $redis->get ( $redisKey );
  652. if (empty ( $redisValue )) {
  653. $actionLogLongle = $action_log->find ( array (
  654. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  655. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=3" . $categoryCondition . $sidCondition,
  656. 'groupby' => 'date_format(updatetime,"%m-%d")',
  657. 'asArray' => true
  658. ) );
  659. $statisticsLongle = array ();
  660. for($d = 0; $d <= 29; $d ++) {
  661. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  662. $falgLongle = true;
  663. foreach ( $actionLogLongle as $value ) {
  664. if ($value ['updatetime'] == $MD) {
  665. array_push ( $statisticsLongle, $value ['count'] );
  666. $falgLongle = false;
  667. break;
  668. }
  669. }
  670. if ($falgLongle)
  671. array_push ( $statisticsLongle, 0 );
  672. }
  673. $statisticsLongle = array_reverse ( $statisticsLongle );
  674. $jsl = json_encode ( $statisticsLongle );
  675. $redis->set ( $redisKey, $jsl );
  676. $data ['statisticsLongle'] = $jsl;
  677. } else {
  678. $data ['statisticsLongle'] = $redisValue;
  679. }
  680. // 添加客户 数30天
  681. $redisKey = date ( 'Y-m-d' ) . 'SC_' . $redisCid . '_' . $redisSid;
  682. // echo $redisKey;
  683. // echo "<br/> date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=1" . $categoryCondition . $sidCondition;
  684. $redisValue = $redis->get ( $redisKey );
  685. if (empty ( $redisValue )) {
  686. $actionLogClient = $action_log->find ( array (
  687. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  688. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=1" . $categoryCondition . $sidCondition,
  689. 'groupby' => 'date_format(updatetime,"%m-%d")',
  690. 'asArray' => true
  691. ) );
  692. $statisticsClient = array ();
  693. for($d = 0; $d <= 29; $d ++) {
  694. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  695. $falgClient = true;
  696. foreach ( $actionLogClient as $value ) {
  697. if ($value ['updatetime'] == $MD) {
  698. array_push ( $statisticsClient, $value ['count'] );
  699. $falgClient = false;
  700. break;
  701. }
  702. }
  703. if ($falgClient)
  704. array_push ( $statisticsClient, 0 );
  705. }
  706. $statisticsClient = array_reverse ( $statisticsClient );
  707. $jsc = json_encode ( $statisticsClient );
  708. $redis->set ( $redisKey, $jsc );
  709. $data ['statisticsClient'] = $jsc;
  710. } else {
  711. $data ['statisticsClient'] = $redisValue;
  712. }
  713. $statisticsDay = array ();
  714. for($d = 0; $d <= 29; $d ++) {
  715. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  716. array_push ( $statisticsDay, $MD );
  717. }
  718. $statisticsDay = array_reverse ( $statisticsDay );
  719. // / Year(updatetime)=".date('Y')." and Month(updatetime)=".date('m')." and
  720. $categoryList = $lcategory->find ( array (
  721. 'asArray' => true
  722. ) );
  723. // 最近30天区域分布图
  724. $redisKey = date ( 'Y-m-d' ) . 'SCCT_' . $redisCid . '_' . $redisSid;
  725. $redisValue = $redis->lrange ( $redisKey, 0, - 1 );
  726. if (empty ( $redisValue )) {
  727. $CategoryClient = $action_log->find ( array (
  728. 'select' => 'cid,COUNT(*) as count,city',
  729. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=1" . $categoryCondition . $sidCondition,
  730. 'groupby' => 'cid',
  731. 'asArray' => true
  732. ) );
  733. $CategoryCompany = $action_log->find ( array (
  734. 'select' => 'cid, COUNT(*) as count,company,districtid',
  735. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and (status=1 )" . $categoryCondition . $sidCondition,
  736. 'groupby' => 'cid,districtid,company',
  737. 'asArray' => true
  738. ) );
  739. $statisticsCategory = array ();
  740. $statisticsCompany = array ();
  741. foreach ( $categoryList as $value ) {
  742. $falgClient = $falgLongle = true;
  743. foreach ( $CategoryClient as $v ) {
  744. if ($value ['cid'] == $v ['cid'] && $v ['cid'] != 12) {
  745. array_push ( $statisticsCategory, array (
  746. 'value' => $v ['count'],
  747. 'name' => str_replace ( "办", "省", $value ['title'] )
  748. ) );
  749. $falgClient = false;
  750. break;
  751. }
  752. }
  753. if ($falgClient) {
  754. array_push ( $statisticsCategory, array (
  755. 'value' => 0,
  756. 'name' => str_replace ( "办", "省", $value ['title'] )
  757. ) );
  758. }
  759. // company statistics
  760. $i = 0;
  761. foreach ( $CategoryCompany as $v ) {
  762. if ($value ['cid'] == $v ['cid'] && $v ['cid'] != 12) {
  763. $i ++;
  764. }
  765. }
  766. array_push ( $statisticsCompany, array (
  767. 'value' => $i,
  768. 'name' => str_replace ( "办", "省", $value ['title'] )
  769. ) );
  770. }
  771. $scctA = json_encode ( $statisticsCompany );
  772. $scctB = json_encode ( $statisticsCategory );
  773. $redis->lpush ( $redisKey, $scctA );
  774. $redis->lpush ( $redisKey, $scctB );
  775. $data ['statisticsCompany'] = $scctA;
  776. $data ['statisticsCategory'] = $scctB;
  777. } else {
  778. $data ['statisticsCompany'] = $redisValue [1];
  779. $data ['statisticsCategory'] = $redisValue [0];
  780. }
  781. // print_r($CategoryClient);
  782. $redisKey = date ( 'Y-m-d' ) . 'SN_' . $redisCid . '_' . $redisSid;
  783. $redisValue = $redis->get ( $redisKey );
  784. if (empty ( $redisValue )) {
  785. $natureList = $action_log->find ( array (
  786. 'select' => 'cid, COUNT(*) as count,nature',
  787. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=1 and nature !=''" . $categoryCondition . $sidCondition,
  788. 'groupby' => 'nature',
  789. 'asArray' => true
  790. ) );
  791. $statisticsNature = array ();
  792. foreach ( $this->nature as $value ) {
  793. $flagNature = true;
  794. foreach ( $natureList as $v ) {
  795. if ($value == $v ['nature']) {
  796. array_push ( $statisticsNature, array (
  797. 'value' => $v ['count'],
  798. 'name' => $value
  799. ) );
  800. $flagNature = false;
  801. break;
  802. }
  803. }
  804. if ($flagNature)
  805. array_push ( $statisticsNature, array (
  806. 'value' => 0,
  807. 'name' => $value
  808. ) );
  809. }
  810. $jsn = json_encode ( $statisticsNature );
  811. $redis->set ( $redisKey, $jsn );
  812. $data ['statisticsNature'] = $jsn;
  813. } else {
  814. $data ['statisticsNature'] = $redisValue;
  815. }
  816. $data ['statisticsDay'] = json_encode ( $statisticsDay );
  817. $data ['categorylist2'] = $categorylist2;
  818. $data ['Ssum'] = round ( ($Ssum / $Rsum) * 100 ) . '%';
  819. $data ['Rsum'] = $Rsum;
  820. $data ['useL2'] = $useL2;
  821. $data ['useL'] = $useL;
  822. $data ['sum'] = $sum;
  823. $data ['max'] = $max;
  824. $data ['max2'] = $max2;
  825. $data ['staffList'] = $staffList;
  826. $data ['cid'] = $cid;
  827. $data ['sid'] = $sid;
  828. $data ['memu'] = "index";
  829. $data ['staff'] = $this->staff;
  830. $this->render ( "/indexStat", $data );
  831. }
  832. function longleStatistics() {
  833. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  834. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  835. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 4;
  836. $districtH = $this->get_args ( 'district' ) ? $this->get_args ( 'district' ) : 0;
  837. Doo::loadModel ( 'action_log' );
  838. $action_log = new action_log ();
  839. Doo::loadModel ( 'staff' );
  840. $staff = new staff ();
  841. Doo::loadModel ( 'client_staff' );
  842. $client_staff = new client_staff ();
  843. Doo::loadModel ( 'longle' );
  844. $longle = new longle ();
  845. Doo::loadModel ( 'L_category' );
  846. $lcategory = new L_category ();
  847. Doo::loadModel ( 'district' );
  848. $district = new district ();
  849. $staffCondition = "";
  850. $categorylist2 = array ();
  851. if ($this->staff [0] ['cid'] != 12) {
  852. $staffCondition = " and cid=" . $this->staff [0] ['cid'];
  853. array_push ( $categorylist2, array (
  854. 'cid' => $this->staff [0] ['cid'],
  855. 'title' => $this->staff [0] ['category']
  856. ) );
  857. } else {
  858. $sql = 'SELECT `CLD_L_category`.cid,`CLD_L_category`.title,count(`CLD_staff`.sid) as count FROM `CLD_L_category` left join `CLD_staff` on `CLD_L_category`.cid=`CLD_staff`.cid group by `CLD_staff`.cid HAVING count(`CLD_staff`.sid)>0 order by count(`CLD_staff`.sid) desc';
  859. $query = Doo::db ()->query ( $sql );
  860. $result = $query->fetchAll ();
  861. $categorylist2 = $result;
  862. }
  863. // 有待优化
  864. Doo::loadModel ( 'department' );
  865. $department = new department ();
  866. $categorylist3 = $categorylist2;
  867. $bakCategory = array ();
  868. foreach ( $categorylist3 as $key => $value ) {
  869. $departList = $department->getDepartmentBycid ( $value ['cid'] );
  870. if (! empty ( $departList )) {
  871. // $bakCategory=$categorylist2[$key];
  872. array_unshift ( $bakCategory, $value );
  873. unset ( $categorylist2 [$key] );
  874. foreach ( $departList as $v ) {
  875. array_unshift ( $bakCategory, array (
  876. 'cid' => $v ['cid'],
  877. 'title' => $value ['title'],
  878. 'count' => $value ['count'],
  879. 'did' => $v ['did'],
  880. 'departmentName' => $v ['departmentName']
  881. ) );
  882. }
  883. }
  884. }
  885. foreach ( $bakCategory as $value ) {
  886. array_unshift ( $categorylist2, $value );
  887. }
  888. $data ['did'] = '';
  889. if (! empty ( $cid )) {
  890. if (is_numeric ( $cid ))
  891. $staffCondition = " and cid=" . $cid;
  892. else {
  893. $cdid = explode ( '-', $cid );
  894. $cid = $cdid [0];
  895. $data ['did'] = $cdid [1];
  896. $staffCondition = " and cid=" . $cdid [0] . " and departmentID=" . $cdid [1];
  897. }
  898. // $staffCondition = " and cid=" . $cid;
  899. }
  900. $staffList = $staff->find ( array (
  901. 'where' => ' username!="admin"' . $staffCondition . ' and nature!=4 and pendStatus!=4 and pendStatus!=1 and pendStatus!=2 ',
  902. 'asArray' => true
  903. ) );
  904. $max = array ();
  905. foreach ( $staffList as $key => $value ) {
  906. $staffList [$key] ['count'] = $client_staff->count ( array (
  907. 'where' => 'sid=' . $value ['sid'],
  908. 'asArray' => true
  909. ) );
  910. array_push ( $max, $staffList [$key] ['count'] . ':' . $value ['username'] );
  911. }
  912. rsort ( $max, SORT_NUMERIC );
  913. $sum = 0;
  914. foreach ( $max as $key => $value ) {
  915. $max [$key] = explode ( ":", $value );
  916. $sum += $max [$key] [0];
  917. }
  918. $max2 = $max;
  919. array_shift ( $max2 );
  920. array_shift ( $max2 );
  921. array_shift ( $max2 );
  922. $lcategoryList = $lcategory->find ( array (
  923. 'asArray' => true
  924. ) );
  925. $useL = array ();
  926. $Rsum = $Ssum = 0;
  927. foreach ( $lcategoryList as $key => $value ) {
  928. $longleR = $longle->count ( array (
  929. 'where' => 'cid=' . $value ['cid'],
  930. 'asArray' => true
  931. ) );
  932. $longleS = $longle->count ( array (
  933. 'where' => 'cid=' . $value ['cid'] . ' and status!=1 and status!=2',
  934. 'asArray' => true
  935. ) );
  936. $Rsum += $longleR;
  937. $Ssum += $longleS;
  938. if (! empty ( $longleS ))
  939. array_push ( $useL, round ( ($longleS / $longleR) * 100 ) . '% :' . $value ['title'] );
  940. else
  941. array_push ( $useL, '0% :' . $value ['title'] );
  942. }
  943. rsort ( $useL, SORT_NUMERIC ); // $sum=0;
  944. foreach ( $useL as $key => $value ) {
  945. $useL [$key] = explode ( ":", $value );
  946. // $sum+=$max[$key][0];
  947. }
  948. $useL2 = $useL;
  949. array_shift ( $useL2 );
  950. array_shift ( $useL2 );
  951. array_shift ( $useL2 );
  952. // statistics
  953. $categoryCondition = " and cid=" . $this->staff [0] ['cid'];
  954. $sidCondition = "";
  955. if (! empty ( $cid ))
  956. $categoryCondition = " and cid=" . $cid;
  957. if (! empty ( $sid ))
  958. $sidCondition = " and sid=" . $sid;
  959. if ($this->staff [0] ['cid'] == 12 && empty ( $cid )) {
  960. $categoryCondition = "";
  961. }
  962. // Year(updatetime)=".date('Y')." and Month(updatetime)=".date('m')." date_format(updatetime,"%m-%d") Day(updatetime)
  963. $actionLogClient = $action_log->find ( array (
  964. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  965. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=4" . $categoryCondition . $sidCondition,
  966. 'groupby' => 'Day(updatetime)',
  967. 'asArray' => true
  968. ) );
  969. $actionLogLongle = $action_log->find ( array (
  970. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  971. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=5" . $categoryCondition . $sidCondition,
  972. 'groupby' => 'Day(updatetime)',
  973. 'asArray' => true
  974. ) );
  975. $actionLogGet = $action_log->find ( array (
  976. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  977. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=6" . $categoryCondition . $sidCondition,
  978. 'groupby' => 'Day(updatetime)',
  979. 'asArray' => true
  980. ) );
  981. $statisticsDay = array ();
  982. $statisticsClient = $statisticsLongle = $statisticsGet = array ();
  983. /**
  984. * for ($d=1;$d<=date("t");$d++){ $MD=date('m')."-".$d;
  985. */
  986. for($d = 0; $d <= 29; $d ++) {
  987. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  988. $falgClient = $falgLongle = $falgGet = true;
  989. array_push ( $statisticsDay, $MD );
  990. foreach ( $actionLogClient as $value ) {
  991. if ($value ['updatetime'] == $MD) {
  992. array_push ( $statisticsClient, $value ['count'] );
  993. $falgClient = false;
  994. break;
  995. }
  996. }
  997. if ($falgClient)
  998. array_push ( $statisticsClient, 0 );
  999. foreach ( $actionLogLongle as $value ) {
  1000. if ($value ['updatetime'] == $MD) {
  1001. array_push ( $statisticsLongle, $value ['count'] );
  1002. $falgLongle = false;
  1003. break;
  1004. }
  1005. }
  1006. if ($falgLongle)
  1007. array_push ( $statisticsLongle, 0 );
  1008. foreach ( $actionLogGet as $value ) {
  1009. if ($value ['updatetime'] == $MD) {
  1010. array_push ( $statisticsGet, $value ['count'] );
  1011. $falgGet = false;
  1012. break;
  1013. }
  1014. }
  1015. if ($falgGet)
  1016. array_push ( $statisticsGet, 0 );
  1017. }
  1018. $statisticsClient = array_reverse ( $statisticsClient );
  1019. $statisticsLongle = array_reverse ( $statisticsLongle );
  1020. $statisticsGet = array_reverse ( $statisticsGet );
  1021. $statisticsDay = array_reverse ( $statisticsDay );
  1022. // /
  1023. $districtCondition = "";
  1024. $topDistrict = $district->get_lvByid ( 0, 0 );
  1025. if (! empty ( $sid )) {
  1026. $s = $staff->getOne ( array (
  1027. 'where' => ' sid=' . $sid,
  1028. 'asArray' => true
  1029. ) );
  1030. $l = $lcategory->find ( array (
  1031. 'where' => ' cid in(' . $s ['cid'] . ')',
  1032. 'asArray' => true
  1033. ) );
  1034. if (! empty ( $s ['othercid'] ))
  1035. $l = $lcategory->find ( array (
  1036. 'where' => ' cid in(' . $s ['cid'] . ',' . $s ['othercid'] . ')',
  1037. 'asArray' => true
  1038. ) );
  1039. if (! empty ( $districtH )) {
  1040. $districtCondition = " and districtid like '" . $districtH . ",%'";
  1041. $sidCondition = "";
  1042. $topDistrict = $district->find ( array (
  1043. 'where' => ' upid=' . $districtH,
  1044. 'asArray' => true
  1045. ) );
  1046. } else {
  1047. $districtCondition = " and districtid like '" . $l [0] ['districtid'] . ",%'";
  1048. $sidCondition = "";
  1049. $topDistrict = $district->find ( array (
  1050. 'where' => ' upid=' . $l [0] ['districtid'],
  1051. 'asArray' => true
  1052. ) );
  1053. }
  1054. $str = array ();
  1055. foreach ( $l as $value ) {
  1056. array_push ( $str, $value ['districtid'] );
  1057. }
  1058. $str = implode ( ",", $str );
  1059. $data ['districtHtml'] = $district->find ( array (
  1060. 'where' => ' id in (' . $str . ')',
  1061. 'asArray' => true
  1062. ) );
  1063. $data ['districtH'] = $l [0] ['districtid'];
  1064. if (! empty ( $districtH ))
  1065. $data ['districtH'] = $districtH;
  1066. }
  1067. // Year(updatetime)=".date('Y')." and Month(updatetime)=".date('m')." and
  1068. if (! empty ( $sid ))
  1069. $districtClient = $action_log->find ( array (
  1070. 'select' => 'city,province,COUNT(*) as count',
  1071. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=" . $status . $categoryCondition . $sidCondition . $districtCondition,
  1072. 'groupby' => 'province',
  1073. 'asArray' => true
  1074. ) );
  1075. else
  1076. $districtClient = $action_log->find ( array (
  1077. 'select' => 'city,province,COUNT(*) as count',
  1078. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=" . $status . $categoryCondition . $sidCondition . $districtCondition,
  1079. 'groupby' => 'city',
  1080. 'asArray' => true
  1081. ) );
  1082. $statisticsLend = array ();
  1083. $statisticsCompany = array ();
  1084. if (! empty ( $sid )) {
  1085. foreach ( $topDistrict as $value ) {
  1086. $falgLend = $falgLongle = true;
  1087. foreach ( $districtClient as $v ) {
  1088. if ($value ['name'] == $v ['province']) {
  1089. array_push ( $statisticsLend, array (
  1090. 'value' => $v ['count'],
  1091. 'name' => $value ['name']
  1092. ) );
  1093. $falgLend = false;
  1094. break;
  1095. }
  1096. }
  1097. if ($falgLend)
  1098. array_push ( $statisticsLend, array (
  1099. 'value' => 0,
  1100. 'name' => $value ['name']
  1101. ) );
  1102. }
  1103. } else {
  1104. foreach ( $topDistrict as $value ) {
  1105. $falgLend = $falgLongle = true;
  1106. foreach ( $districtClient as $v ) {
  1107. if ($value ['name'] == $v ['city']) {
  1108. array_push ( $statisticsLend, array (
  1109. 'value' => $v ['count'],
  1110. 'name' => $value ['name']
  1111. ) );
  1112. $falgLend = false;
  1113. break;
  1114. }
  1115. }
  1116. if ($falgLend)
  1117. array_push ( $statisticsLend, array (
  1118. 'value' => 0,
  1119. 'name' => $value ['name']
  1120. ) );
  1121. }
  1122. }
  1123. // print_r($statisticsLend);die;
  1124. $natureList = $action_log->find ( array (
  1125. 'select' => 'cid, COUNT(*) as count,nature',
  1126. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=" . $status . " and nature !=''" . $categoryCondition . $sidCondition . $districtCondition,
  1127. 'groupby' => 'nature',
  1128. 'asArray' => true
  1129. ) );
  1130. $statisticsNature = array ();
  1131. foreach ( $this->nature as $value ) {
  1132. $flagNature = true;
  1133. foreach ( $natureList as $v ) {
  1134. if ($value == $v ['nature']) {
  1135. array_push ( $statisticsNature, array (
  1136. 'value' => $v ['count'],
  1137. 'name' => $value
  1138. ) );
  1139. $flagNature = false;
  1140. break;
  1141. }
  1142. }
  1143. if ($flagNature)
  1144. array_push ( $statisticsNature, array (
  1145. 'value' => 0,
  1146. 'name' => $value
  1147. ) );
  1148. }
  1149. $data ['statisticsNature'] = json_encode ( $statisticsNature );
  1150. // print_r($statisticsLend);die;
  1151. $data ['statisticsLend'] = json_encode ( $statisticsLend );
  1152. $data ['status'] = $status;
  1153. $data ['statisticsDay'] = json_encode ( $statisticsDay );
  1154. $data ['statisticsClient'] = json_encode ( $statisticsClient );
  1155. $data ['statisticsLongle'] = json_encode ( $statisticsLongle );
  1156. $data ['statisticsGet'] = json_encode ( $statisticsGet );
  1157. $data ['categorylist2'] = $categorylist2;
  1158. $data ['Ssum'] = round ( ($Ssum / $Rsum) * 100 ) . '%';
  1159. $data ['Rsum'] = $Rsum;
  1160. $data ['useL2'] = $useL2;
  1161. $data ['useL'] = $useL;
  1162. $data ['sum'] = $sum;
  1163. $data ['max'] = $max;
  1164. $data ['max2'] = $max2;
  1165. $data ['staffList'] = $staffList;
  1166. $data ['cid'] = $cid;
  1167. $data ['sid'] = $sid;
  1168. $data ['memu'] = "index";
  1169. $data ['staff'] = $this->staff;
  1170. $this->render ( "/indexLongle", $data );
  1171. }
  1172. function index() {
  1173. die ( 'dd' );
  1174. $data ['memu'] = "index";
  1175. $data ['staff'] = $this->staff;
  1176. Doo::loadModel ( 'action_log' );
  1177. $action_log = new action_log ();
  1178. $data ['today'] = explode ( "-", date ( "Y-m-d" ) );
  1179. $str = "";
  1180. if ($this->staff [0] ['isadmin'] != 1) {
  1181. $str = " and (action like '%" . $this->staff [0] ['category'] . "%'";
  1182. $khql = explode ( ",", $this->staff [0] ['othercategory'] );
  1183. if (! empty ( $khql [0] )) {
  1184. foreach ( $khql as $key => $value ) {
  1185. $str .= " or action like '%" . $value . "%'";
  1186. }
  1187. $str .= ")";
  1188. } else
  1189. $str .= ")";
  1190. }
  1191. $data ['actionListNow'] = $action_log->find ( array (
  1192. 'where' => ' updatetime=\'' . date ( "Y-m-d" ) . "'" . $str,
  1193. 'desc' => 'aid',
  1194. 'asArray' => TRUE
  1195. ) );
  1196. $d2 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 1, date ( "Y" ) );
  1197. $strdate = date ( "Y-m-d", $d2 );
  1198. $data ['day2'] = explode ( "-", $strdate );
  1199. $data ['actionListNow2'] = $action_log->find ( array (
  1200. 'where' => ' updatetime=\'' . $strdate . "'" . $str,
  1201. 'desc' => 'aid',
  1202. 'asArray' => TRUE
  1203. ) );
  1204. $d3 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 2, date ( "Y" ) );
  1205. $strdate = date ( "Y-m-d", $d3 );
  1206. $data ['day3'] = explode ( "-", $strdate );
  1207. $data ['actionListNow3'] = $action_log->find ( array (
  1208. 'where' => ' updatetime=\'' . $strdate . "'" . $str,
  1209. 'desc' => 'aid',
  1210. 'asArray' => TRUE
  1211. ) );
  1212. $d4 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 3, date ( "Y" ) );
  1213. $strdate = date ( "Y-m-d", $d4 );
  1214. $data ['day4'] = explode ( "-", $strdate );
  1215. $data ['actionListNow4'] = $action_log->find ( array (
  1216. 'where' => ' updatetime=\'' . $strdate . "'" . $str,
  1217. 'asArray' => TRUE
  1218. ) );
  1219. $d5 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 4, date ( "Y" ) );
  1220. $strdate = date ( "Y-m-d", $d5 );
  1221. $data ['day5'] = explode ( "-", $strdate );
  1222. $data ['actionListNow5'] = $action_log->find ( array (
  1223. 'where' => ' updatetime=\'' . $strdate . "'" . $str,
  1224. 'asArray' => TRUE
  1225. ) );
  1226. $d6 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 5, date ( "Y" ) );
  1227. $strdate = date ( "Y-m-d", $d6 );
  1228. $data ['day6'] = explode ( "-", $strdate );
  1229. $data ['actionListNow6'] = $action_log->find ( array (
  1230. 'where' => ' updatetime=\'' . $strdate . "'" . $str,
  1231. 'asArray' => TRUE
  1232. ) );
  1233. $d7 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 6, date ( "Y" ) );
  1234. $strdate = date ( "Y-m-d", $d7 );
  1235. $data ['day7'] = explode ( "-", $strdate );
  1236. $data ['actionListNow7'] = $action_log->find ( array (
  1237. 'where' => ' updatetime=\'' . $strdate . "'" . $str,
  1238. 'asArray' => TRUE
  1239. ) );
  1240. Doo::loadModel ( 'staff' );
  1241. Doo::loadModel ( 'client_staff' );
  1242. $client_staff = new client_staff ();
  1243. $staff = new staff ();
  1244. $st = $staff->find ( array (
  1245. 'where' => '1',
  1246. 'asArray' => true
  1247. ) );
  1248. foreach ( $st as $key => $value ) {
  1249. $st [$key] ['count'] = $client_staff->count ( array (
  1250. 'where' => 'sid=' . $value ['sid'],
  1251. 'asArray' => true
  1252. ) );
  1253. }
  1254. $data ['staffCount'] = $st;
  1255. $this->render ( "/index", $data );
  1256. }
  1257. function receive() {
  1258. $data ['memu'] = "keyonline";
  1259. $data ['staff'] = $this->staff;
  1260. Doo::loadModel ( 'longle' );
  1261. $longle = new longle ();
  1262. $data ['arrayReceive'] = $longle->getLongleReceive ( $this->staff [0] ['cid'], 1, $this->staff [0] ['othercid'] );
  1263. $this->render ( "/look_receive", $data );
  1264. }
  1265. function doLongleReceive() {
  1266. $arrLid = $this->get_args ( 'lid' ) ? $this->get_args ( 'lid' ) : array ();
  1267. Doo::loadModel ( 'longle_log' );
  1268. Doo::loadModel ( 'longle' );
  1269. foreach ( $arrLid as $key => $value ) {
  1270. $ky = explode ( "-", $value );
  1271. $longle = new longle ();
  1272. $longle_log = new longle_log ();
  1273. $longle->lid = $ky [0];
  1274. $longle->status = 2;
  1275. $longle->statusT = '接收';
  1276. $longle->responsible = $this->staff [0] ['username'];
  1277. // 记录锁状态
  1278. //$longle->statuslog = "1,2";
  1279. $longle->update ();
  1280. $longle_log->lid = $ky [0];
  1281. $longle_log->status = 2;
  1282. $longle_log->statusT = '接收';
  1283. $longle_log->responsible = $this->staff [0] ['username'];
  1284. $longle_log->operator = $this->staff [0] ['username'];
  1285. $longle_log->category = $ky [1];
  1286. $longle_log->dateline = date ( "Y-m-d" );
  1287. $longle_log->insert ();
  1288. }
  1289. return "/receive";
  1290. }
  1291. function addClient() {
  1292. $companyKey = $this->get_args ( 'companyKey' ) ? $this->get_args ( 'companyKey' ) : "";
  1293. $clientname = $this->get_args ( 'clientname' ) ? $this->get_args ( 'clientname' ) : "";
  1294. $gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : "";
  1295. $nicename = $this->get_args ( 'nicename' ) ? $this->get_args ( 'nicename' ) : "";
  1296. $telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : "";
  1297. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1298. $email = $this->get_args ( 'email' ) ? $this->get_args ( 'email' ) : "";
  1299. $qq = $this->get_args ( 'qq' ) ? $this->get_args ( 'qq' ) : "";
  1300. $tid = $this->get_args ( 'tid' ) ? $this->get_args ( 'tid' ) : "";
  1301. $companyname = $this->get_args ( 'companyname' ) ? $this->get_args ( 'companyname' ) : "";
  1302. $local1 = $this->get_args ( 'lv21' ) ? $this->get_args ( 'lv21' ) : "";
  1303. $local2 = $this->get_args ( 'lv22' ) ? $this->get_args ( 'lv22' ) : "";
  1304. $local3 = $this->get_args ( 'lv23' ) ? $this->get_args ( 'lv23' ) : "";
  1305. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  1306. $fax = $this->get_args ( 'fax' ) ? $this->get_args ( 'fax' ) : "";
  1307. $webservice = $this->get_args ( 'webservice' ) ? $this->get_args ( 'webservice' ) : "";
  1308. $department = $this->get_args ( 'department' ) ? $this->get_args ( 'department' ) : "";
  1309. $position = $this->get_args ( 'position' ) ? $this->get_args ( 'position' ) : "";
  1310. $office = $this->get_args ( 'office' ) ? $this->get_args ( 'office' ) : "";
  1311. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1312. $ride = $this->get_args ( 'ride' ) ? $this->get_args ( 'ride' ) : "";
  1313. $landmarks = $this->get_args ( 'landmarks' ) ? $this->get_args ( 'landmarks' ) : "";
  1314. $priority = $this->get_args ( 'priority' ) ? $this->get_args ( 'priority' ) : "";
  1315. $stay = $this->get_args ( 'stay' ) ? $this->get_args ( 'stay' ) : "";
  1316. $mark = $this->get_args ( 'mark' ) ? $this->get_args ( 'mark' ) : "";
  1317. $clientname = trim ( $clientname );
  1318. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  1319. $tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
  1320. if (empty ( $token )) {
  1321. die ( 'illegal request-token' );
  1322. } else {
  1323. session_start ();
  1324. $sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
  1325. header ( 'Content-Type:text/html;charset=utf-8' );
  1326. if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
  1327. die ( '请重新刷新页面' );
  1328. }elseif($_SESSION [$sessionKey]=='repeat'){
  1329. die ( '请勿重复提交客户信息' );
  1330. }else{
  1331. if ($_SESSION [$sessionKey] != $token){
  1332. die ( '请勿重复提交客户信息' );
  1333. } else {
  1334. $_SESSION [$sessionKey] = 'repeat';
  1335. }
  1336. }
  1337. }
  1338. // $companyname = trim ( $companyname );
  1339. if (empty ( $companyname ))
  1340. return "/contacts";
  1341. if (empty ( $this->staff [0] ['sid'] ))
  1342. return "/contacts";
  1343. if (! empty ( $clientname )) {
  1344. // 相同的公司和客户
  1345. Doo::loadModel ( 'company' );
  1346. $company = new company ();
  1347. Doo::loadModel ( 'client' );
  1348. $client = new client ();
  1349. $redis = new Redis ();
  1350. $redis->connect ( '127.0.0.1', '6379' );
  1351. $cinfo = $client->getClientByNameT ( $clientname );
  1352. if (! empty ( $cinfo )) {
  1353. $ninfo = $company->getCompanyByCompanyname ( $companyname );
  1354. if (! empty ( $ninfo )) {
  1355. foreach ( $cinfo as $key => $value ) { // 问题
  1356. if ($value ['companyid'] == $ninfo [0] ['cid'])
  1357. return "/contacts";
  1358. }
  1359. }
  1360. }
  1361. Doo::loadModel ( 'district' );
  1362. $district = new district ();
  1363. // 修改
  1364. Doo::loadClass ( 'XDeode' );
  1365. $XDeode = new XDeode ( 5 );
  1366. //$comId = $XDeode->decode ( $companyKey );
  1367. $companyInfo = $company->getOne ( array (
  1368. 'where' => "companyname like '" . $companyname . "'",
  1369. "asArray" => true
  1370. ) );
  1371. // 更新公司信息
  1372. $lv1 = $district->getbyid ( $local1 );
  1373. $lv2 = $district->getbyid ( $local2 );
  1374. $lv3 = $district->getbyid ( $local3 );
  1375. if (empty ( $lv1 ))
  1376. $lv1 [0] ['name'] = "";
  1377. if (empty ( $lv2 ))
  1378. $lv2 [0] ['name'] = "";
  1379. if (empty ( $lv3 ))
  1380. $lv3 [0] ['name'] = "";
  1381. if (! empty ( $local1 ) && ! empty ( $local2 ))
  1382. $company->local = $lv1 [0] ['name'] . "," . $lv2 [0] ['name'] . "," . $lv3 [0] ['name'];
  1383. if (! empty ( $nature ))
  1384. $company->nature = implode ( ',', $nature );
  1385. if (! empty ( $fax ))
  1386. $company->fax = $fax;
  1387. if (! empty ( $webservice ))
  1388. $company->webservice = $webservice;
  1389. if (! empty ( $address ))
  1390. $company->address = $address;
  1391. if (! empty ( $ride ))
  1392. $company->ride = $ride;
  1393. if (! empty ( $landmarks ))
  1394. $company->landmarks = $landmarks;
  1395. if (! empty ( $office ))
  1396. $company->office = $office;
  1397. if (! empty ( $local1 ) && ! empty ( $local2 ))
  1398. $company->district = $local1 . "," . $local2 . "," . $local3;
  1399. if (! empty ( $stay ))
  1400. $company->stay = $stay;
  1401. if (empty ( $companyInfo )) {
  1402. $company->companyname = $companyname;
  1403. $company->staffid = $this->staff [0] ['sid'];
  1404. $cid = $company->insert ();
  1405. } else { // 不编辑公司,地区判断,作为新公司
  1406. // $cid=$companyInfo['cid'];
  1407. //
  1408. // $companyname=$companyInfo['companyname'];
  1409. //
  1410. // $company->cid=$cid;
  1411. //
  1412. // $company->update();
  1413. $diqu = $local1 . "," . $local2 . "," . $local3;
  1414. $cid = $companyInfo ['cid'];
  1415. $company2 = new company ();
  1416. $companyList = $company2->find ( array (
  1417. 'where' => " companyname like '" . $companyname . "'",
  1418. "asArray" => true
  1419. ) );
  1420. $falg = false;
  1421. // print_r($companyList);
  1422. foreach ( $companyList as $key => $value ) {
  1423. if ($value ['district'] != $diqu) {
  1424. $falg = true;
  1425. } elseif ($value ['district'] == $diqu) {
  1426. $falg = false;
  1427. $cid = $value ['cid'];
  1428. break;
  1429. }
  1430. }
  1431. if ($falg) {
  1432. $company->companyname = $companyname;
  1433. $company->staffid = $this->staff [0] ['sid'];
  1434. $cid = $company->insert ();
  1435. }
  1436. }
  1437. Doo::loadModel ( 'client_staff' );
  1438. $client_staff = new client_staff ();
  1439. $client->clientname = $clientname;
  1440. $client->gender = $gender;
  1441. $client->priority = $priority;
  1442. if (! empty ( $nicename ))
  1443. $client->nicename = $nicename;
  1444. if (! empty ( $telephone ))
  1445. $client->telephone = $telephone;
  1446. if (! empty ( $phone ))
  1447. $client->phone = $phone;
  1448. if (! empty ( $email ))
  1449. $client->email = $email;
  1450. if (! empty ( $qq ) && is_numeric ( $qq ))
  1451. $client->qq = $qq;
  1452. $client->companyid = $cid;
  1453. $client->companyname = $companyname;
  1454. $client->district = $local1 . "," . $local2 . "," . $local3;
  1455. // echo $client->district;
  1456. // die;
  1457. if (! empty ( $tid ))
  1458. $client->tag = implode ( ',', $tid );
  1459. if (! empty ( $fax ))
  1460. $client->fax = $fax;
  1461. if (! empty ( $webservice ))
  1462. $client->webservice = $webservice;
  1463. if (! empty ( $department ))
  1464. $client->department = $department;
  1465. if (! empty ( $position ))
  1466. $client->position = $position;
  1467. if (! empty ( $office ))
  1468. $client->office = $office;
  1469. if (! empty ( $address ))
  1470. $client->address = $address;
  1471. if (! empty ( $ride ))
  1472. $client->ride = $ride;
  1473. if (! empty ( $landmarks ))
  1474. $client->landmarks = $landmarks;
  1475. if (! empty ( $stay ))
  1476. $client->stay = $stay;
  1477. if (! empty ( $mark ))
  1478. $client->mark = $mark;
  1479. $id = $client->insert ();
  1480. $client_staff->cid = $id;
  1481. $client_staff->sid = $this->staff [0] ['sid'];
  1482. $client_staff->insert ();
  1483. // 加入地区记录
  1484. Doo::loadModel ( "district_staff" );
  1485. $district_staff = new district_staff ();
  1486. $district_staff->did = $lv1 [0] ['id'];
  1487. $district_staff->sid = $this->staff [0] ['sid'];
  1488. $district_staff->insert ();
  1489. // 日常行为
  1490. Doo::loadModel ( "action_log" );
  1491. $action_log = new action_log ();
  1492. $action_log->action = $this->staff [0] ['category'] . '<b href="javascript:void(0)" onclick="showStaff(\'' . $this->staff [0] ['sid'] . '\')" >' . $this->staff [0] ['username'] . '</b>添加了<a href="javascript:void(0)" onclick="showClick(\'' . $id . '\')">' . $clientname . '</a>(' . $companyname . ')';
  1493. $action_log->sid = $this->staff [0] ['sid'];
  1494. $action_log->cid = $this->staff [0] ['cid'];
  1495. $action_log->updatetime = date ( "Y-m-d" );
  1496. $action_log->time = date ( "H:i" );
  1497. $action_log->status = 1;
  1498. $action_log->districtid = $local1 . "," . $local2 . "," . $local3;
  1499. $action_log->city = $lv1 [0] ['name'];
  1500. $action_log->province = $lv2 [0] ['name'];
  1501. if (isset ( $nature [0] ))
  1502. $action_log->nature = $nature [0];
  1503. $action_log->company = $companyname;
  1504. $action_log->class = $action_log->iconContacts;
  1505. $action_log->insert ();
  1506. // 事实更新信息中心记录数量 需要更新3个redis 内的值
  1507. $categoryCondition = " and cid=" . $this->staff [0] ['cid'];
  1508. $sidCondition = " and sid=" . $this->staff [0] ['sid'];
  1509. // actionlog免查询值 $alCondition='';
  1510. $alCondition = ' aid>' . REMIT . ' and ';
  1511. // 个人添加数量redis值
  1512. $redisKeyCS = date ( 'Y-m-d' ) . 'SC_' . $this->staff [0] ['cid'] . '_' . $this->staff [0] ['sid'];
  1513. $action_log = new action_log ();
  1514. $actionLogClient = $action_log->find ( array (
  1515. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  1516. 'where' => $alCondition . " status=1" . $sidCondition . $categoryCondition . ' and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
  1517. 'groupby' => 'date_format(updatetime,"%m-%d")',
  1518. 'asArray' => true
  1519. ) );
  1520. $statisticsClient = array ();
  1521. for($d = 0; $d <= 29; $d ++) {
  1522. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  1523. $falgClient = true;
  1524. foreach ( $actionLogClient as $value ) {
  1525. if ($value ['updatetime'] == $MD) {
  1526. array_push ( $statisticsClient, $value ['count'] );
  1527. $falgClient = false;
  1528. break;
  1529. }
  1530. }
  1531. if ($falgClient)
  1532. array_push ( $statisticsClient, 0 );
  1533. }
  1534. $statisticsClient = array_reverse ( $statisticsClient );
  1535. $jsc = json_encode ( $statisticsClient );
  1536. $redis->set ( $redisKeyCS, $jsc );
  1537. // 办事处添加数量reids值
  1538. $redisKeyC = date ( 'Y-m-d' ) . 'SC_' . $this->staff [0] ['cid'] . '_';
  1539. $action_log = new action_log ();
  1540. $actionLogClient = $action_log->find ( array (
  1541. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  1542. 'where' => $alCondition . " status=1" . $categoryCondition . ' and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
  1543. 'groupby' => 'date_format(updatetime,"%m-%d")',
  1544. 'asArray' => true
  1545. ) );
  1546. $statisticsClient = array ();
  1547. for($d = 0; $d <= 29; $d ++) {
  1548. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  1549. $falgClient = true;
  1550. foreach ( $actionLogClient as $value ) {
  1551. if ($value ['updatetime'] == $MD) {
  1552. array_push ( $statisticsClient, $value ['count'] );
  1553. $falgClient = false;
  1554. break;
  1555. }
  1556. }
  1557. if ($falgClient)
  1558. array_push ( $statisticsClient, 0 );
  1559. }
  1560. $statisticsClient = array_reverse ( $statisticsClient );
  1561. $jsc = json_encode ( $statisticsClient );
  1562. $redis->set ( $redisKeyC, $jsc );
  1563. // 全员添加数量的redis值
  1564. $redisKey = date ( 'Y-m-d' ) . 'SC__';
  1565. $action_log = new action_log ();
  1566. $actionLogClient = $action_log->find ( array (
  1567. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  1568. 'where' => $alCondition . ' status=1 and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
  1569. 'groupby' => 'date_format(updatetime,"%m-%d")',
  1570. 'asArray' => true
  1571. ) );
  1572. $statisticsClient = array ();
  1573. for($d = 0; $d <= 29; $d ++) {
  1574. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  1575. $falgClient = true;
  1576. foreach ( $actionLogClient as $value ) {
  1577. if ($value ['updatetime'] == $MD) {
  1578. array_push ( $statisticsClient, $value ['count'] );
  1579. $falgClient = false;
  1580. break;
  1581. }
  1582. }
  1583. if ($falgClient)
  1584. array_push ( $statisticsClient, 0 );
  1585. }
  1586. $statisticsClient = array_reverse ( $statisticsClient );
  1587. $jsc = json_encode ( $statisticsClient );
  1588. $redis->set ( $redisKey, $jsc );
  1589. }
  1590. return "/contacts";
  1591. }
  1592. function addClientByCompany() {
  1593. $companyKey = $this->get_args ( 'companyKey' ) ? $this->get_args ( 'companyKey' ) : "";
  1594. $clientname = $this->get_args ( 'clientname' ) ? $this->get_args ( 'clientname' ) : "";
  1595. $gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : "";
  1596. $nicename = $this->get_args ( 'nicename' ) ? $this->get_args ( 'nicename' ) : "";
  1597. $telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : "";
  1598. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1599. $email = $this->get_args ( 'email' ) ? $this->get_args ( 'email' ) : "";
  1600. $qq = $this->get_args ( 'qq' ) ? $this->get_args ( 'qq' ) : "";
  1601. $tid = $this->get_args ( 'tid' ) ? $this->get_args ( 'tid' ) : "";
  1602. //$companyname = $this->get_args ( 'companyname' ) ? $this->get_args ( 'companyname' ) : "";
  1603. $local1 = $this->get_args ( 'lv21' ) ? $this->get_args ( 'lv21' ) : "";
  1604. $local2 = $this->get_args ( 'lv22' ) ? $this->get_args ( 'lv22' ) : "";
  1605. $local3 = $this->get_args ( 'lv23' ) ? $this->get_args ( 'lv23' ) : "";
  1606. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  1607. $fax = $this->get_args ( 'fax' ) ? $this->get_args ( 'fax' ) : "";
  1608. $webservice = $this->get_args ( 'webservice' ) ? $this->get_args ( 'webservice' ) : "";
  1609. $department = $this->get_args ( 'department' ) ? $this->get_args ( 'department' ) : "";
  1610. $position = $this->get_args ( 'position' ) ? $this->get_args ( 'position' ) : "";
  1611. $office = $this->get_args ( 'office' ) ? $this->get_args ( 'office' ) : "";
  1612. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1613. $ride = $this->get_args ( 'ride' ) ? $this->get_args ( 'ride' ) : "";
  1614. $landmarks = $this->get_args ( 'landmarks' ) ? $this->get_args ( 'landmarks' ) : "";
  1615. $priority = $this->get_args ( 'priority' ) ? $this->get_args ( 'priority' ) : "";
  1616. $stay = $this->get_args ( 'stay' ) ? $this->get_args ( 'stay' ) : "";
  1617. $mark = $this->get_args ( 'mark' ) ? $this->get_args ( 'mark' ) : "";
  1618. $clientname = trim ( $clientname );
  1619. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  1620. if (empty ( $token )) {
  1621. die ( 'illegal request-token' );
  1622. } else {
  1623. session_start ();
  1624. if ($_SESSION ['token_' . $this->staff [0] ['sidKey']] != $token) {
  1625. header ( 'Content-Type:text/html;charset=utf-8' );
  1626. die ( '请勿重复填写客户资料' );
  1627. } else {
  1628. $_SESSION ['token_' . $this->staff [0] ['sidKey']] = '';
  1629. }
  1630. }
  1631. if (empty ( $this->staff [0] ['sid'] ))
  1632. return "/contacts";
  1633. if (! empty ( $clientname )) {
  1634. // 相同的公司和客户
  1635. Doo::loadModel ( 'company' );
  1636. $company = new company ();
  1637. Doo::loadModel ( 'client' );
  1638. $client = new client ();
  1639. $redis = new Redis ();
  1640. $redis->connect ( '127.0.0.1', '6379' );
  1641. $cinfo = $client->getClientByNameT ( $clientname );
  1642. Doo::loadModel ( 'district' );
  1643. $district = new district ();
  1644. // 修改
  1645. Doo::loadClass ( 'XDeode' );
  1646. $XDeode = new XDeode ( 5 );
  1647. $comId = $XDeode->decode ( $companyKey );
  1648. $companyInfo = $company->getOne ( array (
  1649. 'where' => "cid = '" . $comId . "'",
  1650. "asArray" => true
  1651. ) );
  1652. // 更新公司信息
  1653. $lv1 = $district->getbyid ( $local1 );
  1654. $lv2 = $district->getbyid ( $local2 );
  1655. $lv3 = $district->getbyid ( $local3 );
  1656. if (empty ( $lv1 ))
  1657. $lv1 [0] ['name'] = "";
  1658. if (empty ( $lv2 ))
  1659. $lv2 [0] ['name'] = "";
  1660. if (empty ( $lv3 ))
  1661. $lv3 [0] ['name'] = "";
  1662. // if (! empty ( $local1 ) && ! empty ( $local2 ))
  1663. // $company->local = $lv1 [0] ['name'] . "," . $lv2 [0] ['name'] . "," . $lv3 [0] ['name'];
  1664. // if (! empty ( $nature ))
  1665. // $company->nature = implode ( ',', $nature );
  1666. // if (! empty ( $fax ))
  1667. // $company->fax = $fax;
  1668. // if (! empty ( $webservice ))
  1669. // $company->webservice = $webservice;
  1670. // if (! empty ( $address ))
  1671. // $company->address = $address;
  1672. // if (! empty ( $ride ))
  1673. // $company->ride = $ride;
  1674. // if (! empty ( $landmarks ))
  1675. // $company->landmarks = $landmarks;
  1676. // if (! empty ( $office ))
  1677. // $company->office = $office;
  1678. // if (! empty ( $local1 ) && ! empty ( $local2 ))
  1679. // $company->district = $local1 . "," . $local2 . "," . $local3;
  1680. // if (! empty ( $stay ))
  1681. // $company->stay = $stay;
  1682. $cid = $companyInfo ['cid'];
  1683. if (empty ( $companyInfo )) {
  1684. } else { // 不编辑公司,地区判断,作为新公司
  1685. // $cid=$companyInfo['cid'];
  1686. //
  1687. // $companyname=$companyInfo['companyname'];
  1688. //
  1689. // $company->cid=$cid;
  1690. //
  1691. // $company->update();
  1692. // $diqu = $local1 . "," . $local2 . "," . $local3;
  1693. // $cid = $companyInfo ['cid'];
  1694. // $company2 = new company ();
  1695. // $companyList = $company2->find ( array (
  1696. // 'where' => " companyname like '" . $companyname . "'",
  1697. // "asArray" => true
  1698. // ) );
  1699. // $falg = false;
  1700. // // print_r($companyList);
  1701. // foreach ( $companyList as $key => $value ) {
  1702. // if ($value ['district'] != $diqu) {
  1703. // $falg = true;
  1704. // } elseif ($value ['district'] == $diqu) {
  1705. // $falg = false;
  1706. // $cid = $value ['cid'];
  1707. // break;
  1708. // }
  1709. // }
  1710. // if ($falg) {
  1711. // $company->companyname = $companyname;
  1712. // $company->staffid = $this->staff [0] ['sid'];
  1713. // $cid = $company->insert ();
  1714. // }
  1715. }
  1716. Doo::loadModel ( 'client_staff' );
  1717. $client_staff = new client_staff ();
  1718. $client->clientname = $clientname;
  1719. $client->gender = $gender;
  1720. $client->priority = $priority;
  1721. if (! empty ( $nicename ))
  1722. $client->nicename = $nicename;
  1723. if (! empty ( $telephone ))
  1724. $client->telephone = $telephone;
  1725. if (! empty ( $phone ))
  1726. $client->phone = $phone;
  1727. if (! empty ( $email ))
  1728. $client->email = $email;
  1729. if (! empty ( $qq ) && is_numeric ( $qq ))
  1730. $client->qq = $qq;
  1731. $client->companyid = $cid;
  1732. $client->companyname = $companyInfo['companyname'];
  1733. $client->district = $local1 . "," . $local2 . "," . $local3;
  1734. // echo $client->district;
  1735. // die;
  1736. if (! empty ( $tid ))
  1737. $client->tag = implode ( ',', $tid );
  1738. if (! empty ( $fax ))
  1739. $client->fax = $fax;
  1740. if (! empty ( $webservice ))
  1741. $client->webservice = $webservice;
  1742. if (! empty ( $department ))
  1743. $client->department = $department;
  1744. if (! empty ( $position ))
  1745. $client->position = $position;
  1746. if (! empty ( $office ))
  1747. $client->office = $office;
  1748. if (! empty ( $address ))
  1749. $client->address = $address;
  1750. if (! empty ( $ride ))
  1751. $client->ride = $ride;
  1752. if (! empty ( $landmarks ))
  1753. $client->landmarks = $landmarks;
  1754. if (! empty ( $stay ))
  1755. $client->stay = $stay;
  1756. if (! empty ( $mark ))
  1757. $client->mark = $mark;
  1758. $id = $client->insert ();
  1759. $client_staff->cid = $id;
  1760. $client_staff->sid = $this->staff [0] ['sid'];
  1761. $client_staff->insert ();
  1762. // 加入地区记录
  1763. Doo::loadModel ( "district_staff" );
  1764. $district_staff = new district_staff ();
  1765. $district_staff->did = $lv1 [0] ['id'];
  1766. $district_staff->sid = $this->staff [0] ['sid'];
  1767. $district_staff->insert ();
  1768. // 日常行为
  1769. Doo::loadModel ( "action_log" );
  1770. $action_log = new action_log ();
  1771. $action_log->action = $this->staff [0] ['category'] . '<b href="javascript:void(0)" onclick="showStaff(\'' . $this->staff [0] ['sid'] . '\')" >' . $this->staff [0] ['username'] . '</b>添加了<a href="javascript:void(0)" onclick="showClick(\'' . $id . '\')">' . $clientname . '</a>(' . $companyInfo['companyname'] . ')';
  1772. $action_log->sid = $this->staff [0] ['sid'];
  1773. $action_log->cid = $this->staff [0] ['cid'];
  1774. $action_log->updatetime = date ( "Y-m-d" );
  1775. $action_log->time = date ( "H:i" );
  1776. $action_log->status = 1;
  1777. $action_log->districtid = $local1 . "," . $local2 . "," . $local3;
  1778. $action_log->city = $lv1 [0] ['name'];
  1779. $action_log->province = $lv2 [0] ['name'];
  1780. if (isset ( $nature [0] ))
  1781. $action_log->nature = $nature [0];
  1782. $action_log->company = $companyInfo['companyname'];
  1783. $action_log->class = $action_log->iconContacts;
  1784. $action_log->insert ();
  1785. // 事实更新信息中心记录数量 需要更新3个redis 内的值
  1786. $categoryCondition = " and cid=" . $this->staff [0] ['cid'];
  1787. $sidCondition = " and sid=" . $this->staff [0] ['sid'];
  1788. // actionlog免查询值 $alCondition='';
  1789. $alCondition = ' aid>' . REMIT . ' and ';
  1790. // 个人添加数量redis值
  1791. $redisKeyCS = date ( 'Y-m-d' ) . 'SC_' . $this->staff [0] ['cid'] . '_' . $this->staff [0] ['sid'];
  1792. $action_log = new action_log ();
  1793. $actionLogClient = $action_log->find ( array (
  1794. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  1795. 'where' => $alCondition . " status=1" . $sidCondition . $categoryCondition . ' and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
  1796. 'groupby' => 'date_format(updatetime,"%m-%d")',
  1797. 'asArray' => true
  1798. ) );
  1799. $statisticsClient = array ();
  1800. for($d = 0; $d <= 29; $d ++) {
  1801. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  1802. $falgClient = true;
  1803. foreach ( $actionLogClient as $value ) {
  1804. if ($value ['updatetime'] == $MD) {
  1805. array_push ( $statisticsClient, $value ['count'] );
  1806. $falgClient = false;
  1807. break;
  1808. }
  1809. }
  1810. if ($falgClient)
  1811. array_push ( $statisticsClient, 0 );
  1812. }
  1813. $statisticsClient = array_reverse ( $statisticsClient );
  1814. $jsc = json_encode ( $statisticsClient );
  1815. $redis->set ( $redisKeyCS, $jsc );
  1816. // 办事处添加数量reids值
  1817. $redisKeyC = date ( 'Y-m-d' ) . 'SC_' . $this->staff [0] ['cid'] . '_';
  1818. $action_log = new action_log ();
  1819. $actionLogClient = $action_log->find ( array (
  1820. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  1821. 'where' => $alCondition . " status=1" . $categoryCondition . ' and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
  1822. 'groupby' => 'date_format(updatetime,"%m-%d")',
  1823. 'asArray' => true
  1824. ) );
  1825. $statisticsClient = array ();
  1826. for($d = 0; $d <= 29; $d ++) {
  1827. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  1828. $falgClient = true;
  1829. foreach ( $actionLogClient as $value ) {
  1830. if ($value ['updatetime'] == $MD) {
  1831. array_push ( $statisticsClient, $value ['count'] );
  1832. $falgClient = false;
  1833. break;
  1834. }
  1835. }
  1836. if ($falgClient)
  1837. array_push ( $statisticsClient, 0 );
  1838. }
  1839. $statisticsClient = array_reverse ( $statisticsClient );
  1840. $jsc = json_encode ( $statisticsClient );
  1841. $redis->set ( $redisKeyC, $jsc );
  1842. // 全员添加数量的redis值
  1843. $redisKey = date ( 'Y-m-d' ) . 'SC__';
  1844. $action_log = new action_log ();
  1845. $actionLogClient = $action_log->find ( array (
  1846. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  1847. 'where' => $alCondition . ' status=1 and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
  1848. 'groupby' => 'date_format(updatetime,"%m-%d")',
  1849. 'asArray' => true
  1850. ) );
  1851. $statisticsClient = array ();
  1852. for($d = 0; $d <= 29; $d ++) {
  1853. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  1854. $falgClient = true;
  1855. foreach ( $actionLogClient as $value ) {
  1856. if ($value ['updatetime'] == $MD) {
  1857. array_push ( $statisticsClient, $value ['count'] );
  1858. $falgClient = false;
  1859. break;
  1860. }
  1861. }
  1862. if ($falgClient)
  1863. array_push ( $statisticsClient, 0 );
  1864. }
  1865. $statisticsClient = array_reverse ( $statisticsClient );
  1866. $jsc = json_encode ( $statisticsClient );
  1867. $redis->set ( $redisKey, $jsc );
  1868. }
  1869. return "/contacts";
  1870. }
  1871. function mycompany() {
  1872. $search = $this->get_args ( 'search' ) ? $this->get_args ( 'search' ) : "";
  1873. $districtLv = $this->get_args ( 'districtLv' ) ? $this->get_args ( 'districtLv' ) : 0;
  1874. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  1875. $lv1 = $this->get_args ( 'lv1' ) ? $this->get_args ( 'lv1' ) : 0;
  1876. $lv2 = $this->get_args ( 'lv2' ) ? $this->get_args ( 'lv2' ) : 0;
  1877. $lv3 = $this->get_args ( 'lv3' ) ? $this->get_args ( 'lv3' ) : 0;
  1878. $tagList = $this->get_args ( 'tag' ) ? $this->get_args ( 'tag' ) : array ();
  1879. if ($lv1 == 0) {
  1880. $lv1 = isset ( $this->params ['lv1'] ) && is_numeric ( $this->params ['lv1'] ) ? $this->params ['lv1'] : 0;
  1881. if ($lv1 != 0)
  1882. $districtLv = 1;
  1883. }
  1884. if ($lv2 == 0) {
  1885. $lv2 = isset ( $this->params ['lv2'] ) && is_numeric ( $this->params ['lv2'] ) ? $this->params ['lv2'] : 0;
  1886. if ($lv2 != 0)
  1887. $districtLv = 2;
  1888. }
  1889. if ($lv3 == 0) {
  1890. $lv3 = isset ( $this->params ['lv3'] ) && is_numeric ( $this->params ['lv3'] ) ? $this->params ['lv3'] : 0;
  1891. if ($lv2 != 0)
  1892. $districtLv = 3;
  1893. }
  1894. if (empty ( $search ))
  1895. $search = urldecode ( isset ( $this->params ['search'] ) ? $this->params ['search'] : "" );
  1896. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1897. $data['search']=$search;
  1898. $data ['memu'] = "contacts";
  1899. $data ['staff'] = $this->staff;
  1900. //Doo::loadModel ( 'tag' );
  1901. //$tag = new tag ();
  1902. Doo::loadModel ( 'district' );
  1903. Doo::loadModel ( 'company' );
  1904. Doo::loadModel ( 'client' );
  1905. Doo::loadModel ( 'L_category' );
  1906. $lcategory = new L_category ();
  1907. $client = new client ();
  1908. $company = new company ();
  1909. $district = new district ();
  1910. Doo::loadModel ( 'tagCompany' );
  1911. $tagCompany = new tagCompany ();
  1912. Doo::loadModel ( 'tagCompanyNexus' );
  1913. $tagCompanyNexus = new tagCompanyNexus ();
  1914. $data ['district2'] = $district->get_lv ( 1 );
  1915. //$category = $lcategory->getCategoryById ( $this->staff [0] ['cid'], $this->staff [0] ['othercid'] );
  1916. $cateStr = " cid =0 ";
  1917. Doo::loadClass ( 'XDeode' );
  1918. $XDeode = new XDeode ( 5 );
  1919. $didList = explode ( ',', $this->staff [0] ['did'] );
  1920. $didList = array_filter ( $didList );
  1921. $didListContont = array ();
  1922. if (! empty ( $didList )) {
  1923. foreach ( $didList as $key => $value ) {
  1924. array_push ( $didListContont, $XDeode->decode ( $value ) );
  1925. }
  1926. $data ['district'] = $district->getDistrictInId ( implode ( ',', $didListContont ) ); // $district->get_lvByStaffid ( 1, $this->staff [0] ['sid'] );
  1927. } else {
  1928. $data ['district'] = array ();
  1929. }
  1930. $sqstr = '';
  1931. if (! empty ( $didListContont )) {
  1932. foreach ( $didListContont as $key => $value ) {
  1933. if ($key != 0) {
  1934. $sqstr .= " or district like '" . $value . ",%'";
  1935. }
  1936. }
  1937. $cateStr = " ( district like '" . $didListContont [0] . ",%'" . $sqstr . ')';
  1938. }
  1939. // $list = array ();
  1940. // foreach ( $category as $key => $value ) {
  1941. // array_push ( $list, " district like '" . $value ['districtid'] . ",%' " );
  1942. // }
  1943. // if ($this->staff [0] ['isadmin'] != 1)
  1944. // $cateStr = implode ( " or ", $list );
  1945. // else
  1946. // $cateStr = " 1";
  1947. //
  1948. // if (! empty ( $nature ))
  1949. // $cateStr = " 1";
  1950. $size = 300;
  1951. $data ['htmllv2'] = array ();
  1952. $data ['htmllv3'] = array ();
  1953. $condition = "";
  1954. if ($districtLv == 1) {
  1955. $condition = "";
  1956. if (! empty ( $lv1 )) {
  1957. $condition = " district like '" . $lv1 . ",%'";
  1958. $data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
  1959. }
  1960. }
  1961. if ($districtLv == 2) {
  1962. if (! empty ( $lv2 ))
  1963. $condition = " district like '" . $lv1 . "," . $lv2 . ",%'";
  1964. else
  1965. $condition = " district like '" . $lv1 . ",%'";
  1966. $data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
  1967. $data ['htmllv3'] = $district->get_lvByid ( 2, $lv2 );
  1968. }
  1969. if ($districtLv == 3) {
  1970. if (! empty ( $lv3 ))
  1971. $condition = " district like '" . $lv1 . "," . $lv2 . "," . $lv3 . "'";
  1972. else
  1973. $condition = " district like '" . $lv1 . "," . $lv2 . ",%'";
  1974. $data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
  1975. $data ['htmllv3'] = $district->get_lvByid ( 2, $lv2 );
  1976. }
  1977. $districtCount = $condition;
  1978. if (! empty ( $condition ))
  1979. $cateStr = $condition;
  1980. if (!empty($search)){
  1981. $cateStr.=" and companyname like '%".$search."%' ";
  1982. }
  1983. if (! empty ( $nature ))
  1984. $cateStr .= " and nature like '%" . $nature . "%'";
  1985. // echo "<div style='display:none'>".$cateStr."</div><br/>";
  1986. $tagSQL = false;
  1987. if (! empty ( $tagList )) {
  1988. $tagSQL = true;
  1989. foreach ( $tagList as $value ) {
  1990. $cateStr .= " and a.tag like '%" . $value . "%' ";
  1991. }
  1992. }
  1993. if ($this->staff [0] ['isadmin'] != 1) {
  1994. $pageinfo = $this->get_Tpage ( "CLD_company", $cateStr, $page, $size, "", $tagSQL );
  1995. } else {
  1996. if ($tagSQL)
  1997. $pageinfo = $this->get_Tpage ( "CLD_company", $cateStr, $page, $size, "", $tagSQL );
  1998. else {
  1999. $total_page = $company->count ( array () );
  2000. $total = intval ( $total_page / $size );
  2001. $pageinfo ['total_page'] = ($total_page % $size) == 0 ? $total : $total + 1;
  2002. }
  2003. }
  2004. $k = "";
  2005. for($i = 1; $i <= $pageinfo ['total_page']; $i ++) {
  2006. if ($page == $i)
  2007. $k .= "<option value='" . $search . ":" . $i . ":" . $lv1 . ":" . $lv2 . ":" . $lv3 . "' selected>第" . $i . "页</option>";
  2008. else
  2009. $k .= "<option value='" . $search . ":" . $i . ":" . $lv1 . ":" . $lv2 . ":" . $lv3 . "'>第" . $i . "页</option>";
  2010. }
  2011. $data ['pageinfo'] = $k;
  2012. $data ['company'] = $company->getCompanyByDistrict ( $this->staff [0] ['sid'], $cateStr, $this->staff [0] ['isadmin'], $page, $size, $tagSQL );
  2013. // if ($this->staff [0] ['isadmin'] != 1) {
  2014. // $data ['district'] = $district->get_lvByStaffid ( 1, $this->staff [0] ['sid'] );
  2015. // } else {
  2016. // $data ['district'] = $data ['district2'];
  2017. // }
  2018. // 获得标签
  2019. $ClientTagList = $tagCompanyNexus->getTagClientBySid ( $this->staff [0] ['sid'] );
  2020. foreach ( $ClientTagList as $key => $value ) {
  2021. $ClientTagList [$key] ['taginfo'] = $tagCompany->getTagByTidL ( $value ['tag'] );
  2022. }
  2023. foreach ( $data ['company'] as $key => $value ) {
  2024. if (! empty ( $value ['cid'] )) {
  2025. $data ['company'] [$key] ['taginfo'] = array ();
  2026. $data ['company'] [$key] ['tag'] = "";
  2027. foreach ( $ClientTagList as $k => $v ) {
  2028. if ($value ['cid'] == $v ['company']) {
  2029. $data ['company'] [$key] ['taginfo'] = $v ['taginfo'];
  2030. $data ['company'] [$key] ['tag'] = $v ['tag'];
  2031. }
  2032. }
  2033. }
  2034. }
  2035. $comcid = $countL = array ();
  2036. foreach ( $data ['company'] as $key => $value ) {
  2037. array_push ( $comcid, $value ['cid'] );
  2038. }
  2039. $comcid = implode ( ",", $comcid );
  2040. if (! empty ( $comcid ))
  2041. $countL = $client->getCountByCompany ( $comcid );
  2042. foreach ( $data ['company'] as $key => $value ) {
  2043. $data ['company'] [$key] ['count'] = 0;
  2044. foreach ( $countL as $k => $v ) {
  2045. if ($value ['cid'] == $v ['companyid']) {
  2046. $data ['company'] [$key] ['count'] = $v ['count'];
  2047. break;
  2048. }
  2049. }
  2050. }
  2051. $CC1 = "";
  2052. $CC2 = "";
  2053. $CC3 = "";
  2054. $natureHtml = '';
  2055. if (! empty ( $districtCount )) {
  2056. $clientCount = $company->find ( array (
  2057. 'select' => 'district',
  2058. 'where' => "district like '" . $lv1 . ",%'",
  2059. 'asArray' => TRUE
  2060. ) );
  2061. $CC1 = count ( $clientCount );
  2062. if (! empty ( $clientCount ) && ! empty ( $lv2 )) {
  2063. $CC2 = 0;
  2064. foreach ( $clientCount as $key => $value ) {
  2065. if (strpos ( $value ['district'], $lv2 )) {
  2066. $CC2 ++;
  2067. }
  2068. }
  2069. }
  2070. if (! empty ( $clientCount ) && ! empty ( $lv3 )) {
  2071. $CC3 = 0;
  2072. foreach ( $clientCount as $key => $value ) {
  2073. if (strpos ( $value ['district'], $lv3 )) {
  2074. $CC3 ++;
  2075. }
  2076. }
  2077. }
  2078. $clientCount = $company->find ( array (
  2079. 'select' => 'district,nature',
  2080. 'where' => $districtCount,
  2081. 'asArray' => TRUE
  2082. ) );
  2083. $natureCount = array ();
  2084. foreach ( $this->nature as $value ) {
  2085. $natureCount [$value] = 0;
  2086. foreach ( $clientCount as $v ) {
  2087. $ak = explode ( ",", $v ['nature'] );
  2088. foreach ( $ak as $a ) {
  2089. if ($value == $a) {
  2090. $natureCount [$value] ++;
  2091. }
  2092. }
  2093. }
  2094. }
  2095. }
  2096. $natureHtml = '';
  2097. foreach ( $this->nature as $value ) {
  2098. $natureHtml .= '<a href="javascript:void(0)" ';
  2099. if ($value == $nature)
  2100. $natureHtml .= 'class="now"';
  2101. if (isset ( $natureCount [$value] ))
  2102. $natureHtml .= 'onclick="showNature(\'' . $value . '\',this)">' . $value . '(' . $natureCount [$value] . ')</a>';
  2103. else
  2104. $natureHtml .= 'onclick="showNature(\'' . $value . '\',this)">' . $value . '</a>';
  2105. }
  2106. $taglist = $tagCompany->find ( array (
  2107. 'where' => 'sid=' . $this->staff [0] ['sid'],
  2108. 'asArray' => TRUE
  2109. ) );
  2110. if (empty ( $taglist )) {
  2111. for($i = 1; $i <= 7; $i ++) {
  2112. $tag = new tagCompany ();
  2113. $tag->name = "个人标签";
  2114. $tag->sid = $this->staff [0] ['sid'];
  2115. $tag->colorid = $i;
  2116. $tag->insert ();
  2117. }
  2118. }
  2119. $data ['product'] = array ();
  2120. $data ['tagList'] = $tagList;
  2121. $data ['tag'] = $tagCompany->getAllBySid ( $this->staff [0] ['sid'] );
  2122. $data ['natureHtml'] = $natureHtml;
  2123. $data ['CC1'] = $CC1;
  2124. $data ['CC2'] = $CC2;
  2125. $data ['CC3'] = $CC3;
  2126. $data ['lv1'] = $lv1;
  2127. $data ['lv2'] = $lv2;
  2128. $data ['lv3'] = $lv3;
  2129. $data ['districtLv'] = $districtLv;
  2130. $data ['Hnature'] = $nature;
  2131. $data ['nature'] = $this->nature;
  2132. $this->render ( "/contacts_company", $data );
  2133. }
  2134. function contacts() {
  2135. session_start ();
  2136. $data ['memu'] = "contacts";
  2137. $data ['staff'] = $this->staff;
  2138. $search = $this->get_args ( 'search' ) ? trim ( $this->get_args ( 'search' ) ) : "";
  2139. if (empty ( $search ))
  2140. $search = urldecode ( isset ( $this->params ['search'] ) ? $this->params ['search'] : "" );
  2141. $lv1 = $this->get_args ( 'lv1' ) ? $this->get_args ( 'lv1' ) : 0;
  2142. $lv2 = $this->get_args ( 'lv2' ) ? $this->get_args ( 'lv2' ) : 0;
  2143. $lv3 = $this->get_args ( 'lv3' ) ? $this->get_args ( 'lv3' ) : 0;
  2144. $lv4 = $this->get_args ( 'lv4' ) ? $this->get_args ( 'lv4' ) : "";
  2145. $tagList = $this->get_args ( 'tag' ) ? $this->get_args ( 'tag' ) : array ();
  2146. $tooltip = $this->get_args ( 'tooltip' ) ? $this->get_args ( 'tooltip' ) : "";
  2147. $districtLv = $this->get_args ( 'districtLv' ) ? $this->get_args ( 'districtLv' ) : 0;
  2148. if ($lv1 == 0) {
  2149. $lv1 = isset ( $this->params ['lv1'] ) && is_numeric ( $this->params ['lv1'] ) ? $this->params ['lv1'] : 0;
  2150. if ($lv1 != 0)
  2151. $districtLv = 1;
  2152. }
  2153. if ($lv2 == 0) {
  2154. $lv2 = isset ( $this->params ['lv2'] ) && is_numeric ( $this->params ['lv2'] ) ? $this->params ['lv2'] : 0;
  2155. if ($lv2 != 0)
  2156. $districtLv = 2;
  2157. }
  2158. if ($lv3 == 0) {
  2159. $lv3 = isset ( $this->params ['lv3'] ) && is_numeric ( $this->params ['lv3'] ) ? $this->params ['lv3'] : 0;
  2160. if ($lv2 != 0)
  2161. $districtLv = 3;
  2162. }
  2163. $sortV = $this->get_args ( 'sortV' ) ? $this->get_args ( 'sortV' ) : "h";
  2164. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2165. Doo::loadModel ( 'client_staff' );
  2166. Doo::loadModel ( 'client' );
  2167. Doo::loadModel ( 'tag' );
  2168. Doo::loadModel ( 'district' );
  2169. Doo::loadModel ( 'tag_client' );
  2170. Doo::loadModel ( 'L_category' );
  2171. Doo::loadModel ( 'longle' );
  2172. Doo::loadModel ( 'C_tooltip' );
  2173. $c_tooltip = new C_tooltip ();
  2174. $longle = new longle ();
  2175. $client = new client ();
  2176. $category = new L_category ();
  2177. $tagClient = new tag_client ();
  2178. $district = new district ();
  2179. $tag = new tag ();
  2180. $client_staff = new client_staff ();
  2181. $data ['tag'] = $tag->getAllBySid ( $this->staff [0] ['sid'] );
  2182. $data ['district2'] = $district->get_lv ( 1 );
  2183. $page_size = 200;
  2184. $linfo = $category->getCategoryById ( $this->staff [0] ['cid'], $this->staff ['0'] ['othercid'] );
  2185. $staffid = $condition = $a = "";
  2186. // if ($this->staff [0] ['isadmin'] != 1) {
  2187. // 加入办事处地区
  2188. Doo::loadClass ( 'XDeode' );
  2189. $XDeode = new XDeode ( 5 );
  2190. $didList = explode ( ',', $this->staff [0] ['did'] );
  2191. $didList = array_filter ( $didList );
  2192. $didListContont = array ();
  2193. if (! empty ( $didList )) {
  2194. foreach ( $didList as $key => $value ) {
  2195. array_push ( $didListContont, $XDeode->decode ( $value ) );
  2196. }
  2197. $data ['district'] = $district->getDistrictInId ( implode ( ',', $didListContont ) ); // $district->get_lvByStaffid ( 1, $this->staff [0] ['sid'] );
  2198. } else {
  2199. $data ['district'] = array ();
  2200. }
  2201. if (! empty ( $search ))
  2202. $sch = " and ( address like '%" . $search . "%' or clientname like '%" . $search . "%' or companyname like '%" . $search . "%' or qq like '%" . $search . "%' or telephone like '%" . $search . "%' or phone like '%" . $search . "%')";
  2203. else {
  2204. $a = '';
  2205. $sqstr = '';
  2206. if (! empty ( $didListContont )) {
  2207. $a = '';
  2208. foreach ( $didListContont as $key => $value ) {
  2209. if ($key != 0) {
  2210. $sqstr .= " or b.district like '" . $value . ",%'";
  2211. }
  2212. }
  2213. $a = "and ( b.district like '" . $didListContont [0] . ",%'" . $sqstr . ')';
  2214. }
  2215. if (! empty ( $tooltip ))
  2216. $sch = "";
  2217. $staffid = $data ['staff'] [0] ['sid'];
  2218. }
  2219. $data ['htmllv2'] = $data ['htmllv3'] = array ();
  2220. if ($districtLv == 1) {
  2221. $a = "";
  2222. $condition = "";
  2223. if (! empty ( $lv1 )) {
  2224. $condition .= " and district like '" . $lv1 . ",%'";
  2225. $data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
  2226. }
  2227. }
  2228. if ($districtLv == 2) {
  2229. $a = "";
  2230. if (! empty ( $lv2 ))
  2231. $condition .= " and district like '" . $lv1 . "," . $lv2 . ",%'";
  2232. else
  2233. $condition .= " and district like '" . $lv1 . ",%'";
  2234. $data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
  2235. $data ['htmllv3'] = $district->get_lvByid ( 2, $lv2 );
  2236. }
  2237. if ($districtLv == 3) {
  2238. $a = "";
  2239. if (! empty ( $lv3 ))
  2240. $condition .= " and district like '" . $lv1 . "," . $lv2 . "," . $lv3 . "'";
  2241. else
  2242. $condition .= " and district like '" . $lv1 . "," . $lv2 . ",%'";
  2243. $data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
  2244. $data ['htmllv3'] = $district->get_lvByid ( 2, $lv2 );
  2245. }
  2246. $condition .= $a;
  2247. $districtCount = $condition;
  2248. if (! empty ( $lv4 )) {
  2249. $condition .= " and nature like '%" . $lv4 . "%'";
  2250. }
  2251. $tagSQL = false;
  2252. if (! empty ( $tagList )) {
  2253. $tagSQL = true;
  2254. foreach ( $tagList as $value ) {
  2255. $condition .= " and c.tag like '%" . $value . "%' ";
  2256. }
  2257. $search = "";
  2258. }
  2259. if (! empty ( $search ))
  2260. $condition .= $sch;
  2261. // if(!empty($tooltip))
  2262. // $condition.=" and tooltip like '%".$tooltip."%'";
  2263. $pageinfo = array (
  2264. 'lower' => 0,
  2265. 'total_page' => 0,
  2266. 'total_data' => 0
  2267. );
  2268. if (! empty ( $didListContont ) || ! empty ( $search ))
  2269. $pageinfo = $this->get_page ( "CLD_client_staff", $condition, $page, $page_size, "", "", "", $staffid, $search, $tooltip, $this->staff [0] ['cid'], $tagSQL );
  2270. if ($sortV == "h") { // order by a.cid desc
  2271. $limit = " order by cid desc limit " . $pageinfo ['lower'] . " , " . $page_size . " ";
  2272. }
  2273. if ($sortV == "g") { // order by updatetime desc
  2274. $limit = " limit " . $pageinfo ['lower'] . " , " . $page_size . " ";
  2275. }
  2276. if ($sortV == "f") { // order by updatetime desc
  2277. $limit = " limit " . $pageinfo ['lower'] . " , " . $page_size . " ";
  2278. }
  2279. if ($sortV == "i") { // order by servicetime desc
  2280. $limit = " limit " . $pageinfo ['lower'] . " , " . $page_size . " ";
  2281. }
  2282. // 检索是全局
  2283. // echo $condition;
  2284. $data ['clientInfo'] = array ();
  2285. if (! empty ( $didListContont ) || ! empty ( $search ))
  2286. $data ['clientInfo'] = $client_staff->getClientByStaff ( $condition, $limit, $staffid, $this->staff [0] ['sid'], $search, $tooltip, $this->staff [0] ['cid'], $tagSQL );
  2287. // 获取其他办事处的客户
  2288. // if(!empty($districtstr)){
  2289. // $buclient=$client->getClientByDistrict($districtstr);
  2290. //
  2291. // foreach ($buclient as $key=>$vlaue){
  2292. //
  2293. // $falg=true;
  2294. //
  2295. // foreach ($data['clientInfo'] as $y=>$v){
  2296. // if($vlaue['clientname']==$v['clientname']&&$vlaue['companyname']==$v['companyname'])
  2297. // $falg=false;
  2298. // }
  2299. // if($falg)
  2300. // array_push($data['clientInfo'], $vlaue);
  2301. // }
  2302. //
  2303. // }
  2304. $k = "";
  2305. for($i = 1; $i <= $pageinfo ['total_page']; $i ++) {
  2306. if ($page == $i)
  2307. $k .= "<option value='" . $search . ":" . $i . ":" . $lv1 . ":" . $lv2 . ":" . $lv3 . "' selected>第" . $i . "页</option>";
  2308. else
  2309. $k .= "<option value='" . $search . ":" . $i . ":" . $lv1 . ":" . $lv2 . ":" . $lv3 . "'>第" . $i . "页</option>";
  2310. }
  2311. $data ['pageinfo'] = $k;
  2312. Doo::loadModel ( 'product' );
  2313. $product = new product ();
  2314. $data ['nature'] = $this->nature;
  2315. $data ['product'] = $product->getProudct ();
  2316. // 获得标签
  2317. $ClientTagList = $tagClient->getTagClientBySid ( $this->staff [0] ['sid'] );
  2318. $toollist = $c_tooltip->find ( array (
  2319. 'where' => 'cateid=' . $this->staff [0] ['cid'],
  2320. 'asArray' => true
  2321. ) );
  2322. // $ToolTipList=$
  2323. foreach ( $ClientTagList as $key => $value ) {
  2324. $ClientTagList [$key] ['taginfo'] = $tag->getTagByTidL ( $value ['tag'] );
  2325. }
  2326. foreach ( $data ['clientInfo'] as $key => $value ) {
  2327. if (! empty ( $value ['cid'] )) {
  2328. // $tinfo=$tagClient->getTagClientBySCid($value['cid'], $this->staff[0]['sid']);
  2329. $data ['clientInfo'] [$key] ['taginfo'] = array ();
  2330. $data ['clientInfo'] [$key] ['tag'] = "";
  2331. foreach ( $ClientTagList as $k => $v ) {
  2332. // $tag->getTagByTidL($value['tag']);$value['tag'];
  2333. if ($value ['cid'] == $v ['client']) {
  2334. $data ['clientInfo'] [$key] ['taginfo'] = $v ['taginfo'];
  2335. $data ['clientInfo'] [$key] ['tag'] = $v ['tag'];
  2336. }
  2337. }
  2338. // array_pop 可以优化数组
  2339. }
  2340. $data ['clientInfo'] [$key] ['tooltipList'] = array ();
  2341. foreach ( $toollist as $k => $v ) {
  2342. if ($v ['cid'] == $value ['cid']) {
  2343. $data ['clientInfo'] [$key] ['tooltipList'] = explode ( ",", $v ['name'] );
  2344. break;
  2345. } // array_pop 可以优化数组
  2346. }
  2347. // $tl=array();
  2348. // if(!empty($value['tooltip']))
  2349. // $tl=explode(',', $value['tooltip']);
  2350. // $data['clientInfo'][$key]['tooltipList']=$tl;
  2351. $data ['clientInfo'] [$key] ['locount'] = 0; // $longle->count(array('where'=>'clientid='.$value['cid']));
  2352. }
  2353. $CC1 = "";
  2354. $CC2 = "";
  2355. $CC3 = "";
  2356. if (! empty ( $districtCount )) {
  2357. $clientCount = $client->find ( array (
  2358. 'select' => 'district',
  2359. 'where' => "district like '" . $lv1 . ",%'",
  2360. 'asArray' => TRUE
  2361. ) );
  2362. $CC1 = count ( $clientCount );
  2363. if (! empty ( $clientCount ) && ! empty ( $lv2 )) {
  2364. $CC2 = 0;
  2365. foreach ( $clientCount as $key => $value ) {
  2366. if (strpos ( $value ['district'], ','.$lv2.',' )) {
  2367. //echo $value ['district'].'<br/>';
  2368. $CC2 ++;
  2369. }
  2370. }
  2371. }
  2372. if (! empty ( $clientCount ) && ! empty ( $lv3 )) {
  2373. $CC3 = 0;
  2374. foreach ( $clientCount as $key => $value ) {
  2375. if (strpos ( $value ['district'], ','.$lv3 )) {
  2376. $CC3 ++;
  2377. }
  2378. }
  2379. }
  2380. }
  2381. Doo::loadModel ( 'remind' );
  2382. $remind = new remind ();
  2383. // and date_add(time, INTERVAL day DAY) <= CURDATE()
  2384. $remindList = $remind->find ( array (
  2385. 'where' => "staffID = '" . $this->staff [0] ['sid'] . "' and status=0 ",
  2386. 'asc' => 'date_add(time, INTERVAL day DAY)',
  2387. 'asArray' => TRUE
  2388. ) );
  2389. $rc = 0;
  2390. foreach ( $remindList as $key => $value ) {
  2391. $a = strtotime ( $value ['time'] . " +" . $value ['day'] . " days" );
  2392. $b = strtotime ( date ( 'y-m-d' ) );
  2393. if ($a <= $b) {
  2394. $rc ++;
  2395. $remindList [$key] ['isRemind'] = 1;
  2396. } else
  2397. $remindList [$key] ['isRemind'] = 0;
  2398. $remindList [$key] ['Ctime'] = date ( 'm-d', strtotime ( $value ['time'] ) );
  2399. $remindList [$key] ['Etime'] = date ( 'm-d', strtotime ( $value ['time'] . " +" . $value ['day'] . " days" ) );
  2400. }
  2401. $token = $this->set_token ();
  2402. $tokenTime=time().rand(5, 15);
  2403. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  2404. $data['tokenTime']=$tokenTime;
  2405. $data ['token'] = $token;
  2406. $data ['remindCount'] = $rc;
  2407. $data ['remindList'] = $remindList;
  2408. $data ['CC1'] = $CC1;
  2409. $data ['CC2'] = $CC2;
  2410. $data ['CC3'] = $CC3;
  2411. $data ['lv1'] = $lv1;
  2412. $data ['lv2'] = $lv2;
  2413. $data ['lv3'] = $lv3;
  2414. $data ['lv4'] = $lv4;
  2415. $data ['districtLv'] = $districtLv;
  2416. $data ['tagList'] = $tagList;
  2417. $data ['tooltip'] = $this->tooltip;
  2418. $data ['ttip'] = $tooltip;
  2419. $data ['search'] = $search;
  2420. $data ['totalData'] = $pageinfo ['total_data'];
  2421. // $data['messagehtml']=$html;
  2422. $this->render ( "/contacts_client", $data );
  2423. }
  2424. function remindCL() {
  2425. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2426. Doo::loadModel ( 'remind' );
  2427. $remind = new remind ();
  2428. $remind->status = 1;
  2429. $remind->update ( array (
  2430. 'where' => "staffID = '" . $this->staff [0] ['sid'] . "' and rid=" . $rid,
  2431. 'asArray' => TRUE
  2432. ) );
  2433. return "/contacts";
  2434. }
  2435. function communication() {
  2436. $data ['memu'] = "contacts";
  2437. $data ['staff'] = $this->staff;
  2438. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2439. Doo::loadModel ( 'L_category' );
  2440. $L_category = new L_category ();
  2441. Doo::loadModel ( 'staff' );
  2442. $staff = new staff ();
  2443. Doo::loadModel ( 'staffDynamic' );
  2444. $staffDynamic = new staffDynamic ();
  2445. if (! empty ( $cid ))
  2446. $data ['staffList'] = $staff->getStaffByCid ( $cid );
  2447. else
  2448. $data ['staffList'] = $staff->getStaff ( true );
  2449. foreach ( $data ['staffList'] as $key => $value ) {
  2450. if (! empty ( $value ['birthday'] )) {
  2451. $dataD = date ( "d", strtotime ( $value ['birthday'] ) );
  2452. if (date ( 'm' ) == date ( "m", strtotime ( $value ['birthday'] ) )) {
  2453. $now = date ( 'd' );
  2454. $post = $dataD - 7; // date("d",mktime(0,0,0,date("m"),date("d")+7,date("Y")));
  2455. if ($now >= $post && $now <= $dataD) {
  2456. $data ['staffList'] [$key] ['birthday'] = "birthday";
  2457. $data ['staffList'] [$key] ['birthDAY'] = date ( "m-d", strtotime ( $value ['birthday'] ) );
  2458. }
  2459. }
  2460. }
  2461. $happy = date ( "m-d", strtotime ( $value ['birthday'] ) );
  2462. if ($happy == date ( 'm-d' )) {
  2463. $SBL = $staffDynamic->getStaffBirthday ( $happy, $value ['sid'] );
  2464. if (empty ( $SBL )) {
  2465. $staffDynamic->content = '<img src="/global/img/cake.gif"><span class="colOrange">今天过生日!</span>';
  2466. $staffDynamic->cid = $value ['cid'];
  2467. $staffDynamic->category = $value ['category'];
  2468. $staffDynamic->time = time ();
  2469. $staffDynamic->sid = $value ['sid'];
  2470. $staffDynamic->staff = $value ['username'];
  2471. $staffDynamic->insert ();
  2472. }
  2473. }
  2474. }
  2475. $sDynaimic = $staffDynamic->getStaffDynamic ();
  2476. foreach ( $sDynaimic as $key => $value ) {
  2477. $time = date ( "Y-m-d", $value ['time'] );
  2478. $timeArray = explode ( '-', $time );
  2479. $sDynaimic [$key] ['year'] = $timeArray [0];
  2480. $sDynaimic [$key] ['month'] = $timeArray [1];
  2481. $sDynaimic [$key] ['day'] = $timeArray [2];
  2482. }
  2483. $data ['sDynaimic'] = $sDynaimic;
  2484. $data ['category'] = $L_category->getCategory ();
  2485. $data ['cid'] = $cid;
  2486. $this->render ( "/staff_contacts", $data );
  2487. }
  2488. function app() {
  2489. $data ['memu'] = "app";
  2490. $data ['staff'] = $this->staff;
  2491. $this->render ( "/app", $data );
  2492. }
  2493. function synClient() {
  2494. if ($this->staff [0] ['isadmin'] != 1) {
  2495. Doo::loadModel ( 'L_category' );
  2496. Doo::loadModel ( 'client_staff' );
  2497. $client_staff = new client_staff ();
  2498. $cate = new L_category ();
  2499. $district = $cate->getOne ( array (
  2500. 'where' => 'cid=' . $this->staff [0] ['cid'],
  2501. 'asArray' => true
  2502. ) );
  2503. $syn = $client_staff->synClient ( $this->staff [0] ['sid'], $district ['districtid'] );
  2504. $bei = $client_staff->find ( array (
  2505. 'where' => "sid = " . $this->staff [0] ['sid'],
  2506. 'asArray' => true
  2507. ) );
  2508. foreach ( $syn as $value ) {
  2509. $falg = true;
  2510. foreach ( $bei as $v ) {
  2511. if (($v ['cid'] == $value ['cid']) && ($v ['sid'] == $this->staff [0] ['sid'])) {
  2512. $falg = false;
  2513. break;
  2514. }
  2515. }
  2516. if ($falg) {
  2517. $client_staff = new client_staff ();
  2518. $client_staff->sid = $this->staff [0] ['sid'];
  2519. $client_staff->cid = $value ['cid'];
  2520. $client_staff->insert ();
  2521. }
  2522. }
  2523. }
  2524. return "/contacts";
  2525. }
  2526. function DoAddTagCompany() {
  2527. $cid = $this->get_args ( 'id' );
  2528. $tid = $this->get_args ( 'tagALD' );
  2529. Doo::loadModel ( 'tagCompanyNexus' );
  2530. $strtid = implode ( ",", $tid );
  2531. foreach ( $cid as $key => $value ) {
  2532. $tagClient = new tagCompanyNexus ();
  2533. $tagClientInfo = $tagClient->getTagClientBySCid ( $value, $this->staff [0] ['sid'] );
  2534. $ar = explode ( ",", $strtid . ',' . $tagClientInfo ['tag'] );
  2535. $re = array_filter ( array_unique ( $ar ) );
  2536. $tagClient->tag = implode ( ",", $re );
  2537. if (! empty ( $tagClientInfo )) {
  2538. $tagClient->tcid = $tagClientInfo ['tcid'];
  2539. $tagClient->update ();
  2540. } else {
  2541. $tagClient->sid = $this->staff [0] ['sid'];
  2542. $tagClient->company = $value;
  2543. $tagClient->insert ();
  2544. }
  2545. }
  2546. header ( "Location: /mycompany" );
  2547. }
  2548. function DoAddTag() {
  2549. $cid = $this->get_args ( 'id' );
  2550. $tooltipAct = $this->get_args ( 'tooltipAct' ) ? $this->get_args ( 'tooltipAct' ) : "";
  2551. Doo::loadModel ( 'client' );
  2552. if (! empty ( $tooltipAct )) {
  2553. $tid = $this->get_args ( 'tooltiplist' );
  2554. $k = implode ( ",", $tid );
  2555. Doo::loadModel ( 'C_tooltip' );
  2556. $s = " and cateid=" . $this->staff [0] ['cid'];
  2557. if (! empty ( $this->staff [0] ['othercid'] )) {
  2558. $othercid = explode ( ",", $this->staff [0] ['othercid'] );
  2559. foreach ( $othercid as $value ) {
  2560. $s .= " or cateid=" . $value;
  2561. }
  2562. }
  2563. foreach ( $cid as $key => $value ) {
  2564. $C_tooltip = new C_tooltip ();
  2565. $tooltip = $C_tooltip->getOne ( array (
  2566. 'where' => 'cid=' . $value . " " . $s,
  2567. 'asArray' => true
  2568. ) );
  2569. if (empty ( $tooltip )) {
  2570. $C_tooltip->cid = $value;
  2571. $C_tooltip->name = $k;
  2572. $C_tooltip->cateid = $this->staff [0] ['cid'];
  2573. $C_tooltip->insert ();
  2574. } else {
  2575. $C_tooltip->tip = $tooltip ['tip'];
  2576. $C_tooltip->name = $k;
  2577. $C_tooltip->update ();
  2578. }
  2579. }
  2580. } else {
  2581. $tid = $this->get_args ( 'tagALD' );
  2582. Doo::loadModel ( 'tag_client' );
  2583. $strtid = implode ( ",", $tid );
  2584. foreach ( $cid as $key => $value ) {
  2585. $tagClient = new tag_client ();
  2586. $tagClientInfo = $tagClient->getTagClientBySCid ( $value, $this->staff [0] ['sid'] );
  2587. $ar = explode ( ",", $strtid . ',' . $tagClientInfo ['tag'] );
  2588. $re = array_filter ( array_unique ( $ar ) );
  2589. $tagClient->tag = implode ( ",", $re );
  2590. if (! empty ( $tagClientInfo )) {
  2591. $tagClient->tcid = $tagClientInfo ['tcid'];
  2592. $tagClient->update ();
  2593. } else {
  2594. $tagClient->sid = $this->staff [0] ['sid'];
  2595. $tagClient->client = $value;
  2596. $tagClient->insert ();
  2597. }
  2598. }
  2599. }
  2600. header ( "Location: /contacts" );
  2601. }
  2602. function ajaxDeleteTag() {
  2603. $cid = $this->get_args ( 'cid' );
  2604. $tid = $this->get_args ( 'tid' );
  2605. Doo::loadModel ( 'tag_client' );
  2606. $tagClient = new tag_client ();
  2607. $tagInfo = $tagClient->getTagClientBySCid ( $cid, $this->staff [0] ['sid'] );
  2608. $tag = str_replace ( $tid, "", $tagInfo ['tag'] );
  2609. $ar = explode ( ',', $tag );
  2610. $tag = implode ( ',', array_filter ( $ar ) );
  2611. $tagClient->tcid = $tagInfo ['tcid'];
  2612. $tagClient->tag = $tag;
  2613. $tagClient->update ();
  2614. }
  2615. function ajaxDeleteTagCompany() {
  2616. $cid = $this->get_args ( 'cid' );
  2617. $tid = $this->get_args ( 'tid' );
  2618. Doo::loadModel ( 'tagCompanyNexus' );
  2619. $tagClient = new tagCompanyNexus ();
  2620. $tagInfo = $tagClient->getTagClientBySCid ( $cid, $this->staff [0] ['sid'] );
  2621. $tag = str_replace ( $tid, "", $tagInfo ['tag'] );
  2622. $ar = explode ( ',', $tag );
  2623. $tag = implode ( ',', array_filter ( $ar ) );
  2624. $tagClient->tcid = $tagInfo ['tcid'];
  2625. $tagClient->tag = $tag;
  2626. $tagClient->update ();
  2627. }
  2628. function deleteToolTip() {
  2629. $cid = $this->get_args ( 'cid' );
  2630. $cateid = $this->get_args ( 'cateid' );
  2631. $name = $this->get_args ( 'name' );
  2632. Doo::loadModel ( "C_tooltip" );
  2633. $tooltip = new C_tooltip ();
  2634. if (! empty ( $cid ) && ! empty ( $cateid ) && ! empty ( $name )) {
  2635. $tool = $tooltip->getOne ( array (
  2636. 'where' => 'cid=' . $cid . ' and cateid=' . $cateid,
  2637. 'asArray' => true
  2638. ) );
  2639. if (! empty ( $tool )) {
  2640. $name = str_replace ( $name, "", $tool ['name'] );
  2641. $name = explode ( ',', $name );
  2642. $name = implode ( ',', array_filter ( $name ) );
  2643. $tooltip->name = $name;
  2644. $tooltip->tip = $tool ['tip'];
  2645. $tooltip->update ();
  2646. }
  2647. }
  2648. }
  2649. function DoEdiTagCompany() {
  2650. $tag_1 = $this->get_args ( 'tag_1' ) ? $this->get_args ( 'tag_1' ) : "";
  2651. $tag_2 = $this->get_args ( 'tag_2' ) ? $this->get_args ( 'tag_2' ) : "";
  2652. $tag_3 = $this->get_args ( 'tag_3' ) ? $this->get_args ( 'tag_3' ) : "";
  2653. $tag_4 = $this->get_args ( 'tag_4' ) ? $this->get_args ( 'tag_4' ) : "";
  2654. $tag_5 = $this->get_args ( 'tag_5' ) ? $this->get_args ( 'tag_5' ) : "";
  2655. $tag_6 = $this->get_args ( 'tag_6' ) ? $this->get_args ( 'tag_6' ) : "";
  2656. $tag_7 = $this->get_args ( 'tag_7' ) ? $this->get_args ( 'tag_7' ) : "";
  2657. $tid_1 = $this->get_args ( 'tid_1' ) ? $this->get_args ( 'tid_1' ) : 0;
  2658. $tid_2 = $this->get_args ( 'tid_2' ) ? $this->get_args ( 'tid_2' ) : 0;
  2659. $tid_3 = $this->get_args ( 'tid_3' ) ? $this->get_args ( 'tid_3' ) : 0;
  2660. $tid_4 = $this->get_args ( 'tid_4' ) ? $this->get_args ( 'tid_4' ) : 0;
  2661. $tid_5 = $this->get_args ( 'tid_5' ) ? $this->get_args ( 'tid_5' ) : 0;
  2662. $tid_6 = $this->get_args ( 'tid_6' ) ? $this->get_args ( 'tid_6' ) : 0;
  2663. $tid_7 = $this->get_args ( 'tid_7' ) ? $this->get_args ( 'tid_7' ) : 0;
  2664. Doo::loadModel ( 'tagCompany' );
  2665. if (! empty ( $tag_1 ) && ! empty ( $tid_1 )) {
  2666. $tag = new tagCompany ();
  2667. $tag->tid = $tid_1;
  2668. $tag->name = $tag_1;
  2669. $tag->update ();
  2670. }
  2671. if (! empty ( $tag_2 ) && ! empty ( $tid_2 )) {
  2672. $tag = new tagCompany ();
  2673. $tag->tid = $tid_2;
  2674. $tag->name = $tag_2;
  2675. $tag->update ();
  2676. }
  2677. if (! empty ( $tag_3 ) && ! empty ( $tid_3 )) {
  2678. $tag = new tagCompany ();
  2679. $tag->tid = $tid_3;
  2680. $tag->name = $tag_3;
  2681. $tag->update ();
  2682. }
  2683. if (! empty ( $tag_4 ) && ! empty ( $tid_4 )) {
  2684. $tag = new tagCompany ();
  2685. $tag->tid = $tid_4;
  2686. $tag->name = $tag_4;
  2687. $tag->update ();
  2688. }
  2689. if (! empty ( $tag_5 ) && ! empty ( $tid_5 )) {
  2690. $tag = new tagCompany ();
  2691. $tag->tid = $tid_5;
  2692. $tag->name = $tag_5;
  2693. $tag->update ();
  2694. }
  2695. if (! empty ( $tag_6 ) && ! empty ( $tid_6 )) {
  2696. $tag = new tagCompany ();
  2697. $tag->tid = $tid_6;
  2698. $tag->name = $tag_6;
  2699. $tag->update ();
  2700. }
  2701. if (! empty ( $tag_7 ) && ! empty ( $tid_7 )) {
  2702. $tag = new tagCompany ();
  2703. $tag->tid = $tid_7;
  2704. $tag->name = $tag_7;
  2705. $tag->update ();
  2706. }
  2707. return "/mycompany";
  2708. }
  2709. function DoEdiTag() {
  2710. $tag_1 = $this->get_args ( 'tag_1' ) ? $this->get_args ( 'tag_1' ) : "";
  2711. $tag_2 = $this->get_args ( 'tag_2' ) ? $this->get_args ( 'tag_2' ) : "";
  2712. $tag_3 = $this->get_args ( 'tag_3' ) ? $this->get_args ( 'tag_3' ) : "";
  2713. $tag_4 = $this->get_args ( 'tag_4' ) ? $this->get_args ( 'tag_4' ) : "";
  2714. $tag_5 = $this->get_args ( 'tag_5' ) ? $this->get_args ( 'tag_5' ) : "";
  2715. $tag_6 = $this->get_args ( 'tag_6' ) ? $this->get_args ( 'tag_6' ) : "";
  2716. $tag_7 = $this->get_args ( 'tag_7' ) ? $this->get_args ( 'tag_7' ) : "";
  2717. $tid_1 = $this->get_args ( 'tid_1' ) ? $this->get_args ( 'tid_1' ) : 0;
  2718. $tid_2 = $this->get_args ( 'tid_2' ) ? $this->get_args ( 'tid_2' ) : 0;
  2719. $tid_3 = $this->get_args ( 'tid_3' ) ? $this->get_args ( 'tid_3' ) : 0;
  2720. $tid_4 = $this->get_args ( 'tid_4' ) ? $this->get_args ( 'tid_4' ) : 0;
  2721. $tid_5 = $this->get_args ( 'tid_5' ) ? $this->get_args ( 'tid_5' ) : 0;
  2722. $tid_6 = $this->get_args ( 'tid_6' ) ? $this->get_args ( 'tid_6' ) : 0;
  2723. $tid_7 = $this->get_args ( 'tid_7' ) ? $this->get_args ( 'tid_7' ) : 0;
  2724. Doo::loadModel ( 'tag' );
  2725. if (! empty ( $tag_1 ) && ! empty ( $tid_1 )) {
  2726. $tag = new tag ();
  2727. $tag->tid = $tid_1;
  2728. $tag->name = $tag_1;
  2729. $tag->update ();
  2730. }
  2731. if (! empty ( $tag_2 ) && ! empty ( $tid_2 )) {
  2732. $tag = new tag ();
  2733. $tag->tid = $tid_2;
  2734. $tag->name = $tag_2;
  2735. $tag->update ();
  2736. }
  2737. if (! empty ( $tag_3 ) && ! empty ( $tid_3 )) {
  2738. $tag = new tag ();
  2739. $tag->tid = $tid_3;
  2740. $tag->name = $tag_3;
  2741. $tag->update ();
  2742. }
  2743. if (! empty ( $tag_4 ) && ! empty ( $tid_4 )) {
  2744. $tag = new tag ();
  2745. $tag->tid = $tid_4;
  2746. $tag->name = $tag_4;
  2747. $tag->update ();
  2748. }
  2749. if (! empty ( $tag_5 ) && ! empty ( $tid_5 )) {
  2750. $tag = new tag ();
  2751. $tag->tid = $tid_5;
  2752. $tag->name = $tag_5;
  2753. $tag->update ();
  2754. }
  2755. if (! empty ( $tag_6 ) && ! empty ( $tid_6 )) {
  2756. $tag = new tag ();
  2757. $tag->tid = $tid_6;
  2758. $tag->name = $tag_6;
  2759. $tag->update ();
  2760. }
  2761. if (! empty ( $tag_7 ) && ! empty ( $tid_7 )) {
  2762. $tag = new tag ();
  2763. $tag->tid = $tid_7;
  2764. $tag->name = $tag_7;
  2765. $tag->update ();
  2766. }
  2767. return "/contacts";
  2768. }
  2769. function ajaxGetLv2() {
  2770. $lv1 = $this->get_args ( 'lv1' ) ? $this->get_args ( 'lv1' ) : 0;
  2771. $s = $this->get_args ( 's' ) ? $this->get_args ( 's' ) : 0;
  2772. if ($lv1 == 0) {
  2773. echo json_encode ( array (
  2774. "success" => false,
  2775. "info" => ""
  2776. ) );
  2777. die ();
  2778. }
  2779. if (! empty ( $lv1 )) {
  2780. Doo::loadModel ( 'district' );
  2781. $district = new district ();
  2782. $district = $district->get_lvByid ( $s, $lv1 );
  2783. echo json_encode ( array (
  2784. "success" => true,
  2785. "info" => $district
  2786. ) );
  2787. }
  2788. }
  2789. function keyonline() {
  2790. $data ['memu'] = "keyonline";
  2791. $data ['staff'] = $this->staff;
  2792. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  2793. if (empty ( $year ))
  2794. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( 'Y' );
  2795. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  2796. if (empty ( $cid ))
  2797. $cid = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : $this->staff [0] ['cid'];
  2798. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  2799. if (empty ( $staff ))
  2800. $staff = isset ( $this->params ['staff'] ) ? $this->params ['staff'] : "";
  2801. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "";
  2802. if (empty ( $status ))
  2803. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  2804. $search = $this->get_args ( 'search' ) ? $this->get_args ( 'search' ) : "";
  2805. $productW = $this->get_args ( 'product' ) ? $this->get_args ( 'product' ) : "";
  2806. $lidKey = $this->get_args ( 'lid' ) ? $this->get_args ( 'lid' ) : "";
  2807. Doo::loadModel ( 'longle' );
  2808. $longle = new longle ();
  2809. Doo::loadClass ( 'XDeode' );
  2810. $XDeode = new XDeode ( 5 );
  2811. Doo::loadModel ( 'longle_log' );
  2812. $longle_log = new longle_log ();
  2813. $lid =0;
  2814. if(!empty($lidKey)){
  2815. $lid = $XDeode->decode ( $lidKey );
  2816. }
  2817. $data ['longleArray'] = $longle->getLongleByStatus ( $year, $cid, $staff, $status, $search, $productW );
  2818. $longleDetail=$longle->getLongleByLid($lid);
  2819. $longleLogDetail=$longle_log->getLongleByLid ( $lid );
  2820. // 获取接收锁信息
  2821. // $longle->getLongleByRe($this->staff[0]['cid'],1);
  2822. $othstr = "";
  2823. if (! empty ( $this->staff [0] ['othercid'] ))
  2824. $othstr = " cid in (" . $this->staff [0] ['cid'] . "," . $this->staff [0] ['othercid'] . ")";
  2825. else
  2826. $othstr = " cid in (" . $this->staff [0] ['cid'] . ")";
  2827. $data ['reLongle'] = $longle->count ( array (
  2828. 'where' => $othstr . ' and (status=1 or responsible="") and make_day>="2019-01-01"'
  2829. ) );
  2830. $data['lidKey']=$lidKey;
  2831. if (isset($longleDetail[0])){
  2832. $data['longleDetail']=$longleDetail[0];
  2833. }else{
  2834. $data['longleDetail']=array();
  2835. }
  2836. $data ['longleLogHtml'] = $this->_getLongleLogHtml ( $longleLogDetail );
  2837. $data ['cid'] = $cid;
  2838. $data ['year'] = $year;
  2839. $data ['staff'] = $staff;
  2840. $data ['status'] = $status;
  2841. $data ['productName'] = $productW;
  2842. $data ['search'] =$search;
  2843. Doo::loadModel ( 'L_category' );
  2844. Doo::loadModel ( 'staff' );
  2845. Doo::loadModel ( 'product' );
  2846. $product = new product ();
  2847. $staff = new staff ();
  2848. $L_category = new L_category ();
  2849. $data ['product'] = $product->getProudct ();
  2850. $data ['staffu'] = $staff->getUserById ( $this->staff [0] ['sid'] );
  2851. $data ['category'] = $L_category->getCategory ();
  2852. $data ['staffList'] = $staff->getStaffByCid ( $cid );
  2853. if ($cid == 1)
  2854. $data ['cid'] = $data ['category'] [0] ['cid'];
  2855. $dateHtml = "";
  2856. $now = date ( "Y" );
  2857. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  2858. if ($YEARD <= $now) {
  2859. $dateHtml .= '<option ';
  2860. if ($data ['year'] == $YEARD) {
  2861. $dateHtml .= 'selected ';
  2862. }
  2863. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  2864. }
  2865. }
  2866. $data ['dateHtml'] = $dateHtml;
  2867. $this->render ( "/lock_look", $data );
  2868. }
  2869. function keyStatistics() {
  2870. Doo::loadModel ( 'staff' );
  2871. $staff = new staff ();
  2872. Doo::loadModel ( 'longle' );
  2873. $longle = new longle ();
  2874. Doo::loadModel ( 'L_category' );
  2875. $L_category = new L_category ();
  2876. Doo::loadClass ( 'XDeode' );
  2877. $XDeode = new XDeode ( 5 );
  2878. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  2879. $staffCondition = "";
  2880. if ($this->staff [0] ['cid'] != 12){
  2881. $staffCondition = " and cid=" . $this->staff [0] ['cid'];
  2882. $cid=$this->staff [0] ['cid'];
  2883. }else{
  2884. $cid=$this->staff [0] ['cid'];
  2885. if (!empty($cidKey)){
  2886. $cid = $XDeode->decode ( $cidKey );
  2887. if (! is_numeric ( $cid )){
  2888. $cid=$this->staff [0] ['cid'];
  2889. }
  2890. }
  2891. $staffCondition = " and cid=" . $cid;
  2892. }
  2893. $staffList = $staff->find ( array (
  2894. 'where' => "isadmin= 0 and nature !=4 " . $staffCondition,
  2895. 'asArray' => TRUE
  2896. ) );
  2897. //
  2898. $sql = "select COUNT(*) as count,responsible
  2899. from CLD_longle
  2900. where status!= 1 and make_day >='2019-12-01'
  2901. GROUP BY responsible";
  2902. $query = Doo::db ()->query ( $sql );
  2903. $resultSum = $query->fetchAll ();
  2904. $sql = "select COUNT(*) as count,responsible
  2905. from CLD_longle
  2906. where status!= 2 and status!= 1 and make_day >='2019-12-01'
  2907. GROUP BY responsible";
  2908. $query = Doo::db ()->query ( $sql );
  2909. $resultA = $query->fetchAll ();
  2910. foreach ( $staffList as $key => $value ) {
  2911. $sum=$a=0;
  2912. foreach ($resultSum as $k=>$v){
  2913. if($value ['username']==$v['responsible']){
  2914. $sum=$v['count'];
  2915. break;
  2916. }
  2917. }
  2918. foreach ($resultA as $k=>$v){
  2919. if($value ['username']==$v['responsible']){
  2920. $a=$v['count'];
  2921. break;
  2922. }
  2923. }
  2924. $b = $sum - $a;
  2925. $staffList [$key] ['sum'] = $sum;
  2926. $staffList [$key] ['a'] = $a;
  2927. $staffList [$key] ['b'] = $b;
  2928. }
  2929. /* Doo::db ()->beginTransaction ();
  2930. foreach ( $staffList as $key => $value ) { // not in(1,2)
  2931. $sum = $longle->count ( array (
  2932. 'where' => "status!= 1 and responsible ='" . $value ['username'] . "' and make_day >='2019-12-01'",
  2933. 'asArray' => TRUE
  2934. ) );
  2935. $a = $longle->count ( array (
  2936. 'where' => "status!= 2 and status!= 1 and responsible ='" . $value ['username'] . "' and make_day >='2019-12-01'",
  2937. 'asArray' => TRUE
  2938. ) );
  2939. $b = $sum - $a;
  2940. $staffList [$key] ['sum'] = $sum;
  2941. $staffList [$key] ['a'] = $a;
  2942. $staffList [$key] ['b'] = $b;
  2943. }
  2944. Doo::db ()->commit (); */
  2945. $data ['cid'] = $cid;
  2946. $data ['category'] = $L_category->getCategory ();
  2947. $data ['staff'] = $this->staff;
  2948. $data ['staffList'] = $staffList;
  2949. $data ['memu'] = "keyStatistics";
  2950. $this->render ( "lock_count", $data );
  2951. }
  2952. function addDoLockLog() {
  2953. Doo::loadModel ( 'longle_log' );
  2954. Doo::loadModel ( 'longle' );
  2955. Doo::loadModel ( "action_log" );
  2956. Doo::loadModel ( 'client' );
  2957. $clientobj = new client ();
  2958. $longle = new longle ();
  2959. $longle_log = new longle_log ();
  2960. Doo::loadModel ( 'district' );
  2961. $district = new district ();
  2962. $status = $this->get_args ( 'longleStatus' ) ? $this->get_args ( 'longleStatus' ) : 0;
  2963. $lidKey = $this->get_args ( 'klid' ) ? $this->get_args ( 'klid' ) : 0;
  2964. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
  2965. $company = $this->get_args ( 'company' ) ? $this->get_args ( 'company' ) : '';
  2966. $alloted_time = $this->get_args ( 'alloted_time' ) ? $this->get_args ( 'alloted_time' ) : '';
  2967. if (empty ( $lidKey ))
  2968. return "/keyonline/";
  2969. Doo::loadClass ( 'XDeode' );
  2970. $XDeode = new XDeode ( 5 );
  2971. $lid = $XDeode->decode ( $lidKey );
  2972. $linfo = $longle->getLongleByLid ( $lid );
  2973. if ($status == 0)
  2974. return "/keyonline/" . $lid;
  2975. elseif ($status == 3) {
  2976. $clientname = $clientobj->getClientByName2 ( $name, $company );
  2977. if (empty ( $clientname ))
  2978. return "/keyonline/" . $lid;
  2979. if ($name != "") {
  2980. $longle->client = $name;
  2981. $longle->clientid = $clientname [0] ['cid'];
  2982. }
  2983. // if($product!="")
  2984. // $longle->product=$product;
  2985. $longle->statusT = "借出";
  2986. $longle_log->client = $name;
  2987. $longle_log->clientid = $clientname [0] ['cid'];
  2988. $longle_log->product = $linfo [0] ['product'];
  2989. $longle_log->statusT = "借出";
  2990. // 日常行为
  2991. $action_log = new action_log ();
  2992. $action_log->action = $this->staff [0] ['category'] . '<b href="javascript:void(0)" onclick="showStaff(\'' . $this->staff [0] ['sid'] . '\')">' . $this->staff [0] ['username'] . '</b>借出<a href="javascript:void(0)" onclick="showLook(\'' . $linfo [0] ['key_num'] . '\')">' . $linfo [0] ['key_num'] . '</a>给<a href="javascript:void(0)" onclick="showClick(\'' . $clientname [0] ['cid'] . '\')">' . $name . '</a>(' . $clientname [0] ['companyname'] . ')';
  2993. $action_log->sid = $this->staff [0] ['sid'];
  2994. $action_log->cid = $this->staff [0] ['cid'];
  2995. $action_log->updatetime = date ( "Y-m-d" );
  2996. $action_log->time = date ( "H:i" );
  2997. $action_log->status = 4;
  2998. $action_log->districtid = $clientname [0] ['district'];
  2999. $local = $district->getbyidlist ( $clientname [0] ['district'] );
  3000. $action_log->city = $local [0] ['name'];
  3001. $action_log->province = $local [1] ['name'];
  3002. $action_log->company = $clientname [0] ['companyname'];
  3003. Doo::loadModel ( 'company' );
  3004. $company = new company ();
  3005. $companyInfo = $company->getOne ( array (
  3006. 'where' => ' companyname="' . $clientname [0] ['companyname'] . '"',
  3007. 'asArray' => true
  3008. ) );
  3009. $nature = explode ( ',', $companyInfo ['nature'] );
  3010. $action_log->nature = $nature [0];
  3011. $action_log->class = $action_log->iconBorrow;
  3012. $action_log->insert ();
  3013. } elseif ($status == 4) {
  3014. $clientname = $clientobj->getClientByName2 ( $name, $company );
  3015. if (empty ( $clientname ))
  3016. return "/keyonline/" . $lid;
  3017. if ($name != "") {
  3018. $longle->client = $name;
  3019. $longle->clientid = $clientname [0] ['cid'];
  3020. }
  3021. $longle->statusT = "销售";
  3022. $longle_log->client = $name;
  3023. $longle_log->clientid = $clientname [0] ['cid'];
  3024. $longle_log->product = $linfo [0] ['product'];
  3025. $longle_log->statusT = "销售";
  3026. // 日常行为
  3027. $action_log = new action_log ();
  3028. $action_log->action = $this->staff [0] ['category'] . '<b href="javascript:void(0)" onclick="showStaff(\'' . $this->staff [0] ['sid'] . '\')">' . $this->staff [0] ['username'] . '</b>销售<a href="javascript:void(0)" onclick="showLook(\'' . $linfo [0] ['key_num'] . '\')">' . $linfo [0] ['key_num'] . '</a>给<a href="javascript:void(0)" onclick="showClick(\'' . $clientname [0] ['cid'] . '\')">' . $name . '</a>(' . $clientname [0] ['companyname'] . ')';
  3029. $action_log->sid = $this->staff [0] ['sid'];
  3030. $action_log->cid = $this->staff [0] ['cid'];
  3031. $action_log->updatetime = date ( "Y-m-d" );
  3032. $action_log->time = date ( "H:i" );
  3033. $action_log->status = 5;
  3034. $action_log->districtid = $clientname [0] ['district'];
  3035. $local = $district->getbyidlist ( $clientname [0] ['district'] );
  3036. $action_log->city = $local [0] ['name'];
  3037. $action_log->province = $local [1] ['name'];
  3038. $action_log->company = $clientname [0] ['companyname'];
  3039. Doo::loadModel ( 'company' );
  3040. $company = new company ();
  3041. $companyInfo = $company->getOne ( array (
  3042. 'where' => ' companyname="' . $clientname [0] ['companyname'] . '"',
  3043. 'asArray' => true
  3044. ) );
  3045. $nature = explode ( ',', $companyInfo ['nature'] );
  3046. $action_log->nature = $nature [0];
  3047. $action_log->class = $action_log->iconSell;
  3048. $action_log->insert ();
  3049. } elseif ($status == 5) {
  3050. $product = $this->get_args ( 'newProduct' ) ? $this->get_args ( 'newProduct' ) : "";
  3051. if ($product != "")
  3052. $longle->product = $linfo [0] ['product'] . "+" . $product;
  3053. $longle->statusT = "升级";
  3054. $longle_log->product = $linfo [0] ['product'] . "+" . $product;
  3055. $longle_log->statusT = "升级";
  3056. $longle_log->client = $linfo [0] ['client'];
  3057. $longle_log->clientid = $linfo [0] ['clientid'];
  3058. $clientname = $clientobj->getOne ( array (
  3059. 'where' => "cid= '" . $linfo [0] ['clientid'] . "'",
  3060. 'asArray' => TRUE
  3061. ) );
  3062. // 日常行为
  3063. $action_log = new action_log ();
  3064. $action_log->action = $this->staff [0] ['category'] . '<b href="javascript:void(0)" onclick="showStaff(\'' . $this->staff [0] ['sid'] . '\')" >' . $this->staff [0] ['username'] . '</b>为<a href="javascript:void(0)" onclick="showClick(\'' . $linfo [0] ['clientid'] . '\')">' . $linfo [0] ['client'] . '</a>(' . $clientname ['companyname'] . ')升级为<a href="javascript:void(0)" onclick="showLook(\'' . $linfo [0] ['key_num'] . '\')">' . $linfo [0] ['key_num'] . '</a>';
  3065. $action_log->sid = $this->staff [0] ['sid'];
  3066. $action_log->cid = $this->staff [0] ['cid'];
  3067. $action_log->updatetime = date ( "Y-m-d" );
  3068. $action_log->time = date ( "H:i" );
  3069. $action_log->class = $action_log->iconUpdate;
  3070. $action_log->sid = $this->staff [0] ['sid'];
  3071. $action_log->cid = $this->staff [0] ['cid'];
  3072. $action_log->status = 7;
  3073. $action_log->insert ();
  3074. } elseif ($status == 6) {
  3075. $key_num = $this->get_args ( 'key_num' ) ? $this->get_args ( 'key_num' ) : "";
  3076. $key_num2 = explode ( "-", $key_num );
  3077. $key_num = $key_num2 [0] . "-" . $key_num2 [1];
  3078. // if($key_num!="")
  3079. // $longle->key_num=$key_num;
  3080. // 新锁拷贝记录
  3081. $newLongle = new longle ();
  3082. // $newLongle->product=$linfo[0]['product'];
  3083. $newLongle->statusT = "更换";
  3084. $newLongle->status = 6;
  3085. $newLongle->client = $linfo [0] ['client'];
  3086. $newLongle->clientid = $linfo [0] ['clientid'];
  3087. $newlid = $newLongle->update ( array (
  3088. 'where' => ' key_num= \'' . $key_num . "'"
  3089. ) );
  3090. $longleinfo = $longle->getOne ( array (
  3091. 'where' => ' key_num =\'' . $key_num . "'",
  3092. 'asArray' => true
  3093. ) );
  3094. $longleLog = $longle_log->getOne ( array (
  3095. 'where' => ' lid =' . $linfo [0] ['lid'],
  3096. 'desc' => 'logid',
  3097. 'asArray' => true
  3098. ) );
  3099. // 新记录日志
  3100. $newlongle_log = new longle_log ();
  3101. $newlongle_log->statusT = "更换";
  3102. $newlongle_log->status = 6;
  3103. $newlongle_log->client = $linfo [0] ['client'];
  3104. $newlongle_log->new_key_num = $linfo [0] ['key_num'];
  3105. $newlongle_log->product = $linfo [0] ['product'];
  3106. $newlongle_log->category = $this->staff [0] ['category'];
  3107. $newlongle_log->dateline = date ( "Y-m-d" );
  3108. $newlongle_log->operator = $this->staff [0] ['username'];
  3109. $newlongle_log->lid = $longleinfo ['lid'];
  3110. $newlongle_log->insert ();
  3111. $newlongle_log = new longle_log ();
  3112. $newlongle_log->statusT = $longleLog ['statusT'];
  3113. $newlongle_log->status = $longleLog ['status'];
  3114. $newlongle_log->client = $longleLog ['client'];
  3115. $newlongle_log->new_key_num = $longleLog ['new_key_num'];
  3116. $newlongle_log->product = $longleLog ['product'];
  3117. $newlongle_log->category = $longleLog ['category'];
  3118. $newlongle_log->dateline = $longleLog ['dateline'];
  3119. $newlongle_log->operator = $longleLog ['operator'];
  3120. $newlongle_log->lid = $longleinfo ['lid'];
  3121. $newlongle_log->insert ();
  3122. $newLongle = new longle ();
  3123. $newLongle->statusT = $longleLog ['statusT'];
  3124. $newLongle->status = $longleLog ['status'];
  3125. $newlid = $newLongle->update ( array (
  3126. 'where' => ' key_num= \'' . $key_num . "'"
  3127. ) );
  3128. // 新锁状态拷贝
  3129. $longle->statusT = "更换";
  3130. $longle_log->new_key_num = $key_num;
  3131. $longle_log->statusT = "更换";
  3132. $longle_log->client = $linfo [0] ['client'];
  3133. $clientname = $clientobj->getOne ( array (
  3134. 'where' => "cid= '" . $linfo [0] ['clientid'] . "'",
  3135. 'asArray' => TRUE
  3136. ) );
  3137. // 日常行为
  3138. $action_log = new action_log ();
  3139. $action_log->action = $this->staff [0] ['category'] . '<b href="javascript:void(0)" onclick="showStaff(\'' . $this->staff [0] ['sid'] . '\')">' . $this->staff [0] ['username'] . '</b>为<a href="javascript:void(0)" onclick="showClick(\'' . $linfo [0] ['clientid'] . '\')">' . $linfo [0] ['client'] . '</a>(' . $clientname ['companyname'] . ')更换为<a href="javascript:void(0)" onclick="showLook(\'' . $key_num . '\')">' . $key_num . '</a>(' . $linfo [0] ['key_num'] . ')';
  3140. $action_log->sid = $this->staff [0] ['sid'];
  3141. $action_log->cid = $this->staff [0] ['cid'];
  3142. $action_log->updatetime = date ( "Y-m-d" );
  3143. $action_log->time = date ( "H:i" );
  3144. $action_log->class = $action_log->iconReplace;
  3145. $action_log->sid = $this->staff [0] ['sid'];
  3146. $action_log->cid = $this->staff [0] ['cid'];
  3147. $action_log->status = 8;
  3148. $action_log->insert ();
  3149. } elseif ($status == 7) {
  3150. $longle->statusT = "收回";
  3151. $longle_log->statusT = "收回";
  3152. $longle_log->responsible = $linfo [0] ['responsible'];
  3153. // 日常行为
  3154. $action_log = new action_log ();
  3155. $action_log->action = $this->staff [0] ['category'] . '<b href="javascript:void(0)" onclick="showStaff(\'' . $this->staff [0] ['sid'] . '\')">' . $this->staff [0] ['username'] . '</b>收回<a href="javascript:void(0)">' . $linfo [0] ['client'] . '</a>的<a href="javascript:void(0)" onclick="showLook(\'' . $linfo [0] ['key_num'] . '\')">' . $linfo [0] ['key_num'] . '</a>通过<a href="javascript:void(0)" onclick="showStaff(\'' . $this->staff [0] ['responsible'] . '\')">' . $this->staff [0] ['responsible'] . '</a>';
  3156. $action_log->sid = $this->staff [0] ['sid'];
  3157. $action_log->cid = $this->staff [0] ['cid'];
  3158. $action_log->updatetime = date ( "Y-m-d" );
  3159. $action_log->time = date ( "H:i" );
  3160. $action_log->class = $action_log->iconRecycle;
  3161. $action_log->sid = $this->staff [0] ['sid'];
  3162. $action_log->cid = $this->staff [0] ['cid'];
  3163. $action_log->status = 9;
  3164. $action_log->insert ();
  3165. } elseif ($status == 8) {
  3166. $mark = $this->get_args ( 'mark' ) ? $this->get_args ( 'mark' ) : "";
  3167. if (empty ( $mark )) {
  3168. echo json_encode ( array (
  3169. 'msg' => 2
  3170. ) );
  3171. die ();
  3172. }
  3173. $longle_log->mark = $mark;
  3174. // 日常行为
  3175. $action_log = new action_log ();
  3176. $action_log->action = $this->staff [0] ['category'] . '<b href="javascript:void(0)" onclick="showStaff(\'' . $this->staff [0] ['sid'] . '\')">' . $this->staff [0] ['username'] . '</b>为<a href="javascript:void(0)" onclick="showLook(\'' . $linfo [0] ['key_num'] . '\')">' . $linfo [0] ['key_num'] . '</a>添加新备注。';
  3177. $action_log->sid = $this->staff [0] ['sid'];
  3178. $action_log->cid = $this->staff [0] ['cid'];
  3179. $action_log->updatetime = date ( "Y-m-d" );
  3180. $action_log->time = date ( "H:i" );
  3181. $action_log->sid = $this->staff [0] ['sid'];
  3182. $action_log->cid = $this->staff [0] ['cid'];
  3183. $action_log->status = 10;
  3184. $action_log->class = $action_log->iconLock;
  3185. $action_log->insert ();
  3186. } elseif ($status == 9) {
  3187. $longle->statusT = "赠送";
  3188. $longle_log->statusT = "赠送";
  3189. $clientname = $clientobj->getClientByName2 ($name, $company );
  3190. if (empty ( $clientname ))
  3191. return "/keyonline/" . $lid;
  3192. if ($name != "") {
  3193. $longle->client = $name;
  3194. $longle->clientid = $clientname [0] ['cid'];
  3195. }
  3196. $longle_log->client = $name;
  3197. $longle_log->clientid = $clientname [0] ['cid'];
  3198. // 日常行为
  3199. $action_log = new action_log ();
  3200. $action_log->action = $this->staff [0] ['category'] . '<b href="javascript:void(0)" onclick="showStaff(\'' . $this->staff [0] ['username'] . '\')">' . $this->staff [0] ['username'] . '</b>赠送<a href="javascript:void(0)" onclick="showLook(\'' . $linfo [0] ['key_num'] . '\')">' . $linfo [0] ['key_num'] . '</a>给<a href="javascript:void(0)" onclick="showClick(\'' . $clientname [0] ['cid'] . '\')">' . $name . '</a>(' . $clientname [0] ['companyname'] . ')';
  3201. $action_log->updatetime = date ( "Y-m-d" );
  3202. $action_log->time = date ( "H:i" );
  3203. $action_log->class = $action_log->iconRecycle;
  3204. $action_log->sid = $this->staff [0] ['sid'];
  3205. $action_log->cid = $this->staff [0] ['cid'];
  3206. $action_log->status = 6;
  3207. $action_log->districtid = $clientname [0] ['district'];
  3208. $local = $district->getbyidlist ( $clientname [0] ['district'] );
  3209. $action_log->city = $local [0] ['name'];
  3210. $action_log->province = $local [1] ['name'];
  3211. $action_log->company = $clientname [0] ['companyname'];
  3212. Doo::loadModel ( 'company' );
  3213. $company = new company ();
  3214. $companyInfo = $company->getOne ( array (
  3215. 'where' => ' companyname="' . $clientname [0] ['companyname'] . '"',
  3216. 'asArray' => true
  3217. ) );
  3218. $nature = explode ( ',', $companyInfo ['nature'] );
  3219. $action_log->nature = $nature [0];
  3220. $action_log->insert ();
  3221. }elseif($status == 10){
  3222. $longle->alloted_time = $alloted_time;
  3223. $longle_log->mark ='由'.$linfo[0]['alloted_time'].'延期至'.$alloted_time;
  3224. // 日常行为
  3225. $action_log = new action_log ();
  3226. $action_log->action = $this->staff [0] ['category'] . '<b href="javascript:void(0)" onclick="showStaff(\'' . $this->staff [0] ['sid'] . '\')">' . $this->staff [0] ['username'] . '</b>为<a href="javascript:void(0)" onclick="showLook(\'' . $linfo [0] ['key_num'] . '\')">' . $linfo [0] ['key_num'] . '</a>延期至 '.$alloted_time;
  3227. $action_log->sid = $this->staff [0] ['sid'];
  3228. $action_log->cid = $this->staff [0] ['cid'];
  3229. $action_log->updatetime = date ( "Y-m-d" );
  3230. $action_log->time = date ( "H:i" );
  3231. $action_log->sid = $this->staff [0] ['sid'];
  3232. $action_log->cid = $this->staff [0] ['cid'];
  3233. $action_log->status = 12;
  3234. $action_log->class = $action_log->iconLock;
  3235. $action_log->insert ();
  3236. }
  3237. // 记录使用过的状态
  3238. $statuslog = $status . "," . $linfo [0] ['statuslog'];
  3239. $ar = explode ( ',', $statuslog );
  3240. $statuslog = implode ( ',', array_unique ( array_filter ( $ar ) ) );
  3241. $longle->statuslog = $statuslog;
  3242. if ($linfo [0] ['status'] <= 2) {
  3243. if ($status >= 4 && $status <= 2) {
  3244. return "/keyonline/" . $lid;
  3245. }
  3246. }
  3247. if ($lid != 0) {
  3248. $longle->lid = $lid;
  3249. if (!($status == 8||$status == 10))
  3250. $longle->status = $status;
  3251. // if($status!=8)
  3252. $longle->responsible = $this->staff [0] ['username'];
  3253. $longle->update ();
  3254. }
  3255. $longle_log->lid = $lid;
  3256. $longle_log->status = $status;
  3257. $longle_log->operator = $this->staff [0] ['username'];
  3258. // 责任人
  3259. $longle_log->category = $this->staff [0] ['category'];
  3260. $longle_log->dateline = date ( "Y-m-d" );
  3261. $longle_log->insert ();
  3262. echo json_encode ( array (
  3263. 'msg' => 1
  3264. ) );
  3265. die ();
  3266. // return "/keyonline/".$lid;
  3267. }
  3268. function ajaxGetLongleByName() {
  3269. Doo::loadModel ( 'longle_log' );
  3270. Doo::loadModel ( 'longle' );
  3271. $longle = new longle ();
  3272. $longle_log = new longle_log ();
  3273. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
  3274. if (empty ( $name )) {
  3275. echo json_encode ( array (
  3276. "success" => false
  3277. ) );
  3278. die ();
  3279. }
  3280. $ky = $longle->getLongleBykeynum ( $name );
  3281. $t = $longle_log->getLongleByLid ( $ky [0] ['lid'] );
  3282. if (isset ( $t [0] ))
  3283. $tk = $t [0];
  3284. else
  3285. $tk = array ();
  3286. $longleLog = $tk;
  3287. $longleLog ['klid'] = $t [0] ['lid'];
  3288. $longleLog ['longle'] = $ky [0];
  3289. $longleLog ['longleLogHtml'] = $this->_getLongleLogHtml ( $t );
  3290. echo json_encode ( $longleLog );
  3291. }
  3292. function ajaxGetLongleN() {
  3293. Doo::loadModel ( 'longle_log' );
  3294. Doo::loadModel ( 'longle' );
  3295. $longle = new longle ();
  3296. $longle_log = new longle_log ();
  3297. $keynum = $this->get_args ( 'keynum' ) ? $this->get_args ( 'keynum' ) : "";
  3298. if (empty ( $keynum )) {
  3299. echo json_encode ( array (
  3300. "success" => false
  3301. ) );
  3302. die ();
  3303. }
  3304. $ky = $longle->getLongleBykeynum ( $keynum );
  3305. if (! empty ( $ky )) {
  3306. $t = $longle_log->getLongleByLid ( $ky [0] ['lid'] );
  3307. if (isset ( $t [0] ))
  3308. $tk = $t [0];
  3309. else
  3310. $tk = array ();
  3311. $longleLog = $tk;
  3312. $longleLog ['klid'] = $ky [0] ['lid'];
  3313. $longleLog ['longle'] = $ky [0];
  3314. $longleLog ['longleLogHtml'] = $this->_getLongleLogHtml ( $t );
  3315. echo json_encode ( $longleLog );
  3316. }
  3317. }
  3318. function ajaxGetLongle() {
  3319. Doo::loadModel ( 'longle_log' );
  3320. Doo::loadModel ( 'longle' );
  3321. $longle = new longle ();
  3322. $longle_log = new longle_log ();
  3323. Doo::loadClass ( 'XDeode' );
  3324. $XDeode = new XDeode ( 5 );
  3325. $lid = $this->get_args ( 'lid' ) ? $this->get_args ( 'lid' ) : 0;
  3326. if ($lid == 0) {
  3327. echo json_encode ( array (
  3328. "success" => false
  3329. ) );
  3330. die ();
  3331. }
  3332. $t = $longle_log->getLongleByLid ( $lid );
  3333. if (isset ( $t [0] ))
  3334. $tk = $t [0];
  3335. else
  3336. $tk = array ();
  3337. $longleLog = $tk;
  3338. $longleLog ['klid'] = $lid;
  3339. $longleLog ['lidKey'] =$XDeode->encode ( $lid );
  3340. $ky = $longle->getLongleByLid ( $lid );
  3341. $longleLog ['longle'] = $ky [0];
  3342. $longleLog ['longleLogHtml'] = $this->_getLongleLogHtml ( $t );
  3343. echo json_encode ( $longleLog );
  3344. }
  3345. function ajaxGetStaffInfo() {
  3346. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  3347. if ($username == "") {
  3348. echo json_encode ( array (
  3349. "success" => false
  3350. ) );
  3351. die ();
  3352. }
  3353. Doo::loadModel ( 'staff' );
  3354. $staff = new staff ();
  3355. $staffInfo = $staff->getOne ( array (
  3356. 'where' => ' username like "' . $username . '"',
  3357. 'asArray' => TRUE
  3358. ) );
  3359. if (empty ( $staffInfo )) {
  3360. echo json_encode ( array (
  3361. "success" => false,
  3362. 'html' => ''
  3363. ) );
  3364. die ();
  3365. }
  3366. $staffHtml = array (
  3367. 'html' => '<div class="contactPanel"><h1>' . $staffInfo ['username'] . '</h1>
  3368. <table><tbody><tr><th>性别</th><td>' . $staffInfo ['gender'] . '</td><th>办事处</th><td>' . $staffInfo ['category'] . '</td></tr>
  3369. <tr><th>手机</th><td>' . $staffInfo ['telephone'] . '</td><th>电话</th><td>' . $staffInfo ['phone'] . '</td></tr>
  3370. <tr><th>QQ</th><td>' . $staffInfo ['qq'] . '</td><th>邮箱</th><td>' . $staffInfo ['email'] . '</td></tr>
  3371. </tbody></table>
  3372. </div>'
  3373. );
  3374. echo json_encode ( $staffHtml );
  3375. }
  3376. function ajaxGetCompanyByAdd() {
  3377. session_start ();
  3378. $cidKey = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  3379. if (empty($cidKey)){
  3380. echo json_encode ( array (
  3381. "success" => false,
  3382. 'data' => ''
  3383. ) );
  3384. }
  3385. Doo::loadClass ( 'XDeode' );
  3386. $XDeode = new XDeode ( 5 );
  3387. $cid = $XDeode->decode ( $cidKey );
  3388. if (! empty ( $cid )) {
  3389. Doo::loadModel ( 'company' );
  3390. $company = new company ();
  3391. Doo::loadModel ( 'client' );
  3392. Doo::loadModel ( 'district' );
  3393. $district = new district ();
  3394. $client = new client ();
  3395. $districtInfo = $district->get_lv ( 1 );
  3396. // $companyInfo = $client->getClientByCompanyId ( $cid );
  3397. // $companyInfo = $companyInfo [0];
  3398. $companyInfo = $company->getOne ( array (
  3399. 'where' => "cid = " . $cid,
  3400. 'asArray' => TRUE
  3401. ) );
  3402. $companyInfo ['companyKey'] = $XDeode->encode ( $companyInfo ['cid'] );
  3403. // $companyInfo ['companyname'] = $cInfo ['companyname'];
  3404. // $companyInfo ['address'] = $cInfo ['address'];
  3405. // $companyInfo ['ride'] = $cInfo ['ride'];
  3406. // $companyInfo ['landmarks'] = $cInfo ['landmarks'];
  3407. // $companyInfo ['stay'] = $cInfo ['stay'];
  3408. $artld = explode ( ',', $companyInfo ['local'] );
  3409. $districtid = explode ( ',', $companyInfo ['district'] );
  3410. $html = "";
  3411. $html .= '<select name="lv21" id="lv31" onchange="dislv(\'lv31\',\'32\');"><option value="' . $districtid [0] . '">' . $artld [0] . '</option>';
  3412. // foreach ($districtInfo as $key=>$value){
  3413. //
  3414. // $html.='<option selected value="'.$value['id'].'">'.$value['name'].'</option>';
  3415. // }
  3416. $html .= '</select>&nbsp;';
  3417. $html .= '<span id="mlv32">
  3418. <select id="lv32" name="lv22">
  3419. <option selected value="' . $districtid [1] . '" >' . $artld [1] . '</option>
  3420. </select>
  3421. </span>';
  3422. $html .= '<span id="mlv33">
  3423. <select id="lv33" name="lv23">
  3424. <option selected value="' . $districtid [2] . '" >' . $artld [2] . '</option>
  3425. </select>&nbsp;
  3426. </span>';
  3427. $companyInfo ['dishtml'] = $html;
  3428. $companyInfo ['natureAr'] = $this->nature;
  3429. $companyInfo ['natureArlenght'] = 12;
  3430. $token = $this->set_token ();
  3431. $_SESSION ['token_' . $this->staff [0] ['sidKey']] = $token;
  3432. $companyInfo ['token'] = $token;
  3433. echo json_encode ( array (
  3434. "success" => true,
  3435. 'data' => $companyInfo
  3436. ) );
  3437. die ();
  3438. } else
  3439. echo json_encode ( array (
  3440. "success" => false,
  3441. 'data' => ''
  3442. ) );
  3443. die ();
  3444. }
  3445. function doEditCompanyD() {
  3446. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  3447. $companyname = $this->get_args ( 'companyname' ) ? $this->get_args ( 'companyname' ) : "";
  3448. $lv21 = $this->get_args ( 'lv21' ) ? $this->get_args ( 'lv21' ) : 0;
  3449. $lv22 = $this->get_args ( 'lv22' ) ? $this->get_args ( 'lv22' ) : 0;
  3450. $lv23 = $this->get_args ( 'lv23' ) ? $this->get_args ( 'lv23' ) : 0;
  3451. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  3452. $fax = $this->get_args ( 'fax' ) ? $this->get_args ( 'fax' ) : "";
  3453. $webservice = $this->get_args ( 'webservice' ) ? $this->get_args ( 'webservice' ) : "";
  3454. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  3455. $ride = $this->get_args ( 'ride' ) ? $this->get_args ( 'ride' ) : "";
  3456. $stay = $this->get_args ( 'stay' ) ? $this->get_args ( 'stay' ) : "";
  3457. $landmarks = $this->get_args ( 'landmarks' ) ? $this->get_args ( 'landmarks' ) : "";
  3458. if (empty ( $cid ) || empty ( $companyname )) {
  3459. echo json_encode ( array (
  3460. "success" => false
  3461. ) );
  3462. die ();
  3463. }
  3464. Doo::loadModel ( "company" );
  3465. Doo::loadModel ( "client" );
  3466. $client = new client ();
  3467. $company = new company ();
  3468. $company->cid = $cid;
  3469. if (! empty ( $lv21 ) && ! empty ( $lv22 ) && ! empty ( $lv23 )) {
  3470. Doo::loadModel ( 'district' );
  3471. $district = new district ();
  3472. // 更新公司信息
  3473. $lv1 = $district->getbyid ( $lv21 );
  3474. $lv2 = $district->getbyid ( $lv22 );
  3475. $lv3 = $district->getbyid ( $lv23 );
  3476. $company->district = $lv21 . "," . $lv22 . "," . $lv23;
  3477. $company->local = $lv1 [0] ['name'] . "," . $lv2 [0] ['name'] . "," . $lv3 [0] ['name'];
  3478. }
  3479. if (! empty ( $nature )) {
  3480. $nature = implode ( ",", $nature );
  3481. $company->nature = $nature;
  3482. }
  3483. if (! empty ( $companyname )) {
  3484. $company->companyname = $companyname;
  3485. $client->companyname = $companyname;
  3486. }
  3487. if (! empty ( $fax ))
  3488. $company->fax = $fax;
  3489. if (! empty ( $webservice ))
  3490. $company->webservice = $webservice;
  3491. $company->address = $address;
  3492. $company->ride = $ride;
  3493. $company->stay = $stay;
  3494. $company->landmarks = $landmarks;
  3495. $company->update ();
  3496. $client->update ( array (
  3497. 'where' => ' companyid =' . $cid
  3498. ) );
  3499. echo json_encode ( array (
  3500. "success" => true
  3501. ) );
  3502. die ();
  3503. }
  3504. function ajaxEditCompany() {
  3505. $companyname = $this->get_args ( 'companyId' ) ? $this->get_args ( 'companyId' ) : 0;
  3506. if (! empty ( $companyname )) {
  3507. Doo::loadModel ( 'company' );
  3508. $company = new company ();
  3509. $companyInfo = $company->getOne ( array (
  3510. 'where' => "cid = '" . $companyname . "'",
  3511. 'asArray' => TRUE
  3512. ) );
  3513. if (! empty ( $companyInfo )) {
  3514. Doo::loadModel ( 'district' );
  3515. $district = new district ();
  3516. $districtinfo = $district->get_lv ( 1 );
  3517. $dinfo = $district->getbyidlist ( $companyInfo ['district'] );
  3518. $html = '
  3519. <div class="contactInfo clearfix">
  3520. <div class="header">
  3521. <h1 class="companyName">' . $companyInfo ['companyname'] . '</h1>
  3522. </div>
  3523. </div>
  3524. <div class="lockRecord">
  3525. <div class="contactPanel">
  3526. <table>
  3527. <tbody><tr><th>单位全称</th><td colspan="3"><input type="text" name="companyname" id="companyname" value="' . $companyInfo ['companyname'] . '"></td></tr>
  3528. <tr><th>地区</th><td colspan="3">
  3529. <select name="lv21" id="lv21" onchange="dislv(\'lv21\',22);">
  3530. <option value="0">请选择</option>';
  3531. foreach ( $districtinfo as $key => $value ) {
  3532. if ($value ['id'] == $dinfo [0] ['id'])
  3533. $html .= '<option selected value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  3534. else
  3535. $html .= '<option value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  3536. }
  3537. $html .= '</select>
  3538. <span id="mlv22">
  3539. <select id="lv22">
  3540. <option value="' . $dinfo [1] ['id'] . '">' . $dinfo [1] ['name'] . '</option>
  3541. </select>
  3542. </span>
  3543. <span id="mlv23">
  3544. <select id="lv23">
  3545. <option value="' . $dinfo [2] ['id'] . '">' . $dinfo [2] ['name'] . '</option>
  3546. </select>&nbsp;
  3547. </span>
  3548. </td></tr>
  3549. ';
  3550. $html .= '<tr><th>性质</th><td colspan="3">';
  3551. $ntre = explode ( ",", $companyInfo ['nature'] );
  3552. foreach ( $this->nature as $key => $value ) {
  3553. $falg = true;
  3554. foreach ( $ntre as $k => $v ) {
  3555. if ($value == $v) {
  3556. $falg = false;
  3557. $html .= '<label><input type="checkbox" checked name="nature[]" value="' . $value . '">' . $value . '</label>&nbsp;';
  3558. }
  3559. }
  3560. if ($falg)
  3561. $html .= '<label><input type="checkbox" name="nature[]" value="' . $value . '">' . $value . '</label>&nbsp;';
  3562. }
  3563. $html .= ' </td></tr>
  3564. <tr><th>传真</th><td><input type="text" name="fax" id="fax" value="' . $companyInfo ['fax'] . '"> </td><th>主页</th><td><input type="text" name="webservice" id="webservice" value="' . $companyInfo ['webservice'] . '"> </td></tr>
  3565. <tr><th>单位地址</th><td colspan="3"><input type="text" name="address" id="address" value="' . $companyInfo ['address'] . '"> </td></tr>
  3566. <tr><th>乘车路线</th><td colspan="3"><input type="text" name="ride" id="ride" value="' . $companyInfo ['ride'] . '"> </td></tr>
  3567. <tr><th>地标建筑</th><td colspan="3"><input type="text" name="landmarks" id="landmarks" value="' . $companyInfo ['landmarks'] . '"> </td></tr>
  3568. <tr><th>住宿参考</th><td colspan="3"><input type="text" name="stay" id="stay" value="' . $companyInfo ['stay'] . '"> </td></tr>
  3569. <tr><td colspan="4"><input type="hidden" name="cid" id="cid" value="' . $companyInfo ['cid'] . '"><input type="button" onclick="doCompanyEdit()" class="button" value="确定"><span id="editCompanyD"></span></td></tr>
  3570. </tbody></table>
  3571. <div class="bsAlert bsInfo">单位全称将与该单位已存在的客户进行同步;其他单位信息不会进行同步;<br>单位信息随该单位第一位客户录入,并作为“在这添加客户”的基础数据</div>
  3572. </div>
  3573. </div>
  3574. ';
  3575. echo json_encode ( array (
  3576. "success" => true,
  3577. 'html' => $html
  3578. ) );
  3579. die ();
  3580. }
  3581. } else
  3582. echo json_encode ( array (
  3583. "success" => false,
  3584. 'html' => ''
  3585. ) );
  3586. die ();
  3587. }
  3588. function ajaxGetCompany() {
  3589. $companyIdKey = $this->get_args ( 'companyId' ) ? $this->get_args ( 'companyId' ) : 0;
  3590. if (empty($companyIdKey)){
  3591. echo json_encode ( array (
  3592. "success" => false,
  3593. 'html' => ''
  3594. ) );
  3595. }
  3596. Doo::loadClass ( 'XDeode' );
  3597. $XDeode = new XDeode ( 5 );
  3598. $companyname = $XDeode->decode ( $companyIdKey );
  3599. if (! empty ( $companyname )) {
  3600. Doo::loadModel ( 'company' );
  3601. $company = new company ();
  3602. $companyInfo = $company->getOne ( array (
  3603. 'where' => "cid = '" . $companyname . "'",
  3604. 'asArray' => TRUE
  3605. ) );
  3606. if (! empty ( $companyInfo )) {
  3607. Doo::loadModel ( 'client' );
  3608. Doo::loadModel ( 'staff' );
  3609. Doo::loadModel ( 'client_staff' );
  3610. Doo::loadModel ( 'longle' );
  3611. $longle = new longle ();
  3612. $client_staff = new client_staff ();
  3613. $staff = new staff ();
  3614. $client = new client ();
  3615. Doo::loadModel ( 'district' );
  3616. $district = new district ();
  3617. $clientlist = $client->getClientByCompanyId ( $companyInfo ['cid'] );
  3618. $department = $client->getDepartment ( $companyInfo ['cid'] );
  3619. Doo::loadModel ( "tagCompanyNexus" );
  3620. Doo::loadModel ( "tagCompany" );
  3621. $tag = new tagCompany ();
  3622. $tag_client = new tagCompanyNexus ();
  3623. $tagId = $tag_client->getTagClientBySCid ( $companyInfo ['cid'], $this->staff [0] ['sid'] );
  3624. $taginfo = $tag->getTagByTidL ( $tagId ['tag'] );
  3625. $taghtml = "";
  3626. foreach ( $taginfo as $key => $value ) {
  3627. $taghtml .= '<span class="contactsTag tagCol-0' . $value ['colorid'] . '">' . $value ['name'] . '</span>';
  3628. }
  3629. $html = '<div class="header">
  3630. <h1 class="companyName"><div class="fR">
  3631. <a class="icon- add" node-syn="show" href="javascript:void(0)" title="同步地址信息">S</a>
  3632. <a href="javascript:void(0)" title="编辑单位" class="icon- edit" onclick="editByCompany(' . $companyInfo ['cid'] . ')" >I</a> |
  3633. <a title="在这个单位下添加客户" href="javascript:void(0)" class="icon- add" onclick="addClientByCompany(\'' . $companyIdKey . '\')" >H</a></div>' . $companyInfo ['companyname'] . '</h1>
  3634. <div class="contactPanel">
  3635. <table>
  3636. <tbody>
  3637. <tr><th>单位地区</th><td><span>' . $companyInfo ['local'] . '</span></td><th>单位性质</th><td>' . $companyInfo ['nature'] . '</td></tr>
  3638. <tr><th>单位地址</th><td colspan="3">' . $companyInfo ['address'] . '</td></tr>
  3639. <tr><th>单位乘车</th><td colspan="3">' . $companyInfo ['ride'] . '</td></tr>
  3640. <tr><th>单位地标</th><td colspan="3">' . $companyInfo ['landmarks'] . '</td></tr>
  3641. <tr><th>单位住宿</th><td colspan="3">' . $companyInfo ['stay'] . '</td></tr>
  3642. <tr><td colspan="4">
  3643. ' . $taghtml . '
  3644. </td></tr>
  3645. <tr><td colspan="4" >
  3646. <a class="button" style="display:none" node-synadd="true" href="javascript:void(0)">确定同步</a>
  3647. <span node-synAdd="msg" class="bsAlert bsSuccess fL hide"></span>
  3648. <span class="hide" id="skop">已选择 <span id="tl">0</span>/<span id="bl">' . sizeof ( $clientlist ) . '</span>
  3649. <input type="checkbox" name="CASYN[]" cas-all="TR" class="hide" value="19595" style="display: inline-block;">全选客户
  3650. </td>
  3651. </tr>
  3652. </tbody></table></div>
  3653. <h2 class="cate">';
  3654. $html .= '<a href="javascript:void(0)" onclick="departmentC()" class="now">不限</a>';
  3655. foreach ( $department as $key => $value ) {
  3656. if ($value != "")
  3657. $html .= '<a href="javascript:void(0)" onclick="departmentC(\'' . $value ['department'] . '\')">' . $value ['department'] . '</a>';
  3658. }
  3659. $html .= '</h2></div><script>$(".header .cate a").click(function(){
  3660. $(this).addClass("now").siblings("a").removeClass("now");
  3661. });
  3662. </script>';
  3663. $html .= '<div class="lockRecord autoHeightR2" >';
  3664. foreach ( $clientlist as $key => $value ) {
  3665. $scinfo = $client_staff->getClientByCid ( $value ['cid'] );
  3666. $staffinfo = $staff->getUserById ( $scinfo ['sid'] );
  3667. // 客户信息
  3668. $html .= '<div class="contactPanel" id="PART_' . $value ['department'] . '">
  3669. <h1><p class="fR">' . $staffinfo [0] ['category'] . '-<a href="javascript:void(0)" onclick="getStaffInfo(\'' . $staffinfo [0] ['username'] . '\')" >
  3670. ' . $staffinfo [0] ['username'] . '</a></p>
  3671. <input type="checkbox" name="CASYN[]" CAS-NUM="TR" class="hide" value="' . $value ['cid'] . '">
  3672. <a href="javascript:void(0)" onclick="getClientInfo(\'' . $value ['cid'] . '\')" class="clientName">' . $value ['clientname'] . ' </a>
  3673. <i class="icon- sport">' . $value ['priority'] . '</i><a class="icon- edit" title="编辑客户" href="javascript:clientEdit(' . $value ['cid'] . ')">I</a></h1><table>
  3674. <tbody><tr><th>性别</th><td>' . $value ['gender'] . '</td><th>昵称</th><td>' . $value ['nicename'] . '</td></tr>
  3675. <tr><th>部门</th><td>' . $value ['department'] . '</td><th>办公室</th><td>' . $value ['office'] . '</td></tr>
  3676. <tr><th>手机</th><td>' . $value ['telephone'] . '</td><th>电话</th><td>' . $value ['phone'] . '</td></tr>
  3677. <tr><th>QQ</th><td>' . $value ['qq'] . '</td><th>邮箱</th><td>' . $value ['email'] . '</td></tr>
  3678. <tr node-ck=fz ><th>备注</th><td >' . $value ['mark'] . '</td>
  3679. </tr>';
  3680. $longleinfo = $longle->getLongleByClientid ( $value ['cid'] );
  3681. if (empty ( $longleinfo )) {
  3682. $longleinfo = array (
  3683. 0 => array (
  3684. 'lid' => '',
  3685. 'key_num' => '',
  3686. 'product' => '',
  3687. 'statusT' => ''
  3688. )
  3689. );
  3690. }
  3691. $html .= '<tr node-ck=fz ><th>软件锁</th><td colspan="3"><a href="javascript:void(0)" onclick="getLongleLog(' . $longleinfo [0] ['lid'] . ')">' . $longleinfo [0] ['key_num'] . '</a>/' . $longleinfo [0] ['product'] . '/' . $longleinfo [0] ['statusT'] . '</td></tr>';
  3692. $districtList = $district->getbyidlist ( $value ['district'] );
  3693. $localdis = '';
  3694. foreach ( $districtList as $lov ) {
  3695. $localdis .= ' ' . $lov ['name'];
  3696. }
  3697. $html .= '
  3698. <tr node-synCom=pany style="display:none" ><th>客户地区</th><td colspan="4">' . $localdis . '</td></tr>
  3699. <tr node-synCom=pany style="display:none" ><th>客户地址</th><td colspan="4">' . $value ['address'] . '</td></tr>
  3700. <tr node-synCom=pany style="display:none" ><th>客户乘车</th><td colspan="4">' . $value ['ride'] . '</td></tr>
  3701. <tr node-synCom=pany style="display:none" ><th>客户地标</th><td colspan="4">' . $value ['landmarks'] . '</td></tr>
  3702. <tr node-synCom=pany style="display:none" ><th>客户住宿</th><td colspan="4">' . $value ['stay'] . '</td></tr>';
  3703. $html .= '</tbody></table></div>';
  3704. }
  3705. $html .= "</div><script type='text/javascript'>
  3706. $(\"a[node-syn=show]\").click(function() {
  3707. $(\"a[node-synadd='true']\").show();
  3708. $('input[CAS-NUM=TR]').show();
  3709. $('#skop').show();
  3710. $('tr[node-ck=fz]').hide();
  3711. $('tr[node-synCom=pany]').show();
  3712. });
  3713. $(\"input[cas-all='TR']\").click(function() {
  3714. if (this.checked) {
  3715. $(\"input[CAS-NUM=TR]:checkbox\").each(function() {
  3716. $(this).attr(\"checked\", true);
  3717. })
  3718. }else{
  3719. $(\"input[CAS-NUM=TR]:checkbox\").each(function() {
  3720. $(this).attr(\"checked\", false);
  3721. })
  3722. }
  3723. $('#tl').html($('input[CAS-NUM=TR]:checked').length);
  3724. });
  3725. $(\"input[CAS-NUM='TR']\").click(function() {
  3726. $('#tl').html($('input[CAS-NUM=TR]:checked').length);
  3727. });
  3728. $(\"a[node-synadd='true']\").click(function() {
  3729. var id_array=new Array();
  3730. $('input[CAS-NUM=TR]:checked').each(function(){
  3731. id_array.push($(this).val());
  3732. });
  3733. if(id_array.length==0){
  3734. alert('未选中客户');
  3735. }else{
  3736. var idstr=id_array.join(',');
  3737. var url='/ajaxSetCompanyAddress';
  3738. $.ajax({
  3739. url:url,
  3740. type: 'post',
  3741. cache: false,
  3742. dataType: 'json',
  3743. data: {
  3744. cidString:idstr,
  3745. company:" . $companyInfo ['cid'] . "
  3746. },
  3747. global: true,
  3748. success: function(data){
  3749. if(data.status>0){
  3750. $(\"span[node-synAdd=msg]\").html('同步成功');
  3751. for(var i=0;i<id_array.length;i++){
  3752. $(\"td[node-address=company_\"+id_array[i]+\"]\").html('" . $companyInfo ['address'] . "');
  3753. }
  3754. $(\"a[node-synadd='true']\").hide();
  3755. $('input[CAS-NUM=TR]').hide();
  3756. $('#skop').hide();
  3757. $(\"span[node-synAdd=msg]\").show().delay(2000).fadeOut();
  3758. }else if(data.status==-1){
  3759. $(\"span[node-synAdd=msg]\").html('操作不成功');
  3760. $(\"span[node-synAdd=msg]\").show().delay(2000).fadeOut();
  3761. }else if(data.status==0){
  3762. $(\"span[node-synAdd=msg]\").html('地址已同步过');
  3763. $(\"span[node-synAdd=msg]\").show().delay(2000).fadeOut();
  3764. }
  3765. },
  3766. error:function(err){
  3767. }
  3768. });
  3769. }
  3770. });
  3771. autoFlashHeight();
  3772. </script>";
  3773. echo json_encode ( array (
  3774. "success" => true,
  3775. 'html' => $html
  3776. ) );
  3777. die ();
  3778. }
  3779. }
  3780. die ();
  3781. }
  3782. function ajaxSetCompanyAddress() {
  3783. $cidString = $this->get_args ( 'cidString' ) ? $this->get_args ( 'cidString' ) : "";
  3784. $companyId = $this->get_args ( 'company' ) && is_numeric ( $this->get_args ( 'company' ) ) ? $this->get_args ( 'company' ) : 0;
  3785. if (! empty ( $cidString ) && ! empty ( $companyId )) {
  3786. Doo::loadModel ( 'client' );
  3787. $client = new client ();
  3788. Doo::loadModel ( 'company' );
  3789. $company = new company ();
  3790. $cidList = explode ( ',', $cidString );
  3791. foreach ( $cidList as $value ) {
  3792. if (! is_numeric ( $value ))
  3793. die ( 'illegal request3' );
  3794. }
  3795. $companyInfo = $company->getOne ( array (
  3796. 'where' => "cid = '" . $companyId . "'",
  3797. 'asArray' => TRUE
  3798. ) );
  3799. $client->address = $companyInfo ['address'];
  3800. $client->ride = $companyInfo ['ride'];
  3801. $client->landmarks = $companyInfo ['landmarks'];
  3802. $client->stay = $companyInfo ['stay'];
  3803. $client->local = $companyInfo ['local'];
  3804. $client->district = $companyInfo ['district'];
  3805. $falg = $client->update ( array (
  3806. 'where' => 'companyid =' . $companyInfo ['cid'] . ' and cid in (' . $cidString . ')'
  3807. ) );
  3808. echo json_encode ( array (
  3809. 'status' => $falg,
  3810. 'msg' => 'illegal request2'
  3811. ) );
  3812. die ();
  3813. }
  3814. echo json_encode ( array (
  3815. 'status' => - 1,
  3816. 'msg' => 'illegal request'
  3817. ) );
  3818. die ();
  3819. }
  3820. function checkclicomname() { // 地区区分
  3821. $companyname = $this->get_args ( 'companyname' ) ? $this->get_args ( 'companyname' ) : "";
  3822. $clientname = $this->get_args ( 'clientname' ) ? $this->get_args ( 'clientname' ) : "";
  3823. $district1 = $this->get_args ( 'district1' ) ? $this->get_args ( 'district1' ) : 0;
  3824. $district2 = $this->get_args ( 'district2' ) ? $this->get_args ( 'district2' ) : 0;
  3825. $district3 = $this->get_args ( 'district3' ) ? $this->get_args ( 'district3' ) : 0;
  3826. Doo::loadModel ( 'client' );
  3827. $client = new client ();
  3828. $local = $district1 . "," . $district2 . "," . $district3;
  3829. $companyname = trim ( $companyname );
  3830. $clientname = trim ( $clientname );
  3831. $clientinfo = $client->getClientToName ( $clientname, $companyname, $local );
  3832. if (! empty ( $clientinfo )) {
  3833. echo json_encode ( array (
  3834. 'success' => false
  3835. ) );
  3836. } else {
  3837. echo json_encode ( array (
  3838. 'success' => true
  3839. ) );
  3840. }
  3841. }
  3842. function ajaxGetClientInfoN() {
  3843. $clientname = $this->get_args ( 'client' ) ? $this->get_args ( 'client' ) : "";
  3844. if ($clientname == "") {
  3845. echo json_encode ( array (
  3846. "success" => false
  3847. ) );
  3848. die ();
  3849. }
  3850. Doo::loadModel ( 'client' );
  3851. Doo::loadModel ( 'client_staff' );
  3852. Doo::loadModel ( 'longle' );
  3853. Doo::loadModel ( 'company' );
  3854. Doo::loadModel ( 'service_log' );
  3855. $service_log = new service_log ();
  3856. $company = new company ();
  3857. $longle = new longle ();
  3858. $client = new client ();
  3859. $client_staff = new client_staff ();
  3860. $clientInfo = $client->getOne ( array (
  3861. "where" => ' cid like "' . $clientname . '"',
  3862. 'asArray' => TRUE
  3863. ) );
  3864. if (empty ( $clientInfo )) {
  3865. echo json_encode ( array (
  3866. "success" => false,
  3867. 'html' => ''
  3868. ) );
  3869. die ();
  3870. }
  3871. // 获取锁
  3872. $longleInfo = $longle->getLongleByClientid ( $clientname );
  3873. $k = "";
  3874. foreach ( $longleInfo as $key => $value ) {
  3875. if ($value ['status'] == 6 || $value ['status'] == 7)
  3876. $k .= '<a href="javascript:void(0)" class="disenable" onclick="getLock(' . $value ['lid'] . ')" >' . $value ['key_num'] . '/' . $value ['product'] . '/' . $value ['statusT'] . '</a>&nbsp; ';
  3877. else
  3878. $k .= '<a href="javascript:void(0)" onclick="getLock(' . $value ['lid'] . ')" >' . $value ['key_num'] . '/' . $value ['product'] . '/' . $value ['statusT'] . '</a>&nbsp; ';
  3879. }
  3880. // 获取办事人
  3881. $staffInfo = $client_staff->getClientByCid ( $clientInfo ['cid'] );
  3882. // 获取公司信息
  3883. $companyInfo = $company->getCompanyByCid ( $clientInfo ['companyid'] );
  3884. $serviceLog = $service_log->getServiceByClientid ( $clientInfo ['cid'] );
  3885. $u = "";
  3886. $order = array (
  3887. "\r\n",
  3888. "\n",
  3889. "\r"
  3890. );
  3891. $replace = '</br>';
  3892. foreach ( $serviceLog as $key => $value ) {
  3893. $datetime = explode ( "-", $value ['date'] );
  3894. $u .= '<div class="infoFlowList">
  3895. <div class="dateTitle">
  3896. <em class="month"><span class="num">' . $datetime ['1'] . '</span><span class="text">-' . $datetime ['2'] . '</span></em>
  3897. <span class="year">' . $datetime ['0'] . '</span>
  3898. </div>
  3899. <ul class="flowList">';
  3900. if ($value ['status'] == 1)
  3901. $u .= '<li class="item iconService">上门服务</li>';
  3902. elseif ($value ['status'] == 2)
  3903. $u .= '<li class="item iconPhone">电话拜访</li>';
  3904. elseif ($value ['status'] == 3)
  3905. $u .= '<li class="item iconOther">其他</li>';
  3906. $u .= '
  3907. <li class="item">' . $value ['category'] . '<a href="javascript:void(0)" onclick="getStaffInfo(\'' . $value ['staffname'] . '\')" >' . $value ['staffname'] . '</a></li>
  3908. <li class="item">
  3909. ' . str_replace ( $order, $replace, $value ['mark'] ) . '
  3910. </li>
  3911. </ul>
  3912. </div>';
  3913. }
  3914. Doo::loadModel ( "tag_client" );
  3915. Doo::loadModel ( "tag" );
  3916. $tag = new tag ();
  3917. $tag_client = new tag_client ();
  3918. $tagId = $tag_client->getTagClientBySCid ( $clientInfo ['cid'], $this->staff [0] ['sid'] );
  3919. $taginfo = $tag->getTagByTidL ( $tagId ['tag'] );
  3920. // $taghtml="";
  3921. //
  3922. // foreach ($taginfo as $key=>$value){
  3923. // $taghtml.='<span class="contactsTag tagCol-0'.$value['colorid'].'">'.$value['name'].'</span>';
  3924. // }
  3925. $mhtml = "";
  3926. $dhtml = "";
  3927. for($month = 1; $month <= 12; $month ++) {
  3928. if (date ( "m" ) == $month)
  3929. $mhtml .= '<option selected value="' . $month . '">' . $month . '月</option>';
  3930. else
  3931. $mhtml .= '<option value="' . $month . '">' . $month . '月</option>';
  3932. }
  3933. for($day = 1; $day <= 31; $day ++) {
  3934. if (date ( "d" ) == $day)
  3935. $dhtml .= '<option selected value="' . $day . '">' . $day . '日</option>';
  3936. else
  3937. $dhtml .= '<option value="' . $day . '">' . $day . '日</option>';
  3938. }
  3939. // $b="";
  3940. // if(!empty($staffInfo))
  3941. // $b='<p class="fR">'.$staffInfo['category'].'-<a href="javascript:void(0)" onclick="getStaffInfo(\''.$staffInfo['username'].'\')" >'.$staffInfo['username'].'</a></p>'.$clientInfo['clientname'].' ';
  3942. //
  3943. $m = "";
  3944. if (! empty ( $companyInfo )) {
  3945. $m = '
  3946. <table width="100%">
  3947. <tbody>
  3948. <tr><th>单位全称</th><td colspan="3"><a href="javascript:void(0)" >' . $companyInfo [0] ['companyname'] . '</a></td></tr>
  3949. <tr><th>地区</th><td>' . $companyInfo [0] ['local'] . '</td><th>部门/职位</th><td>' . $clientInfo ['department'] . '/' . $clientInfo ['position'] . '</td></tr>
  3950. <tr><th>传真</th><td>' . $companyInfo [0] ['fax'] . '</td><th>办公室</th><td>' . $clientInfo ['office'] . '</td></tr>
  3951. <tr><th>单位地址</th><td colspan="3">' . $companyInfo [0] ['address'] . '</td></tr>
  3952. <tr><th>乘车路线</th><td colspan="3">' . $companyInfo [0] ['ride'] . '</td></tr>
  3953. <tr><th>地标建筑</th><td colspan="3">' . $companyInfo [0] ['landmarks'] . '</td></tr>
  3954. <tr><th>参考住宿</th><td colspan="3">' . $clientInfo ['stay'] . '</td></tr>
  3955. <tr><th>单位主页</th><td colspan="3">' . $clientInfo ['webservice'] . '</td></tr>
  3956. </tbody></table>
  3957. ';
  3958. }
  3959. $clientHtml = array (
  3960. 'html' => '
  3961. <div class="modal-dialog ">
  3962. <div class="modal-content">
  3963. <div class="modal-header">
  3964. <h3><span class="fR"><a>' . $staffInfo ['category'] . ' ' . $staffInfo ['username'] . '</a></span>' . $clientInfo ['clientname'] . '</h3>
  3965. </div>
  3966. <div class="modal-body">
  3967. <div class="modalClientTable">
  3968. <table width="100%">
  3969. <tbody><tr><th>性别</th><td>' . $clientInfo ['gender'] . '</td><th>昵称</th><td>' . $clientInfo ['nicename'] . '</td></tr>
  3970. <tr><th>手机</th><td>' . $clientInfo ['telephone'] . '</td><th>QQ</th><td>' . $clientInfo ['qq'] . '</td></tr>
  3971. <tr><th>电话</th><td>' . $clientInfo ['phone'] . '</td><th>邮箱</th><td>' . $clientInfo ['email'] . '</td></tr>
  3972. <tr><th>软件锁</th><td colspan="3"> <div class="lockContent">' . $k . '</div></td></tr>
  3973. <tr><td colspan="4">
  3974. </td></tr>
  3975. </tbody>
  3976. </table>
  3977. ' . $m . '
  3978. <div class="clearfix">
  3979. ' . $u . '
  3980. </div>
  3981. </div>
  3982. </div>
  3983. <div class="modal-footer">
  3984. <a href="javascript:void(0)" onclick="closeClick()" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a>
  3985. </div>
  3986. </div></div>'
  3987. );
  3988. echo json_encode ( $clientHtml );
  3989. }
  3990. function ajaxGetClientInfo() {
  3991. $clientname = $this->get_args ( 'client' )&&is_numeric($this->get_args ( 'client' )) ? $this->get_args ( 'client' ) : "";
  3992. if ($clientname == "") {
  3993. echo json_encode ( array (
  3994. "success" => false
  3995. ) );
  3996. die ();
  3997. }
  3998. Doo::loadModel ( 'client' );
  3999. Doo::loadModel ( 'client_staff' );
  4000. Doo::loadModel ( 'longle' );
  4001. Doo::loadModel ( 'company' );
  4002. Doo::loadModel ( 'service_log' );
  4003. Doo::loadModel ( "district" );
  4004. $district = new district ();
  4005. $service_log = new service_log ();
  4006. $company = new company ();
  4007. $longle = new longle ();
  4008. $client = new client ();
  4009. $client_staff = new client_staff ();
  4010. $clientInfo = $client->getOne ( array (
  4011. "where" => ' cid = "' . $clientname . '"',
  4012. 'asArray' => TRUE
  4013. ) );
  4014. if (empty ( $clientInfo )) {
  4015. echo json_encode ( array (
  4016. "success" => false,
  4017. 'html' => ''
  4018. ) );
  4019. die ();
  4020. }
  4021. // 获取锁
  4022. $longleInfo = $longle->getLongleByClientid ( $clientInfo ['cid'] );
  4023. $k = "";
  4024. foreach ( $longleInfo as $key => $value ) {
  4025. if ($value ['status'] == 6 || $value ['status'] == 7)
  4026. $k .= '<a href="javascript:void(0)" class="disenable" onclick="getLock(' . $value ['lid'] . ')" >' . $value ['key_num'] . '/' . $value ['product'] . '/' . $value ['statusT'] . '</a>&nbsp; ';
  4027. else
  4028. $k .= '<a href="javascript:void(0)" onclick="getLock(' . $value ['lid'] . ')" >' . $value ['key_num'] . '/' . $value ['product'] . '/' . $value ['statusT'] . '</a>&nbsp; ';
  4029. }
  4030. // 获取办事人
  4031. $staffInfo = $client_staff->getClientByCid ( $clientInfo ['cid'] );
  4032. $b = "";
  4033. if (! empty ( $staffInfo ))
  4034. $b = '<p class="fR">' . $staffInfo ['category'] . '-<a href="javascript:void(0)" onclick="getStaffInfo(\'' . $staffInfo ['username'] . '\')" >' . $staffInfo ['username'] . '</a></p>' . $clientInfo ['clientname'] . '<i class="icon- sport">' . $clientInfo ['priority'] . '</i>';
  4035. // 获取公司信息
  4036. $companyInfo = $company->getCompanyByCid ( $clientInfo ['companyid'] );
  4037. $serviceLog = $service_log->getServiceByClientid ( $clientInfo ['cid'] );
  4038. $local = $district->getbyidlist ( $clientInfo ['district'] );
  4039. if (! isset ( $local [1] ))
  4040. $local [1] ['name'] = "";
  4041. if (! isset ( $local [2] ))
  4042. $local [2] ['name'] = "";
  4043. $m = "";
  4044. if (! empty ( $companyInfo )) {
  4045. $m = '<div class="contactPanel">
  4046. <table>
  4047. <tbody>
  4048. <tr><th>单位全称</th><td colspan="3"><a href="javascript:void(0)" onclick="getCompany(\'' . $companyInfo [0] ['cidKey'] . '\')">' . $companyInfo [0] ['companyname'] . '</a></td></tr>
  4049. <tr><th>单位主页</th><td colspan="3">' . $clientInfo ['webservice'] . '</td></tr>
  4050. <tr><th>客户地区</th><td>' . $local [0] ['name'] . ',' . $local [1] ['name'] . ',' . $local [2] ['name'] . '</td><th>部门/职位</th><td>' . $clientInfo ['department'] . '/' . $clientInfo ['position'] . '</td></tr>
  4051. <tr><th>客户传真</th><td>' . $clientInfo ['fax'] . '</td><th>办公室</th><td>' . $clientInfo ['office'] . '</td></tr>
  4052. <tr><th>客户地址</th><td colspan="3">' . $clientInfo ['address'] . '</td></tr>
  4053. <tr><th>客户乘车</th><td colspan="3">' . $clientInfo ['ride'] . '</td></tr>
  4054. <tr><th>客户地标</th><td colspan="3">' . $clientInfo ['landmarks'] . '</td></tr>
  4055. <tr><th>客户住宿</th><td colspan="3">' . $clientInfo ['stay'] . '</td></tr>
  4056. </tbody></table>
  4057. </div>';
  4058. }
  4059. $u = "";
  4060. $order = array (
  4061. "\r\n",
  4062. "\n",
  4063. "\r"
  4064. );
  4065. $replace = '</br>';
  4066. foreach ( $serviceLog as $key => $value ) {
  4067. $datetime = explode ( "-", $value ['date'] );
  4068. $u .= '<div class="infoFlowList">
  4069. <div class="dateTitle">
  4070. <em class="month"><span class="num">' . $datetime ['1'] . '</span><span class="text">-' . $datetime ['2'] . '</span></em>
  4071. <span class="year">' . $datetime ['0'] . '</span>
  4072. </div>
  4073. <ul class="flowList">';
  4074. if ($value ['status'] == 1)
  4075. $u .= '<li class="item iconService">上门服务<';
  4076. elseif ($value ['status'] == 2)
  4077. $u .= '<li class="item iconPhone">电话拜访<';
  4078. elseif ($value ['status'] == 3)
  4079. $u .= '<li class="item iconOther">其他<';
  4080. $u .= $value ['category'] . '<a href="javascript:void(0)" onclick="getStaffInfo(\'' . $value ['staffname'] . '\')" >' . $value ['staffname'] . '</a></li>
  4081. <li class="item">
  4082. ' . str_replace ( $order, $replace, $value ['mark'] ) . '
  4083. </li>
  4084. </ul>
  4085. </div>';
  4086. }
  4087. Doo::loadModel ( "tag_client" );
  4088. Doo::loadModel ( "tag" );
  4089. $tag = new tag ();
  4090. $tag_client = new tag_client ();
  4091. $tagId = $tag_client->getTagClientBySCid ( $clientInfo ['cid'], $this->staff [0] ['sid'] );
  4092. $taginfo = $tag->getTagByTidL ( $tagId ['tag'] );
  4093. $taghtml = "";
  4094. foreach ( $taginfo as $key => $value ) {
  4095. $taghtml .= '<span class="contactsTag tagCol-0' . $value ['colorid'] . '">' . $value ['name'] . '</span>';
  4096. }
  4097. $mhtml = "";
  4098. $dhtml = "";
  4099. $yhtml = "";
  4100. for($year = 2020; $year >= 2004; $year --) {
  4101. if (date ( "Y" ) == $year)
  4102. $yhtml .= '<option selected value="' . $year . '">' . $year . '年</option>';
  4103. else
  4104. $yhtml .= '<option value="' . $year . '">' . $year . '年</option>';
  4105. }
  4106. for($month = 1; $month <= 12; $month ++) {
  4107. if (date ( "m" ) == $month)
  4108. $mhtml .= '<option selected value="' . $month . '">' . $month . '月</option>';
  4109. else
  4110. $mhtml .= '<option value="' . $month . '">' . $month . '月</option>';
  4111. }
  4112. for($day = 1; $day <= 31; $day ++) {
  4113. if (date ( "d" ) == $day)
  4114. $dhtml .= '<option selected value="' . $day . '">' . $day . '日</option>';
  4115. else
  4116. $dhtml .= '<option value="' . $day . '">' . $day . '日</option>';
  4117. }
  4118. $clientHtml = array (
  4119. 'html' => '<div class="contactInfo clearfix">
  4120. <div class="contactPanel">
  4121. <h1>' . $b . '<a data-original-title="编辑客户" data-toggle="ctooltip" data-placement="right" href="javascript:clientEdit(' . $clientInfo ['cid'] . ')" class="icon- edit">I</a></h1>
  4122. <table>
  4123. <tbody><tr><th>性别</th><td>' . $clientInfo ['gender'] . '</td><th>昵称</th><td>' . $clientInfo ['nicename'] . '</td></tr>
  4124. <tr><th>手机</th><td>' . $clientInfo ['telephone'] . '</td><th>QQ</th><td>' . $clientInfo ['qq'] . '</td></tr>
  4125. <tr><th>电话</th><td>' . $clientInfo ['phone'] . '</td><th>邮箱</th><td>' . $clientInfo ['email'] . '</td></tr>
  4126. <tr><th>软件锁</th><td colspan="3"><div class="lockContent">' . $k . '</div></td></tr>
  4127. <tr><th>备注</th><td colspan="3">' . $clientInfo ['mark'] . '</td></tr>
  4128. <tr><td colspan="4">
  4129. ' . $taghtml . '
  4130. </td></tr>
  4131. </tbody></table>
  4132. </div>
  4133. ' . $m . '
  4134. </div>
  4135. <div class="lockRecord autoHeightR1" >
  4136. <!--添加记录按钮-->
  4137. <div class="addRecord addRecordButton clearfix" >
  4138. <a href="#" onclick="slideupInfo(this)">+ 打开添加服务记录</a>
  4139. </div>
  4140. <!--添加记录-->
  4141. <div class="addRecord addRecordForm clearfix hide">
  4142. <a onclick="slidedownInfo(this)" class="fR slidedownInfo">- 关闭添加记录</a>
  4143. <form name="lk" action="/addServiceLog" method="post" >
  4144. <div class="control-group">
  4145. <div class="controls">
  4146. <label class="radio inline">
  4147. <input type="radio" name="logstatus" id="status" checked value="2">电话拜访
  4148. </label>
  4149. <label class="radio inline">
  4150. <input type="radio" name="logstatus" id="status" value="1" >上门服务
  4151. </label>
  4152. <label class="radio inline">
  4153. <input type="radio" name="logstatus" id="status" value="3">其他
  4154. </label>
  4155. </div>
  4156. </div>
  4157. <div class="control-group">
  4158. <div class="controls">时间:
  4159. <select name="y" id="y">
  4160. ' . $yhtml . '
  4161. </select>
  4162. <select name="m" id="m">
  4163. ' . $mhtml . '
  4164. </select>
  4165. <select name="d" id="d">
  4166. ' . $dhtml . '
  4167. </select>
  4168. </div>
  4169. </div>
  4170. <link href="' . WEB_SITE_GLOBAL . 'css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
  4171. <!--添加记录-备注-->
  4172. <!--<div class="control-group">
  4173. <div class="controls">
  4174. <select name="date" id="date">
  4175. <option value="2013">2013</option>
  4176. </select>
  4177. </div>
  4178. </div>-->
  4179. <div class="control-group">
  4180. <div class="controls" onclick="slideupInfo()">
  4181. <textarea name="mark" id="mark" style="width:95%" rows="5"></textarea>
  4182. <div class="bsAlert bsWarning"><b>含泪告知:</b>客户记录暂时无法修改!删除!,添加时请谨慎。点击确定添加成功后,信息会立即出现在下方!注意咯,别猛戳‘确定添加’导致重复添加了哦~</div>
  4183. </div>
  4184. </div>
  4185. <div class="control-group">
  4186. <div class="controls">
  4187. <div style="display:inline-block;margin-right:10px"><label><input name="Remind" onclick="reFK()" type="checkbox" value="1"> 添加提醒</label></div>
  4188. <span id="reHL" class="hide">
  4189. <div>
  4190. 限期:
  4191. <input type="date" name="time" id="dtp_input2" value="" class="hide"/>
  4192. </div>
  4193. <div>
  4194. 备注:<input id="remark" name="remark" type="text"></span>
  4195. </div>
  4196. </div>
  4197. <div class="control-group">
  4198. <div class="controls clearfix">
  4199. <input type="button" value="确定添加" id="conSer" onclick="aServiceLog(\'' . $this->staff [0] ['category'] . '\',\'' . $this->staff [0] ['username'] . '\',' . $clientInfo ['cid'] . ')" class="button"></input>
  4200. <div id="load"></div>
  4201. </div>
  4202. </div>
  4203. </div>
  4204. </form>
  4205. </div>
  4206. <!--添加记录按钮-->
  4207. <!--记录列表-->
  4208. <div id="kl"></div>
  4209. ' . $u . '
  4210. <script type="text/javascript">autoFlashHeight();</script> </div>'
  4211. );
  4212. echo json_encode ( $clientHtml );
  4213. }
  4214. function ajaxGetCompanyInfo() {
  4215. }
  4216. function checkClient() {
  4217. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
  4218. $company = $this->get_args ( 'company' ) ? $this->get_args ( 'company' ) : "";
  4219. if (! empty ( $name )&&! empty ( $company )) {
  4220. Doo::loadModel ( 'client' );
  4221. $client = new client ();
  4222. $clientInfo = $client->getClientByName2 ( $name, $company );
  4223. if (! empty ( $clientInfo ))
  4224. echo json_encode ( array (
  4225. "success" => true
  4226. ) );
  4227. else
  4228. echo json_encode ( array (
  4229. "success" => false
  4230. ) );
  4231. } else {
  4232. echo json_encode ( array (
  4233. "success" => false
  4234. ) );
  4235. }
  4236. }
  4237. function searchClient() {
  4238. $searchDbInforItem = $this->get_args ( 'searchDbInforItem' ) ? $this->get_args ( 'searchDbInforItem' ) : "";
  4239. if (! empty ( $searchDbInforItem )) {
  4240. Doo::loadModel ( 'client' );
  4241. $client = new client ();
  4242. $clientInfo = $client->getClientByName ( $searchDbInforItem );
  4243. echo json_encode ( $clientInfo );
  4244. } else {
  4245. echo json_encode ( array (
  4246. 0 => array (
  4247. 'clientname' => ''
  4248. )
  4249. ) );
  4250. }
  4251. }
  4252. function searchCompany() {
  4253. $searchDbInforItem = $this->get_args ( 'searchDbInforItem' ) ? $this->get_args ( 'searchDbInforItem' ) : "";
  4254. if (! empty ( $searchDbInforItem )) {
  4255. Doo::loadModel ( 'company' );
  4256. $company = new company ();
  4257. $clientInfo = $company->searchCompany ( $searchDbInforItem );
  4258. echo json_encode ( $clientInfo );
  4259. } else {
  4260. echo json_encode ( array (
  4261. 0 => array (
  4262. 'companyname' => '',
  4263. 'local' => ''
  4264. )
  4265. ) );
  4266. }
  4267. }
  4268. function checkCompany() {
  4269. $searchDbInforItem = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
  4270. $searchDbInforItem = explode ( '-', $searchDbInforItem );
  4271. $this->nature ['naturelenght'] = 15;
  4272. Doo::loadModel ( 'district' );
  4273. $district = new district ();
  4274. $d = $district->get_lv ( 1 );
  4275. $html = '<option vlaue="0">请选择</option>';
  4276. foreach ( $d as $key => $value ) {
  4277. $html .= '<option value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  4278. }
  4279. $this->nature ['district'] = $html;
  4280. if (! empty ( $searchDbInforItem )) {
  4281. Doo::loadModel ( 'company' );
  4282. $company = new company ();
  4283. if (! isset ( $searchDbInforItem [1] )) {
  4284. echo json_encode ( array (
  4285. "success" => false,
  4286. 'nature' => $this->nature
  4287. ) );
  4288. die ();
  4289. }
  4290. $clientInfo = $company->getCompanyByName ( $searchDbInforItem [0], $searchDbInforItem [1] );
  4291. if (! empty ( $clientInfo ))
  4292. echo json_encode ( array (
  4293. "success" => true,
  4294. 'data' => $clientInfo
  4295. ) );
  4296. else
  4297. echo json_encode ( array (
  4298. "success" => false,
  4299. 'nature' => $this->nature
  4300. ) );
  4301. } else {
  4302. echo json_encode ( array (
  4303. "success" => false,
  4304. 'nature' => $this->nature
  4305. ) );
  4306. }
  4307. }
  4308. function checkLongle() {
  4309. $searchDbInforItem = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
  4310. $searchDbInforItem = explode ( ' ', $searchDbInforItem );
  4311. if (! empty ( $searchDbInforItem )) {
  4312. Doo::loadModel ( 'longle' );
  4313. $longle = new longle ();
  4314. $clientInfo = $longle->getLongleBykeynum ( $searchDbInforItem [0] );
  4315. if (! empty ( $clientInfo ))
  4316. echo json_encode ( array (
  4317. "success" => true
  4318. ) );
  4319. else
  4320. echo json_encode ( array (
  4321. "success" => false
  4322. ) );
  4323. } else {
  4324. echo json_encode ( array (
  4325. "success" => false
  4326. ) );
  4327. }
  4328. }
  4329. function searchLongle() {
  4330. $searchDbInforItem = $this->get_args ( 'searchDbInforItem' ) ? $this->get_args ( 'searchDbInforItem' ) : "";
  4331. if (! empty ( $searchDbInforItem )) {
  4332. Doo::loadModel ( 'longle' );
  4333. $longle = new longle ();
  4334. $longleInfo = $longle->getLongleBykeynum2 ( $searchDbInforItem );
  4335. echo json_encode ( $longleInfo );
  4336. } else {
  4337. echo json_encode ( array (
  4338. 0 => array (
  4339. 'clientname' => ''
  4340. )
  4341. ) );
  4342. }
  4343. }
  4344. function updateChangeCompany() {
  4345. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4346. $clientID = $this->get_args ( 'clientID' ) ? $this->get_args ( 'clientID' ) : 0;
  4347. $companyname = $this->get_args ( 'companyname' ) ? $this->get_args ( 'companyname' ) : "";
  4348. Doo::loadModel ( 'company' );
  4349. Doo::loadModel ( 'client' );
  4350. $client = new client ();
  4351. $company = new company ();
  4352. $companyname = explode ( "-", $companyname );
  4353. if (isset ( $companyname [1] ))
  4354. $k = $company->getCompanyByName ( $companyname [0], $companyname [1] );
  4355. else
  4356. $k = array ();
  4357. if (! empty ( $cid ) && ! empty ( $k ) && ! empty ( $clientID )) {
  4358. $client->cid = $clientID;
  4359. $client->companyid = $cid;
  4360. $client->companyname = $companyname [0];
  4361. $client->update ();
  4362. } else {
  4363. $local1 = $this->get_args ( 'lv21' ) ? $this->get_args ( 'lv21' ) : 0;
  4364. $local2 = $this->get_args ( 'lv22' ) ? $this->get_args ( 'lv22' ) : 0;
  4365. $local3 = $this->get_args ( 'lv23' ) ? $this->get_args ( 'lv23' ) : 0;
  4366. Doo::loadModel ( 'district' );
  4367. $district = new district ();
  4368. // 更新公司信息
  4369. $lv1 = $district->getbyid ( $local1 );
  4370. $lv2 = $district->getbyid ( $local2 );
  4371. $lv3 = $district->getbyid ( $local3 );
  4372. if (empty ( $local1 ) || empty ( $local2 ))
  4373. return "/";
  4374. if (! empty ( $local1 ) && ! empty ( $local2 ))
  4375. $company->local = $lv1 [0] ['name'] . "," . $lv2 [0] ['name'] . "," . $lv3 [0] ['name'];
  4376. if (! empty ( $local1 ) && ! empty ( $local2 ))
  4377. $company->district = $local1 . "," . $local2 . "," . $local3;
  4378. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  4379. $fax = $this->get_args ( 'fax' ) ? $this->get_args ( 'fax' ) : "";
  4380. $webservice = $this->get_args ( 'webservice' ) ? $this->get_args ( 'webservice' ) : "";
  4381. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  4382. $landmarks = $this->get_args ( 'landmarks' ) ? $this->get_args ( 'landmarks' ) : "";
  4383. $stay = $this->get_args ( 'stay' ) ? $this->get_args ( 'stay' ) : "";
  4384. $ride = $this->get_args ( 'ride' ) ? $this->get_args ( 'ride' ) : "";
  4385. $nature = implode ( ",", $nature );
  4386. $company->companyname = $companyname [0];
  4387. $company->ride = $ride;
  4388. $company->fax = $fax;
  4389. $company->webservice = $webservice;
  4390. $company->address = $address;
  4391. $company->landmarks = $landmarks;
  4392. $company->stay = $stay;
  4393. $company->nature = $nature;
  4394. $cid = $company->insert ();
  4395. $client->cid = $clientID;
  4396. $client->companyid = $cid;
  4397. $client->companyname = $companyname [0];
  4398. $client->update ();
  4399. }
  4400. return "/contacts";
  4401. }
  4402. function AddClientInfo() { // 不编辑公司
  4403. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4404. $clientname = $this->get_args ( 'clientname' ) ? $this->get_args ( 'clientname' ) : "";
  4405. $gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : "";
  4406. $nicename = $this->get_args ( 'nicename' ) ? $this->get_args ( 'nicename' ) : "";
  4407. $telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : "";
  4408. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  4409. $email = $this->get_args ( 'email' ) ? $this->get_args ( 'email' ) : "";
  4410. $unit = $this->get_args ( 'unit' ) ? $this->get_args ( 'unit' ) : "";
  4411. $fax = $this->get_args ( 'fax' ) ? $this->get_args ( 'fax' ) : "";
  4412. $webservice = $this->get_args ( 'webservice' ) ? $this->get_args ( 'webservice' ) : "";
  4413. $department = $this->get_args ( 'department' ) ? $this->get_args ( 'department' ) : "";
  4414. $position = $this->get_args ( 'position' ) ? $this->get_args ( 'position' ) : "";
  4415. $office = $this->get_args ( 'office' ) ? $this->get_args ( 'office' ) : "";
  4416. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  4417. $ride = $this->get_args ( 'ride' ) ? $this->get_args ( 'ride' ) : "";
  4418. $landmarks = $this->get_args ( 'landmarks' ) ? $this->get_args ( 'landmarks' ) : "";
  4419. $qq = $this->get_args ( 'qq' ) ? $this->get_args ( 'qq' ) : "";
  4420. $priority = $this->get_args ( 'priority' ) ? $this->get_args ( 'priority' ) : 5;
  4421. $stay = $this->get_args ( 'stay' ) ? $this->get_args ( 'stay' ) : "";
  4422. $mark = $this->get_args ( 'mark' ) ? $this->get_args ( 'mark' ) : "";
  4423. $lv21 = $this->get_args ( 'lv21' ) ? $this->get_args ( 'lv21' ) : "";
  4424. $lv22 = $this->get_args ( 'lv22' ) ? $this->get_args ( 'lv22' ) : "";
  4425. $lv23 = $this->get_args ( 'lv23' ) ? $this->get_args ( 'lv23' ) : "";
  4426. if (! empty ( $cid ) && ! empty ( $clientname )) {
  4427. Doo::loadModel ( 'client' );
  4428. Doo::loadModel ( 'district' );
  4429. $district = new district ();
  4430. $client = new client ();
  4431. $client->cid = $cid;
  4432. $client->clientname = $clientname;
  4433. $client->gender = $gender;
  4434. $client->nicename = $nicename;
  4435. $client->telephone = $telephone;
  4436. $client->phone = $phone;
  4437. $client->email = $email;
  4438. // if(!empty($unit)){
  4439. // $client->unit=$unit;
  4440. // $client->companyname=$unit;
  4441. // }
  4442. if (! empty ( $lv21 ) && ! empty ( $lv22 ) && ! empty ( $lv23 )) {
  4443. $client->district = $lv21 . "," . $lv22 . "," . $lv23;
  4444. }
  4445. if (! empty ( $client->district )) {
  4446. $districtList = $district->find ( array (
  4447. 'where' => 'id in(' . $client->district . ')',
  4448. 'asArray' => true
  4449. ) );
  4450. $jsonString = array ();
  4451. foreach ( $districtList as $value ) {
  4452. array_push ( $jsonString, $value ['name'] );
  4453. }
  4454. $jsonString = implode ( ",", $jsonString );
  4455. if (! empty ( $jsonString ))
  4456. $client->local = $jsonString;
  4457. }
  4458. $client->fax = $fax;
  4459. $client->webservice = $webservice;
  4460. $client->department = $department;
  4461. $client->position = $position;
  4462. $client->office = $office;
  4463. $client->address = $address;
  4464. $client->ride = $ride;
  4465. $client->landmarks = $landmarks;
  4466. $client->qq = $qq;
  4467. $client->stay = $stay;
  4468. $client->priority = $priority;
  4469. $client->mark = $mark;
  4470. $client->updatetime = time ();
  4471. $client->update ();
  4472. // Doo::loadModel ( 'company' );
  4473. // $company = new company();
  4474. // $companyid=$client->getOne(array('where'=>' cid='.$cid,'asArray'=>true));
  4475. // $company->office=$office;
  4476. // $company->fax=$fax;
  4477. // $company->address=$address;
  4478. // $company->ride=$ride;
  4479. // $company->landmarks=$landmarks;
  4480. // $company->cid=$companyid['companyid'];
  4481. // if(!empty($unit)){
  4482. // $company->companyname=$unit;
  4483. // }
  4484. // $company->update();
  4485. $clientInfo = $client->getOne ( array (
  4486. 'where' => ' cid=' . $cid,
  4487. 'asArray' => true
  4488. ) );
  4489. // 日常行为
  4490. Doo::loadModel ( "action_log" );
  4491. $action_log = new action_log ();
  4492. $action_log->action = $this->staff [0] ['category'] . '<b href="javascript:void(0)" onclick="showStaff(\'' . $this->staff [0] ['sid'] . '\')" >' . $this->staff [0] ['username'] . '</b>编辑了<a href="javascript:void(0)" onclick="showClick(\'' . $cid . '\')">' . $clientname . '</a>(' . $clientInfo ['companyname'] . ')';
  4493. $action_log->sid = $this->staff [0] ['sid'];
  4494. $action_log->cid = $this->staff [0] ['cid'];
  4495. $action_log->updatetime = date ( "Y-m-d" );
  4496. $action_log->time = date ( "H:i" );
  4497. $action_log->class = $action_log->iconContacts;
  4498. $action_log->status = 2;
  4499. $action_log->districtid = $clientInfo ['district'];
  4500. $local = $district->getbyidlist ( $clientInfo ['district'] );
  4501. $action_log->city = $local [0] ['name'];
  4502. $action_log->province = $local [1] ['name'];
  4503. $action_log->company = $clientInfo ['companyname'];
  4504. Doo::loadModel ( 'company' );
  4505. $company = new company ();
  4506. $companyInfo = $company->getOne ( array (
  4507. 'where' => ' companyname="' . $clientInfo ['companyname'] . '"',
  4508. 'asArray' => true
  4509. ) );
  4510. $nature = explode ( ',', $companyInfo ['nature'] );
  4511. $action_log->nature = $nature [0];
  4512. $action_log->insert ();
  4513. echo json_encode ( array (
  4514. "success" => true
  4515. ) );
  4516. die ();
  4517. } else
  4518. echo json_encode ( array (
  4519. "success" => false
  4520. ) );
  4521. die ();
  4522. }
  4523. function ajaxClientInfo() {
  4524. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4525. if (! empty ( $cid )) {
  4526. Doo::loadModel ( 'client' );
  4527. Doo::loadModel ( 'company' );
  4528. $company = new company ();
  4529. $client = new client ();
  4530. $info = $client->getOne ( array (
  4531. 'where' => ' cid=' . $cid,
  4532. 'asArray' => true
  4533. ) );
  4534. $cinfo = $company->getOne ( array (
  4535. 'where' => ' cid=' . $info ['companyid'],
  4536. 'asArray' => true
  4537. ) );
  4538. Doo::loadClass ( 'XDeode' );
  4539. $XDeode = new XDeode ( 5 );
  4540. $cinfo['cidKey']=$XDeode->encode ( $cinfo['cid'] );
  4541. Doo::loadModel ( 'district' );
  4542. $district = new district ();
  4543. $districtLv1 = $district->get_lv ( 1 );
  4544. $info ['districtList'] = $district->getbyidlist ( $info ['district'] );
  4545. $optionHtml = '<option vlaue="0">请选择</option>';
  4546. foreach ( $districtLv1 as $key => $value ) {
  4547. if ($value ['name'] == $info ['districtList'] [0] ['name']) {
  4548. $optionHtml .= '<option selected value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  4549. } else
  4550. $optionHtml .= '<option value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  4551. }
  4552. $districtLv2 = $district->get_lvByid ( 2, $info ['districtList'] [0] ['id'] );
  4553. $optionHtml2 = '';
  4554. foreach ( $districtLv2 as $key => $value ) {
  4555. if ($value ['name'] == $info ['districtList'] [1] ['name'])
  4556. $optionHtml2 .= '<option selected value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  4557. else
  4558. $optionHtml2 .= '<option value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  4559. }
  4560. $districtLv3 = $district->get_lvByid ( 2, $info ['districtList'] [1] ['id'] );
  4561. $optionHtml3 = '';
  4562. foreach ( $districtLv3 as $key => $value ) {
  4563. if ($value ['name'] == $info ['districtList'] [2] ['name'])
  4564. $optionHtml3 .= '<option selected value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  4565. else
  4566. $optionHtml3 .= '<option value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  4567. }
  4568. $info ['districtLv1'] = $optionHtml;
  4569. $info ['districtLv2'] = $optionHtml2;
  4570. $info ['districtLv3'] = $optionHtml3;
  4571. $info ['companyInfo'] = $cinfo;
  4572. echo json_encode ( array (
  4573. "success" => true,
  4574. 'html' => $info
  4575. ) );
  4576. die ();
  4577. } else
  4578. echo json_encode ( array (
  4579. "success" => false,
  4580. 'html' => ''
  4581. ) );
  4582. die ();
  4583. }
  4584. /**
  4585. * 为客户添加服务日志
  4586. */
  4587. function ajaxAddServiceLog() {
  4588. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "";
  4589. $clientid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  4590. $mark = $this->get_args ( 'mark' ) ? $this->get_args ( 'mark' ) : "";
  4591. $m = $this->get_args ( 'm' ) ? $this->get_args ( 'm' ) : "";
  4592. $d = $this->get_args ( 'd' ) ? $this->get_args ( 'd' ) : "";
  4593. $y = $this->get_args ( 'y' ) ? $this->get_args ( 'y' ) : date ( "Y" );
  4594. $Remind = $this->get_args ( 'Remind' ) ? $this->get_args ( 'Remind' ) : 0;
  4595. $time = $this->get_args ( 'time' ) ? $this->get_args ( 'time' ) : 0;
  4596. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  4597. if (! empty ( $status ) && ! empty ( $clientid )) {
  4598. Doo::loadModel ( 'service_log' );
  4599. Doo::loadModel ( 'client_staff' );
  4600. Doo::loadModel ( 'client' );
  4601. Doo::loadModel ( 'district' );
  4602. $district = new district ();
  4603. $client = new client ();
  4604. $clientStaff = new client_staff ();
  4605. $service_log = new service_log ();
  4606. $service_log->status = $status;
  4607. $service_log->clientid = $clientid;
  4608. $service_log->mark = htmlspecialchars ( $mark );
  4609. $service_log->date = $y . "-" . $m . "-" . $d;
  4610. $service_log->category = $this->staff [0] ['category'];
  4611. $service_log->staffname = $this->staff [0] ['username'];
  4612. $service_log->staffid = $this->staff [0] ['sid'];
  4613. $service_log->insert ();
  4614. // 日常行为
  4615. Doo::loadModel ( "action_log" );
  4616. Doo::loadModel ( "client" );
  4617. $client = new client ();
  4618. // 记录服务时间
  4619. $client->cid = $clientid;
  4620. $client->servicetime = time ();
  4621. $client->update ();
  4622. $action_log = new action_log ();
  4623. $clientInfo = $client->getOne ( array (
  4624. 'where' => ' cid=' . $clientid,
  4625. 'asArray' => TRUE
  4626. ) );
  4627. $action_log->action = $this->staff [0] ['category'] . '<b href="javascript:void(0)" onclick="showStaff(\'' . $this->staff [0] ['sid'] . '\')">' . $this->staff [0] ['username'] . '</b>为<a href="javascript:void(0)" onclick="showClick(\'' . $clientid . '\')">' . $clientInfo ['clientname'] . '</a>(' . $clientInfo ['companyname'] . ')添加新客户记录。';
  4628. $action_log->sid = $this->staff [0] ['sid'];
  4629. $action_log->cid = $this->staff [0] ['cid'];
  4630. $action_log->updatetime = date ( "Y-m-d" );
  4631. $action_log->time = date ( "H:i" );
  4632. $action_log->status = 3;
  4633. $action_log->districtid = $clientInfo ['district'];
  4634. $local = $district->getbyidlist ( $clientInfo ['district'] );
  4635. $action_log->city = $local [0] ['name'];
  4636. $action_log->province = $local [1] ['name'];
  4637. $action_log->company = $clientInfo ['companyname'];
  4638. Doo::loadModel ( 'company' );
  4639. $company = new company ();
  4640. $companyInfo = $company->getOne ( array (
  4641. 'where' => ' companyname="' . $clientInfo ['companyname'] . '"',
  4642. 'asArray' => true
  4643. ) );
  4644. $nature = explode ( ',', $companyInfo ['nature'] );
  4645. $action_log->nature = $nature [0];
  4646. $action_log->class = $action_log->iconContacts;
  4647. $action_log->insert ();
  4648. // 更新信息中心服务日志统计数量
  4649. $redis = new Redis ();
  4650. $redis->connect ( '127.0.0.1', '6379' );
  4651. $categoryCondition = " and cid=" . $this->staff [0] ['cid'];
  4652. $sidCondition = " and sid=" . $this->staff [0] ['sid'];
  4653. // actionlog免查询值 $alCondition='';
  4654. $alCondition = ' aid>' . REMIT . ' and ';
  4655. // 个人服务日志数量redis值
  4656. $redisKeyCS = date ( 'Y-m-d' ) . 'SL_' . $this->staff [0] ['cid'] . '_' . $this->staff [0] ['sid'];
  4657. $action_log = new action_log ();
  4658. $actionLogLongle = $action_log->find ( array (
  4659. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  4660. 'where' => $alCondition . " status=3 " . $categoryCondition . $sidCondition . " and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) ",
  4661. 'groupby' => 'date_format(updatetime,"%m-%d")',
  4662. 'asArray' => true
  4663. ) );
  4664. $statisticsLongle = array ();
  4665. for($d = 0; $d <= 29; $d ++) {
  4666. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  4667. $falgLongle = true;
  4668. foreach ( $actionLogLongle as $value ) {
  4669. if ($value ['updatetime'] == $MD) {
  4670. array_push ( $statisticsLongle, $value ['count'] );
  4671. $falgLongle = false;
  4672. break;
  4673. }
  4674. }
  4675. if ($falgLongle)
  4676. array_push ( $statisticsLongle, 0 );
  4677. }
  4678. $statisticsLongle = array_reverse ( $statisticsLongle );
  4679. $jsl = json_encode ( $statisticsLongle );
  4680. $redis->set ( $redisKeyCS, $jsl );
  4681. // 办事处服务日志数量reids值
  4682. $redisKeyC = date ( 'Y-m-d' ) . 'SL_' . $this->staff [0] ['cid'] . '_';
  4683. $action_log = new action_log ();
  4684. $actionLogLongle = $action_log->find ( array (
  4685. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  4686. 'where' => $alCondition . " status=3 " . $categoryCondition . " and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) ",
  4687. 'groupby' => 'date_format(updatetime,"%m-%d")',
  4688. 'asArray' => true
  4689. ) );
  4690. $statisticsLongle = array ();
  4691. for($d = 0; $d <= 29; $d ++) {
  4692. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  4693. $falgLongle = true;
  4694. foreach ( $actionLogLongle as $value ) {
  4695. if ($value ['updatetime'] == $MD) {
  4696. array_push ( $statisticsLongle, $value ['count'] );
  4697. $falgLongle = false;
  4698. break;
  4699. }
  4700. }
  4701. if ($falgLongle)
  4702. array_push ( $statisticsLongle, 0 );
  4703. }
  4704. $statisticsLongle = array_reverse ( $statisticsLongle );
  4705. $jsl = json_encode ( $statisticsLongle );
  4706. $redis->set ( $redisKeyC, $jsl );
  4707. // 全员处服务日志数量的redis值
  4708. $redisKey = date ( 'Y-m-d' ) . 'SL__';
  4709. $action_log = new action_log ();
  4710. $actionLogLongle = $action_log->find ( array (
  4711. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  4712. 'where' => $alCondition . " status=3 and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) ",
  4713. 'groupby' => 'date_format(updatetime,"%m-%d")',
  4714. 'asArray' => true
  4715. ) );
  4716. $statisticsLongle = array ();
  4717. for($d = 0; $d <= 29; $d ++) {
  4718. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  4719. $falgLongle = true;
  4720. foreach ( $actionLogLongle as $value ) {
  4721. if ($value ['updatetime'] == $MD) {
  4722. array_push ( $statisticsLongle, $value ['count'] );
  4723. $falgLongle = false;
  4724. break;
  4725. }
  4726. }
  4727. if ($falgLongle)
  4728. array_push ( $statisticsLongle, 0 );
  4729. }
  4730. $statisticsLongle = array_reverse ( $statisticsLongle );
  4731. $jsl = json_encode ( $statisticsLongle );
  4732. $redis->set ( $redisKey, $jsl );
  4733. if (! empty ( $Remind )) {
  4734. Doo::loadModel ( 'remind' );
  4735. $remindObj = new remind ();
  4736. $datetime1 = new DateTime ( date ( 'Y-m-d' ) );
  4737. $datetime2 = new DateTime ( $time );
  4738. $interval = $datetime1->diff ( $datetime2 );
  4739. $remindObj->day = $interval->format ( '%a' );
  4740. $remindObj->remark = $remark;
  4741. $remindObj->time = date ( "Y-m-d" );
  4742. $remindObj->clientName = $clientInfo ['clientname'];
  4743. $remindObj->clientID = $clientid;
  4744. $remindObj->companyName = $clientInfo ['companyname'];
  4745. $remindObj->companyID = $companyInfo ['cid'];
  4746. $remindObj->staffID = $this->staff [0] ['sid'];
  4747. if ($status == 1)
  4748. $remindObj->class = "iconService";
  4749. if ($status == 2)
  4750. $remindObj->class = "iconPhone";
  4751. if ($status == 3)
  4752. $remindObj->class = "iconOther";
  4753. $remindObj->insert ();
  4754. }
  4755. echo json_encode ( array (
  4756. "success" => true,
  4757. 'html' => ''
  4758. ) );
  4759. die ();
  4760. } else
  4761. echo json_encode ( array (
  4762. "success" => false,
  4763. 'html' => ''
  4764. ) );
  4765. die ();
  4766. }
  4767. function _getLongleLogHtml($longleLog = array()) {
  4768. $html = "";
  4769. foreach ( $longleLog as $key => $value ) {
  4770. $dateline = explode ( "-", $value ['dateline'] );
  4771. $html .= '<div class="infoFlowList">
  4772. <div class="dateTitle">
  4773. <em class="month"><span class="num">' . $dateline [1] . '</span><span class="text">-' . $dateline [2] . '</span></em>
  4774. <span class="year">' . $dateline [0] . '</span>
  4775. </div>
  4776. ';
  4777. // 备注
  4778. if ($value ['status'] == 8) {
  4779. $html .= '
  4780. <ul class="flowList">
  4781. <li class="item iconLock">备注<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
  4782. <li class="item">' . $value ['mark'] . '</li>
  4783. </ul>';
  4784. } elseif ($value ['status'] == 10) {
  4785. $html .= '
  4786. <ul class="flowList">
  4787. <li class="item iconLock">延期<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
  4788. <li class="item">' . $value ['mark'] . '</li>
  4789. </ul>';
  4790. // 生成
  4791. }elseif ($value ['status'] == 1) {
  4792. $html .= '<ul class="flowList">
  4793. <li class="item iconGenerate">生成<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
  4794. </ul>';
  4795. // 接收
  4796. } elseif ($value ['status'] == 2) {
  4797. $html .= '<ul class="flowList">
  4798. <li class="item iconReceive">接收<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
  4799. </ul>';
  4800. // 借出
  4801. } elseif ($value ['status'] == 3) {
  4802. $html .= '<ul class="flowList">
  4803. <li class="item iconBorrow">借出<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
  4804. <li class="item">' . $value ['product'] . '</li>
  4805. <li class="item"><a href="javascript:void(0);" onclick="getClientInfo(\'' . $value ['clientid'] .'\')" >' . $value ['client'] . '</a></li>
  4806. </ul>';
  4807. // 销售
  4808. } elseif ($value ['status'] == 4) {
  4809. $html .= '<ul class="flowList">
  4810. <li class="item iconSell">销售<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
  4811. <li class="item">' . $value ['product'] . '</li>
  4812. <li class="item"><a href="javascript:void(0);" onclick="getClientInfo(\'' . $value ['clientid'] . '\')" >' . $value ['client'] . '</a></li>
  4813. </ul>';
  4814. // 升级
  4815. } elseif ($value ['status'] == 5) {
  4816. $html .= '<ul class="flowList">
  4817. <li class="item iconUpdate">升级<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
  4818. <li class="item">' . $value ['product'] . '</li>
  4819. <li class="item"><a href="javascript:void(0);" onclick="getClientInfo(\'' . $value ['clientid'] . '\')" >' . $value ['client'] . '</a></li>
  4820. </ul>';
  4821. // 更换
  4822. } elseif ($value ['status'] == 6) {
  4823. $html .= '<ul class="flowList">
  4824. <li class="item iconReplace">更换<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')">' . $value ['operator'] . '</a></li>
  4825. <li class="item"><a href="javascript:void(0);" onclick="getLockByName(\'' . $value ['new_key_num'] . '\')">' . $value ['new_key_num'] . '</a>
  4826. <li class="item"><a href="javascript:void(0);" onclick="getClientInfo(\'' . $value ['clientid'] . '\')" >' . $value ['client'] . '</a></li>
  4827. </ul>';
  4828. // 回收
  4829. } elseif ($value ['status'] == 7) {
  4830. Doo::loadModel ( 'staff' );
  4831. $staff = new staff ();
  4832. $staffinfo = $staff->getOne ( array (
  4833. 'where' => ' username like "' . $value ['responsible'] . '"',
  4834. 'asArray' => true
  4835. ) );
  4836. if (empty ( $staffinfo ))
  4837. $staffinfo ['category'] = "";
  4838. $html .= '<ul class="flowList">
  4839. <li class="item iconRecycle">收回<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')">' . $value ['operator'] . '</a></li>
  4840. <li class="item">' . $staffinfo ['category'] . '<a href="javascript:void(0);" id="ajaxStaff" data="' . $value ['responsible'] . '">' . $value ['responsible'] . '</a></li>
  4841. </ul>';
  4842. } elseif ($value ['status'] == 9) {
  4843. $html .= '<ul class="flowList">
  4844. <li class="item iconGif">赠送 &lt; ' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')">' . $value ['operator'] . '</a></li>
  4845. <li class="item"><a href="javascript:void(0);" onclick="getClientInfo(\'' . $value ['clientid'] . '\')" >' . $value ['client'] . '</a></li>
  4846. </ul>';
  4847. }
  4848. $html .= '</div>';
  4849. }
  4850. return $html;
  4851. }
  4852. function adminLock() {
  4853. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  4854. $data ['emsg'] = "";
  4855. if ($emsg != "")
  4856. $data ['emsg'] = "请填写完整的数据";
  4857. $data ['memu'] = "keyonline";
  4858. $data ['staff'] = $this->staff;
  4859. if ($this->staff [0] ['isadmin'] != 1)
  4860. return "/adminmyinfo";
  4861. Doo::loadModel ( 'L_category' );
  4862. $L_category = new L_category ();
  4863. $data ['category'] = $L_category->getCategory ();
  4864. $data ['time'] = time ();
  4865. $this->render ( "/admin/admin_addlock", $data );
  4866. }
  4867. function adminAddLock() {
  4868. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4869. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  4870. if ($cid != 0 && $path != "") {
  4871. Doo::loadModel ( 'longle' );
  4872. Doo::loadModel ( 'L_category' );
  4873. $L_category = new L_category ();
  4874. Doo::loadModel ( 'longle_log' );
  4875. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/" . iconv ( "UTF-8", "GB2312", $path ) );
  4876. // print_r($exlArray);die;
  4877. // echo json_encode($exlArray);die;
  4878. $category = $L_category->getCategoryById ( $cid );
  4879. foreach ( $exlArray as $key => $value ) {
  4880. // 锁记录
  4881. $longle = new longle ();
  4882. $longle->key_num = str_replace ( "'", "", $value ['key_num'] );
  4883. $longle->product = str_replace ( "'", "", $value ['product'] );
  4884. $longle->make_day = $value ['make_day'];
  4885. $longle->alloted_time = $value ['alloted_time'];
  4886. $longle->status = 1;
  4887. $longle->statusT = "生成";
  4888. $longle->cid = $cid;
  4889. $longle->category = $category [0] ['title'];
  4890. $longle->SerialNumber = $value ['SerialNumber'];
  4891. $longle->version = $value ['version'];
  4892. $lid = $longle->insert ();
  4893. // 锁日志记录
  4894. $longle_log = new longle_log ();
  4895. $longle_log->lid = $lid;
  4896. $longle_log->status = 1;
  4897. $longle_log->statusT = "生成";
  4898. $longle_log->operator = $this->staff [0] ['username'];
  4899. $longle_log->product = $longle->product;
  4900. $longle_log->category = $this->staff [0] ['category'];
  4901. $longle_log->dateline = date ( "Y-m-d" );
  4902. $id = $longle_log->insert ();
  4903. }
  4904. // 记录日常行为
  4905. Doo::loadModel ( "action_log" );
  4906. $action_log = new action_log ();
  4907. $action_log->action = '总部<b href="javascript:void(0)" onclick="showStaff(\'' . $this->staff [0] ['sid'] . '\')" >' . $this->staff [0] ['username'] . '</b>生成<a href="javascript:void(0)" onclick="showLook(\'' . str_replace ( "'", "", $exlArray [0] ['key_num'] ) . '\')">' . str_replace ( "'", "", $exlArray [0] ['key_num'] ) . '</a>等<b>' . count ( $exlArray ) . '</b>个锁';
  4908. $action_log->sid = $this->staff [0] ['sid'];
  4909. $action_log->cid = $this->staff [0] ['cid'];
  4910. $action_log->class = $action_log->iconGenerate;
  4911. $action_log->updatetime = date ( "Y-m-d" );
  4912. $action_log->time = date ( "H:i" );
  4913. $action_log->status = 11;
  4914. $action_log->insert ();
  4915. return "/keyonline";
  4916. } else
  4917. return "/adminlock/error";
  4918. }
  4919. function avatarCM() {
  4920. $vid = isset ( $this->params ['vid'] ) ? $this->params ['vid'] : 0;
  4921. if (! empty ( $vid )) {
  4922. Doo::loadModel ( "verify" );
  4923. $verify = new verify ();
  4924. Doo::loadModel ( 'staff' );
  4925. $staff = new staff ();
  4926. $list = $verify->getOne ( array (
  4927. 'where' => 'vid=' . $vid,
  4928. 'asArray' => true
  4929. ) );
  4930. if (empty ( $list ))
  4931. return "/adminverify";
  4932. $avatar = json_decode ( $list ['staff'] );
  4933. foreach ( $avatar as $key => $value ) {
  4934. $uinfo = $staff->getOne ( array (
  4935. 'where' => 'sid=' . $value [0],
  4936. 'asArray' => true
  4937. ) );
  4938. $avatar [$key] ['2'] = $uinfo ['avatar'];
  4939. }
  4940. $verify->staff = json_encode ( $avatar );
  4941. $verify->update ( array (
  4942. 'where' => 'vid=' . $vid
  4943. ) );
  4944. }
  4945. return "/adminverify";
  4946. }
  4947. function adminmyinfo() {
  4948. $data ['memu'] = "adminmyinfo";
  4949. $data ['staff'] = $this->staff;
  4950. $birArray = explode ( '-', $this->staff [0] ['birthday'] );
  4951. $data ['year'] = $birArray [0];
  4952. $year = date ( 'Y' );
  4953. $yearHtml = "";
  4954. for(; $year >= 1900; $year --) {
  4955. $yearHtml .= '<option ';
  4956. if ($data ['year'] == $year)
  4957. $yearHtml .= 'selected';
  4958. $yearHtml .= ' value="' . $year . '">' . $year . '</option>';
  4959. }
  4960. $data ['yearHtml'] = $yearHtml;
  4961. $data ['month'] = 01;
  4962. $data ['day'] = 01;
  4963. if (isset ( $birArray [1] )) {
  4964. $data ['month'] = $birArray [1];
  4965. $data ['day'] = $birArray [2];
  4966. }
  4967. $data ['msg'] = urldecode ( $this->params ['msg'] );
  4968. $this->render ( "/admin/admin_myinfo", $data );
  4969. }
  4970. function updateMyinfo() {
  4971. $telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : 0;
  4972. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : 0;
  4973. $email = $this->get_args ( 'email' ) ? $this->get_args ( 'email' ) : "";
  4974. $qq = is_numeric ( $this->get_args ( 'qq' ) ) ? $_POST ['qq'] : 0;
  4975. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4976. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  4977. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : "";
  4978. $position = $this->get_args ( 'position' ) ? $this->get_args ( 'position' ) : "";
  4979. $gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : "男";
  4980. $oldpassword = $this->get_args ( 'oldpassword' ) ? $this->get_args ( 'oldpassword' ) : "";
  4981. $newpassword = $this->get_args ( 'newpassword' ) ? $this->get_args ( 'newpassword' ) : "";
  4982. $rnewpassword = $this->get_args ( 'rnewpassword' ) ? $this->get_args ( 'rnewpassword' ) : "";
  4983. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  4984. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  4985. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  4986. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  4987. Doo::loadModel ( 'staff' );
  4988. $staff = new staff ();
  4989. Doo::loadModel ( 'staffDynamic' );
  4990. $staffDynamic = new staffDynamic ();
  4991. $staff->sid = $this->staff [0] ['sid'];
  4992. if (! empty ( $remittanceName ))
  4993. $staff->remittanceName = $remittanceName;
  4994. if (! empty ( $bankName ))
  4995. $staff->bankName = $bankName;
  4996. if (! empty ( $bankNumber ))
  4997. $staff->bankNumber = $bankNumber;
  4998. if (! empty ( $coupletNumber ))
  4999. $staff->coupletNumber = $coupletNumber;
  5000. $content = "";
  5001. $ext = "更新了他的";
  5002. if ($telephone != 0 && $this->staff [0] ['telephone'] != $telephone) {
  5003. $staff->telephone = $telephone;
  5004. $content .= "<b>手机</b>&nbsp;";
  5005. }
  5006. if ($phone != 0 && $this->staff [0] ['phone'] != $phone) {
  5007. $staff->phone = $phone;
  5008. $content .= "<b>电话</b>&nbsp;";
  5009. }
  5010. if ($qq != 0 && $this->staff [0] ['qq'] != $qq) {
  5011. $staff->qq = $qq;
  5012. $content .= "<b>QQ</b>&nbsp;";
  5013. }
  5014. if ($year != 2014) {
  5015. $staff->birthday = $year . "-" . $month . "-" . $day;
  5016. $content .= "<b>生日</b>&nbsp;";
  5017. }
  5018. if ($email != "" && filter_var ( $email, FILTER_VALIDATE_EMAIL ) && $this->staff [0] ['email'] != $email) {
  5019. $staff->email = $email;
  5020. $content .= "<b>邮箱</b>&nbsp;";
  5021. }
  5022. if (! empty ( $position )) {
  5023. $staff->position = $position;
  5024. $content .= "<b>职位</b>&nbsp;";
  5025. }
  5026. $staff->gender = $gender;
  5027. $msg = "更新成功";
  5028. if ($this->staff [0] ['passwork'] == md5 ( $oldpassword )) {
  5029. if ($newpassword == $rnewpassword && (! empty ( $newpassword )))
  5030. $staff->passwork = md5 ( $newpassword );
  5031. else
  5032. $msg = "密码不一致";
  5033. } else {
  5034. if ($oldpassword != "")
  5035. $msg = "密码错误";
  5036. }
  5037. if (! empty ( $content )) {
  5038. $staffDynamic->content = $ext . $content;
  5039. $staffDynamic->cid = $this->staff [0] ['cid'];
  5040. $staffDynamic->category = $this->staff [0] ['category'];
  5041. $staffDynamic->time = time ();
  5042. $staffDynamic->sid = $this->staff [0] ['sid'];
  5043. $staffDynamic->staff = $this->staff [0] ['username'];
  5044. $staffDynamic->insert ();
  5045. }
  5046. $staff->update ( array (
  5047. 'where' => ' sid=' . $this->staff [0] ['sid']
  5048. ) );
  5049. return "/adminmyinfo/" . $msg;
  5050. }
  5051. function admincontacts() {
  5052. $data ['memu'] = "admincontacts";
  5053. $data ['staff'] = $this->staff;
  5054. Doo::loadModel ( 'L_category' );
  5055. Doo::loadModel ( 'staff' );
  5056. $staff = new staff ();
  5057. $L_category = new L_category ();
  5058. $this->render ( "/admin/admin_addContacts", $data );
  5059. }
  5060. /**
  5061. * 微信通知设置
  5062. */
  5063. // function notificationConf() {
  5064. // Doo::loadModel ( "notificationConf" );
  5065. // $notificationConf = new notificationConf ();
  5066. // $detail = $notificationConf->getNotificationConfBySid ( $this->staff [0] ['sid'] );
  5067. // $rule = json_decode ( $detail ['conf'], true );
  5068. // $data ['rule'] = $rule;
  5069. // $data ['memu'] = "notificationConf";
  5070. // $data ['staff'] = $this->staff;
  5071. // $this->render ( "/admin/invoiceNotificationConf", $data );
  5072. // }
  5073. // function ajaxSetNotificationConf() {
  5074. // $notificationType = $this->get_args ( 'notificationType' ) ? $this->get_args ( 'notificationType' ) : "";
  5075. // $notificationValue = $this->get_args ( 'notificationValue' ) ? $this->get_args ( 'notificationValue' ) : '';
  5076. // if (! empty ( $notificationType ) && ! empty ( $notificationValue ) && ! empty ( $this->staff [0] ['sid'] )) {
  5077. // Doo::loadModel ( "notificationConf" );
  5078. // $notificationConf = new notificationConf ();
  5079. // $detail = $notificationConf->getNotificationConfBySid ( $this->staff [0] ['sid'] );
  5080. // if (empty ( $detail )) {
  5081. // $rule = array (
  5082. // $notificationType => $notificationValue
  5083. // );
  5084. // $rule = json_encode ( $rule );
  5085. // $item = array (
  5086. // 'sid' => $this->staff [0] ['sid'],
  5087. // 'conf' => $rule
  5088. // );
  5089. // $notificationConf->addNotification ( $item );
  5090. // } else {
  5091. // $rule = json_decode ( $detail ['conf'], true );
  5092. // $rule [$notificationType] = $notificationValue;
  5093. // $rule = json_encode ( $rule );
  5094. // $item = array (
  5095. // 'nid' => $detail ['nid'],
  5096. // 'conf' => $rule
  5097. // );
  5098. // $notificationConf->setNotificationByCondition ( $item );
  5099. // }
  5100. // echo json_encode ( array (
  5101. // 'status' => 1,
  5102. // 'msgType' => $notificationType,
  5103. // 'msg' => ''
  5104. // ) );
  5105. // die ();
  5106. // }
  5107. // echo json_encode ( array (
  5108. // 'status' => 2,
  5109. // 'msgType' => $notificationType,
  5110. // 'msg' => 'illegal request'
  5111. // ) );
  5112. // die ();
  5113. // }
  5114. function eMailTask() {
  5115. Doo::loadModel ( 'tag' );
  5116. $tag = new tag ();
  5117. Doo::loadModel ( 'district' );
  5118. $district = new district ();
  5119. $tagList = $tag->getAllBySid ( $this->staff [0] ['sid'] );
  5120. $districtList = $district->get_lv ( 1 );
  5121. $districtlv2List=$district->get_lvByid(2,$districtList[0]['id']);
  5122. $data ['tagList'] = $tagList;
  5123. $data ['districtList'] = $districtList;
  5124. $data ['districtlv2List'] = $districtlv2List;
  5125. $data ['memu'] = "eMailTask";
  5126. $data ['staff'] = $this->staff;
  5127. $data ['mailMemu'] = 'eMailTask';
  5128. $data ['nature'] = $this->nature;
  5129. $this->render ( "/mail_create", $data );
  5130. }
  5131. function eMialCenter() {
  5132. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  5133. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : 0;
  5134. Doo::loadModel ( 'eMailList' );
  5135. $eMailList = new eMailList ();
  5136. Doo::loadModel ( 'tag' );
  5137. $tag = new tag ();
  5138. Doo::loadModel ( 'staff' );
  5139. $staff = new staff ();
  5140. $dateCondition = "status!=2 and Year(date) =" . $year;
  5141. if (! empty ( $month ))
  5142. $dateCondition = "Year(date) =" . $year . " and Month(date) = " . $month;
  5143. $mailList = $eMailList->find ( array (
  5144. 'where' => $dateCondition,
  5145. 'asc' => 'status',
  5146. 'desc' => 'elid',
  5147. 'asArray' => true
  5148. ) );
  5149. foreach ( $mailList as $key => $value ) {
  5150. $mailList [$key] ['clientName2'] = $mailList [$key] ['clientName3'] = array ();
  5151. $mailList [$key] ['clientName'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName'] ) ), true );
  5152. if (! empty ( $value ['clientName2'] ))
  5153. $mailList [$key] ['clientName2'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName2'] ) ), true );
  5154. if (! empty ( $value ['clientName3'] ))
  5155. $mailList [$key] ['clientName3'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName3'] ) ), true );
  5156. $mailList [$key] ['illegalEmail'] = json_decode ( $value ['illegalEmail'], true );
  5157. $mailList [$key] ['sendEmail'] = json_decode ( $value ['sendEmail'], true );
  5158. $mailList [$key] ['clientCount'] = count ( $mailList [$key] ['clientName'] ) + count ( $mailList [$key] ['clientName2'] ) + count ( $mailList [$key] ['clientName3'] );
  5159. $mailList [$key] ['tag'] = array ();
  5160. $kks = $staff->getOne ( array (
  5161. 'where' => 'username like "' . $value ['staffName'] . '"',
  5162. 'asArray' => true
  5163. ) );
  5164. $mailList [$key] ['category'] = $kks ['category'];
  5165. if (! empty ( $value ['tag'] ))
  5166. $mailList [$key] ['tag'] = $tag->find ( array (
  5167. 'where' => 'tid in ( ' . $value ['tag'] . ') ',
  5168. 'asArray' => true
  5169. ) );
  5170. }
  5171. $dateHtml = "";
  5172. $now = date ( "Y" );
  5173. for($YEARD = 2014; $YEARD <= 2050; $YEARD ++) {
  5174. if ($YEARD <= $now) {
  5175. $dateHtml .= '<option ';
  5176. if ($year == $YEARD)
  5177. $dateHtml .= ' selected ';
  5178. $dateHtml .= ' value="' . $YEARD . '">' . $YEARD . '</option>';
  5179. }
  5180. }
  5181. $monthHtml = '<option value="0">所有月份</option>';
  5182. for($i = 1; $i <= 12; $i ++) {
  5183. $monthHtml .= '<option ';
  5184. if ($i == $month)
  5185. $monthHtml .= ' selected ';
  5186. $monthHtml .= ' value="' . $i . '">' . $i . '</option>';
  5187. }
  5188. $data ['monthHtml'] = $monthHtml;
  5189. $data ['dateHtml'] = $dateHtml;
  5190. $data ['mailList'] = $mailList;
  5191. $data ['memu'] = "eMailTask";
  5192. $data ['staff'] = $this->staff;
  5193. $data ['mailMemu'] = 'eMialCenter';
  5194. $data ['nature'] = $this->nature;
  5195. $this->render ( "/mailCenter", $data );
  5196. }
  5197. function authMail() {
  5198. $elid = isset ( $this->params ['elid'] ) ? $this->params ['elid'] : 0;
  5199. if (! empty ( $elid )) {
  5200. Doo::loadModel ( 'eMailList' );
  5201. $eMailList = new eMailList ();
  5202. $eMailList->examine = 2;
  5203. $eMailList->mark = $this->staff [0] ['username'] . "已同意";
  5204. $eMailList->update ( array (
  5205. 'where' => 'elid=' . $elid,
  5206. 'asArray' => true
  5207. ) );
  5208. }
  5209. return '/eMialCenter';
  5210. }
  5211. function editMailView() {
  5212. $elid = isset ( $this->params ['elid'] ) ? $this->params ['elid'] : 0;
  5213. Doo::loadModel ( 'tag' );
  5214. $tag = new tag ();
  5215. Doo::loadModel ( 'district' );
  5216. $district = new district ();
  5217. Doo::loadModel ( 'eMailList' );
  5218. $eMList = new eMailList ();
  5219. $mail = $eMList->getOne ( array (
  5220. 'where' => 'elid =' . $elid . '',
  5221. 'asArray' => true
  5222. ) );
  5223. if (empty ( $mail ))
  5224. return "/eMailList";
  5225. $mail ['tagList'] = explode ( ",", $mail ['tag'] );
  5226. $tagList = $tag->getAllBySid ( $this->staff [0] ['sid'] );
  5227. $districtList = $district->get_lv ( 1 );
  5228. $tagHtml = '';
  5229. foreach ( $tagList as $key => $value ) {
  5230. $tagHtml .= '<label><span data-original-title="' . $value ['name'] . '" data-toggle="ctooltip" data-placement="right" class="contactsTag tagCol-0' . $value ['colorid'] . '">
  5231. <input type="checkbox" name="tagId[]"';
  5232. foreach ( $mail ['tagList'] as $k => $v ) {
  5233. if ($value ['tid'] == $v) {
  5234. $tagHtml .= ' checked ';
  5235. break;
  5236. }
  5237. }
  5238. $tagHtml .= ' value="' . $value ['tid'] . '"></span></label>';
  5239. }
  5240. $districtHtml = '';
  5241. foreach ( $districtList as $key => $value ) {
  5242. $districtHtml .= '<option value="' . $value ['id'] . '"';
  5243. if ($value ['id'] == $mail ['districtId'])
  5244. $districtHtml .= 'selected';
  5245. $districtHtml .= '>' . $value ['name'] . '</option>';
  5246. }
  5247. $natureHtml = '';
  5248. $natList = explode ( ",", $mail ['nature'] );
  5249. foreach ( $this->nature as $key => $value ) {
  5250. $natureHtml .= '<label><input type="checkbox" name="nature[]" ';
  5251. foreach ( $natList as $k => $v ) {
  5252. if ($value == $v) {
  5253. $natureHtml .= ' checked ';
  5254. break;
  5255. }
  5256. }
  5257. $natureHtml .= 'value="' . $value . '">' . $value . '</label>';
  5258. }
  5259. $data ['natureHtml'] = $natureHtml;
  5260. $data ['districtHtml'] = $districtHtml;
  5261. $data ['tagHtml'] = $tagHtml;
  5262. $data ['mail'] = $mail;
  5263. $data ['tagList'] = $tagList;
  5264. $data ['districtList'] = $districtList;
  5265. $data ['memu'] = "eMailTask";
  5266. $data ['staff'] = $this->staff;
  5267. $data ['mailMemu'] = 'eMailList';
  5268. $data ['nature'] = $this->nature;
  5269. $this->render ( "/mailEdit", $data );
  5270. }
  5271. function editEmail() {
  5272. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  5273. $skin = $this->get_args ( 'skin' ) ? $this->get_args ( 'skin' ) : "";
  5274. $content = isset ( $_POST ['content'] ) ? $_POST ['content'] : "";
  5275. $tagId = $this->get_args ( 'tagId' ) ? $this->get_args ( 'tagId' ) : array ();
  5276. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : array ();
  5277. $natureNULL = $this->get_args ( 'natureNULL' ) ? $this->get_args ( 'natureNULL' ) : "";
  5278. $did = $this->get_args ( 'did' ) ? $this->get_args ( 'did' ) : "";
  5279. $stype = $this->get_args ( 'stype' ) ? $this->get_args ( 'stype' ) : "";
  5280. $elid = $this->get_args ( 'elid' ) ? $this->get_args ( 'elid' ) : "";
  5281. if (! empty ( $title ) && ! empty ( $elid ) && (! empty ( $tagId ) || ! empty ( $did ))) {
  5282. Doo::loadModel ( 'eMailList' );
  5283. $eMailList = new eMailList ();
  5284. $etid = $eMailList->getOne ( array (
  5285. 'select' => 'etid,annexName,annex',
  5286. 'where' => 'elid=' . $elid,
  5287. 'asArray' => true
  5288. ) );
  5289. Doo::loadModel ( 'eMailTemplate' );
  5290. $eMailTemplate = new eMailTemplate ();
  5291. Doo::loadModel ( 'eMailJournal' );
  5292. $eMailJournal = new eMailJournal ();
  5293. if ($natureNULL != 'NULL') {
  5294. if (empty ( $tagId ) && ! empty ( $did ) && empty ( $nature ))
  5295. die ( '请选择性质' );
  5296. }
  5297. // annex
  5298. $annexPath = "";
  5299. $annexEXT = $this->_GetFileEXT ( $_FILES ["annex"] ["name"] );
  5300. $annexName = "";
  5301. if (isset ( $_FILES ['annex'] ['name'] )) {
  5302. if ((($annexEXT == "doc") || ($annexEXT == "xls") || ($annexEXT == "pdf") || ($annexEXT == "ppt") || ($annexEXT == "txt") || ($annexEXT == "smr") || ($annexEXT == "spu") || ($annexEXT == "zip") || ($annexEXT == "rar") || ($annexEXT == "jpg") || ($annexEXT == "png")) && ($_FILES ["annex"] ["size"] < 10485760)) {
  5303. $path = DOO::conf ()->SITE_PATH . "upload/emailAnnex/";
  5304. if (! file_exists ( $path . $_FILES ["annex"] ["name"] )) {
  5305. $fileName = time () . "." . $annexEXT;
  5306. $annexName = $_FILES ['annex'] ['name'];
  5307. $annexPath = $path . $fileName;
  5308. move_uploaded_file ( $_FILES ["annex"] ["tmp_name"], $annexPath );
  5309. $annexPath = $this->webPath . $fileName;
  5310. }
  5311. }
  5312. }
  5313. if (! empty ( $annexPath )) {
  5314. $annexHtml = '<table style="width:100%;margin:10px 0">
  5315. <thead>
  5316. <tr>
  5317. <th align="left" colspan="2" style="background-color:ff6501;color:#fff;font-size:16px;padding:5px">下载附件:</th>
  5318. </tr>
  5319. </thead>
  5320. <tbody>
  5321. <tr>
  5322. <td style="padding:5px"><a href="' . $annexPath . '" target="_blank" style="font-size:16px">' . $annexName . '</a></td>
  5323. <td>&nbsp;</td>
  5324. </tr>
  5325. </tbody>
  5326. </table>';
  5327. } elseif (! empty ( $etid ['annexName'] ) && empty ( $annexPath ))
  5328. $annexHtml = $etid ['annex'];
  5329. $smartcostMail = 'smartcost_mail_1';
  5330. $info = "";
  5331. // html template
  5332. if ($skin == 1) {
  5333. $html = '<div><table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  5334. <tbody><tr><td align="center"><table style="margin:20px;background-color:#fff;box-shadow:0px 1px 6px rgba(0, 0, 0, 0.3);width:60%;" cellpadding="0" cellspacing="0" align="center">
  5335. <tbody><tr>
  5336. <td style="background-color:#ff6501;padding:20px 0 25px;" align="center">
  5337. <span style="vertical-align:bottom;font-size:20px;color:#fff;">' . $title . '</span>
  5338. </td></tr><tr><td>
  5339. <table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;border-top:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  5340. <tbody><tr><td style="padding: 0 40px;" align="left">
  5341. <p style="margin-top:40px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;"><b>CLIENTNAME</b>,您好</p>
  5342. </td></tr><tr><td style="padding: 0 40px;" align="left">
  5343. <p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;">我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
  5344. <p style="margin-top:0px;margin-bottom:20px;color:#383838;font-size:16px;line-height:32px;">
  5345. ' . $content . '</p>
  5346. </td></tr>
  5347. <tr><td align="left" style="padding: 0 40px;background:#fff">
  5348. ' . $annexHtml . '
  5349. </td></tr>
  5350. <tr> <td style="padding: 20px 40px;border-top:1px dashed #ddd" align="left">
  5351. <p style="margin-bottom:10px;color:#383838;font-size:16px;line-height:22px;border-left:2px solid #FF6501;padding-left:5px">
  5352. 纵横公路造价软件' . $this->staff [0] ['category'] . '办事处</p>
  5353. <table>
  5354. <tr><th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td></tr>
  5355. <tr><th align="right">联系人:</th><td>' . $this->staff [0] ['username'] . '</td></tr>
  5356. <tr><th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr>
  5357. <tr><th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td></tr>
  5358. <tr><th align="right">邮箱:</th><td>' . $this->staff [0] ['email'] . '</td></tr>
  5359. </table></td></tr></tbody></table></td></tr><tr>
  5360. <td style="padding: 0 40px;background-color:#383838;"><p style="color:#fff;padding:10px 0;text-align:center;margin:0">珠海纵横创新软件有限公司 <a href="http://www.smartcost.com.cn" style="color:#fff;text-decoration: underline;">smartcost.com.cn</a></p></td>
  5361. </tr></tbody></table></td></tr></tbody></table></div>';
  5362. $info = '<table><tr><th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td></tr>
  5363. <tr><th align="right">联系人:</th><td>' . $this->staff [0] ['username'] . '</td></tr>
  5364. <tr><th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr>
  5365. <tr><th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td></tr>
  5366. <tr><th align="right">邮箱:</th><td>' . $this->staff [0] ['email'] . '</td></tr></table>';
  5367. } elseif ($skin == 2) {
  5368. $smartcostMail = 'smartcost_mail_2';
  5369. $html = '<table cellspacing="0" cellpadding="0" style="background-color:#e4e4e4; width:100%;"><tbody><tr><td>
  5370. <table align="center" cellspacing="0" cellpadding="0" style="background-color:#f8f8f8; width:640px;margin-bottom:20px">
  5371. <tbody><tr><td align="left" style="background-color:#e4e4e4;"><p style="margin-top:10px;margin-bottom:10px;color:#999;font-size:16px;line-height:32px;">
  5372. <b><span name="titleHtml">' . $title . '</span></b></p></td>
  5373. </tr><tr><td><table align="center" cellspacing="0" cellpadding="0" style="border:1px solid #ddd;"><tbody><tr>
  5374. <td align="center" style="background-color:#EEF2F5;padding:20px 0 "><a style="text-decoration:none;" href="http://www.teambition.com/" target="_blank"><img width="291px" height="46" src="http://zonghengvideo.qiniudn.com/maillogo1.png"></a></td>
  5375. </tr><tr><td align="center" style="background-color:#fff;"><img width="640" height="191" src="http://zonghengvideo.qiniudn.com/hero.jpg"></td>
  5376. </tr><tr><td align="left" style="background-color:#fff;padding:40px;border-bottom:1px solid #ddd;">
  5377. <p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;"><b>CLIENTNAME</b>,您好</p>
  5378. <p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;">我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
  5379. <p name="contentHtml" style="margin-top:0px;margin-bottom:15px;color:#383838;font-size:16px;line-height:32px;">' . $content . '</p></td>
  5380. </tr>
  5381. <tr><td align="left" style="padding: 0 40px;background:#fff">
  5382. ' . $annexHtml . '
  5383. </td></tr>
  5384. <tr><td style="padding: 10px 0;background:#EEF2F5"><table><tbody><tr>
  5385. <td style="font-size:14pxl;color:#333;padding:0 20px"><b>纵横公路造价软件' . $this->staff [0] ['category'] . '办事处</b><br>' . $this->staff [0] ['username'] . '</td>
  5386. <td><table><tbody><tr style="font-size:12px;color:#666">
  5387. <th align="right">电话:</th><td style="padding:0 20px 0 0">' . $this->staff [0] ['phone'] . '</td>
  5388. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#666">
  5389. <th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5390. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td>
  5391. </tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr>
  5392. <td style="padding: 0 40px;background-color:#383838;"><p style="color:#fff;padding:10px 0;text-align:center;margin:0;font-size:12px">珠海纵横创新软件有限公司 <a href="http://www.smartcost.com.cn" style="color:#fff;text-decoration:underline;">smartcost.com.cn</a></p></td>
  5393. </tr></tbody></table></td></tr></tbody> </table>';
  5394. $info = '<table><tbody><tr style="font-size:12px;color:#666">
  5395. <th align="right">电话:</th><td style="padding:0 20px 0 0">' . $this->staff [0] ['phone'] . '</td>
  5396. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#666">
  5397. <th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5398. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td>
  5399. </tr></tbody></table>';
  5400. } else {
  5401. $smartcostMail = 'smartcost_mail_3';
  5402. $html = '<table cellspacing="0" cellpadding="0" style="background-color:#ECF0E1; width:100%">
  5403. <tbody>
  5404. <tr>
  5405. <td>
  5406. <table align="center" cellspacing="0" cellpadding="0" style="width:698px;margin-bottom:30px;margin-top:30px;">
  5407. <tbody>
  5408. <tr>
  5409. <td>
  5410. <table align="center" cellspacing="0" cellpadding="0" style="border:1px solid #ccc;width:100%;border-top:none">
  5411. <tbody>
  5412. <tr>
  5413. <td align="right" style="background:#fff url(http://zonghengvideo.qiniudn.com/mail3-top-bg.png) no-repeat top center;padding:30px 20px 20px 20px;border-bottom:1px solid #E9EBE2;">
  5414. <div style="position:relative;text-align:right">
  5415. <b style="font-size:24px;color:#8A9F98;z-index:999"><span name="titleHtml">' . $title . '</span></b>
  5416. <div style="width:80px;height:80px;position:absolute;top:0;left:0"><img src="http://zonghengvideo.qiniudn.com/zonghenglogo.png"></div>
  5417. </div>
  5418. </td>
  5419. </tr>
  5420. <tr>
  5421. <td align="left" style="background-color:#fff;padding:40px;border-bottom:1px solid #ddd;">
  5422. <p style="margin-top:0px;margin-bottom:10px;color:#666;font-size:16px;line-height:32px;"><b>CLIENTNAME</b>,您好</p>
  5423. <p style="margin-top:0px;margin-bottom:10px;color:#666;font-size:16px;line-height:32px;">我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
  5424. <p name="contentHtml" style="margin-top:0px;margin-bottom:15px;color:#666;font-size:16px;line-height:32px;">' . $content . '</p></td>
  5425. </tr>
  5426. <tr><td align="left" style="padding: 0 40px;background:#fff">
  5427. ' . $annexHtml . '
  5428. </td></tr>
  5429. <tr>
  5430. <td style="padding: 10px 0 0;background:#F6F6F6;">
  5431. <table>
  5432. <tbody><tr>
  5433. <td style="font-size:14pxl;color:#666;padding:0 20px"><b>纵横公路造价软件' . $this->staff [0] ['category'] . '办事处</b><br>' . $this->staff [0] ['username'] . '<br><a href="http://www.smartcost.com.cn" style="color:#666;font-size:12px;text-decoration:underline;">smartcost.com.cn</a></td>
  5434. <td>
  5435. <table style="width:100%">
  5436. <tbody><tr style="font-size:12px;color:#496781">
  5437. <th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td>
  5438. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td>
  5439. </tr>
  5440. <tr style="font-size:12px;color:#496781">
  5441. <th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5442. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td>
  5443. </tr>
  5444. </tbody></table>
  5445. </td>
  5446. </tr>
  5447. </tbody></table>
  5448. </td>
  5449. </tr>
  5450. <tr>
  5451. <td style="background:#F6F6F6 url(http://zonghengvideo.qiniudn.com/mail3-bottom-bg.png) no-repeat bottom center;"><p style="color:#fff;padding:0 0 20px;text-align:center;margin:0;font-size:12px"></p></td>
  5452. </tr>
  5453. </tbody>
  5454. </table></td>
  5455. </tr>
  5456. </tbody>
  5457. </table></td>
  5458. </tr>
  5459. </tbody>
  5460. </table>';
  5461. $info = '<table><tr style="font-size:12px;color:#496781"><th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td>
  5462. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#496781">
  5463. <th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5464. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td></tr></table>
  5465. ';
  5466. }
  5467. Doo::loadModel ( 'tag_client' );
  5468. $tagClient = new tag_client ();
  5469. Doo::loadModel ( 'client' );
  5470. $client = new client ();
  5471. Doo::loadModel ( 'company' );
  5472. $company = new company ();
  5473. $eMailTemplate->title = $title;
  5474. $eMailTemplate->skin = $skin;
  5475. $eMailTemplate->content = $content;
  5476. if (! empty ( $tagId ))
  5477. $eMailTemplate->tag = implode ( ",", $tagId );
  5478. $eMailTemplate->staffId = $this->staff [0] ['sid'];
  5479. $eMailTemplate->staffName = $this->staff [0] ['username'];
  5480. $eMailTemplate->status = 0;
  5481. $eMailTemplate->html = $html;
  5482. if (! empty ( $annexPath )) {
  5483. $eMailTemplate->annex = $annexPath;
  5484. $eMailTemplate->annexName = $annexName;
  5485. }
  5486. $etid = $eMailTemplate->update ( array (
  5487. 'where' => 'etid=' . $etid ['etid']
  5488. ) );
  5489. // create email list
  5490. $tagCondition = "";
  5491. $tagArray = array ();
  5492. foreach ( $tagId as $value ) {
  5493. array_push ( $tagArray, " tag like '%" . $value . "%' " );
  5494. }
  5495. if (! empty ( $tagArray ))
  5496. $tagCondition = ' and (' . implode ( " or ", $tagArray ) . ')';
  5497. $clientList = $tagClient->find ( array (
  5498. 'select' => 'client',
  5499. 'where' => 'sid=' . $this->staff [0] ['sid'] . $tagCondition,
  5500. 'asArray' => true
  5501. ) );
  5502. $clientArray = array ();
  5503. foreach ( $clientList as $value ) {
  5504. array_push ( $clientArray, $value ['client'] );
  5505. }
  5506. $clientEmailList = array ();
  5507. if (! empty ( $clientArray ))
  5508. $clientEmailList = $client->find ( array (
  5509. 'select' => 'email,cid,nicename as clientname,companyname',
  5510. 'where' => 'cid in (' . implode ( ",", $clientArray ) . ')',
  5511. 'asArray' => true
  5512. ) );
  5513. //
  5514. if ($stype == 2) {
  5515. // 获取性质相关数据
  5516. $cidList = '';
  5517. if ($natureNULL == '') {
  5518. $nD = array ();
  5519. foreach ( $nature as $key => $value ) {
  5520. array_push ( $nD, ' nature like "' . $value . '"' );
  5521. // $nD=' nature like "'.$value.'"';
  5522. }
  5523. $nD = implode ( ' or ', $nD );
  5524. $companycid = $company->find ( array (
  5525. 'select' => 'cid',
  5526. 'where' => $nD,
  5527. 'asArray' => true
  5528. ) );
  5529. $cidList = array ();
  5530. foreach ( $companycid as $key => $value ) {
  5531. array_push ( $cidList, $value ['cid'] );
  5532. }
  5533. $cidList = implode ( ',', $cidList );
  5534. if (! empty ( $cidList ))
  5535. $cidList = ' and companyid in (' . $cidList . ')';
  5536. else
  5537. $cidList = '';
  5538. }
  5539. // 'select'=>'email,cid,nicename as clientname,companyname,district'
  5540. $clientEmailList = $client->find ( array (
  5541. 'select' => 'email,cid,nicename as clientname,companyname,district',
  5542. 'where' => 'district like "' . $did . ',%" ' . $cidList,
  5543. 'asArray' => true
  5544. ) );
  5545. }
  5546. // ;datediff(curdate(), 'date')>=10
  5547. $eMailJournal->delete ( array (
  5548. 'where' => "datediff(curdate(), date)>=7"
  5549. ) );
  5550. $eMailJournal->delete ( array (
  5551. 'where' => 'DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(date)'
  5552. ) );
  5553. $checkMail = $eMailJournal->find ( array (
  5554. 'where' => 'DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(date)',
  5555. ' groupby' => 'email',
  5556. 'asArray' => true
  5557. ) );
  5558. $emailNameList = $emailArray = $illegalEmail = $sendEmail = array ();
  5559. Doo::db ()->beginTransaction ();
  5560. foreach ( $clientEmailList as $value ) {
  5561. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  5562. if (! empty ( $checkMail )) {
  5563. $falg = true;
  5564. foreach ( $checkMail as $v ) {
  5565. if ($v ['email'] == $value ['email']) {
  5566. $Bdate = strtotime ( $v ['date'] ) + 7 * 24 * 3600;
  5567. if ($Bdate <= time ()) {
  5568. array_push ( $emailArray, $value ['email'] );
  5569. array_push ( $emailNameList, $value );
  5570. $eMailJournal->date = date ( "Y-m-d" );
  5571. $eMailJournal->update ( array (
  5572. 'where' => 'ejid=' . $v ['ejid']
  5573. ) );
  5574. } else {
  5575. array_push ( $sendEmail, $value );
  5576. }
  5577. $falg = false;
  5578. break;
  5579. }
  5580. }
  5581. if ($falg) {
  5582. array_push ( $emailArray, $value ['email'] );
  5583. array_push ( $emailNameList, $value );
  5584. $eMailJournal->clientId = $value ['cid'];
  5585. $eMailJournal->status = 1;
  5586. $eMailJournal->email = $value ['email'];
  5587. $eMailJournal->date = date ( "Y-m-d" );
  5588. $eMailJournal->insert ();
  5589. }
  5590. } else {
  5591. array_push ( $emailArray, $value ['email'] );
  5592. array_push ( $emailNameList, $value );
  5593. $eMailJournal->clientId = $value ['cid'];
  5594. $eMailJournal->status = 1;
  5595. $eMailJournal->email = $value ['email'];
  5596. $eMailJournal->date = date ( "Y-m-d" );
  5597. $eMailJournal->insert ();
  5598. }
  5599. } else {
  5600. array_push ( $illegalEmail, $value );
  5601. }
  5602. }
  5603. Doo::db ()->commit ();
  5604. // echo json_encode($illegalEmail);
  5605. // json_encode(array_slice($illegalEmail,0,100))
  5606. // $kk=gzcompress();
  5607. // $ll=gzuncompress($kk);
  5608. // ."</br>".strlen($kk)."</br>".strlen($ll);die;
  5609. $size = floor ( count ( $emailArray ) / 3 );
  5610. if (! empty ( $emailArray )) {
  5611. if (count ( $emailArray ) < 3) {
  5612. $list = array (
  5613. 0 => $emailArray,
  5614. 1 => array (),
  5615. 2 => array ()
  5616. );
  5617. } else
  5618. $list = array_chunk ( $emailArray, $size );
  5619. } else
  5620. $list = array (
  5621. 0 => array (),
  5622. 1 => array (),
  5623. 2 => array ()
  5624. );
  5625. $emailJson = array ();
  5626. foreach ( $list as $value ) {
  5627. $em = array ();
  5628. foreach ( $value as $v ) {
  5629. array_push ( $em, $v );
  5630. }
  5631. array_push ( $emailJson, $em );
  5632. }
  5633. $size = floor ( count ( $emailNameList ) / 3 );
  5634. if (! empty ( $emailNameList )) {
  5635. if (count ( $emailNameList ) < 3) {
  5636. $list = array (
  5637. 0 => $emailNameList,
  5638. 1 => array (),
  5639. 2 => array ()
  5640. );
  5641. } else
  5642. $list = array_chunk ( $emailNameList, $size );
  5643. } else
  5644. $list = array (
  5645. 0 => array (),
  5646. 1 => array (),
  5647. 2 => array ()
  5648. );
  5649. $emailNameJson = array ();
  5650. foreach ( $list as $value ) {
  5651. $em = array ();
  5652. foreach ( $value as $v ) {
  5653. array_push ( $em, $v );
  5654. }
  5655. array_push ( $emailNameJson, $em );
  5656. }
  5657. //
  5658. $eMailList->date = date ( "Y-m-d" );
  5659. $eMailList->clientEmail = base64_encode ( gzcompress ( json_encode ( $emailJson [0] ) ) );
  5660. $eMailList->clientEmail2 = base64_encode ( gzcompress ( json_encode ( $emailJson [1] ) ) );
  5661. $eMailList->clientEmail3 = base64_encode ( gzcompress ( json_encode ( $emailJson [2] ) ) );
  5662. $eMailList->clientName = base64_encode ( gzcompress ( json_encode ( $emailNameJson [0] ) ) );
  5663. $eMailList->clientName2 = base64_encode ( gzcompress ( json_encode ( $emailNameJson [1] ) ) );
  5664. $eMailList->clientName3 = base64_encode ( gzcompress ( json_encode ( $emailNameJson [2] ) ) );
  5665. $eMailList->illegalEmail = json_encode ( array_slice ( $illegalEmail, 0, 100 ) ); // json_encode($illegalEmail);
  5666. $eMailList->sendEmail = json_encode ( $sendEmail );
  5667. $eMailList->templateName = $smartcostMail;
  5668. $eMailList->eTitle = $title;
  5669. $eMailList->html = $html;
  5670. $eMailList->content = $content;
  5671. $eMailList->info = $info;
  5672. if (! empty ( $annexName )) {
  5673. $eMailList->annex = $annexHtml;
  5674. $eMailList->annexName = $annexName;
  5675. }
  5676. if ($stype == 1) {
  5677. $eMailList->tag = implode ( ",", $tagId );
  5678. $eMailList->districtId = "";
  5679. $eMailList->nature = "";
  5680. }
  5681. if ($stype == 2) {
  5682. $eMailList->districtId = $did;
  5683. $eMailList->nature = implode ( ",", $nature );
  5684. $eMailList->tag = "";
  5685. }
  5686. $eMailList->update ( array (
  5687. 'where' => 'elid=' . $elid
  5688. ) );
  5689. return "/eMailList";
  5690. }
  5691. return "/eMailTask";
  5692. }
  5693. function createEmail() {
  5694. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  5695. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  5696. $skin = $this->get_args ( 'skin' ) ? $this->get_args ( 'skin' ) : "";
  5697. $content = isset ( $_POST ['content'] ) ? $_POST ['content'] : "";
  5698. $tagId = $this->get_args ( 'tagId' ) ? $this->get_args ( 'tagId' ) : array ();
  5699. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : array ();
  5700. $natureNULL = $this->get_args ( 'natureNULL' ) ? $this->get_args ( 'natureNULL' ) : "";
  5701. $did = $this->get_args ( 'did' ) ? $this->get_args ( 'did' ) : "";
  5702. $didCity = $this->get_args ( 'didCity' ) ? $this->get_args ( 'didCity' ) : "";
  5703. $stype = $this->get_args ( 'stype' ) ? $this->get_args ( 'stype' ) : "";
  5704. if (! empty ( $title ) && (! empty ( $tagId ) || ! empty ( $did ))) {
  5705. Doo::loadModel ( 'eMailTemplate' );
  5706. $eMailTemplate = new eMailTemplate ();
  5707. Doo::loadModel ( 'eMailJournal' );
  5708. $eMailJournal = new eMailJournal ();
  5709. if ($natureNULL != 'NULL') {
  5710. if (empty ( $tagId ) && ! empty ( $did ) && empty ( $nature )) {
  5711. header ( 'Content-Type:text/html;charset=utf-8' );
  5712. die ( '请选择性质' );
  5713. }
  5714. }
  5715. // annex
  5716. $annexPath = "";
  5717. $annexEXT = $this->_GetFileEXT ( $_FILES ["annex"] ["name"] );
  5718. $annexName = "";
  5719. if (isset ( $_FILES ['annex'] ['name'] )) {
  5720. if ((($annexEXT == "doc") || ($annexEXT == "docx") || ($annexEXT == "xls") || ($annexEXT == "pdf") || ($annexEXT == "ppt") || ($annexEXT == "txt") || ($annexEXT == "smr") || ($annexEXT == "spu") || ($annexEXT == "zip") || ($annexEXT == "rar") || ($annexEXT == "jpg") || ($annexEXT == "png")) && ($_FILES ["annex"] ["size"] < 10485760)) {
  5721. $path = DOO::conf ()->SITE_PATH . "upload/emailAnnex/";
  5722. if (! file_exists ( $path . $_FILES ["annex"] ["name"] )) {
  5723. $fileName = time () . "." . $annexEXT;
  5724. $annexName = $_FILES ['annex'] ['name'];
  5725. $annexPath = $path . $fileName;
  5726. move_uploaded_file ( $_FILES ["annex"] ["tmp_name"], $annexPath );
  5727. $annexPath = $this->webPath . $fileName;
  5728. }
  5729. }
  5730. }
  5731. $annexHtml = '<table style="width:100%;margin:10px 0">
  5732. <thead>
  5733. <tr>
  5734. <th align="left" colspan="2">下载附件:</th>
  5735. </tr>
  5736. </thead>
  5737. <tbody>
  5738. <tr>
  5739. <td><a href="' . $annexPath . '" target="_blank">' . $annexName . '</a></td>
  5740. <td>&nbsp;</td>
  5741. </tr>
  5742. </tbody>
  5743. </table>';
  5744. $smartcostMail = 'smartcost_mail_1';
  5745. $info = "";
  5746. // html template
  5747. if ($skin == 1) {
  5748. $html = '<div><table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  5749. <tbody><tr><td align="center"><table style="margin:20px;background-color:#fff;box-shadow:0px 1px 6px rgba(0, 0, 0, 0.3);width:60%;" cellpadding="0" cellspacing="0" align="center">
  5750. <tbody><tr>
  5751. <td style="background-color:#ff6501;padding:20px 0 25px;" align="center">
  5752. <span style="vertical-align:bottom;font-size:20px;color:#fff;">' . $title . '</span>
  5753. </td></tr><tr><td>
  5754. <table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;border-top:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  5755. <tbody><tr><td style="padding: 0 40px;" align="left">
  5756. <p style="margin-top:40px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;"><b>CLIENTNAME</b></p>
  5757. </td></tr><tr><td style="padding: 0 40px;" align="left">
  5758. <p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;">您好,我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
  5759. <p style="margin-top:0px;margin-bottom:20px;color:#383838;font-size:16px;line-height:32px;">
  5760. ' . $content . '</p>
  5761. </td></tr>
  5762. <tr><td align="left" style="padding: 0 40px;background:#fff">
  5763. ' . $annexHtml . '
  5764. </td></tr>
  5765. <tr>
  5766. <td style="padding: 10px 0 0;background:#F6F6F6;">
  5767. <table>
  5768. <tr>
  5769. <td style="font-size:14pxl;color:#666;padding:0 20px"><b>纵横软件公司' . $this->staff [0] ['category'] . '服务中心</b><br>' . $this->staff [0] ['username'] . '<br>
  5770. <a href="[图片]http://www.smartcost.com.cn" style="color:#666;font-size:12px;text-decoration:underline;">[图片]smartcost.com.cn</a></td>
  5771. <td>
  5772. <table>
  5773. <tr style="font-size:12px;color:#666">
  5774. <th align="right">电话:</th><td style="padding:0 20px 0 0">' . $this->staff [0] ['phone'] . '</td>
  5775. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td>
  5776. </tr>
  5777. <tr style="font-size:12px;color:#666">
  5778. <th align="right">Q Q:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5779. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td>
  5780. </tr>
  5781. </table>
  5782. </td>
  5783. </tr>
  5784. </table>
  5785. </td></tr></tbody></table></td></tr><tr>
  5786. <td style="padding: 0 40px;background-color:#383838;"><p style="color:#fff;padding:10px 0;text-align:center;margin:0">珠海纵横创新软件有限公司 <a href="http://www.smartcost.com.cn" style="color:#fff;text-decoration: underline;">smartcost.com.cn</a></p></td>
  5787. </tr></tbody></table></td></tr></tbody></table></div>';
  5788. $info = '<table><tr><th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td></tr>
  5789. <tr><th align="right">联系人:</th><td>' . $this->staff [0] ['username'] . '</td></tr>
  5790. <tr><th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr>
  5791. <tr><th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td></tr>
  5792. <tr><th align="right">邮箱:</th><td>' . $this->staff [0] ['email'] . '</td></tr></table>';
  5793. } elseif ($skin == 2) {
  5794. $smartcostMail = 'smartcost_mail_2';
  5795. $html = '<table cellspacing="0" cellpadding="0" style="background-color:#e4e4e4; width:100%;"><tbody><tr><td>
  5796. <table align="center" cellspacing="0" cellpadding="0" style="background-color:#f8f8f8; width:640px;margin-bottom:20px">
  5797. <tbody><tr><td align="left" style="background-color:#e4e4e4;"><p style="margin-top:10px;margin-bottom:10px;color:#999;font-size:16px;line-height:32px;">
  5798. <b><span name="titleHtml">' . $title . '</span></b></p></td>
  5799. </tr><tr><td><table align="center" cellspacing="0" cellpadding="0" style="border:1px solid #ddd;"><tbody><tr>
  5800. <td align="center" style="background-color:#EEF2F5;padding:20px 0 "><a style="text-decoration:none;" href="http://www.teambition.com/" target="_blank"><img width="291px" height="46" src="http://zonghengvideo.qiniudn.com/maillogo1.png"></a></td>
  5801. </tr><tr><td align="center" style="background-color:#fff;"><img width="640" height="191" src="http://zonghengvideo.qiniudn.com/hero.jpg"></td>
  5802. </tr><tr><td align="left" style="background-color:#fff;padding:40px;border-bottom:1px solid #ddd;">
  5803. <p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;"><b>CLIENTNAME</b></p>
  5804. <p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;">您好,我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
  5805. <p name="contentHtml" style="margin-top:0px;margin-bottom:15px;color:#383838;font-size:16px;line-height:32px;">' . $content . '</p></td>
  5806. </tr>
  5807. <tr><td align="left" style="padding: 0 40px;background:#fff">
  5808. ' . $annexHtml . '
  5809. </td></tr>
  5810. <tr>
  5811. <td style="padding: 10px 0;background:#F6F6F6">
  5812. <table>
  5813. <tbody>
  5814. <tr>
  5815. <td style="font-size:14pxl;color:#333;padding:0 20px">
  5816. <b>纵横公路造价软件' . $this->staff [0] ['category'] . '服务中心</b><br>' . $this->staff [0] ['username'] . '</td>
  5817. <td>
  5818. <table>
  5819. <tbody>
  5820. <tr style="font-size:12px;color:#666">
  5821. <th align="right">电话:</th><td style="padding:0 20px 0 0">' . $this->staff [0] ['phone'] . '</td>
  5822. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#666">
  5823. <th align="right">Q Q:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5824. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td>
  5825. </tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr>
  5826. <td style="padding: 0 40px;background-color:#383838;"><p style="color:#fff;padding:10px 0;text-align:center;margin:0;font-size:12px">珠海纵横创新软件有限公司 <a href="http://www.smartcost.com.cn" style="color:#fff;text-decoration:underline;">smartcost.com.cn</a></p></td>
  5827. </tr></tbody></table></td></tr></tbody> </table>';
  5828. $info = '<table><tbody><tr style="font-size:12px;color:#666">
  5829. <th align="right">电话:</th><td style="padding:0 20px 0 0">' . $this->staff [0] ['phone'] . '</td>
  5830. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#666">
  5831. <th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5832. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td>
  5833. </tr></tbody></table>';
  5834. } else {
  5835. $smartcostMail = 'smartcost_mail_3';
  5836. $html = '<table cellspacing="0" cellpadding="0" style="background-color:#ECF0E1; width:100%">
  5837. <tbody>
  5838. <tr>
  5839. <td>
  5840. <table align="center" cellspacing="0" cellpadding="0" style="width:698px;margin-bottom:30px;margin-top:30px;">
  5841. <tbody>
  5842. <tr>
  5843. <td>
  5844. <table align="center" cellspacing="0" cellpadding="0" style="border:1px solid #ccc;width:100%;border-top:none">
  5845. <tbody>
  5846. <tr>
  5847. <td align="right" style="background:#fff url(http://zonghengvideo.qiniudn.com/mail3-top-bg.png) no-repeat top center;padding:30px 20px 20px 20px;border-bottom:1px solid #E9EBE2;">
  5848. <div style="position:relative;text-align:right">
  5849. <b style="font-size:24px;color:#8A9F98;z-index:999"><span name="titleHtml">' . $title . '</span></b>
  5850. <div style="width:80px;height:80px;position:absolute;top:0;left:0"><img src="http://zonghengvideo.qiniudn.com/zonghenglogo.png"></div>
  5851. </div>
  5852. </td>
  5853. </tr>
  5854. <tr>
  5855. <td align="left" style="background-color:#fff;padding:40px;border-bottom:1px solid #ddd;">
  5856. <p style="margin-top:0px;margin-bottom:10px;color:#666;font-size:16px;line-height:32px;"><b>CLIENTNAME</b></p>
  5857. <p style="margin-top:0px;margin-bottom:10px;color:#666;font-size:16px;line-height:32px;">您好,我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
  5858. <p name="contentHtml" style="margin-top:0px;margin-bottom:15px;color:#666;font-size:16px;line-height:32px;">' . $content . '</p></td>
  5859. </tr>
  5860. <tr><td align="left" style="padding: 0 40px;background:#fff">
  5861. ' . $annexHtml . '
  5862. </td></tr>
  5863. <tr>
  5864. <td style="padding: 10px 0 0;background:#F6F6F6;">
  5865. <table>
  5866. <tbody><tr>
  5867. <td style="font-size:14pxl;color:#666;padding:0 20px"><b>纵横公路造价软件' . $this->staff [0] ['category'] . '服务中心</b><br>' . $this->staff [0] ['username'] . '<br><a href="http://www.smartcost.com.cn" style="color:#666;font-size:12px;text-decoration:underline;">smartcost.com.cn</a></td>
  5868. <td>
  5869. <table style="width:100%">
  5870. <tbody><tr style="font-size:12px;color:#496781">
  5871. <th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td>
  5872. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td>
  5873. </tr>
  5874. <tr style="font-size:12px;color:#496781">
  5875. <th align="right">Q Q:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5876. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td>
  5877. </tr>
  5878. </tbody></table>
  5879. </td>
  5880. </tr>
  5881. </tbody></table>
  5882. </td>
  5883. </tr>
  5884. <tr>
  5885. <td style="background:#F6F6F6 url(http://zonghengvideo.qiniudn.com/mail3-bottom-bg.png) no-repeat bottom center;"><p style="color:#fff;padding:0 0 20px;text-align:center;margin:0;font-size:12px"></p></td>
  5886. </tr>
  5887. </tbody>
  5888. </table></td>
  5889. </tr>
  5890. </tbody>
  5891. </table></td>
  5892. </tr>
  5893. </tbody>
  5894. </table>';
  5895. $info = '<table><tr style="font-size:12px;color:#496781"><th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td>
  5896. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#496781">
  5897. <th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5898. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td></tr></table>
  5899. ';
  5900. }
  5901. $eMailTemplate->title = $title;
  5902. $eMailTemplate->skin = $skin;
  5903. $eMailTemplate->content = $content;
  5904. if (! empty ( $tagId ))
  5905. $eMailTemplate->tag = implode ( ",", $tagId );
  5906. $eMailTemplate->staffId = $this->staff [0] ['sid'];
  5907. $eMailTemplate->staffName = $this->staff [0] ['username'];
  5908. $eMailTemplate->status = 0;
  5909. $eMailTemplate->html = $html;
  5910. $eMailTemplate->annex = $annexPath;
  5911. $eMailTemplate->annexName = $annexName;
  5912. $etid = $eMailTemplate->insert ();
  5913. // create email list
  5914. Doo::loadModel ( 'tag_client' );
  5915. $tagClient = new tag_client ();
  5916. Doo::loadModel ( 'client' );
  5917. $client = new client ();
  5918. Doo::loadModel ( 'eMailList' );
  5919. $eMailList = new eMailList ();
  5920. Doo::loadModel ( 'company' );
  5921. $company = new company ();
  5922. $tagCondition = "";
  5923. $tagArray = array ();
  5924. foreach ( $tagId as $value ) {
  5925. array_push ( $tagArray, " tag like '%" . $value . "%' " );
  5926. }
  5927. if (! empty ( $tagArray ))
  5928. $tagCondition = ' and (' . implode ( " or ", $tagArray ) . ')';
  5929. $clientList = $tagClient->find ( array (
  5930. 'select' => 'client',
  5931. 'where' => 'sid=' . $this->staff [0] ['sid'] . $tagCondition,
  5932. 'asArray' => true
  5933. ) );
  5934. $clientArray = array ();
  5935. foreach ( $clientList as $value ) {
  5936. array_push ( $clientArray, $value ['client'] );
  5937. }
  5938. $clientEmailList = array ();
  5939. if (! empty ( $clientArray ))
  5940. $clientEmailList = $client->find ( array (
  5941. 'select' => 'email,cid,nicename as clientname,companyname',
  5942. 'where' => 'cid in (' . implode ( ",", $clientArray ) . ')',
  5943. 'asArray' => true
  5944. ) );
  5945. //
  5946. if ($stype == 2) {
  5947. // 获取性质相关数据
  5948. $cidList = '';
  5949. if ($natureNULL == '') {
  5950. $nD = array ();
  5951. foreach ( $nature as $key => $value ) {
  5952. array_push ( $nD, ' nature like "' . $value . '"' );
  5953. // $nD=' nature like "'.$value.'"';
  5954. }
  5955. $nD = implode ( ' or ', $nD );
  5956. $companycid = $company->find ( array (
  5957. 'select' => 'cid',
  5958. 'where' => $nD,
  5959. 'asArray' => true
  5960. ) );
  5961. $cidList = array ();
  5962. foreach ( $companycid as $key => $value ) {
  5963. array_push ( $cidList, $value ['cid'] );
  5964. }
  5965. $cidList = implode ( ',', $cidList );
  5966. if (! empty ( $cidList ))
  5967. $cidList = ' and companyid in (' . $cidList . ')';
  5968. else
  5969. $cidList = '';
  5970. }
  5971. // 'select'=>'email,cid,nicename as clientname,companyname,district'
  5972. $where='district like "' . $did . ',%" ' . $cidList;
  5973. if ($didCity!="ALL"){
  5974. Doo::loadClass ( 'XDeode' );
  5975. $XDeode = new XDeode ( 5 );
  5976. $didCity = $XDeode->decode ( $didCity );
  5977. $where='district like "' . $did . ','.$didCity.',%" ' . $cidList;
  5978. }
  5979. $clientEmailList = $client->find ( array (
  5980. 'select' => 'email,cid,nicename as clientname,companyname,district',
  5981. 'where' => $where,
  5982. 'asArray' => true
  5983. ) );
  5984. }
  5985. // ;datediff(curdate(), 'date')>=10
  5986. $eMailJournal->delete ( array (
  5987. 'where' => "datediff(curdate(), date)>=7"
  5988. ) );
  5989. $checkMail = $eMailJournal->find ( array (
  5990. 'where' => 'DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(date)',
  5991. ' groupby' => 'email',
  5992. 'asArray' => true
  5993. ) );
  5994. $emailNameList = $emailArray = $illegalEmail = $sendEmail = array ();
  5995. Doo::db ()->beginTransaction ();
  5996. foreach ( $clientEmailList as $value ) {
  5997. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  5998. if (! empty ( $checkMail )) {
  5999. $falg = true;
  6000. foreach ( $checkMail as $v ) {
  6001. if ($v ['email'] == $value ['email']) {
  6002. $Bdate = strtotime ( $v ['date'] ) + 7 * 24 * 3600;
  6003. if ($Bdate <= time ()) {
  6004. array_push ( $emailArray, $value ['email'] );
  6005. array_push ( $emailNameList, $value );
  6006. $eMailJournal->date = date ( "Y-m-d" );
  6007. $eMailJournal->update ( array (
  6008. 'where' => 'ejid=' . $v ['ejid']
  6009. ) );
  6010. } else {
  6011. array_push ( $sendEmail, $value );
  6012. }
  6013. $falg = false;
  6014. break;
  6015. }
  6016. }
  6017. if ($falg) {
  6018. array_push ( $emailArray, $value ['email'] );
  6019. array_push ( $emailNameList, $value );
  6020. $eMailJournal->clientId = $value ['cid'];
  6021. $eMailJournal->status = 1;
  6022. $eMailJournal->email = $value ['email'];
  6023. $eMailJournal->date = date ( "Y-m-d" );
  6024. // $eMailJournal->insert();
  6025. }
  6026. } else {
  6027. array_push ( $emailArray, $value ['email'] );
  6028. array_push ( $emailNameList, $value );
  6029. $eMailJournal->clientId = $value ['cid'];
  6030. $eMailJournal->status = 1;
  6031. $eMailJournal->email = $value ['email'];
  6032. $eMailJournal->date = date ( "Y-m-d" );
  6033. // $eMailJournal->insert();
  6034. }
  6035. } else {
  6036. array_push ( $illegalEmail, $value );
  6037. }
  6038. }
  6039. Doo::db ()->commit ();
  6040. // echo json_encode($illegalEmail);
  6041. // json_encode(array_slice($illegalEmail,0,100))
  6042. // $kk=gzcompress();
  6043. // $ll=gzuncompress($kk);
  6044. // ."</br>".strlen($kk)."</br>".strlen($ll);die;
  6045. $size = floor ( count ( $emailArray ) / 3 );
  6046. if (! empty ( $emailArray )) {
  6047. if (count ( $emailArray ) < 3) {
  6048. $list = array (
  6049. 0 => $emailArray,
  6050. 1 => array (),
  6051. 2 => array ()
  6052. );
  6053. } else
  6054. $list = array_chunk ( $emailArray, $size );
  6055. } else
  6056. $list = array (
  6057. 0 => array (),
  6058. 1 => array (),
  6059. 2 => array ()
  6060. );
  6061. $emailJson = array ();
  6062. foreach ( $list as $value ) {
  6063. $em = array ();
  6064. foreach ( $value as $v ) {
  6065. array_push ( $em, $v );
  6066. }
  6067. array_push ( $emailJson, $em );
  6068. }
  6069. $size = floor ( count ( $emailNameList ) / 3 );
  6070. if (! empty ( $emailNameList )) {
  6071. if (count ( $emailNameList ) < 3) {
  6072. $list = array (
  6073. 0 => $emailNameList,
  6074. 1 => array (),
  6075. 2 => array ()
  6076. );
  6077. } else
  6078. $list = array_chunk ( $emailNameList, $size );
  6079. } else
  6080. $list = array (
  6081. 0 => array (),
  6082. 1 => array (),
  6083. 2 => array ()
  6084. );
  6085. $emailNameJson = array ();
  6086. foreach ( $list as $value ) {
  6087. $em = array ();
  6088. foreach ( $value as $v ) {
  6089. array_push ( $em, $v );
  6090. }
  6091. array_push ( $emailNameJson, $em );
  6092. }
  6093. //
  6094. $eMailList->date = date ( "Y-m-d" );
  6095. $eMailList->clientEmail = base64_encode ( gzcompress ( json_encode ( $emailJson [0] ) ) );
  6096. $eMailList->clientEmail2 = base64_encode ( gzcompress ( json_encode ( $emailJson [1] ) ) );
  6097. $eMailList->clientEmail3 = base64_encode ( gzcompress ( json_encode ( $emailJson [2] ) ) );
  6098. $eMailList->clientName = base64_encode ( gzcompress ( json_encode ( $emailNameJson [0] ) ) );
  6099. $eMailList->clientName2 = base64_encode ( gzcompress ( json_encode ( $emailNameJson [1] ) ) );
  6100. $eMailList->clientName3 = base64_encode ( gzcompress ( json_encode ( $emailNameJson [2] ) ) );
  6101. $eMailList->illegalEmail = json_encode ( array_slice ( $illegalEmail, 0, 100 ) ); // json_encode($illegalEmail);
  6102. $eMailList->sendEmail = json_encode ( $sendEmail );
  6103. $eMailList->etid = $etid;
  6104. $eMailList->templateName = $smartcostMail;
  6105. $eMailList->eTitle = $title;
  6106. $eMailList->html = $html;
  6107. $eMailList->content = $content;
  6108. $eMailList->info = $info;
  6109. if (! empty ( $annexName ))
  6110. $eMailList->annex = $annexHtml;
  6111. $eMailList->annexName = $annexName;
  6112. $eMailList->staffId = $this->staff [0] ['sid'];
  6113. $eMailList->staffName = $this->staff [0] ['username'];
  6114. if ($stype == 1)
  6115. $eMailList->tag = implode ( ",", $tagId );
  6116. if ($stype == 2) {
  6117. $eMailList->districtId = $did;
  6118. $eMailList->nature = implode ( ",", $nature );
  6119. }
  6120. $eMailList->insert ();
  6121. // 创建邮件地址
  6122. // 'http://sendcloud.sohu.com/webapi/list_member.add.json';
  6123. // print_r($emailJson);
  6124. // die;
  6125. return "/eMailList";
  6126. }
  6127. return "/eMailTask";
  6128. }
  6129. function eMailList() {
  6130. Doo::loadModel ( 'eMailList' );
  6131. $eMailList = new eMailList ();
  6132. Doo::loadModel ( 'tag' );
  6133. $tag = new tag ();
  6134. $mailList = $eMailList->find ( array (
  6135. 'where' => 'staffId=' . $this->staff [0] ['sid'],
  6136. 'desc' => 'elid',
  6137. 'asArray' => true
  6138. ) );
  6139. foreach ( $mailList as $key => $value ) {
  6140. $mailList [$key] ['clientName2'] = $mailList [$key] ['clientName3'] = array ();
  6141. $mailList [$key] ['clientName'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName'] ) ), true );
  6142. if (! empty ( $value ['clientName2'] ))
  6143. $mailList [$key] ['clientName2'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName2'] ) ), true );
  6144. if (! empty ( $value ['clientName3'] ))
  6145. $mailList [$key] ['clientName3'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName3'] ) ), true );
  6146. $mailList [$key] ['illegalEmail'] = json_decode ( $value ['illegalEmail'], true );
  6147. $mailList [$key] ['sendEmail'] = json_decode ( $value ['sendEmail'], true );
  6148. $mailList [$key] ['clientCount'] = count ( $mailList [$key] ['clientName'] ) + count ( $mailList [$key] ['clientName2'] ) + count ( $mailList [$key] ['clientName3'] );
  6149. $mailList [$key] ['tag'] = array ();
  6150. if (! empty ( $value ['tag'] ))
  6151. $mailList [$key] ['tag'] = $tag->find ( array (
  6152. 'where' => 'tid in ( ' . $value ['tag'] . ') ',
  6153. 'asArray' => true
  6154. ) );
  6155. }
  6156. $data ['mailList'] = $mailList;
  6157. $data ['memu'] = "eMailTask";
  6158. $data ['staff'] = $this->staff;
  6159. $data ['mailMemu'] = 'eMailList';
  6160. $this->render ( "/mail_list", $data );
  6161. }
  6162. function showEmailContent() {
  6163. $elid = isset ( $this->params ['elid'] ) ? $this->params ['elid'] : 0;
  6164. Doo::loadModel ( 'eMailList' );
  6165. $eMList = new eMailList ();
  6166. $isSend = $eMList->getOne ( array (
  6167. 'where' => 'elid =' . $elid . '',
  6168. 'asArray' => true
  6169. ) );
  6170. echo htmlspecialchars ( $isSend ['content'] );
  6171. }
  6172. function postEmail() {
  6173. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  6174. $elid = isset ( $this->params ['elid'] ) ? $this->params ['elid'] : 0;
  6175. $send = isset ( $this->params ['send'] ) ? $this->params ['send'] : 0;
  6176. Doo::loadModel ( 'eMailList' );
  6177. $eMList = new eMailList ();
  6178. if (! empty ( $elid )) {
  6179. $isSend = $eMList->getOne ( array (
  6180. 'select' => 'send' . $send,
  6181. 'where' => 'elid =' . $elid . ' and status=0 and send' . $send . '=1',
  6182. 'asArray' => true
  6183. ) );
  6184. if (! empty ( $isSend ))
  6185. die ( '这批邮件已经发送' );
  6186. if ($send == 1)
  6187. $send = '';
  6188. $eMailList = $eMList->getOne ( array (
  6189. 'select' => 'eTitle,staffName,clientName' . $send . ' as clientName,clientEmail' . $send . ' as clientEmail,annex,info,content,templateName',
  6190. 'where' => 'elid =' . $elid . ' and status=0',
  6191. 'asArray' => true
  6192. ) );
  6193. if ($send == "")
  6194. $send = 1;
  6195. $sql = "update `CLD_eMailList` set send" . $send . "='1' where elid = '" . $elid . "'";
  6196. Doo::db ()->query ( $sql );
  6197. $isSend = $eMList->getOne ( array (
  6198. 'where' => 'elid =' . $elid . ' and status=0 and send1=1 and send2=1 and send3=1',
  6199. 'asArray' => true
  6200. ) );
  6201. if (! empty ( $isSend )) {
  6202. $sql = "update `CLD_eMailList` set status='2' where elid = '" . $elid . "'";
  6203. Doo::db ()->query ( $sql );
  6204. }
  6205. $toFormatMail = array ();
  6206. $sub = array ();
  6207. // file_put_contents("test.txt", "This is another something.<br/>", FILE_APPEND);
  6208. // sleep(4);
  6209. // die;
  6210. $toMail = json_decode ( gzuncompress ( base64_decode ( $eMailList ['clientEmail'] ) ), true );
  6211. // $toMailCount=count($toMail);
  6212. $subMail = json_decode ( gzuncompress ( base64_decode ( $eMailList ['clientName'] ) ), true );
  6213. $chunkMail = array_chunk ( $toMail, 80 );
  6214. $chunkSubMail = array_chunk ( $subMail, 80 );
  6215. $vii = 0;
  6216. foreach ( $chunkMail as $key => $value ) {
  6217. $l = $s = $c = $i = $cate = $con = $annex = array ();
  6218. $toFormatMail ['to'] = $value;
  6219. $cn = $chunkSubMail [$key];
  6220. foreach ( $cn as $v ) {
  6221. array_push ( $l, $eMailList ['eTitle'] );
  6222. array_push ( $s, $eMailList ['staffName'] );
  6223. array_push ( $c, $v ['clientname'] );
  6224. array_push ( $annex, $eMailList ['annex'] );
  6225. array_push ( $i, $eMailList ['info'] );
  6226. // array_push($con, $eMailList['content']);
  6227. array_push ( $cate, $this->staff [0] ['category'] );
  6228. }
  6229. $sub ['%eTitle%'] = $l;
  6230. $sub ['%staffName%'] = $s;
  6231. $sub ['%clientName%'] = $c;
  6232. $sub ['%category%'] = $cate;
  6233. $sub ['%info%'] = $i;
  6234. // $sub['%content%']=$con;
  6235. $sub ['%annex%'] = $annex;
  6236. $toFormatMail ['sub'] = $sub;
  6237. $url = 'http://sendcloud.sohu.com/webapi/mail.send_template.xml';
  6238. $param = array (
  6239. 'api_user' => 'cldmail',
  6240. 'api_key' => 'cDO1GjtY1seH',
  6241. 'template_invoke_name' => $eMailList ['templateName'],
  6242. 'from' => $this->staff [0] ['email'],
  6243. 'fromname' => '纵横' . $eMailList ['staffName'],
  6244. 'subject' => $eMailList ['eTitle'],
  6245. 'substitution_vars' => json_encode ( $toFormatMail )
  6246. );
  6247. $post_data = http_build_query ( $param );
  6248. $ch = curl_init ();
  6249. curl_setopt ( $ch, CURLOPT_POST, 1 );
  6250. curl_setopt ( $ch, CURLOPT_URL, $url );
  6251. curl_setopt ( $ch, CURLOPT_HEADER, false ); // 设定是否输出页面内容
  6252. curl_setopt ( $ch, CURLOPT_NOBODY, false );
  6253. curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_data );
  6254. $result = curl_exec ( $ch );
  6255. curl_close ( $ch );
  6256. /*
  6257. * if($result=='success'){ $eM=new eMailList(); $eM->status='2'; $eM->update(array('where'=>'elid=?','param'=>array($elid))); }
  6258. */
  6259. }
  6260. // die;
  6261. return '/eMailList';
  6262. }
  6263. }
  6264. function a() {
  6265. $substitution_vars = $this->get_args ( 'substitution_vars' );
  6266. file_put_contents ( DOO::conf ()->SITE_PATH . 'upload/' . "_" . time () . "_" . rand ( 100, 999 ) . ".log", $substitution_vars );
  6267. }
  6268. function deleteEmail() {
  6269. $elid = isset ( $this->params ['elid'] ) ? $this->params ['elid'] : 0;
  6270. if (! empty ( $elid )) {
  6271. $sql = "DELETE FROM `CLD_eMailList` where elid = '" . $elid . "'";
  6272. Doo::db ()->query ( $sql );
  6273. return '/eMailList';
  6274. }
  6275. }
  6276. /**
  6277. * 发送post请求
  6278. * @param string $url 请求地址
  6279. * @param array $post_data post键值对数据
  6280. * @return string
  6281. */
  6282. function sendPost($url, $post_data) {
  6283. $postdata = http_build_query ( $post_data );
  6284. // X-Amzn-Authorization: AWS3 AWSAccessKeyId=AKIAIDSE5VYNX5ERJHXQ,Signature=lBP67vCvGlDMBQ=dofZxg8E8SUEXAMPLE,Algorithm=HmacSHA256,SignedHeaders=qG1BdSh9QyYPlWLnjqvjDXjyPdFjl7fUSkfs0Hk2
  6285. $options = array (
  6286. 'http' => array (
  6287. 'method' => 'POST',
  6288. 'header' => '
  6289. Content-Type: application/x-www-form-urlencoded
  6290. ',
  6291. 'content' => $postdata,
  6292. 'timeout' => 15 * 60
  6293. )
  6294. ); // 超时时间(单位:s)
  6295. $context = stream_context_create ( $options );
  6296. $result = file_get_contents ( $url, false, $context );
  6297. return $result;
  6298. }
  6299. function avatar() {
  6300. $result = array ();
  6301. $result ['success'] = false;
  6302. $successNum = 0;
  6303. // 定义一个变量用以储存当前头像的序号
  6304. $avatarNumber = 1;
  6305. $i = 0;
  6306. $msg = '';
  6307. // 上传目录
  6308. $dir = DOO::conf ()->SITE_PATH . "global/avatar";
  6309. // 遍历所有文件域
  6310. while ( list ( $key, $val ) = each ( $_FILES ) ) {
  6311. if ($_FILES [$key] ['error'] > 0)
  6312. $msg .= $_FILES [$key] ['error'];
  6313. else {
  6314. $fileName = 'avatar_' . $this->staff [0] ['sid'];
  6315. // 原始图片(file 域的名称:__source,如果客户端定义可以上传的话,可在此处理)。
  6316. if ($key == '__source') { // 当前头像基于原图的初始化参数,用于修改头像时保证界面的视图跟保存头像时一致。帮助提升用户体验度。修改头像时设置默认加载的原图的url为此图片的url+该参数即可。
  6317. $initParams = $_POST ["__initParams"];
  6318. $virtualPath = $dir . "/" . $fileName . "_" . $avatarNumber . ".jpg";
  6319. $result ['sourceUrl'] = '/' . $virtualPath . $initParams;
  6320. move_uploaded_file ( $_FILES [$key] ["tmp_name"], $virtualPath );
  6321. $successNum ++;
  6322. } else if (strpos ( $key, '__avatar' ) === 0) { // 头像图片(file 域的名称:__avatar1,2,3...)。
  6323. $virtualPath = $dir . "/" . $fileName . "_" . $avatarNumber . ".jpg";
  6324. $result ['avatarUrls'] [$i] = '/' . $virtualPath;
  6325. move_uploaded_file ( $_FILES [$key] ["tmp_name"], $virtualPath );
  6326. $avatarNumber ++;
  6327. $successNum ++;
  6328. $i ++;
  6329. }
  6330. }
  6331. }
  6332. $result ['msg'] = $msg;
  6333. if ($successNum > 0)
  6334. $result ['success'] = true;
  6335. // 返回图片的保存结果(返回内容为json字符串)
  6336. Doo::loadModel ( 'staff' );
  6337. $staff = new staff ();
  6338. $staff->sid = $this->staff [0] ['sid'];
  6339. $staff->avatar = "/global/avatar/" . $fileName;
  6340. $staff->update ();
  6341. echo json_encode ( $result );
  6342. }
  6343. function lockUpload() {
  6344. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6345. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6346. $file = $_FILES ['Filedata'] ['tmp_name'];
  6347. $error = false;
  6348. if (! is_uploaded_file ( $file )) {
  6349. $error = '400 Bad Request';
  6350. }
  6351. if ($error) {
  6352. header ( 'HTTP/1.0 ' . $error );
  6353. die ( 'Error ' . $error );
  6354. } else {
  6355. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6356. $this->IoHandler = new IoHandler ();
  6357. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6358. // $filedir=$_POST['time'];
  6359. // 调用定义物理路径
  6360. $t = DOO::conf ()->SITE_PATH . "upload/";
  6361. $this->IoHandler->MakeDir ( $t );
  6362. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6363. if ($filename != 'xlsx')
  6364. return "";
  6365. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6366. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6367. $upload_dir = $t . "/" . $upload_file;
  6368. $k = move_uploaded_file ( $file, $upload_dir );
  6369. if ($k) {
  6370. // "series/".$filedir."/".
  6371. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6372. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6373. }
  6374. }
  6375. }
  6376. }
  6377. function getAuthentication() {
  6378. }
  6379. function loadCVS() {
  6380. Doo::loadModel ( 'longle' );
  6381. $longle = new longle ();
  6382. $list = $longle->find ( array (
  6383. 'select' => 'key_num',
  6384. 'asArray' => TRUE
  6385. ) );
  6386. $file = fopen ( DOO::conf ()->SITE_PATH . "upload/key2.csv", 'r' );
  6387. while ( $data = fgetcsv ( $file ) ) {
  6388. $goods_list [$data [0]] = $data [1];
  6389. }
  6390. fclose ( $file );
  6391. $sqlArray = array ();
  6392. $sql = 'UPDATE CLD_longle SET SerialNumber = CASE key_num ';
  6393. foreach ( $list as $key => $value ) {
  6394. if (array_key_exists ( $value ['key_num'], $goods_list )) {
  6395. // echo $value['key_num'].'-'.$goods_list[$value['key_num']].'<br/>';
  6396. // $longle->SerialNumber=$goods_list[$value['key_num']];
  6397. // $longle->update(array('where'=>'key_num="'.$value['key_num'].'"'));
  6398. $sql .= ' WHEN "' . $value ['key_num'] . '" THEN "' . $goods_list [$value ['key_num']] . '" ';
  6399. array_push ( $sqlArray, '"' . $value ['key_num'] . '"' );
  6400. unset ( $goods_list [$value ['key_num']] );
  6401. }
  6402. }
  6403. $sql .= 'END WHERE key_num IN (' . implode ( ',', $sqlArray ) . ')';
  6404. echo $sql . '<br/>--------------------------------<br/>';
  6405. foreach ( $goods_list as $key => $value ) {
  6406. echo $key . ',' . $value . '<br/>';
  6407. }
  6408. }
  6409. private function getRandChar($length) {
  6410. $str = null;
  6411. $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
  6412. $max = strlen ( $strPol ) - 1;
  6413. for($i = 0; $i < $length; $i ++) {
  6414. $str .= $strPol [rand ( 0, $max )]; // rand($min,$max)生成介于min和max两个数之间的一个随机整数
  6415. }
  6416. return $str;
  6417. }
  6418. // private function getReceiptCount(){
  6419. // $status=2;
  6420. // $year=date('Y');
  6421. // Doo::loadModel('receipt');
  6422. // $receipt=new receipt();
  6423. // $dateCondition=" and Year(date) =".$year;
  6424. // $approvalCondition=' and nowStaff like "%'.$this->staff[0]['sid'].'%" ';
  6425. // $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  6426. // return count($receiptList);
  6427. // }
  6428. // private function getExeCount(){
  6429. // Doo::loadModel('receipt');
  6430. // $receipt=new receipt();
  6431. // $receiptList=$receipt->find(array('where'=>'(executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and executeStaff NOT LIKE \'%'.$this->staff[0]['sid'].'%\' ) and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  6432. // return count($receiptList);
  6433. // }
  6434. /**
  6435. * 格式化excel文件为数组
  6436. * @param unknown_type $file_url
  6437. * @param unknown_type $mcid
  6438. */
  6439. function _format_excel_to_array($file_url = "") {
  6440. if (! file_exists ( $file_url ))
  6441. return array ();
  6442. Doo::loadClass ( 'PHPExcel' );
  6443. $PHPExcel = new PHPExcel ();
  6444. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6445. if (! $PHPReader->canRead ( $file_url )) {
  6446. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6447. if (! $PHPReader->canRead ( $file_url )) {
  6448. echo 'no Excel';
  6449. return;
  6450. }
  6451. }
  6452. $PHPExcel = $PHPReader->load ( $file_url );
  6453. /**
  6454. * 读取excel文件中的第一个工作表
  6455. */
  6456. $currentSheet = $PHPExcel->getSheet ( 0 );
  6457. /**
  6458. * 取得最大的列号
  6459. */
  6460. $allColumn = $currentSheet->getHighestColumn ();
  6461. /**
  6462. * 取得一共有多少行
  6463. */
  6464. $allRow = $currentSheet->getHighestRow ();
  6465. $excel_array = array ();
  6466. for($currentRow = 2; $currentRow <= $allRow; $currentRow ++) {
  6467. $excel_column = array ();
  6468. // 后期改进
  6469. if ($allColumn == 'AM')
  6470. $allColumn = 'Z';
  6471. /**
  6472. * 从第A列开始输出
  6473. */
  6474. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6475. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6476. /**
  6477. * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312',
  6478. */
  6479. $val = "'" . addslashes ( $val ) . "'";
  6480. if ($currentColumn == 'A')
  6481. $excel_column ['key_num'] = $val;
  6482. elseif ($currentColumn == 'C')
  6483. $excel_column ['product'] = $val;
  6484. elseif ($currentColumn == 'D') {
  6485. $val = str_replace ( "'", "", $val );
  6486. $excel_column ['make_day'] = $this->excelTime ( $val );
  6487. } elseif ($currentColumn == 'E') {
  6488. $val = str_replace ( "'", "", $val );
  6489. $excel_column ['alloted_time'] = $this->excelTime ( $val );
  6490. } elseif ($currentColumn == 'F') {
  6491. $val = str_replace ( "'", "", $val );
  6492. $excel_column ['version'] = $val;
  6493. } elseif ($currentColumn == 'B') {
  6494. $val = str_replace ( "'", "", $val );
  6495. $excel_column ['SerialNumber'] = $val;
  6496. }
  6497. }
  6498. array_push ( $excel_array, $excel_column );
  6499. }
  6500. return $excel_array;
  6501. }
  6502. function excelTime($date, $time = false) {
  6503. if (function_exists ( 'GregorianToJD' )) {
  6504. if (is_numeric ( $date )) {
  6505. $jd = GregorianToJD ( 1, 1, 1970 );
  6506. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6507. $date = explode ( '/', $gregorian );
  6508. $date_str = str_pad ( $date [2], 4, '0', STR_PAD_LEFT ) . "-" . str_pad ( $date [0], 2, '0', STR_PAD_LEFT ) . "-" . str_pad ( $date [1], 2, '0', STR_PAD_LEFT ) . ($time ? " 00:00:00" : '');
  6509. return $date_str;
  6510. }
  6511. } else {
  6512. $date = $date > 25568 ? $date + 1 : 25569;
  6513. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6514. $ofs = (70 * 365 + 17 + 2) * 86400;
  6515. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6516. }
  6517. return $date;
  6518. }
  6519. function _GetFileEXT($filename) {
  6520. $pics = explode ( '.', $filename );
  6521. $num = count ( $pics );
  6522. return $pics [$num - 1];
  6523. }
  6524. /**
  6525. * 获取get或者POST值
  6526. * @param string $name 属性名称
  6527. * @return fixed 值
  6528. */
  6529. function get_args($name) {
  6530. if (isset ( $_GET [$name] )) {
  6531. if (is_array ( $_GET [$name] ))
  6532. return $_GET [$name];
  6533. else {
  6534. return addslashes ( $_GET [$name] );
  6535. }
  6536. } elseif (isset ( $_POST [$name] )) {
  6537. if (is_array ( $_POST [$name] ))
  6538. return $_POST [$name];
  6539. else {
  6540. return addslashes ( $_POST [$name] );
  6541. }
  6542. } else {
  6543. return false;
  6544. }
  6545. }
  6546. function get_previous($on_page = 1) {
  6547. return $on_page != 0 ? $on_page - 1 : $on_page;
  6548. }
  6549. /**
  6550. * 获得分页数据
  6551. * @param unknown_type $table
  6552. * @param unknown_type $condition
  6553. * @param unknown_type $on_page
  6554. * @param unknown_type $page_size
  6555. */
  6556. function get_Tpage($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $tagSQL) {
  6557. $page_c = "";
  6558. $page ['previous'] = $this->get_previous ( $on_page );
  6559. $page ['on_page'] = $on_page;
  6560. $total_count = $this->get_table_Tcount ( $table, $condition, $tagSQL );
  6561. $total = intval ( $total_count / $page_size );
  6562. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6563. $page ['total_data'] = $total_count;
  6564. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6565. $i = 1;
  6566. $page_max = 1;
  6567. if ($on_page > 10) {
  6568. $page_max = intval ( $on_page / 10 ) + 1;
  6569. $i = intval ( $on_page / 10 ) * 10 - 1;
  6570. }
  6571. $page ['page'] = $page_c;
  6572. $page ['lower'] = (-- $on_page) * $page_size;
  6573. return $page;
  6574. }
  6575. /**
  6576. * 获得分页数据
  6577. * @param unknown_type $table
  6578. * @param unknown_type $condition
  6579. * @param unknown_type $on_page
  6580. * @param unknown_type $page_size
  6581. */
  6582. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page", $staffid = "", $search, $tooltip, $cateid, $tagSQL) {
  6583. $page_c = "";
  6584. $page ['previous'] = $this->get_previous ( $on_page );
  6585. $page ['on_page'] = $on_page;
  6586. $total_count = $this->get_table_count ( $table, $condition, $staffid, $search, $tooltip, $cateid, $tagSQL );
  6587. $total = intval ( $total_count / $page_size );
  6588. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6589. $page ['total_data'] = $total_count;
  6590. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6591. $i = 1;
  6592. $page_max = 1;
  6593. if ($on_page > 10) {
  6594. $page_max = intval ( $on_page / 10 ) + 1;
  6595. $i = intval ( $on_page / 10 ) * 10 - 1;
  6596. }
  6597. for(; $i <= $page ['total_page']; $i ++) {
  6598. if ($i == $on_page) {
  6599. if ($other == "page")
  6600. $page_c .= '<a href="javascript:void(0);" class="current">' . $i . '</a>';
  6601. else
  6602. $page_c .= '&nbsp;<span class="current">' . $i . '</span>&nbsp;';
  6603. } else if ($other == "page")
  6604. $page_c .= '<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>';
  6605. else
  6606. $page_c .= '&nbsp;<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>&nbsp;';
  6607. if ($i == (10 * $page_max))
  6608. break;
  6609. }
  6610. $page ['page'] = $page_c;
  6611. $page ['lower'] = (-- $on_page) * $page_size;
  6612. return $page;
  6613. }
  6614. /**
  6615. * 获取总页数
  6616. * @param unknown_type $table
  6617. * @param unknown_type $condition
  6618. */
  6619. public function get_table_Tcount($table = "", $condition = "", $tagSQL) {
  6620. if ($tagSQL)
  6621. $sql = "select count(*) as count from CLD_tagCompanyNexus as a left join CLD_company as b on (a.company=b.cid ) where " . $condition;
  6622. else
  6623. $sql = "select count(*) as count from CLD_company where " . $condition;
  6624. $query = Doo::db ()->query ( $sql );
  6625. $result = $query->fetch ();
  6626. return $result ['count'];
  6627. }
  6628. /**
  6629. * 获取总页数
  6630. * @param unknown_type $table
  6631. * @param unknown_type $condition
  6632. */
  6633. public function get_table_count($table = "", $condition = "", $staffid = "", $search, $tooltip, $cateid, $tagSQL) {
  6634. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  6635. // echo $staffid;die;
  6636. //
  6637. if (! empty ( $staffid )) {
  6638. // $staffid="and a.sid= '".$staffid."'"; " . $table . " as a left join on (a.cid=b.cid ".$staffid.")
  6639. $sql = "select count(*) as count from CLD_client as b left join CLD_tag_client as c on (b.cid=c.client) where 1 " . $condition;
  6640. } else {
  6641. if (strlen ( $condition ) == 1 || empty ( $condition ))
  6642. $sql = "select count(*) as count from CLD_client as a " . $condition;
  6643. else
  6644. $sql = "select count(*) as count from CLD_client as a left join CLD_tag_client as c on (a.cid=c.client) where 1 " . $condition;
  6645. }
  6646. if (! empty ( $search ))
  6647. $sql = "select count(*) as count from CLD_client as a where 1 " . $condition;
  6648. if (! empty ( $tooltip )) {
  6649. $condition = str_replace ( "a.", "c.", $condition );
  6650. if ($tagSQL)
  6651. $sql = "select count(*) as count from CLD_C_tooltip as a left join CLD_tag_client as c on (a.cid=c.client) left join CLD_client as b on (c.client=b.cid ) where a.name like '%" . $tooltip . "%' and a.cateid = " . $cateid . " " . $condition;
  6652. else
  6653. $sql = "select count(*) as count from CLD_C_tooltip as a left join CLD_client as b on (a.cid=b.cid ) where a.name like '%" . $tooltip . "%' and a.cateid = " . $cateid . " " . $condition;
  6654. }
  6655. // echo $sql;
  6656. $query = Doo::db ()->query ( $sql );
  6657. $result = $query->fetch ();
  6658. return $result ['count'];
  6659. }
  6660. /**
  6661. * 生成token
  6662. * @return string
  6663. */
  6664. function set_token() {
  6665. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  6666. $str = sha1 ( $str ); // 加密
  6667. return $str;
  6668. }
  6669. }
  6670. ?>