| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938 | 
							- <?php
 
- /**
 
-  * @author darkredz
 
-  */
 
- class MainController extends DooController {
 
- 	public $staff;
 
- 	public $nature = array (
 
- 			'1' => '设计',
 
- 			'2' => '造价管理',
 
- 			'3' => '业主',
 
- 			'4' => '交通局',
 
- 			'5' => '公路局',
 
- 			'6' => '审计',
 
- 			'7' => '财政',
 
- 			'8' => '审核',
 
- 			'9' => '施工',
 
- 			'10' => '咨询',
 
- 			'11' => '招标代理',
 
- 			'12' => '监理',
 
- 			'13' => '学校',
 
- 			'14' => '个人',
 
- 			'15' => '合作伙伴' 
 
- 	);
 
- 	public $tooltip = array (
 
- 			'1' => array (
 
- 					'L',
 
- 					'点击筛选标签' 
 
- 			),
 
- 			'2' => array (
 
- 					'M',
 
- 					'点击筛选标签' 
 
- 			),
 
- 			'3' => array (
 
- 					'N',
 
- 					'点击筛选标签' 
 
- 			),
 
- 			'4' => array (
 
- 					'O',
 
- 					'点击筛选标签' 
 
- 			),
 
- 			'5' => array (
 
- 					'P',
 
- 					'点击筛选标签' 
 
- 			),
 
- 			'6' => array (
 
- 					'Q',
 
- 					'点击筛选标签' 
 
- 			),
 
- 			'7' => array (
 
- 					'R',
 
- 					'点击筛选标签' 
 
- 			) 
 
- 	);
 
- 	public $webPath = "http://cld.smartcost.com.cn/upload/emailAnnex/";
 
- 	public function beforeRun($resource, $action) {
 
- 		
 
- 		// 主权限获得与判断
 
- 		Doo::loadModel ( 'staff' );
 
- 		$staff = new staff ();
 
- 		$detail = array ();
 
- 		if (isset ( $_COOKIE ["staff"] ))
 
- 			$detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
 
- 		else
 
- 			$detail ['sid'] = 0;
 
- 		
 
- 		$flag = false;
 
- 		$accessModular = 'EMAIL';
 
- 		if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
 
- 			$flag = true;
 
- 		} else {
 
- 			$flag = false;
 
- 		}
 
- 		
 
- 		if ($flag === false) {
 
- 			$accessModular = 'INFORMATION';
 
- 			if (empty ( $detail ['cldAccessArray'] ))
 
- 				return '/settingEmployeeInfo';
 
- 			else {
 
- 				
 
- 				if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
 
- 					if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
 
- 						$flag = true;
 
- 					} else {
 
- 						$flag = false;
 
- 					}
 
- 				} else {
 
- 					$flag = false;
 
- 				}
 
- 			}
 
- 		}
 
- 		
 
- 		if ($flag === false) {
 
- 			$accessModular = 'DIRECTORIES';
 
- 			if (empty ( $detail ['cldAccessArray'] ))
 
- 				die ( 'illegal request' );
 
- 			else {
 
- 				
 
- 				if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
 
- 					if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
 
- 						$flag = true;
 
- 					} else {
 
- 						$flag = false;
 
- 					}
 
- 				} else {
 
- 					$flag = false;
 
- 				}
 
- 			}
 
- 		}
 
- 		
 
- 		if ($flag === false) {
 
- 			$accessModular = 'LOCK';
 
- 			if (empty ( $detail ['cldAccessArray'] ))
 
- 				die ( 'illegal request' );
 
- 			else {
 
- 				
 
- 				if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
 
- 					if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
 
- 						$flag = true;
 
- 					} else {
 
- 						$flag = false;
 
- 					}
 
- 				} else {
 
- 					$flag = false;
 
- 				}
 
- 			}
 
- 		}
 
- 		
 
- 		if ($detail ['sid'] == superHR && ! $flag)
 
- 			return '/settingEmployeeInfo';
 
- 		elseif (! $flag && $action == 'logStatistics')
 
- 			return '/settingEmployeeInfo';
 
- 		elseif (! $flag)
 
- 			die ( 'illegal request' );
 
- 	}
 
- 	function __construct() {
 
- 		
 
- 		// phpinfo();die;
 
- 		// include './protected/config/common.conf.php';
 
- 		// include $config['BASE_PATH'].'diagnostic/debug.php';
 
- 		if (isset ( $_COOKIE ["staff"] )) {
 
- 			if (! empty ( $_COOKIE ["staff"] )) {
 
- 				Doo::loadModel ( 'staff' );
 
- 				$staff = new staff ();
 
- 				$this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
 
- 				
 
- 				return "";
 
- 			}
 
- 		}
 
- 		
 
- 		Doo::loadCore ( 'uri/DooUriRouter' );
 
- 		$router = new DooUriRouter ();
 
- 		$routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
 
- 		
 
- 		if ($routeRs ['1'] != "login") {
 
- 			header ( 'Content-Type:text/html;charset=utf-8' );
 
- 			@header ( "Location: /login" );
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 优化actionLog表
 
- 	 */
 
- 	function backUpActionLog() {
 
- 		Doo::loadModel ( 'action_log' );
 
- 		$action_log = new action_log ();
 
- 		
 
- 		$date = date ( "Y" );
 
- 		$tableName = 'CLD_action_log' . $date;
 
- 		$action_log->copyActionLogToBakTable ( $tableName );
 
- 		$action_log = new action_log ();
 
- 		$aid = 0;
 
- 		$action_log->delActionLogByAid ( $aid );
 
- 	}
 
- 	function login() {
 
- 		$passwork = $this->get_args ( 'passwork' ) ? $this->get_args ( 'passwork' ) : 0;
 
- 		$uid = $this->get_args ( 'user' ) ? $this->get_args ( 'user' ) : 0;
 
- 		
 
- 		Doo::loadModel ( 'staff' );
 
- 		$staff = new staff ();
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 5 );
 
- 		
 
- 		if (! empty ( $passwork )) {
 
- 			$userinfo = $staff->checkUser ( $uid, $passwork );
 
- 			if (! empty ( $userinfo )) {
 
- 				setcookie ( "staff", $XDeode->encode ( $userinfo [0] ['sid'] ), time () + 36000, "/" );
 
- 				
 
- 				
 
- // 				$text = 'CLDV2_CP';
 
- // 				$algorithm = 'aes192';
 
- // 				$password = '1234567890abcdef1234567890abcdef'; //node js required 32 byte length key
 
- // 				$iv = '1234567890abcdef'; //must be 16 byte length OPENSSL_RAW_DATA
 
- // 				$staffV2= bin2hex(openssl_encrypt($userinfo [0] ['sid'] , $algorithm, $text )); 
 
- 				
 
- 				Doo::loadClass ( 'crypto' );
 
- 				$crypto = new crypto ( );
 
- 				$staffV2=$crypto->encrypt( $userinfo [0] ['sid'],'CLDV2_CP');
 
- 				setcookie ( "staffV2", $staffV2, time () + 36000, "/" );
 
- 				
 
- 				return "/";
 
- 			}
 
- 		}
 
- 		
 
- 		// 检测员工状态
 
- 		$data ['application'] = 0;
 
- 		$detail = $staff->getStaffByName ( $uid );
 
- 		if (! empty ( $detail )) {
 
- 			if ($detail ['pendStatus'] == 1) {
 
- 				$data ['application'] = 1;
 
- 			} elseif ($detail ['pendStatus'] == 2) {
 
- 				$data ['application'] = 2;
 
- 			}
 
- 		}
 
- 		
 
- 		$data ['staff'] = $detail; // $staff->getUser ();
 
- 		$data ['login'] = "";
 
- 		if (! empty ( $passwork ))
 
- 			$data ['login'] = "inputErrow";
 
- 		
 
- 		$this->render ( "/login", $data );
 
- 	}
 
- 	function out() {
 
- 		setcookie ( "staff", "", time () - 3600, "/" );
 
- 		setcookie ( "staffV2", "", time () - 3600, "/" );
 
- 		return "/";
 
- 	}
 
- 	function test() {
 
- 		// 实例化redis
 
- 	}
 
- 	function index2() {
 
- 		// include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
 
- 		$cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
 
- 		$sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
 
- 		$page = $this->get_args ( 'page' ) ? $this->get_args ( 'page' ) : 1;
 
- 		
 
- 		Doo::loadModel ( 'action_log' );
 
- 		$action_log = new action_log ();
 
- 		Doo::loadModel ( 'staff' );
 
- 		$staff = new staff ();
 
- 		Doo::loadModel ( 'client_staff' );
 
- 		$client_staff = new client_staff ();
 
- 		Doo::loadModel ( 'longle' );
 
- 		$longle = new longle ();
 
- 		Doo::loadModel ( 'L_category' );
 
- 		$lcategory = new L_category ();
 
- 		
 
- 		$limit = 50;
 
- 		$p = $page;
 
- 		if ($page != 1)
 
- 			$page = $page * $limit - 1;
 
- 		else
 
- 			$page --;
 
- 		
 
- 		$condition = "";
 
- 		// if (!empty($cid) && $cid != 12) {
 
- 		// $condition = " and cid=" . $cid . " and sid=" . $sid;
 
- 		// }
 
- 		
 
- 		$staffCondition = "";
 
- 		$categorylist2 = array ();
 
- 		if ($this->staff [0] ['cid'] != 12) {
 
- 			$staffCondition = " and cid=" . $this->staff [0] ['cid'];
 
- 			array_push ( $categorylist2, array (
 
- 					'cid' => $this->staff [0] ['cid'],
 
- 					'title' => $this->staff [0] ['category'] 
 
- 			) );
 
- 			if (! empty ( $sid ))
 
- 				$condition = " and cid=" . $this->staff [0] ['cid'] . " and sid=" . $sid;
 
- 			else
 
- 				$condition = " and cid=" . $this->staff [0] ['cid'];
 
- 		} else {
 
- 			$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';
 
- 			$query = Doo::db ()->query ( $sql );
 
- 			$result = $query->fetchAll ();
 
- 			$categorylist2 = $result;
 
- 		}
 
- 		
 
- 		// 有待优化
 
- 		Doo::loadModel ( 'department' );
 
- 		$department = new department ();
 
- 		$categorylist3 = $categorylist2;
 
- 		$bakCategory = array ();
 
- 		foreach ( $categorylist3 as $key => $value ) {
 
- 			$departList = $department->getDepartmentBycid ( $value ['cid'] );
 
- 			if (! empty ( $departList )) {
 
- 				// $bakCategory=$categorylist2[$key];
 
- 				
 
- 				array_unshift ( $bakCategory, $value );
 
- 				
 
- 				unset ( $categorylist2 [$key] );
 
- 				foreach ( $departList as $v ) {
 
- 					array_unshift ( $bakCategory, array (
 
- 							'cid' => $v ['cid'],
 
- 							'title' => $value ['title'],
 
- 							'count' => $value ['count'],
 
- 							'did' => $v ['did'],
 
- 							'departmentName' => $v ['departmentName'] 
 
- 					) );
 
- 				}
 
- 			}
 
- 		}
 
- 		
 
- 		foreach ( $bakCategory as $value ) {
 
- 			array_unshift ( $categorylist2, $value );
 
- 		}
 
- 		
 
- 		$data ['did'] = '';
 
- 		if (! empty ( $cid )) {
 
- 			
 
- 			$staffCondition = " and cid=" . $cid;
 
- 			if (! is_numeric ( $cid )) {
 
- 				$cdid = explode ( '-', $cid );
 
- 				$cid = $cdid [0];
 
- 				$data ['did'] = $cdid [1];
 
- 				$staffCondition = " and cid=" . $cid . " and departmentID=" . $cdid [1];
 
- 			}
 
- 			
 
- 			if (! empty ( $sid ))
 
- 				$condition = " and cid=" . $cid . " and sid=" . $sid;
 
- 			else
 
- 				$condition = " and cid=" . $cid;
 
- 		}
 
- 		
 
- 		/*
 
- 		 * $itemCategoryList=$action_log->find(array('select'=>'updatetime,COUNT(*)', 'where'=>" Year(updatetime)=2014",'groupby'=>'Month(updatetime)','asArray'=>true)); print_r($itemCategoryList);die;
 
- 		 */
 
- 		
 
- 		$staffList = $staff->find ( array (
 
- 				'where' => ' username!="admin" ' . $staffCondition . $staffCondition . ' and nature!=4 and pendStatus!=4 and pendStatus!=1 and pendStatus!=2 ',
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		$alCondition = ' aid>' . REMIT . '  ';
 
- 		
 
- 		$actionLogList = $action_log->find ( array (
 
- 				'where' => $alCondition . $condition,
 
- 				'limit' => $page . ',' . $limit,
 
- 				'desc' => 'aid',
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		// echo $condition;
 
- 		
 
- 		// 抽取日期 ,'groupby'=>'updatetime'
 
- 		$dateLog = $action_log->find ( array (
 
- 				'select' => 'updatetime',
 
- 				'where' => $alCondition . $condition,
 
- 				'limit' => $limit,
 
- 				'desc' => 'aid',
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		$dl = array ();
 
- 		foreach ( $dateLog as $value ) {
 
- 			array_push ( $dl, $value ['updatetime'] );
 
- 		}
 
- 		
 
- 		$dateLog = array_unique ( $dl );
 
- 		$log = array ();
 
- 		foreach ( $dateLog as $key => $value ) {
 
- 			$log [$value] = array ();
 
- 			foreach ( $actionLogList as $k => $v ) {
 
- 				if ($value == $v ['updatetime']) {
 
- 					array_push ( $log [$value], $v );
 
- 					unset ( $actionLogList [$k] );
 
- 				}
 
- 			}
 
- 		}
 
- 		
 
- 		$max = array ();
 
- 		foreach ( $staffList as $key => $value ) {
 
- 			$staffList [$key] ['count'] = $client_staff->count ( array (
 
- 					'where' => 'sid=' . $value ['sid'],
 
- 					'asArray' => true 
 
- 			) );
 
- 			array_push ( $max, $staffList [$key] ['count'] . ':' . $value ['username'] );
 
- 		}
 
- 		rsort ( $max, SORT_NUMERIC );
 
- 		$sum = 0;
 
- 		foreach ( $max as $key => $value ) {
 
- 			$max [$key] = explode ( ":", $value );
 
- 			$sum += $max [$key] [0];
 
- 		}
 
- 		$max2 = $max;
 
- 		array_shift ( $max2 );
 
- 		array_shift ( $max2 );
 
- 		array_shift ( $max2 );
 
- 		
 
- 		$lcategoryList = $lcategory->find ( array (
 
- 				'asArray' => true 
 
- 		) );
 
- 		$useL = array ();
 
- 		$Rsum = $Ssum = 0;
 
- 		foreach ( $lcategoryList as $key => $value ) {
 
- 			$longleR = $longle->count ( array (
 
- 					'where' => 'cid=' . $value ['cid'],
 
- 					'asArray' => true 
 
- 			) );
 
- 			$longleS = $longle->count ( array (
 
- 					'where' => 'cid=' . $value ['cid'] . ' and status!=1 and status!=2',
 
- 					'asArray' => true 
 
- 			) );
 
- 			$Rsum += $longleR;
 
- 			$Ssum += $longleS;
 
- 			if (! empty ( $longleS ))
 
- 				array_push ( $useL, round ( ($longleS / $longleR) * 100 ) . '% :' . $value ['title'] );
 
- 			else
 
- 				array_push ( $useL, '0% :' . $value ['title'] );
 
- 		}
 
- 		rsort ( $useL, SORT_NUMERIC ); // $sum=0;
 
- 		foreach ( $useL as $key => $value ) {
 
- 			$useL [$key] = explode ( ":", $value );
 
- 			// $sum+=$max[$key][0];
 
- 		}
 
- 		
 
- 		$useL2 = $useL;
 
- 		array_shift ( $useL2 );
 
- 		array_shift ( $useL2 );
 
- 		array_shift ( $useL2 );
 
- 		
 
- 		$data ['Ssum'] = round ( ($Ssum / $Rsum) * 100 ) . '%';
 
- 		$data ['Rsum'] = $Rsum;
 
- 		$data ['useL2'] = $useL2;
 
- 		$data ['useL'] = $useL;
 
- 		$data ['sum'] = $sum;
 
- 		$data ['max'] = $max;
 
- 		$data ['max2'] = $max2;
 
- 		$data ['log'] = $log;
 
- 		$data ['page'] = $p;
 
- 		$data ['staffList'] = $staffList;
 
- 		$data ['categorylist2'] = $categorylist2;
 
- 		$data ['cid'] = $cid;
 
- 		$data ['sid'] = $sid;
 
- 		$data ['memu'] = "index";
 
- 		$data ['staff'] = $this->staff;
 
- 		$this->render ( "index2", $data );
 
- 	}
 
- 	function indexPage() {
 
- 		$sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
 
- 		$cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
 
- 		$page = $this->get_args ( 'page' ) ? $this->get_args ( 'page' ) : 1;
 
- 		
 
- 		Doo::loadModel ( 'action_log' );
 
- 		$action_log = new action_log ();
 
- 		
 
- 		$limit = 50;
 
- 		$p = $page;
 
- 		// if ($page!=1)
 
- 		// $page=$page*$limit-1;
 
- 		// else
 
- 		// $page--;
 
- 		
 
- 		$page = (-- $p) * $limit;
 
- 		
 
- 		/*
 
- 		 * $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']; }
 
- 		 */
 
- 		$condition = "";
 
- 		if (! empty ( $cid ) && $cid != 12) {
 
- 			$condition = " and cid=" . $cid . " and sid=" . $sid;
 
- 		}
 
- 		
 
- 		$staffCondition = "";
 
- 		if ($this->staff [0] ['cid'] != 12) {
 
- 			$staffCondition = " and cid=" . $this->staff [0] ['cid'];
 
- 			if (! empty ( $sid ))
 
- 				$condition = " and cid=" . $this->staff [0] ['cid'] . " and sid=" . $sid;
 
- 			else
 
- 				$condition = " and cid=" . $this->staff [0] ['cid'];
 
- 		}
 
- 		
 
- 		$actionLogList = $action_log->find ( array (
 
- 				'where' => ' 1 ' . $condition,
 
- 				'limit' => $page . ',' . $limit,
 
- 				'desc' => 'aid',
 
- 				'asArray' => true 
 
- 		) );
 
- 		// 抽取日期 ,'groupby'=>'updatetime'
 
- 		$dateLog = $action_log->find ( array (
 
- 				'select' => 'updatetime',
 
- 				'where' => ' 1 ' . $condition,
 
- 				'limit' => $page . ',' . $limit,
 
- 				'desc' => 'aid',
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		$dl = array ();
 
- 		foreach ( $dateLog as $value ) {
 
- 			array_push ( $dl, $value ['updatetime'] );
 
- 		}
 
- 		
 
- 		$dateLog = array_unique ( $dl );
 
- 		
 
- 		$log = array ();
 
- 		foreach ( $dateLog as $key => $value ) {
 
- 			$log [$value] = array ();
 
- 			foreach ( $actionLogList as $k => $v ) {
 
- 				if ($value == $v ['updatetime']) {
 
- 					array_push ( $log [$value], $v );
 
- 					unset ( $actionLogList [$k] );
 
- 				}
 
- 			}
 
- 		}
 
- 		
 
- 		$html = '';
 
- 		foreach ( $log as $key => $value ) {
 
- 			$html .= '<div class="item">
 
- 				  			<div class="date">' . $key . '</div>
 
- 				  			<dl class="recordList clearfix">';
 
- 			foreach ( $value as $k => $v ) {
 
- 				$html .= '<dd class="' . $v ['class'] . '"><span class="fR">' . $v ['time'] . '</span>' . $v ['action'] . '</dd>';
 
- 			}
 
- 			$html .= '</dl></div>';
 
- 		}
 
- 		echo $html;
 
- 	}
 
- 	function logStatistics() {
 
- 		$sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
 
- 		$cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
 
- 		
 
- 		Doo::loadModel ( 'action_log' );
 
- 		$action_log = new action_log ();
 
- 		Doo::loadModel ( 'staff' );
 
- 		$staff = new staff ();
 
- 		Doo::loadModel ( 'client_staff' );
 
- 		$client_staff = new client_staff ();
 
- 		Doo::loadModel ( 'longle' );
 
- 		$longle = new longle ();
 
- 		Doo::loadModel ( 'L_category' );
 
- 		$lcategory = new L_category ();
 
- 		Doo::loadModel ( 'department' );
 
- 		$department = new department ();
 
- 		
 
- 		$redis = new Redis ();
 
- 		$redis->connect ( '127.0.0.1', '6379' ); // 120.27.200.79
 
- 		
 
- 		$staffCondition = "";
 
- 		$categorylist2 = array ();
 
- 		if ($this->staff [0] ['cid'] != 12) {
 
- 			$staffCondition = " and cid=" . $this->staff [0] ['cid'];
 
- 			// array_push ( $categorylist2, array (
 
- 			// 'cid' => $this->staff [0] ['cid'],
 
- 			// 'title' => $this->staff [0] ['category']
 
- 			// ) );
 
- 			$otherC = $lcategory->getCategoryById ( $this->staff [0] ['cid'], $this->staff [0] ['othercid'] );
 
- 			foreach ( $otherC as $value ) {
 
- 				array_push ( $categorylist2, array (
 
- 						'cid' => $value ['cid'],
 
- 						'title' => $value ['title'] 
 
- 				) );
 
- 			}
 
- 		} else {
 
- 			$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';
 
- 			$query = Doo::db ()->query ( $sql );
 
- 			$result = $query->fetchAll ();
 
- 			$categorylist2 = $result;
 
- 			
 
- 			// $otherC=$lcategory->getCategoryById($this->staff [0] ['cid'],$this->staff [0] ['othercid']);
 
- 		}
 
- 		
 
- 		// print_r($categorylist2);
 
- 		
 
- 		// 有待优化
 
- 		$categorylist3 = $categorylist2;
 
- 		$bakCategory = array ();
 
- 		foreach ( $categorylist3 as $key => $value ) {
 
- 			$departList = $department->getDepartmentBycid ( $value ['cid'] );
 
- 			if (! empty ( $departList )) {
 
- 				// $bakCategory=$categorylist2[$key];
 
- 				
 
- 				array_unshift ( $bakCategory, $value );
 
- 				
 
- 				unset ( $categorylist2 [$key] );
 
- 				foreach ( $departList as $v ) {
 
- 					array_unshift ( $bakCategory, array (
 
- 							'cid' => $v ['cid'],
 
- 							'title' => $value ['title'],
 
- 							'count' => @$value ['count'],
 
- 							'did' => $v ['did'],
 
- 							'departmentName' => $v ['departmentName'] 
 
- 					) );
 
- 				}
 
- 			}
 
- 		}
 
- 		
 
- 		foreach ( $bakCategory as $value ) {
 
- 			array_unshift ( $categorylist2, $value );
 
- 		}
 
- 		// array_unshift($categorylist2,$bakCategory);
 
- 		
 
- 		// print_r($categorylist2);
 
- 		$did = $data ['did'] = '';
 
- 		
 
- 		$othercateSql = '';
 
- 		if (! empty ( $this->staff [0] ['othercid'] ))
 
- 			$othercateSql = " or (othercid like '" . $this->staff [0] ['othercid'] . "')";
 
- 		if (! empty ( $cid )) { //
 
- 			if (is_numeric ( $cid ))
 
- 				$staffCondition = " and cid=" . $cid . $othercateSql;
 
- 			else {
 
- 				$cdid = explode ( '-', $cid );
 
- 				$cid = $cdid [0];
 
- 				$data ['did'] = $did = $cdid [1];
 
- 				$staffCondition = " and cid=" . $cdid [0] . " and departmentID=" . $cdid [1] . $othercateSql;
 
- 			}
 
- 		}
 
- 		// echo $staffCondition;
 
- 		// echo $staffCondition;
 
- 		// Doo::db()->beginTransaction();
 
- 		$staffList = $staff->find ( array (
 
- 				'where' => ' username !="admin"' . $staffCondition . ' and nature!=4 and pendStatus!=4 and pendStatus!=1 and pendStatus!=2 ',
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		$max = array ();
 
- 		$sum = 0;
 
- 		// 客户总数
 
- 		$redisKey = date ( 'Y-m-d' ) . '_logStatisticsCSum_' . $this->staff [0] ['cid'];
 
- 		$redisValue = $redis->lrange ( $redisKey, 0, - 1 );
 
- 		if (empty ( $redisValue )) {
 
- 			$kkk = array ();
 
- 			foreach ( $staffList as $key => $value ) {
 
- 				$staffList [$key] ['count'] = $client_staff->count ( array (
 
- 						'where' => 'sid=' . $value ['sid'],
 
- 						'asArray' => true 
 
- 				) );
 
- 				
 
- 				array_push ( $max, $staffList [$key] ['count'] . ':' . $value ['username'] );
 
- 				if ($this->staff [0] ['cid'] == 12)
 
- 					array_push ( $kkk, $staffList [$key] ['count'] );
 
- 				if ($this->staff [0] ['cid'] == $value ['cid'] && $this->staff [0] ['cid'] != 12) {
 
- 					array_push ( $kkk, $staffList [$key] ['count'] );
 
- 				}
 
- 			}
 
- 			foreach ( $kkk as $key => $value ) {
 
- 				$sum += $value;
 
- 			}
 
- 			
 
- 			$sortMaxStr = json_encode ( $max );
 
- 			$redis->lpush ( $redisKey, $sum );
 
- 			$redis->lpush ( $redisKey, $sortMaxStr );
 
- 		} else {
 
- 			$sum = $redisValue [1];
 
- 			$max = json_decode ( $redisValue [0], true );
 
- 		}
 
- 		
 
- 		rsort ( $max, SORT_NUMERIC );
 
- 		foreach ( $max as $key => $value ) {
 
- 			$max [$key] = explode ( ":", $value );
 
- 			// $sum+=$max[$key][0];
 
- 		}
 
- 		$max2 = $max;
 
- 		array_shift ( $max2 );
 
- 		array_shift ( $max2 );
 
- 		array_shift ( $max2 );
 
- 		
 
- 		$lcategoryList = $lcategory->find ( array (
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		$useL = array ();
 
- 		$Rsum = $Ssum = 0;
 
- 		$redisKey = date ( 'Y-m-d' ) . '_logStatisticsLongle';
 
- 		$redisValue = $redis->lrange ( $redisKey, 0, - 1 );
 
- 		if (empty ( $redisValue )) {
 
- 			foreach ( $lcategoryList as $key => $value ) {
 
- 				$longleR = $longle->count ( array (
 
- 						'where' => 'cid=' . $value ['cid'],
 
- 						'asArray' => true 
 
- 				) );
 
- 				$longleS = $longle->count ( array (
 
- 						'where' => 'cid=' . $value ['cid'] . ' and status!=1 and status!=2',
 
- 						'asArray' => true 
 
- 				) );
 
- 				$Rsum += $longleR;
 
- 				$Ssum += $longleS;
 
- 				if (! empty ( $longleS ))
 
- 					array_push ( $useL, round ( ($longleS / $longleR) * 100 ) . '% :' . $value ['title'] );
 
- 				else
 
- 					array_push ( $useL, '0% :' . $value ['title'] );
 
- 			}
 
- 			$useLStr = json_encode ( $useL );
 
- 			$redis->lpush ( $redisKey, $Rsum );
 
- 			$redis->lpush ( $redisKey, $Ssum );
 
- 			$redis->lpush ( $redisKey, $useLStr );
 
- 		} else {
 
- 			$useL = $redisValue [0];
 
- 			$useL = json_decode ( $useL, true );
 
- 			$Ssum = $redisValue [1];
 
- 			$Rsum = $redisValue [2];
 
- 		}
 
- 		
 
- 		rsort ( $useL, SORT_NUMERIC );
 
- 		foreach ( $useL as $key => $value ) {
 
- 			$useL [$key] = explode ( ":", $value );
 
- 		}
 
- 		
 
- 		$useL2 = $useL;
 
- 		array_shift ( $useL2 );
 
- 		array_shift ( $useL2 );
 
- 		array_shift ( $useL2 );
 
- 		
 
- 		// statistics
 
- 		
 
- 		// 30天操作日志数
 
- 		$categoryCondition = " and cid=" . $this->staff [0] ['cid'];
 
- 		$redisCid = $this->staff [0] ['cid'];
 
- 		$sidCondition = $redisSid = "";
 
- 		if (! empty ( $cid )) {
 
- 			$categoryCondition = " and cid=" . $cid;
 
- 			$redisCid = $cid;
 
- 		}
 
- 		if (! empty ( $sid )) {
 
- 			$redisSid = $sid;
 
- 			$sidCondition = " and sid=" . $sid;
 
- 		}
 
- 		if ($this->staff [0] ['cid'] == 12 && empty ( $cid )) {
 
- 			$categoryCondition = "";
 
- 			$redisCid = '';
 
- 		}
 
- 		
 
- 		// if(!empty($did))
 
- 		// $categoryCondition=$categoryCondition.' and departmentID='.$did;
 
- 		
 
- 		$redisKey = date ( 'Y-m-d' ) . 'SL_' . $redisCid . '_' . $redisSid;
 
- 		$redisValue = $redis->get ( $redisKey );
 
- 		if (empty ( $redisValue )) {
 
- 			$actionLogLongle = $action_log->find ( array (
 
- 					'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
 
- 					'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=3" . $categoryCondition . $sidCondition,
 
- 					'groupby' => 'date_format(updatetime,"%m-%d")',
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			$statisticsLongle = array ();
 
- 			for($d = 0; $d <= 29; $d ++) {
 
- 				$MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
 
- 				$falgLongle = true;
 
- 				
 
- 				foreach ( $actionLogLongle as $value ) {
 
- 					if ($value ['updatetime'] == $MD) {
 
- 						array_push ( $statisticsLongle, $value ['count'] );
 
- 						$falgLongle = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 				if ($falgLongle)
 
- 					array_push ( $statisticsLongle, 0 );
 
- 			}
 
- 			$statisticsLongle = array_reverse ( $statisticsLongle );
 
- 			$jsl = json_encode ( $statisticsLongle );
 
- 			$redis->set ( $redisKey, $jsl );
 
- 			$data ['statisticsLongle'] = $jsl;
 
- 		} else {
 
- 			$data ['statisticsLongle'] = $redisValue;
 
- 		}
 
- 		
 
- 		// 添加客户 数30天
 
- 		$redisKey = date ( 'Y-m-d' ) . 'SC_' . $redisCid . '_' . $redisSid;
 
- 		
 
- 		// echo $redisKey;
 
- 		// echo "<br/> date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=1" . $categoryCondition . $sidCondition;
 
- 		
 
- 		$redisValue = $redis->get ( $redisKey );
 
- 		if (empty ( $redisValue )) {
 
- 			$actionLogClient = $action_log->find ( array (
 
- 					'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
 
- 					'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=1" . $categoryCondition . $sidCondition,
 
- 					'groupby' => 'date_format(updatetime,"%m-%d")',
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			$statisticsClient = array ();
 
- 			for($d = 0; $d <= 29; $d ++) {
 
- 				$MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
 
- 				$falgClient = true;
 
- 				
 
- 				foreach ( $actionLogClient as $value ) {
 
- 					if ($value ['updatetime'] == $MD) {
 
- 						array_push ( $statisticsClient, $value ['count'] );
 
- 						$falgClient = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 				if ($falgClient)
 
- 					array_push ( $statisticsClient, 0 );
 
- 			}
 
- 			$statisticsClient = array_reverse ( $statisticsClient );
 
- 			$jsc = json_encode ( $statisticsClient );
 
- 			$redis->set ( $redisKey, $jsc );
 
- 			$data ['statisticsClient'] = $jsc;
 
- 		} else {
 
- 			$data ['statisticsClient'] = $redisValue;
 
- 		}
 
- 		
 
- 		$statisticsDay = array ();
 
- 		for($d = 0; $d <= 29; $d ++) {
 
- 			$MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
 
- 			array_push ( $statisticsDay, $MD );
 
- 		}
 
- 		$statisticsDay = array_reverse ( $statisticsDay );
 
- 		
 
- 		// / Year(updatetime)=".date('Y')." and Month(updatetime)=".date('m')." and
 
- 		$categoryList = $lcategory->find ( array (
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		// 最近30天区域分布图
 
- 		$redisKey = date ( 'Y-m-d' ) . 'SCCT_' . $redisCid . '_' . $redisSid;
 
- 		$redisValue = $redis->lrange ( $redisKey, 0, - 1 );
 
- 		if (empty ( $redisValue )) {
 
- 			$CategoryClient = $action_log->find ( array (
 
- 					'select' => 'cid,COUNT(*) as count,city',
 
- 					'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=1" . $categoryCondition . $sidCondition,
 
- 					'groupby' => 'cid',
 
- 					'asArray' => true 
 
- 			) );
 
- 			$CategoryCompany = $action_log->find ( array (
 
- 					'select' => 'cid, COUNT(*) as count,company,districtid',
 
- 					'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and (status=1 )" . $categoryCondition . $sidCondition,
 
- 					'groupby' => 'cid,districtid,company',
 
- 					'asArray' => true 
 
- 			) );
 
- 			$statisticsCategory = array ();
 
- 			$statisticsCompany = array ();
 
- 			foreach ( $categoryList as $value ) {
 
- 				$falgClient = $falgLongle = true;
 
- 				foreach ( $CategoryClient as $v ) {
 
- 					if ($value ['cid'] == $v ['cid'] && $v ['cid'] != 12) {
 
- 						array_push ( $statisticsCategory, array (
 
- 								'value' => $v ['count'],
 
- 								'name' => str_replace ( "办", "省", $value ['title'] ) 
 
- 						) );
 
- 						$falgClient = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 				if ($falgClient) {
 
- 					
 
- 					array_push ( $statisticsCategory, array (
 
- 							'value' => 0,
 
- 							'name' => str_replace ( "办", "省", $value ['title'] ) 
 
- 					) );
 
- 				}
 
- 				
 
- 				// company statistics
 
- 				$i = 0;
 
- 				foreach ( $CategoryCompany as $v ) {
 
- 					if ($value ['cid'] == $v ['cid'] && $v ['cid'] != 12) {
 
- 						$i ++;
 
- 					}
 
- 				}
 
- 				array_push ( $statisticsCompany, array (
 
- 						'value' => $i,
 
- 						'name' => str_replace ( "办", "省", $value ['title'] ) 
 
- 				) );
 
- 			}
 
- 			
 
- 			$scctA = json_encode ( $statisticsCompany );
 
- 			$scctB = json_encode ( $statisticsCategory );
 
- 			$redis->lpush ( $redisKey, $scctA );
 
- 			$redis->lpush ( $redisKey, $scctB );
 
- 			$data ['statisticsCompany'] = $scctA;
 
- 			$data ['statisticsCategory'] = $scctB;
 
- 		} else {
 
- 			$data ['statisticsCompany'] = $redisValue [1];
 
- 			$data ['statisticsCategory'] = $redisValue [0];
 
- 		}
 
- 		
 
- 		// print_r($CategoryClient);
 
- 		
 
- 		$redisKey = date ( 'Y-m-d' ) . 'SN_' . $redisCid . '_' . $redisSid;
 
- 		$redisValue = $redis->get ( $redisKey );
 
- 		if (empty ( $redisValue )) {
 
- 			$natureList = $action_log->find ( array (
 
- 					'select' => 'cid, COUNT(*) as count,nature',
 
- 					'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=1 and nature !=''" . $categoryCondition . $sidCondition,
 
- 					'groupby' => 'nature',
 
- 					'asArray' => true 
 
- 			) );
 
- 			$statisticsNature = array ();
 
- 			foreach ( $this->nature as $value ) {
 
- 				$flagNature = true;
 
- 				foreach ( $natureList as $v ) {
 
- 					if ($value == $v ['nature']) {
 
- 						array_push ( $statisticsNature, array (
 
- 								'value' => $v ['count'],
 
- 								'name' => $value 
 
- 						) );
 
- 						$flagNature = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 				if ($flagNature)
 
- 					array_push ( $statisticsNature, array (
 
- 							'value' => 0,
 
- 							'name' => $value 
 
- 					) );
 
- 			}
 
- 			
 
- 			$jsn = json_encode ( $statisticsNature );
 
- 			$redis->set ( $redisKey, $jsn );
 
- 			$data ['statisticsNature'] = $jsn;
 
- 		} else {
 
- 			$data ['statisticsNature'] = $redisValue;
 
- 		}
 
- 		
 
- 		$data ['statisticsDay'] = json_encode ( $statisticsDay );
 
- 		$data ['categorylist2'] = $categorylist2;
 
- 		$data ['Ssum'] = round ( ($Ssum / $Rsum) * 100 ) . '%';
 
- 		$data ['Rsum'] = $Rsum;
 
- 		$data ['useL2'] = $useL2;
 
- 		$data ['useL'] = $useL;
 
- 		$data ['sum'] = $sum;
 
- 		$data ['max'] = $max;
 
- 		$data ['max2'] = $max2;
 
- 		
 
- 		$data ['staffList'] = $staffList;
 
- 		$data ['cid'] = $cid;
 
- 		$data ['sid'] = $sid;
 
- 		$data ['memu'] = "index";
 
- 		$data ['staff'] = $this->staff;
 
- 		$this->render ( "/indexStat", $data );
 
- 	}
 
- 	function longleStatistics() {
 
- 		$sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
 
- 		$cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
 
- 		$status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 4;
 
- 		$districtH = $this->get_args ( 'district' ) ? $this->get_args ( 'district' ) : 0;
 
- 		
 
- 		Doo::loadModel ( 'action_log' );
 
- 		$action_log = new action_log ();
 
- 		Doo::loadModel ( 'staff' );
 
- 		$staff = new staff ();
 
- 		Doo::loadModel ( 'client_staff' );
 
- 		$client_staff = new client_staff ();
 
- 		Doo::loadModel ( 'longle' );
 
- 		$longle = new longle ();
 
- 		Doo::loadModel ( 'L_category' );
 
- 		$lcategory = new L_category ();
 
- 		Doo::loadModel ( 'district' );
 
- 		$district = new district ();
 
- 		
 
- 		$staffCondition = "";
 
- 		$categorylist2 = array ();
 
- 		if ($this->staff [0] ['cid'] != 12) {
 
- 			$staffCondition = " and cid=" . $this->staff [0] ['cid'];
 
- 			array_push ( $categorylist2, array (
 
- 					'cid' => $this->staff [0] ['cid'],
 
- 					'title' => $this->staff [0] ['category'] 
 
- 			) );
 
- 		} else {
 
- 			$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';
 
- 			$query = Doo::db ()->query ( $sql );
 
- 			$result = $query->fetchAll ();
 
- 			$categorylist2 = $result;
 
- 		}
 
- 		
 
- 		// 有待优化
 
- 		Doo::loadModel ( 'department' );
 
- 		$department = new department ();
 
- 		$categorylist3 = $categorylist2;
 
- 		$bakCategory = array ();
 
- 		foreach ( $categorylist3 as $key => $value ) {
 
- 			$departList = $department->getDepartmentBycid ( $value ['cid'] );
 
- 			if (! empty ( $departList )) {
 
- 				// $bakCategory=$categorylist2[$key];
 
- 				
 
- 				array_unshift ( $bakCategory, $value );
 
- 				
 
- 				unset ( $categorylist2 [$key] );
 
- 				foreach ( $departList as $v ) {
 
- 					array_unshift ( $bakCategory, array (
 
- 							'cid' => $v ['cid'],
 
- 							'title' => $value ['title'],
 
- 							'count' => $value ['count'],
 
- 							'did' => $v ['did'],
 
- 							'departmentName' => $v ['departmentName'] 
 
- 					) );
 
- 				}
 
- 			}
 
- 		}
 
- 		foreach ( $bakCategory as $value ) {
 
- 			array_unshift ( $categorylist2, $value );
 
- 		}
 
- 		
 
- 		$data ['did'] = '';
 
- 		if (! empty ( $cid )) {
 
- 			if (is_numeric ( $cid ))
 
- 				$staffCondition = " and cid=" . $cid;
 
- 			else {
 
- 				$cdid = explode ( '-', $cid );
 
- 				$cid = $cdid [0];
 
- 				$data ['did'] = $cdid [1];
 
- 				$staffCondition = " and cid=" . $cdid [0] . " and departmentID=" . $cdid [1];
 
- 			}
 
- 			// $staffCondition = " and cid=" . $cid;
 
- 		}
 
- 		
 
- 		$staffList = $staff->find ( array (
 
- 				'where' => ' username!="admin"' . $staffCondition . ' and nature!=4 and pendStatus!=4 and pendStatus!=1 and pendStatus!=2 ',
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		$max = array ();
 
- 		foreach ( $staffList as $key => $value ) {
 
- 			$staffList [$key] ['count'] = $client_staff->count ( array (
 
- 					'where' => 'sid=' . $value ['sid'],
 
- 					'asArray' => true 
 
- 			) );
 
- 			array_push ( $max, $staffList [$key] ['count'] . ':' . $value ['username'] );
 
- 		}
 
- 		rsort ( $max, SORT_NUMERIC );
 
- 		$sum = 0;
 
- 		foreach ( $max as $key => $value ) {
 
- 			$max [$key] = explode ( ":", $value );
 
- 			$sum += $max [$key] [0];
 
- 		}
 
- 		$max2 = $max;
 
- 		array_shift ( $max2 );
 
- 		array_shift ( $max2 );
 
- 		array_shift ( $max2 );
 
- 		
 
- 		$lcategoryList = $lcategory->find ( array (
 
- 				'asArray' => true 
 
- 		) );
 
- 		$useL = array ();
 
- 		$Rsum = $Ssum = 0;
 
- 		foreach ( $lcategoryList as $key => $value ) {
 
- 			$longleR = $longle->count ( array (
 
- 					'where' => 'cid=' . $value ['cid'],
 
- 					'asArray' => true 
 
- 			) );
 
- 			$longleS = $longle->count ( array (
 
- 					'where' => 'cid=' . $value ['cid'] . ' and status!=1 and status!=2',
 
- 					'asArray' => true 
 
- 			) );
 
- 			$Rsum += $longleR;
 
- 			$Ssum += $longleS;
 
- 			if (! empty ( $longleS ))
 
- 				array_push ( $useL, round ( ($longleS / $longleR) * 100 ) . '% :' . $value ['title'] );
 
- 			else
 
- 				array_push ( $useL, '0% :' . $value ['title'] );
 
- 		}
 
- 		rsort ( $useL, SORT_NUMERIC ); // $sum=0;
 
- 		foreach ( $useL as $key => $value ) {
 
- 			$useL [$key] = explode ( ":", $value );
 
- 			// $sum+=$max[$key][0];
 
- 		}
 
- 		
 
- 		$useL2 = $useL;
 
- 		array_shift ( $useL2 );
 
- 		array_shift ( $useL2 );
 
- 		array_shift ( $useL2 );
 
- 		
 
- 		// statistics
 
- 		
 
- 		$categoryCondition = " and cid=" . $this->staff [0] ['cid'];
 
- 		$sidCondition = "";
 
- 		if (! empty ( $cid ))
 
- 			$categoryCondition = " and cid=" . $cid;
 
- 		if (! empty ( $sid ))
 
- 			$sidCondition = " and sid=" . $sid;
 
- 		if ($this->staff [0] ['cid'] == 12 && empty ( $cid )) {
 
- 			$categoryCondition = "";
 
- 		}
 
- 		
 
- 		// Year(updatetime)=".date('Y')." and Month(updatetime)=".date('m')." date_format(updatetime,"%m-%d") Day(updatetime)
 
- 		
 
- 		$actionLogClient = $action_log->find ( array (
 
- 				'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
 
- 				'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=4" . $categoryCondition . $sidCondition,
 
- 				'groupby' => 'Day(updatetime)',
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		$actionLogLongle = $action_log->find ( array (
 
- 				'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
 
- 				'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=5" . $categoryCondition . $sidCondition,
 
- 				'groupby' => 'Day(updatetime)',
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		$actionLogGet = $action_log->find ( array (
 
- 				'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
 
- 				'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=6" . $categoryCondition . $sidCondition,
 
- 				'groupby' => 'Day(updatetime)',
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		$statisticsDay = array ();
 
- 		$statisticsClient = $statisticsLongle = $statisticsGet = array ();
 
- 		
 
- 		/**
 
- 		 * for ($d=1;$d<=date("t");$d++){ $MD=date('m')."-".$d;
 
- 		 */
 
- 		
 
- 		for($d = 0; $d <= 29; $d ++) {
 
- 			$MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
 
- 			$falgClient = $falgLongle = $falgGet = true;
 
- 			array_push ( $statisticsDay, $MD );
 
- 			foreach ( $actionLogClient as $value ) {
 
- 				if ($value ['updatetime'] == $MD) {
 
- 					array_push ( $statisticsClient, $value ['count'] );
 
- 					$falgClient = false;
 
- 					break;
 
- 				}
 
- 			}
 
- 			if ($falgClient)
 
- 				array_push ( $statisticsClient, 0 );
 
- 			
 
- 			foreach ( $actionLogLongle as $value ) {
 
- 				if ($value ['updatetime'] == $MD) {
 
- 					array_push ( $statisticsLongle, $value ['count'] );
 
- 					$falgLongle = false;
 
- 					break;
 
- 				}
 
- 			}
 
- 			if ($falgLongle)
 
- 				array_push ( $statisticsLongle, 0 );
 
- 			
 
- 			foreach ( $actionLogGet as $value ) {
 
- 				if ($value ['updatetime'] == $MD) {
 
- 					array_push ( $statisticsGet, $value ['count'] );
 
- 					$falgGet = false;
 
- 					break;
 
- 				}
 
- 			}
 
- 			if ($falgGet)
 
- 				array_push ( $statisticsGet, 0 );
 
- 		}
 
- 		
 
- 		$statisticsClient = array_reverse ( $statisticsClient );
 
- 		$statisticsLongle = array_reverse ( $statisticsLongle );
 
- 		$statisticsGet = array_reverse ( $statisticsGet );
 
- 		$statisticsDay = array_reverse ( $statisticsDay );
 
- 		
 
- 		// /
 
- 		$districtCondition = "";
 
- 		$topDistrict = $district->get_lvByid ( 0, 0 );
 
- 		if (! empty ( $sid )) {
 
- 			$s = $staff->getOne ( array (
 
- 					'where' => ' sid=' . $sid,
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			$l = $lcategory->find ( array (
 
- 					'where' => ' cid in(' . $s ['cid'] . ')',
 
- 					'asArray' => true 
 
- 			) );
 
- 			if (! empty ( $s ['othercid'] ))
 
- 				$l = $lcategory->find ( array (
 
- 						'where' => ' cid in(' . $s ['cid'] . ',' . $s ['othercid'] . ')',
 
- 						'asArray' => true 
 
- 				) );
 
- 			
 
- 			if (! empty ( $districtH )) {
 
- 				$districtCondition = " and districtid like '" . $districtH . ",%'";
 
- 				$sidCondition = "";
 
- 				$topDistrict = $district->find ( array (
 
- 						'where' => ' upid=' . $districtH,
 
- 						'asArray' => true 
 
- 				) );
 
- 			} else {
 
- 				$districtCondition = " and districtid like '" . $l [0] ['districtid'] . ",%'";
 
- 				$sidCondition = "";
 
- 				$topDistrict = $district->find ( array (
 
- 						'where' => ' upid=' . $l [0] ['districtid'],
 
- 						'asArray' => true 
 
- 				) );
 
- 			}
 
- 			
 
- 			$str = array ();
 
- 			foreach ( $l as $value ) {
 
- 				array_push ( $str, $value ['districtid'] );
 
- 			}
 
- 			$str = implode ( ",", $str );
 
- 			$data ['districtHtml'] = $district->find ( array (
 
- 					'where' => ' id in (' . $str . ')',
 
- 					'asArray' => true 
 
- 			) );
 
- 			$data ['districtH'] = $l [0] ['districtid'];
 
- 			if (! empty ( $districtH ))
 
- 				$data ['districtH'] = $districtH;
 
- 		}
 
- 		
 
- 		// Year(updatetime)=".date('Y')." and Month(updatetime)=".date('m')." and
 
- 		if (! empty ( $sid ))
 
- 			$districtClient = $action_log->find ( array (
 
- 					'select' => 'city,province,COUNT(*) as count',
 
- 					'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=" . $status . $categoryCondition . $sidCondition . $districtCondition,
 
- 					'groupby' => 'province',
 
- 					'asArray' => true 
 
- 			) );
 
- 		else
 
- 			$districtClient = $action_log->find ( array (
 
- 					'select' => 'city,province,COUNT(*) as count',
 
- 					'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=" . $status . $categoryCondition . $sidCondition . $districtCondition,
 
- 					'groupby' => 'city',
 
- 					'asArray' => true 
 
- 			) );
 
- 		
 
- 		$statisticsLend = array ();
 
- 		$statisticsCompany = array ();
 
- 		
 
- 		if (! empty ( $sid )) {
 
- 			foreach ( $topDistrict as $value ) {
 
- 				$falgLend = $falgLongle = true;
 
- 				foreach ( $districtClient as $v ) {
 
- 					
 
- 					if ($value ['name'] == $v ['province']) {
 
- 						array_push ( $statisticsLend, array (
 
- 								'value' => $v ['count'],
 
- 								'name' => $value ['name'] 
 
- 						) );
 
- 						$falgLend = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 				if ($falgLend)
 
- 					array_push ( $statisticsLend, array (
 
- 							'value' => 0,
 
- 							'name' => $value ['name'] 
 
- 					) );
 
- 			}
 
- 		} else {
 
- 			foreach ( $topDistrict as $value ) {
 
- 				$falgLend = $falgLongle = true;
 
- 				foreach ( $districtClient as $v ) {
 
- 					
 
- 					if ($value ['name'] == $v ['city']) {
 
- 						array_push ( $statisticsLend, array (
 
- 								'value' => $v ['count'],
 
- 								'name' => $value ['name'] 
 
- 						) );
 
- 						$falgLend = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 				if ($falgLend)
 
- 					array_push ( $statisticsLend, array (
 
- 							'value' => 0,
 
- 							'name' => $value ['name'] 
 
- 					) );
 
- 			}
 
- 		}
 
- 		// print_r($statisticsLend);die;
 
- 		$natureList = $action_log->find ( array (
 
- 				'select' => 'cid, COUNT(*) as count,nature',
 
- 				'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=" . $status . " and nature !=''" . $categoryCondition . $sidCondition . $districtCondition,
 
- 				'groupby' => 'nature',
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		$statisticsNature = array ();
 
- 		foreach ( $this->nature as $value ) {
 
- 			$flagNature = true;
 
- 			foreach ( $natureList as $v ) {
 
- 				if ($value == $v ['nature']) {
 
- 					array_push ( $statisticsNature, array (
 
- 							'value' => $v ['count'],
 
- 							'name' => $value 
 
- 					) );
 
- 					$flagNature = false;
 
- 					break;
 
- 				}
 
- 			}
 
- 			if ($flagNature)
 
- 				array_push ( $statisticsNature, array (
 
- 						'value' => 0,
 
- 						'name' => $value 
 
- 				) );
 
- 		}
 
- 		$data ['statisticsNature'] = json_encode ( $statisticsNature );
 
- 		
 
- 		// print_r($statisticsLend);die;
 
- 		$data ['statisticsLend'] = json_encode ( $statisticsLend );
 
- 		
 
- 		$data ['status'] = $status;
 
- 		$data ['statisticsDay'] = json_encode ( $statisticsDay );
 
- 		$data ['statisticsClient'] = json_encode ( $statisticsClient );
 
- 		$data ['statisticsLongle'] = json_encode ( $statisticsLongle );
 
- 		$data ['statisticsGet'] = json_encode ( $statisticsGet );
 
- 		$data ['categorylist2'] = $categorylist2;
 
- 		
 
- 		$data ['Ssum'] = round ( ($Ssum / $Rsum) * 100 ) . '%';
 
- 		$data ['Rsum'] = $Rsum;
 
- 		$data ['useL2'] = $useL2;
 
- 		$data ['useL'] = $useL;
 
- 		$data ['sum'] = $sum;
 
- 		$data ['max'] = $max;
 
- 		$data ['max2'] = $max2;
 
- 		
 
- 		$data ['staffList'] = $staffList;
 
- 		$data ['cid'] = $cid;
 
- 		$data ['sid'] = $sid;
 
- 		$data ['memu'] = "index";
 
- 		$data ['staff'] = $this->staff;
 
- 		$this->render ( "/indexLongle", $data );
 
- 	}
 
- 	function index() {
 
- 		die ( 'dd' );
 
- 		$data ['memu'] = "index";
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		Doo::loadModel ( 'action_log' );
 
- 		$action_log = new action_log ();
 
- 		
 
- 		$data ['today'] = explode ( "-", date ( "Y-m-d" ) );
 
- 		
 
- 		$str = "";
 
- 		if ($this->staff [0] ['isadmin'] != 1) {
 
- 			$str = " and (action like '%" . $this->staff [0] ['category'] . "%'";
 
- 			$khql = explode ( ",", $this->staff [0] ['othercategory'] );
 
- 			if (! empty ( $khql [0] )) {
 
- 				foreach ( $khql as $key => $value ) {
 
- 					$str .= " or action like '%" . $value . "%'";
 
- 				}
 
- 				$str .= ")";
 
- 			} else
 
- 				$str .= ")";
 
- 		}
 
- 		
 
- 		$data ['actionListNow'] = $action_log->find ( array (
 
- 				'where' => ' updatetime=\'' . date ( "Y-m-d" ) . "'" . $str,
 
- 				'desc' => 'aid',
 
- 				'asArray' => TRUE 
 
- 		) );
 
- 		
 
- 		$d2 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 1, date ( "Y" ) );
 
- 		$strdate = date ( "Y-m-d", $d2 );
 
- 		
 
- 		$data ['day2'] = explode ( "-", $strdate );
 
- 		$data ['actionListNow2'] = $action_log->find ( array (
 
- 				'where' => ' updatetime=\'' . $strdate . "'" . $str,
 
- 				'desc' => 'aid',
 
- 				'asArray' => TRUE 
 
- 		) );
 
- 		
 
- 		$d3 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 2, date ( "Y" ) );
 
- 		$strdate = date ( "Y-m-d", $d3 );
 
- 		
 
- 		$data ['day3'] = explode ( "-", $strdate );
 
- 		$data ['actionListNow3'] = $action_log->find ( array (
 
- 				'where' => ' updatetime=\'' . $strdate . "'" . $str,
 
- 				'desc' => 'aid',
 
- 				'asArray' => TRUE 
 
- 		) );
 
- 		
 
- 		$d4 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 3, date ( "Y" ) );
 
- 		$strdate = date ( "Y-m-d", $d4 );
 
- 		
 
- 		$data ['day4'] = explode ( "-", $strdate );
 
- 		$data ['actionListNow4'] = $action_log->find ( array (
 
- 				'where' => ' updatetime=\'' . $strdate . "'" . $str,
 
- 				'asArray' => TRUE 
 
- 		) );
 
- 		
 
- 		$d5 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 4, date ( "Y" ) );
 
- 		$strdate = date ( "Y-m-d", $d5 );
 
- 		
 
- 		$data ['day5'] = explode ( "-", $strdate );
 
- 		$data ['actionListNow5'] = $action_log->find ( array (
 
- 				'where' => ' updatetime=\'' . $strdate . "'" . $str,
 
- 				'asArray' => TRUE 
 
- 		) );
 
- 		
 
- 		$d6 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 5, date ( "Y" ) );
 
- 		$strdate = date ( "Y-m-d", $d6 );
 
- 		
 
- 		$data ['day6'] = explode ( "-", $strdate );
 
- 		$data ['actionListNow6'] = $action_log->find ( array (
 
- 				'where' => ' updatetime=\'' . $strdate . "'" . $str,
 
- 				'asArray' => TRUE 
 
- 		) );
 
- 		
 
- 		$d7 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 6, date ( "Y" ) );
 
- 		$strdate = date ( "Y-m-d", $d7 );
 
- 		
 
- 		$data ['day7'] = explode ( "-", $strdate );
 
- 		$data ['actionListNow7'] = $action_log->find ( array (
 
- 				'where' => ' updatetime=\'' . $strdate . "'" . $str,
 
- 				'asArray' => TRUE 
 
- 		) );
 
- 		
 
- 		Doo::loadModel ( 'staff' );
 
- 		Doo::loadModel ( 'client_staff' );
 
- 		
 
- 		$client_staff = new client_staff ();
 
- 		$staff = new staff ();
 
- 		
 
- 		$st = $staff->find ( array (
 
- 				'where' => '1',
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		foreach ( $st as $key => $value ) {
 
- 			$st [$key] ['count'] = $client_staff->count ( array (
 
- 					'where' => 'sid=' . $value ['sid'],
 
- 					'asArray' => true 
 
- 			) );
 
- 		}
 
- 		
 
- 		$data ['staffCount'] = $st;
 
- 		
 
- 		$this->render ( "/index", $data );
 
- 	}
 
- 	function receive() {
 
- 		$data ['memu'] = "keyonline";
 
- 		
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		Doo::loadModel ( 'longle' );
 
- 		
 
- 		$longle = new longle ();
 
- 		
 
- 		$data ['arrayReceive'] = $longle->getLongleReceive ( $this->staff [0] ['cid'], 1, $this->staff [0] ['othercid'] );
 
- 		
 
- 		$this->render ( "/look_receive", $data );
 
- 	}
 
- 	function doLongleReceive() {
 
- 		$arrLid = $this->get_args ( 'lid' ) ? $this->get_args ( 'lid' ) : array ();
 
- 		
 
- 		Doo::loadModel ( 'longle_log' );
 
- 		Doo::loadModel ( 'longle' );
 
- 		
 
- 		foreach ( $arrLid as $key => $value ) {
 
- 			
 
- 			$ky = explode ( "-", $value );
 
- 			
 
- 			$longle = new longle ();
 
- 			$longle_log = new longle_log ();
 
- 			
 
- 			$longle->lid = $ky [0];
 
- 			
 
- 			$longle->status = 2;
 
- 			$longle->statusT = '接收';
 
- 			$longle->responsible = $this->staff [0] ['username'];
 
- 			
 
- 			// 记录锁状态
 
- 			
 
- 			$longle->statuslog = "1,2";
 
- 			
 
- 			$longle->update ();
 
- 			
 
- 			$longle_log->lid = $ky [0];
 
- 			$longle_log->status = 2;
 
- 			$longle_log->statusT = '接收';
 
- 			$longle_log->responsible = $this->staff [0] ['username'];
 
- 			$longle_log->operator = $this->staff [0] ['username'];
 
- 			$longle_log->category = $ky [1];
 
- 			$longle_log->dateline = date ( "Y-m-d" );
 
- 			$longle_log->insert ();
 
- 		}
 
- 		
 
- 		return "/receive";
 
- 	}
 
- 	function addClient() {
 
- 		$companyKey = $this->get_args ( 'companyKey' ) ? $this->get_args ( 'companyKey' ) : "";
 
- 		
 
- 		$clientname = $this->get_args ( 'clientname' ) ? $this->get_args ( 'clientname' ) : "";
 
- 		$gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : "";
 
- 		$nicename = $this->get_args ( 'nicename' ) ? $this->get_args ( 'nicename' ) : "";
 
- 		$telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : "";
 
- 		$phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
 
- 		$email = $this->get_args ( 'email' ) ? $this->get_args ( 'email' ) : "";
 
- 		$qq = $this->get_args ( 'qq' ) ? $this->get_args ( 'qq' ) : "";
 
- 		$tid = $this->get_args ( 'tid' ) ? $this->get_args ( 'tid' ) : "";
 
- 		$companyname = $this->get_args ( 'companyname' ) ? $this->get_args ( 'companyname' ) : "";
 
- 		
 
- 		$local1 = $this->get_args ( 'lv21' ) ? $this->get_args ( 'lv21' ) : "";
 
- 		$local2 = $this->get_args ( 'lv22' ) ? $this->get_args ( 'lv22' ) : "";
 
- 		$local3 = $this->get_args ( 'lv23' ) ? $this->get_args ( 'lv23' ) : "";
 
- 		
 
- 		$nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
 
- 		
 
- 		$fax = $this->get_args ( 'fax' ) ? $this->get_args ( 'fax' ) : "";
 
- 		$webservice = $this->get_args ( 'webservice' ) ? $this->get_args ( 'webservice' ) : "";
 
- 		$department = $this->get_args ( 'department' ) ? $this->get_args ( 'department' ) : "";
 
- 		$position = $this->get_args ( 'position' ) ? $this->get_args ( 'position' ) : "";
 
- 		$office = $this->get_args ( 'office' ) ? $this->get_args ( 'office' ) : "";
 
- 		$address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
 
- 		$ride = $this->get_args ( 'ride' ) ? $this->get_args ( 'ride' ) : "";
 
- 		$landmarks = $this->get_args ( 'landmarks' ) ? $this->get_args ( 'landmarks' ) : "";
 
- 		$priority = $this->get_args ( 'priority' ) ? $this->get_args ( 'priority' ) : "";
 
- 		$stay = $this->get_args ( 'stay' ) ? $this->get_args ( 'stay' ) : "";
 
- 		$mark = $this->get_args ( 'mark' ) ? $this->get_args ( 'mark' ) : "";
 
- 		
 
- 		$clientname = trim ( $clientname );
 
- 		
 
- 		$token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
 
- 		$tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
 
- 		
 
- 		if (empty ( $token )) {
 
- 			die ( 'illegal request-token' );
 
- 		} else {
 
- 			session_start ();
 
- 			$sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
 
- 			header ( 'Content-Type:text/html;charset=utf-8' );
 
- 			if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
 
- 				die ( '请重新刷新发票申请页面' );
 
- 			}elseif($_SESSION [$sessionKey]=='repeat'){
 
-                 die ( '请勿重复申请发票' );
 
-             }else{
 
-             	if ($_SESSION [$sessionKey] != $token){
 
-             		die ( '请勿重复填写客户资料' );
 
-             	} else {
 
-             		$_SESSION [$sessionKey] = 'repeat';
 
-             	}
 
-             } 
 
- 		}
 
- 		
 
- 		// $companyname = trim ( $companyname );
 
- 		
 
- 		if (empty ( $companyname ))
 
- 			return "/contacts";
 
- 		
 
- 		if (empty ( $this->staff [0] ['sid'] ))
 
- 			return "/contacts";
 
- 		
 
- 		if (! empty ( $clientname )) {
 
- 			
 
- 			// 相同的公司和客户
 
- 			Doo::loadModel ( 'company' );
 
- 			$company = new company ();
 
- 			Doo::loadModel ( 'client' );
 
- 			$client = new client ();
 
- 			
 
- 			$redis = new Redis ();
 
- 			$redis->connect ( '127.0.0.1', '6379' );
 
- 			
 
- 			$cinfo = $client->getClientByNameT ( $clientname );
 
- 			if (! empty ( $cinfo )) {
 
- 				$ninfo = $company->getCompanyByCompanyname ( $companyname );
 
- 				if (! empty ( $ninfo )) {
 
- 					foreach ( $cinfo as $key => $value ) { // 问题
 
- 						if ($value ['companyid'] == $ninfo [0] ['cid'])
 
- 							return "/contacts";
 
- 					}
 
- 				}
 
- 			}
 
- 			
 
- 			Doo::loadModel ( 'district' );
 
- 			$district = new district ();
 
- 			
 
- 			// 修改
 
- 			Doo::loadClass ( 'XDeode' );
 
- 			$XDeode = new XDeode ( 5 );
 
- 			//$comId = $XDeode->decode ( $companyKey );
 
- 			
 
- 			$companyInfo = $company->getOne ( array (
 
- 					'where' => "companyname like '" . $companyname . "'",
 
- 					"asArray" => true 
 
- 			) );
 
- 			
 
- 			// 更新公司信息
 
- 			$lv1 = $district->getbyid ( $local1 );
 
- 			$lv2 = $district->getbyid ( $local2 );
 
- 			$lv3 = $district->getbyid ( $local3 );
 
- 			
 
- 			if (empty ( $lv1 ))
 
- 				$lv1 [0] ['name'] = "";
 
- 			
 
- 			if (empty ( $lv2 ))
 
- 				$lv2 [0] ['name'] = "";
 
- 			if (empty ( $lv3 ))
 
- 				$lv3 [0] ['name'] = "";
 
- 			
 
- 			if (! empty ( $local1 ) && ! empty ( $local2 ))
 
- 				$company->local = $lv1 [0] ['name'] . "," . $lv2 [0] ['name'] . "," . $lv3 [0] ['name'];
 
- 			
 
- 			if (! empty ( $nature ))
 
- 				$company->nature = implode ( ',', $nature );
 
- 			
 
- 			if (! empty ( $fax ))
 
- 				$company->fax = $fax;
 
- 			
 
- 			if (! empty ( $webservice ))
 
- 				$company->webservice = $webservice;
 
- 			
 
- 			if (! empty ( $address ))
 
- 				$company->address = $address;
 
- 			
 
- 			if (! empty ( $ride ))
 
- 				$company->ride = $ride;
 
- 			
 
- 			if (! empty ( $landmarks ))
 
- 				$company->landmarks = $landmarks;
 
- 			
 
- 			if (! empty ( $office ))
 
- 				$company->office = $office;
 
- 			
 
- 			if (! empty ( $local1 ) && ! empty ( $local2 ))
 
- 				$company->district = $local1 . "," . $local2 . "," . $local3;
 
- 			
 
- 			if (! empty ( $stay ))
 
- 				$company->stay = $stay;
 
- 			
 
- 			if (empty ( $companyInfo )) {
 
- 				$company->companyname = $companyname;
 
- 				$company->staffid = $this->staff [0] ['sid'];
 
- 				$cid = $company->insert ();
 
- 			} else { // 不编辑公司,地区判断,作为新公司
 
- 			         // $cid=$companyInfo['cid'];
 
- 			         //
 
- 			         // $companyname=$companyInfo['companyname'];
 
- 			         //
 
- 			         // $company->cid=$cid;
 
- 			         //
 
- 			         // $company->update();
 
- 				$diqu = $local1 . "," . $local2 . "," . $local3;
 
- 				$cid = $companyInfo ['cid'];
 
- 				$company2 = new company ();
 
- 				$companyList = $company2->find ( array (
 
- 						'where' => " companyname like '" . $companyname . "'",
 
- 						"asArray" => true 
 
- 				) );
 
- 				
 
- 				$falg = false;
 
- 				// print_r($companyList);
 
- 				foreach ( $companyList as $key => $value ) {
 
- 					if ($value ['district'] != $diqu) {
 
- 						$falg = true;
 
- 					} elseif ($value ['district'] == $diqu) {
 
- 						$falg = false;
 
- 						$cid = $value ['cid'];
 
- 						break;
 
- 					}
 
- 				}
 
- 				
 
- 				if ($falg) {
 
- 					$company->companyname = $companyname;
 
- 					$company->staffid = $this->staff [0] ['sid'];
 
- 					$cid = $company->insert ();
 
- 				}
 
- 			}
 
- 			
 
- 			Doo::loadModel ( 'client_staff' );
 
- 			$client_staff = new client_staff ();
 
- 			
 
- 			$client->clientname = $clientname;
 
- 			$client->gender = $gender;
 
- 			$client->priority = $priority;
 
- 			
 
- 			if (! empty ( $nicename ))
 
- 				$client->nicename = $nicename;
 
- 			if (! empty ( $telephone ))
 
- 				$client->telephone = $telephone;
 
- 			if (! empty ( $phone ))
 
- 				$client->phone = $phone;
 
- 			if (! empty ( $email ))
 
- 				$client->email = $email;
 
- 			if (! empty ( $qq ) && is_numeric ( $qq ))
 
- 				$client->qq = $qq;
 
- 			
 
- 			$client->companyid = $cid;
 
- 			$client->companyname = $companyname;
 
- 			$client->district = $local1 . "," . $local2 . "," . $local3;
 
- 			// echo $client->district;
 
- 			// die;
 
- 			
 
- 			if (! empty ( $tid ))
 
- 				$client->tag = implode ( ',', $tid );
 
- 			
 
- 			if (! empty ( $fax ))
 
- 				$client->fax = $fax;
 
- 			
 
- 			if (! empty ( $webservice ))
 
- 				$client->webservice = $webservice;
 
- 			
 
- 			if (! empty ( $department ))
 
- 				$client->department = $department;
 
- 			
 
- 			if (! empty ( $position ))
 
- 				$client->position = $position;
 
- 			
 
- 			if (! empty ( $office ))
 
- 				$client->office = $office;
 
- 			
 
- 			if (! empty ( $address ))
 
- 				$client->address = $address;
 
- 			
 
- 			if (! empty ( $ride ))
 
- 				$client->ride = $ride;
 
- 			
 
- 			if (! empty ( $landmarks ))
 
- 				$client->landmarks = $landmarks;
 
- 			
 
- 			if (! empty ( $stay ))
 
- 				$client->stay = $stay;
 
- 			
 
- 			if (! empty ( $mark ))
 
- 				$client->mark = $mark;
 
- 			
 
- 			$id = $client->insert ();
 
- 			
 
- 			$client_staff->cid = $id;
 
- 			$client_staff->sid = $this->staff [0] ['sid'];
 
- 			$client_staff->insert ();
 
- 			
 
- 			// 加入地区记录
 
- 			Doo::loadModel ( "district_staff" );
 
- 			$district_staff = new district_staff ();
 
- 			$district_staff->did = $lv1 [0] ['id'];
 
- 			$district_staff->sid = $this->staff [0] ['sid'];
 
- 			$district_staff->insert ();
 
- 			
 
- 			// 日常行为
 
- 			Doo::loadModel ( "action_log" );
 
- 			$action_log = new action_log ();
 
- 			
 
- 			$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 . ')';
 
- 			$action_log->sid = $this->staff [0] ['sid'];
 
- 			$action_log->cid = $this->staff [0] ['cid'];
 
- 			$action_log->updatetime = date ( "Y-m-d" );
 
- 			$action_log->time = date ( "H:i" );
 
- 			$action_log->status = 1;
 
- 			$action_log->districtid = $local1 . "," . $local2 . "," . $local3;
 
- 			$action_log->city = $lv1 [0] ['name'];
 
- 			$action_log->province = $lv2 [0] ['name'];
 
- 			if (isset ( $nature [0] ))
 
- 				$action_log->nature = $nature [0];
 
- 			$action_log->company = $companyname;
 
- 			$action_log->class = $action_log->iconContacts;
 
- 			$action_log->insert ();
 
- 			
 
- 			// 事实更新信息中心记录数量 需要更新3个redis 内的值
 
- 			$categoryCondition = " and cid=" . $this->staff [0] ['cid'];
 
- 			$sidCondition = " and sid=" . $this->staff [0] ['sid'];
 
- 			
 
- 			// actionlog免查询值 $alCondition='';
 
- 			$alCondition = ' aid>' . REMIT . ' and ';
 
- 			
 
- 			// 个人添加数量redis值
 
- 			$redisKeyCS = date ( 'Y-m-d' ) . 'SC_' . $this->staff [0] ['cid'] . '_' . $this->staff [0] ['sid'];
 
- 			$action_log = new action_log ();
 
- 			$actionLogClient = $action_log->find ( array (
 
- 					'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
 
- 					'where' => $alCondition . " status=1" . $sidCondition . $categoryCondition . ' and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
 
- 					'groupby' => 'date_format(updatetime,"%m-%d")',
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			$statisticsClient = array ();
 
- 			for($d = 0; $d <= 29; $d ++) {
 
- 				$MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
 
- 				$falgClient = true;
 
- 				
 
- 				foreach ( $actionLogClient as $value ) {
 
- 					if ($value ['updatetime'] == $MD) {
 
- 						array_push ( $statisticsClient, $value ['count'] );
 
- 						$falgClient = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 				if ($falgClient)
 
- 					array_push ( $statisticsClient, 0 );
 
- 			}
 
- 			$statisticsClient = array_reverse ( $statisticsClient );
 
- 			$jsc = json_encode ( $statisticsClient );
 
- 			$redis->set ( $redisKeyCS, $jsc );
 
- 			
 
- 			// 办事处添加数量reids值
 
- 			$redisKeyC = date ( 'Y-m-d' ) . 'SC_' . $this->staff [0] ['cid'] . '_';
 
- 			$action_log = new action_log ();
 
- 			$actionLogClient = $action_log->find ( array (
 
- 					'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
 
- 					'where' => $alCondition . " status=1" . $categoryCondition . ' and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
 
- 					'groupby' => 'date_format(updatetime,"%m-%d")',
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			$statisticsClient = array ();
 
- 			for($d = 0; $d <= 29; $d ++) {
 
- 				$MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
 
- 				$falgClient = true;
 
- 				
 
- 				foreach ( $actionLogClient as $value ) {
 
- 					if ($value ['updatetime'] == $MD) {
 
- 						array_push ( $statisticsClient, $value ['count'] );
 
- 						$falgClient = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 				if ($falgClient)
 
- 					array_push ( $statisticsClient, 0 );
 
- 			}
 
- 			$statisticsClient = array_reverse ( $statisticsClient );
 
- 			$jsc = json_encode ( $statisticsClient );
 
- 			$redis->set ( $redisKeyC, $jsc );
 
- 			
 
- 			// 全员添加数量的redis值
 
- 			$redisKey = date ( 'Y-m-d' ) . 'SC__';
 
- 			$action_log = new action_log ();
 
- 			$actionLogClient = $action_log->find ( array (
 
- 					'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
 
- 					'where' => $alCondition . ' status=1  and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
 
- 					'groupby' => 'date_format(updatetime,"%m-%d")',
 
- 					'asArray' => true 
 
- 			) );
 
- 			$statisticsClient = array ();
 
- 			for($d = 0; $d <= 29; $d ++) {
 
- 				$MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
 
- 				$falgClient = true;
 
- 				
 
- 				foreach ( $actionLogClient as $value ) {
 
- 					if ($value ['updatetime'] == $MD) {
 
- 						array_push ( $statisticsClient, $value ['count'] );
 
- 						$falgClient = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 				if ($falgClient)
 
- 					array_push ( $statisticsClient, 0 );
 
- 			}
 
- 			$statisticsClient = array_reverse ( $statisticsClient );
 
- 			$jsc = json_encode ( $statisticsClient );
 
- 			$redis->set ( $redisKey, $jsc );
 
- 		}
 
- 		
 
- 		return "/contacts";
 
- 	}
 
- 	function addClientByCompany() {
 
- 		$companyKey = $this->get_args ( 'companyKey' ) ? $this->get_args ( 'companyKey' ) : "";
 
- 		
 
- 		$clientname = $this->get_args ( 'clientname' ) ? $this->get_args ( 'clientname' ) : "";
 
- 		$gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : "";
 
- 		$nicename = $this->get_args ( 'nicename' ) ? $this->get_args ( 'nicename' ) : "";
 
- 		$telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : "";
 
- 		$phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
 
- 		$email = $this->get_args ( 'email' ) ? $this->get_args ( 'email' ) : "";
 
- 		$qq = $this->get_args ( 'qq' ) ? $this->get_args ( 'qq' ) : "";
 
- 		$tid = $this->get_args ( 'tid' ) ? $this->get_args ( 'tid' ) : "";
 
- 		//$companyname = $this->get_args ( 'companyname' ) ? $this->get_args ( 'companyname' ) : "";
 
- 		
 
- 		$local1 = $this->get_args ( 'lv21' ) ? $this->get_args ( 'lv21' ) : "";
 
- 		$local2 = $this->get_args ( 'lv22' ) ? $this->get_args ( 'lv22' ) : "";
 
- 		$local3 = $this->get_args ( 'lv23' ) ? $this->get_args ( 'lv23' ) : "";
 
- 		
 
- 		$nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
 
- 		
 
- 		$fax = $this->get_args ( 'fax' ) ? $this->get_args ( 'fax' ) : "";
 
- 		$webservice = $this->get_args ( 'webservice' ) ? $this->get_args ( 'webservice' ) : "";
 
- 		$department = $this->get_args ( 'department' ) ? $this->get_args ( 'department' ) : "";
 
- 		$position = $this->get_args ( 'position' ) ? $this->get_args ( 'position' ) : "";
 
- 		$office = $this->get_args ( 'office' ) ? $this->get_args ( 'office' ) : "";
 
- 		$address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
 
- 		$ride = $this->get_args ( 'ride' ) ? $this->get_args ( 'ride' ) : "";
 
- 		$landmarks = $this->get_args ( 'landmarks' ) ? $this->get_args ( 'landmarks' ) : "";
 
- 		$priority = $this->get_args ( 'priority' ) ? $this->get_args ( 'priority' ) : "";
 
- 		$stay = $this->get_args ( 'stay' ) ? $this->get_args ( 'stay' ) : "";
 
- 		$mark = $this->get_args ( 'mark' ) ? $this->get_args ( 'mark' ) : "";
 
- 		
 
- 		$clientname = trim ( $clientname );
 
- 		
 
- 		$token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
 
- 		if (empty ( $token )) {
 
- 			die ( 'illegal request-token' );
 
- 		} else {
 
- 			session_start ();
 
- 			if ($_SESSION ['token_' . $this->staff [0] ['sidKey']] != $token) {
 
- 				header ( 'Content-Type:text/html;charset=utf-8' );
 
- 				die ( '请勿重复填写客户资料' );
 
- 			} else {
 
- 				$_SESSION ['token_' . $this->staff [0] ['sidKey']] = '';
 
- 			}
 
- 		}
 
- 		
 
- 		if (empty ( $this->staff [0] ['sid'] ))
 
- 			return "/contacts";
 
- 		
 
- 		if (! empty ( $clientname )) {
 
- 			
 
- 			// 相同的公司和客户
 
- 			Doo::loadModel ( 'company' );
 
- 			$company = new company ();
 
- 			Doo::loadModel ( 'client' );
 
- 			$client = new client ();
 
- 			
 
- 			$redis = new Redis ();
 
- 			$redis->connect ( '127.0.0.1', '6379' );
 
- 			
 
- 			$cinfo = $client->getClientByNameT ( $clientname );
 
- 			
 
- 			
 
- 			Doo::loadModel ( 'district' );
 
- 			$district = new district ();
 
- 			
 
- 			// 修改
 
- 			Doo::loadClass ( 'XDeode' );
 
- 			$XDeode = new XDeode ( 5 );
 
- 			$comId = $XDeode->decode ( $companyKey );
 
- 			$companyInfo = $company->getOne ( array (
 
- 					'where' => "cid = '" . $comId . "'",
 
- 					"asArray" => true 
 
- 			) );
 
- 			
 
- 			// 更新公司信息
 
- 			$lv1 = $district->getbyid ( $local1 );
 
- 			$lv2 = $district->getbyid ( $local2 );
 
- 			$lv3 = $district->getbyid ( $local3 );
 
- 			
 
- 			if (empty ( $lv1 ))
 
- 				$lv1 [0] ['name'] = "";
 
- 			
 
- 			if (empty ( $lv2 ))
 
- 				$lv2 [0] ['name'] = "";
 
- 			if (empty ( $lv3 ))
 
- 				$lv3 [0] ['name'] = "";
 
- 			
 
- // 			if (! empty ( $local1 ) && ! empty ( $local2 ))
 
- // 				$company->local = $lv1 [0] ['name'] . "," . $lv2 [0] ['name'] . "," . $lv3 [0] ['name'];
 
- 			
 
- // 			if (! empty ( $nature ))
 
- // 				$company->nature = implode ( ',', $nature );
 
- 			
 
- // 			if (! empty ( $fax ))
 
- // 				$company->fax = $fax;
 
- 			
 
- // 			if (! empty ( $webservice ))
 
- // 				$company->webservice = $webservice;
 
- 			
 
- // 			if (! empty ( $address ))
 
- // 				$company->address = $address;
 
- 			
 
- // 			if (! empty ( $ride ))
 
- // 				$company->ride = $ride;
 
- 			
 
- // 			if (! empty ( $landmarks ))
 
- // 				$company->landmarks = $landmarks;
 
- 			
 
- // 			if (! empty ( $office ))
 
- // 				$company->office = $office;
 
- 			
 
- // 			if (! empty ( $local1 ) && ! empty ( $local2 ))
 
- // 				$company->district = $local1 . "," . $local2 . "," . $local3;
 
- 			
 
- // 			if (! empty ( $stay ))
 
- // 				$company->stay = $stay;
 
- 			
 
- 				
 
- 			$cid = $companyInfo ['cid'];
 
- 			if (empty ( $companyInfo )) {
 
- 				
 
- 			} else { // 不编辑公司,地区判断,作为新公司
 
- 			         // $cid=$companyInfo['cid'];
 
- 			         //
 
- 			         // $companyname=$companyInfo['companyname'];
 
- 			         //
 
- 			         // $company->cid=$cid;
 
- 			         //
 
- 			         // $company->update();
 
- // 				$diqu = $local1 . "," . $local2 . "," . $local3;
 
- // 				$cid = $companyInfo ['cid'];
 
- // 				$company2 = new company ();
 
- // 				$companyList = $company2->find ( array (
 
- // 						'where' => " companyname like '" . $companyname . "'",
 
- // 						"asArray" => true 
 
- // 				) );
 
- 				
 
- // 				$falg = false;
 
- // 				// print_r($companyList);
 
- // 				foreach ( $companyList as $key => $value ) {
 
- // 					if ($value ['district'] != $diqu) {
 
- // 						$falg = true;
 
- // 					} elseif ($value ['district'] == $diqu) {
 
- // 						$falg = false;
 
- // 						$cid = $value ['cid'];
 
- // 						break;
 
- // 					}
 
- // 				}
 
- 				
 
- // 				if ($falg) {
 
- // 					$company->companyname = $companyname;
 
- // 					$company->staffid = $this->staff [0] ['sid'];
 
- // 					$cid = $company->insert ();
 
- // 				}
 
- 			}
 
- 			
 
- 			Doo::loadModel ( 'client_staff' );
 
- 			$client_staff = new client_staff ();
 
- 			
 
- 			$client->clientname = $clientname;
 
- 			$client->gender = $gender;
 
- 			$client->priority = $priority;
 
- 			
 
- 			if (! empty ( $nicename ))
 
- 				$client->nicename = $nicename;
 
- 			if (! empty ( $telephone ))
 
- 				$client->telephone = $telephone;
 
- 			if (! empty ( $phone ))
 
- 				$client->phone = $phone;
 
- 			if (! empty ( $email ))
 
- 				$client->email = $email;
 
- 			if (! empty ( $qq ) && is_numeric ( $qq ))
 
- 				$client->qq = $qq;
 
- 			
 
- 			$client->companyid = $cid;
 
- 			$client->companyname = $companyInfo['companyname'];
 
- 			$client->district = $local1 . "," . $local2 . "," . $local3;
 
- 			// echo $client->district;
 
- 			// die;
 
- 			
 
- 			if (! empty ( $tid ))
 
- 				$client->tag = implode ( ',', $tid );
 
- 			
 
- 			if (! empty ( $fax ))
 
- 				$client->fax = $fax;
 
- 			
 
- 			if (! empty ( $webservice ))
 
- 				$client->webservice = $webservice;
 
- 			
 
- 			if (! empty ( $department ))
 
- 				$client->department = $department;
 
- 			
 
- 			if (! empty ( $position ))
 
- 				$client->position = $position;
 
- 			
 
- 			if (! empty ( $office ))
 
- 				$client->office = $office;
 
- 			
 
- 			if (! empty ( $address ))
 
- 				$client->address = $address;
 
- 			
 
- 			if (! empty ( $ride ))
 
- 				$client->ride = $ride;
 
- 			
 
- 			if (! empty ( $landmarks ))
 
- 				$client->landmarks = $landmarks;
 
- 			
 
- 			if (! empty ( $stay ))
 
- 				$client->stay = $stay;
 
- 			
 
- 			if (! empty ( $mark ))
 
- 				$client->mark = $mark;
 
- 			
 
- 			$id = $client->insert ();
 
- 			
 
- 			$client_staff->cid = $id;
 
- 			$client_staff->sid = $this->staff [0] ['sid'];
 
- 			$client_staff->insert ();
 
- 			
 
- 			// 加入地区记录
 
- 			Doo::loadModel ( "district_staff" );
 
- 			$district_staff = new district_staff ();
 
- 			$district_staff->did = $lv1 [0] ['id'];
 
- 			$district_staff->sid = $this->staff [0] ['sid'];
 
- 			$district_staff->insert ();
 
- 			
 
- 			// 日常行为
 
- 			Doo::loadModel ( "action_log" );
 
- 			$action_log = new action_log ();
 
- 			
 
- 			$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'] . ')';
 
- 			$action_log->sid = $this->staff [0] ['sid'];
 
- 			$action_log->cid = $this->staff [0] ['cid'];
 
- 			$action_log->updatetime = date ( "Y-m-d" );
 
- 			$action_log->time = date ( "H:i" );
 
- 			$action_log->status = 1;
 
- 			$action_log->districtid = $local1 . "," . $local2 . "," . $local3;
 
- 			$action_log->city = $lv1 [0] ['name'];
 
- 			$action_log->province = $lv2 [0] ['name'];
 
- 			if (isset ( $nature [0] ))
 
- 				$action_log->nature = $nature [0];
 
- 			$action_log->company = $companyInfo['companyname'];
 
- 			$action_log->class = $action_log->iconContacts;
 
- 			$action_log->insert ();
 
- 			
 
- 			// 事实更新信息中心记录数量 需要更新3个redis 内的值
 
- 			$categoryCondition = " and cid=" . $this->staff [0] ['cid'];
 
- 			$sidCondition = " and sid=" . $this->staff [0] ['sid'];
 
- 			
 
- 			// actionlog免查询值 $alCondition='';
 
- 			$alCondition = ' aid>' . REMIT . ' and ';
 
- 			
 
- 			// 个人添加数量redis值
 
- 			$redisKeyCS = date ( 'Y-m-d' ) . 'SC_' . $this->staff [0] ['cid'] . '_' . $this->staff [0] ['sid'];
 
- 			$action_log = new action_log ();
 
- 			$actionLogClient = $action_log->find ( array (
 
- 					'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
 
- 					'where' => $alCondition . " status=1" . $sidCondition . $categoryCondition . ' and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
 
- 					'groupby' => 'date_format(updatetime,"%m-%d")',
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			$statisticsClient = array ();
 
- 			for($d = 0; $d <= 29; $d ++) {
 
- 				$MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
 
- 				$falgClient = true;
 
- 				
 
- 				foreach ( $actionLogClient as $value ) {
 
- 					if ($value ['updatetime'] == $MD) {
 
- 						array_push ( $statisticsClient, $value ['count'] );
 
- 						$falgClient = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 				if ($falgClient)
 
- 					array_push ( $statisticsClient, 0 );
 
- 			}
 
- 			$statisticsClient = array_reverse ( $statisticsClient );
 
- 			$jsc = json_encode ( $statisticsClient );
 
- 			$redis->set ( $redisKeyCS, $jsc );
 
- 			
 
- 			// 办事处添加数量reids值
 
- 			$redisKeyC = date ( 'Y-m-d' ) . 'SC_' . $this->staff [0] ['cid'] . '_';
 
- 			$action_log = new action_log ();
 
- 			$actionLogClient = $action_log->find ( array (
 
- 					'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
 
- 					'where' => $alCondition . " status=1" . $categoryCondition . ' and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
 
- 					'groupby' => 'date_format(updatetime,"%m-%d")',
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			$statisticsClient = array ();
 
- 			for($d = 0; $d <= 29; $d ++) {
 
- 				$MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
 
- 				$falgClient = true;
 
- 				
 
- 				foreach ( $actionLogClient as $value ) {
 
- 					if ($value ['updatetime'] == $MD) {
 
- 						array_push ( $statisticsClient, $value ['count'] );
 
- 						$falgClient = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 				if ($falgClient)
 
- 					array_push ( $statisticsClient, 0 );
 
- 			}
 
- 			$statisticsClient = array_reverse ( $statisticsClient );
 
- 			$jsc = json_encode ( $statisticsClient );
 
- 			$redis->set ( $redisKeyC, $jsc );
 
- 			
 
- 			// 全员添加数量的redis值
 
- 			$redisKey = date ( 'Y-m-d' ) . 'SC__';
 
- 			$action_log = new action_log ();
 
- 			$actionLogClient = $action_log->find ( array (
 
- 					'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
 
- 					'where' => $alCondition . ' status=1  and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
 
- 					'groupby' => 'date_format(updatetime,"%m-%d")',
 
- 					'asArray' => true 
 
- 			) );
 
- 			$statisticsClient = array ();
 
- 			for($d = 0; $d <= 29; $d ++) {
 
- 				$MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
 
- 				$falgClient = true;
 
- 				
 
- 				foreach ( $actionLogClient as $value ) {
 
- 					if ($value ['updatetime'] == $MD) {
 
- 						array_push ( $statisticsClient, $value ['count'] );
 
- 						$falgClient = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 				if ($falgClient)
 
- 					array_push ( $statisticsClient, 0 );
 
- 			}
 
- 			$statisticsClient = array_reverse ( $statisticsClient );
 
- 			$jsc = json_encode ( $statisticsClient );
 
- 			$redis->set ( $redisKey, $jsc );
 
- 		}
 
- 		
 
- 		return "/contacts";
 
- 	}
 
- 	function mycompany() {
 
- 		$search = $this->get_args ( 'search' ) ? $this->get_args ( 'search' ) : "";
 
- 		$districtLv = $this->get_args ( 'districtLv' ) ? $this->get_args ( 'districtLv' ) : 0;
 
- 		$nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
 
- 		$lv1 = $this->get_args ( 'lv1' ) ? $this->get_args ( 'lv1' ) : 0;
 
- 		$lv2 = $this->get_args ( 'lv2' ) ? $this->get_args ( 'lv2' ) : 0;
 
- 		$lv3 = $this->get_args ( 'lv3' ) ? $this->get_args ( 'lv3' ) : 0;
 
- 		
 
- 		$tagList = $this->get_args ( 'tag' ) ? $this->get_args ( 'tag' ) : array ();
 
- 		if ($lv1 == 0) {
 
- 			$lv1 = isset ( $this->params ['lv1'] ) && is_numeric ( $this->params ['lv1'] ) ? $this->params ['lv1'] : 0;
 
- 			if ($lv1 != 0)
 
- 				$districtLv = 1;
 
- 		}
 
- 		if ($lv2 == 0) {
 
- 			$lv2 = isset ( $this->params ['lv2'] ) && is_numeric ( $this->params ['lv2'] ) ? $this->params ['lv2'] : 0;
 
- 			if ($lv2 != 0)
 
- 				$districtLv = 2;
 
- 		}
 
- 		if ($lv3 == 0) {
 
- 			$lv3 = isset ( $this->params ['lv3'] ) && is_numeric ( $this->params ['lv3'] ) ? $this->params ['lv3'] : 0;
 
- 			if ($lv2 != 0)
 
- 				$districtLv = 3;
 
- 		}
 
- 		
 
- 		if (empty ( $search ))
 
- 			$search = urldecode ( isset ( $this->params ['search'] ) ? $this->params ['search'] : "" );
 
- 		
 
- 		$page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
 
- 		$data['search']=$search;
 
- 		$data ['memu'] = "contacts";
 
- 		$data ['staff'] = $this->staff;
 
-         //Doo::loadModel ( 'tag' );
 
-         //$tag = new tag ();
 
- 		Doo::loadModel ( 'district' );
 
- 		Doo::loadModel ( 'company' );
 
- 		Doo::loadModel ( 'client' );
 
- 		Doo::loadModel ( 'L_category' );
 
- 		
 
- 		$lcategory = new L_category ();
 
- 		$client = new client ();
 
- 		$company = new company ();
 
- 		$district = new district ();
 
- 		Doo::loadModel ( 'tagCompany' );
 
- 		$tagCompany = new tagCompany ();
 
- 		Doo::loadModel ( 'tagCompanyNexus' );
 
- 		$tagCompanyNexus = new tagCompanyNexus ();
 
- 		
 
- 		$data ['district2'] = $district->get_lv ( 1 );
 
- 		//$category = $lcategory->getCategoryById ( $this->staff [0] ['cid'], $this->staff [0] ['othercid'] );
 
- 		$cateStr = " cid =0 ";
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 5 );
 
- 		
 
- 		$didList = explode ( ',', $this->staff [0] ['did'] );
 
- 		$didList = array_filter ( $didList );
 
- 		$didListContont = array ();
 
- 		if (! empty ( $didList )) {
 
- 			foreach ( $didList as $key => $value ) {
 
- 				array_push ( $didListContont, $XDeode->decode ( $value ) );
 
- 			}
 
- 			
 
- 			$data ['district'] = $district->getDistrictInId ( implode ( ',', $didListContont ) ); // $district->get_lvByStaffid ( 1, $this->staff [0] ['sid'] );
 
- 		} else {
 
- 			$data ['district'] = array ();
 
- 		}
 
- 		
 
- 		$sqstr = '';
 
- 		if (! empty ( $didListContont )) {
 
- 			
 
- 			foreach ( $didListContont as $key => $value ) {
 
- 				if ($key != 0) {
 
- 					$sqstr .= " or district like '" . $value . ",%'";
 
- 				}
 
- 			}
 
- 			$cateStr = " ( district like '" . $didListContont [0] . ",%'" . $sqstr . ')';
 
- 		}
 
- 		
 
- 		// $list = array ();
 
- 		// foreach ( $category as $key => $value ) {
 
- 		// array_push ( $list, " district like '" . $value ['districtid'] . ",%' " );
 
- 		// }
 
- 		// if ($this->staff [0] ['isadmin'] != 1)
 
- 		// $cateStr = implode ( " or ", $list );
 
- 		// else
 
- 		// $cateStr = " 1";
 
- 		//
 
- 		
 
- 		// if (! empty ( $nature ))
 
- 		// $cateStr = " 1";
 
- 		
 
- 		$size = 300;
 
- 		
 
- 		$data ['htmllv2'] = array ();
 
- 		$data ['htmllv3'] = array ();
 
- 		$condition = "";
 
- 		
 
- 		if ($districtLv == 1) {
 
- 			$condition = "";
 
- 			
 
- 			if (! empty ( $lv1 )) {
 
- 				$condition = " district like '" . $lv1 . ",%'";
 
- 				$data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
 
- 			}
 
- 		}
 
- 		
 
- 		if ($districtLv == 2) {
 
- 			if (! empty ( $lv2 ))
 
- 				$condition = " district like '" . $lv1 . "," . $lv2 . ",%'";
 
- 			else
 
- 				$condition = "  district like '" . $lv1 . ",%'";
 
- 			
 
- 			$data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
 
- 			$data ['htmllv3'] = $district->get_lvByid ( 2, $lv2 );
 
- 		}
 
- 		
 
- 		if ($districtLv == 3) {
 
- 			if (! empty ( $lv3 ))
 
- 				$condition = "  district like '" . $lv1 . "," . $lv2 . "," . $lv3 . "'";
 
- 			else
 
- 				$condition = " district like '" . $lv1 . "," . $lv2 . ",%'";
 
- 			
 
- 			$data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
 
- 			$data ['htmllv3'] = $district->get_lvByid ( 2, $lv2 );
 
- 		}
 
- 		
 
- 		$districtCount = $condition;
 
- 		
 
- 		if (! empty ( $condition ))
 
- 			$cateStr = $condition;
 
-         if (!empty($search)){
 
-             $cateStr.=" and companyname like '%".$search."%' ";
 
-         }
 
- 		if (! empty ( $nature ))
 
- 			$cateStr .= " and nature like '%" . $nature . "%'";
 
- 			
 
- 			// echo "<div style='display:none'>".$cateStr."</div><br/>";
 
- 		$tagSQL = false;
 
- 		if (! empty ( $tagList )) {
 
- 			$tagSQL = true;
 
- 			foreach ( $tagList as $value ) {
 
- 				$cateStr .= " and a.tag like '%" . $value . "%' ";
 
- 			}
 
- 		}
 
- 		
 
- 		if ($this->staff [0] ['isadmin'] != 1) {
 
- 			$pageinfo = $this->get_Tpage ( "CLD_company", $cateStr, $page, $size, "", $tagSQL );
 
- 		} else {
 
- 			if ($tagSQL)
 
- 				$pageinfo = $this->get_Tpage ( "CLD_company", $cateStr, $page, $size, "", $tagSQL );
 
- 			else {
 
- 				$total_page = $company->count ( array () );
 
- 				$total = intval ( $total_page / $size );
 
- 				$pageinfo ['total_page'] = ($total_page % $size) == 0 ? $total : $total + 1;
 
- 			}
 
- 		}
 
- 		
 
- 		$k = "";
 
- 		for($i = 1; $i <= $pageinfo ['total_page']; $i ++) {
 
- 			if ($page == $i)
 
- 				$k .= "<option value='" . $search . ":" . $i . ":" . $lv1 . ":" . $lv2 . ":" . $lv3 . "' selected>第" . $i . "页</option>";
 
- 			else
 
- 				$k .= "<option value='" . $search . ":" . $i . ":" . $lv1 . ":" . $lv2 . ":" . $lv3 . "'>第" . $i . "页</option>";
 
- 		}
 
- 		
 
- 		$data ['pageinfo'] = $k;
 
- 		
 
- 		$data ['company'] = $company->getCompanyByDistrict ( $this->staff [0] ['sid'], $cateStr, $this->staff [0] ['isadmin'], $page, $size, $tagSQL );
 
- 		
 
- 		// if ($this->staff [0] ['isadmin'] != 1) {
 
- 		// $data ['district'] = $district->get_lvByStaffid ( 1, $this->staff [0] ['sid'] );
 
- 		// } else {
 
- 		// $data ['district'] = $data ['district2'];
 
- 		// }
 
- 		
 
- 		// 获得标签
 
- 		$ClientTagList = $tagCompanyNexus->getTagClientBySid ( $this->staff [0] ['sid'] );
 
- 		
 
- 		foreach ( $ClientTagList as $key => $value ) {
 
- 			$ClientTagList [$key] ['taginfo'] = $tagCompany->getTagByTidL ( $value ['tag'] );
 
- 		}
 
- 		
 
- 		foreach ( $data ['company'] as $key => $value ) {
 
- 			if (! empty ( $value ['cid'] )) {
 
- 				$data ['company'] [$key] ['taginfo'] = array ();
 
- 				$data ['company'] [$key] ['tag'] = "";
 
- 				
 
- 				foreach ( $ClientTagList as $k => $v ) {
 
- 					if ($value ['cid'] == $v ['company']) {
 
- 						$data ['company'] [$key] ['taginfo'] = $v ['taginfo'];
 
- 						$data ['company'] [$key] ['tag'] = $v ['tag'];
 
- 					}
 
- 				}
 
- 			}
 
- 		}
 
- 		
 
- 		$comcid = $countL = array ();
 
- 		foreach ( $data ['company'] as $key => $value ) {
 
- 			array_push ( $comcid, $value ['cid'] );
 
- 		}
 
- 		
 
- 		$comcid = implode ( ",", $comcid );
 
- 		if (! empty ( $comcid ))
 
- 			$countL = $client->getCountByCompany ( $comcid );
 
- 		
 
- 		foreach ( $data ['company'] as $key => $value ) {
 
- 			$data ['company'] [$key] ['count'] = 0;
 
- 			foreach ( $countL as $k => $v ) {
 
- 				if ($value ['cid'] == $v ['companyid']) {
 
- 					$data ['company'] [$key] ['count'] = $v ['count'];
 
- 					break;
 
- 				}
 
- 			}
 
- 		}
 
- 		
 
- 		$CC1 = "";
 
- 		$CC2 = "";
 
- 		$CC3 = "";
 
- 		$natureHtml = '';
 
- 		if (! empty ( $districtCount )) {
 
- 			$clientCount = $company->find ( array (
 
- 					'select' => 'district',
 
- 					'where' => "district like '" . $lv1 . ",%'",
 
- 					'asArray' => TRUE 
 
- 			) );
 
- 			$CC1 = count ( $clientCount );
 
- 			if (! empty ( $clientCount ) && ! empty ( $lv2 )) {
 
- 				$CC2 = 0;
 
- 				foreach ( $clientCount as $key => $value ) {
 
- 					if (strpos ( $value ['district'], $lv2 )) {
 
- 						$CC2 ++;
 
- 					}
 
- 				}
 
- 			}
 
- 			
 
- 			if (! empty ( $clientCount ) && ! empty ( $lv3 )) {
 
- 				$CC3 = 0;
 
- 				foreach ( $clientCount as $key => $value ) {
 
- 					if (strpos ( $value ['district'], $lv3 )) {
 
- 						$CC3 ++;
 
- 					}
 
- 				}
 
- 			}
 
- 			
 
- 			$clientCount = $company->find ( array (
 
- 					'select' => 'district,nature',
 
- 					'where' => $districtCount,
 
- 					'asArray' => TRUE 
 
- 			) );
 
- 			
 
- 			$natureCount = array ();
 
- 			foreach ( $this->nature as $value ) {
 
- 				$natureCount [$value] = 0;
 
- 				foreach ( $clientCount as $v ) {
 
- 					$ak = explode ( ",", $v ['nature'] );
 
- 					foreach ( $ak as $a ) {
 
- 						if ($value == $a) {
 
- 							$natureCount [$value] ++;
 
- 						}
 
- 					}
 
- 				}
 
- 			}
 
- 		}
 
- 		
 
- 		$natureHtml = '';
 
- 		foreach ( $this->nature as $value ) {
 
- 			$natureHtml .= '<a href="javascript:void(0)" ';
 
- 			if ($value == $nature)
 
- 				$natureHtml .= 'class="now"';
 
- 			if (isset ( $natureCount [$value] ))
 
- 				$natureHtml .= 'onclick="showNature(\'' . $value . '\',this)">' . $value . '(' . $natureCount [$value] . ')</a>';
 
- 			else
 
- 				$natureHtml .= 'onclick="showNature(\'' . $value . '\',this)">' . $value . '</a>';
 
- 		}
 
- 		
 
- 		$taglist = $tagCompany->find ( array (
 
- 				'where' => 'sid=' . $this->staff [0] ['sid'],
 
- 				'asArray' => TRUE 
 
- 		) );
 
- 		if (empty ( $taglist )) {
 
- 			for($i = 1; $i <= 7; $i ++) {
 
- 				$tag = new tagCompany ();
 
- 				$tag->name = "个人标签";
 
- 				$tag->sid = $this->staff [0] ['sid'];
 
- 				$tag->colorid = $i;
 
- 				$tag->insert ();
 
- 			}
 
- 		}
 
- 		
 
- 		$data ['product'] = array ();
 
- 		$data ['tagList'] = $tagList;
 
- 		$data ['tag'] = $tagCompany->getAllBySid ( $this->staff [0] ['sid'] );
 
- 		$data ['natureHtml'] = $natureHtml;
 
- 		$data ['CC1'] = $CC1;
 
- 		$data ['CC2'] = $CC2;
 
- 		$data ['CC3'] = $CC3;
 
- 		$data ['lv1'] = $lv1;
 
- 		$data ['lv2'] = $lv2;
 
- 		$data ['lv3'] = $lv3;
 
- 		$data ['districtLv'] = $districtLv;
 
- 		$data ['Hnature'] = $nature;
 
- 		$data ['nature'] = $this->nature;
 
- 		
 
- 		$this->render ( "/contacts_company", $data );
 
- 	}
 
- 	function contacts() {
 
- 		
 
- 		session_start ();
 
- 		
 
- 		$data ['memu'] = "contacts";
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		$search = $this->get_args ( 'search' ) ? trim ( $this->get_args ( 'search' ) ) : "";
 
- 		if (empty ( $search ))
 
- 			$search = urldecode ( isset ( $this->params ['search'] ) ? $this->params ['search'] : "" );
 
- 		
 
- 		$lv1 = $this->get_args ( 'lv1' ) ? $this->get_args ( 'lv1' ) : 0;
 
- 		$lv2 = $this->get_args ( 'lv2' ) ? $this->get_args ( 'lv2' ) : 0;
 
- 		$lv3 = $this->get_args ( 'lv3' ) ? $this->get_args ( 'lv3' ) : 0;
 
- 		
 
- 		$lv4 = $this->get_args ( 'lv4' ) ? $this->get_args ( 'lv4' ) : "";
 
- 		$tagList = $this->get_args ( 'tag' ) ? $this->get_args ( 'tag' ) : array ();
 
- 		$tooltip = $this->get_args ( 'tooltip' ) ? $this->get_args ( 'tooltip' ) : "";
 
- 		
 
- 		$districtLv = $this->get_args ( 'districtLv' ) ? $this->get_args ( 'districtLv' ) : 0;
 
- 		
 
- 		if ($lv1 == 0) {
 
- 			$lv1 = isset ( $this->params ['lv1'] ) && is_numeric ( $this->params ['lv1'] ) ? $this->params ['lv1'] : 0;
 
- 			if ($lv1 != 0)
 
- 				$districtLv = 1;
 
- 		}
 
- 		if ($lv2 == 0) {
 
- 			$lv2 = isset ( $this->params ['lv2'] ) && is_numeric ( $this->params ['lv2'] ) ? $this->params ['lv2'] : 0;
 
- 			if ($lv2 != 0)
 
- 				$districtLv = 2;
 
- 		}
 
- 		if ($lv3 == 0) {
 
- 			$lv3 = isset ( $this->params ['lv3'] ) && is_numeric ( $this->params ['lv3'] ) ? $this->params ['lv3'] : 0;
 
- 			if ($lv2 != 0)
 
- 				$districtLv = 3;
 
- 		}
 
- 		
 
- 		$sortV = $this->get_args ( 'sortV' ) ? $this->get_args ( 'sortV' ) : "h";
 
- 		
 
- 		$page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
 
- 		
 
- 		Doo::loadModel ( 'client_staff' );
 
- 		Doo::loadModel ( 'client' );
 
- 		Doo::loadModel ( 'tag' );
 
- 		Doo::loadModel ( 'district' );
 
- 		Doo::loadModel ( 'tag_client' );
 
- 		Doo::loadModel ( 'L_category' );
 
- 		Doo::loadModel ( 'longle' );
 
- 		Doo::loadModel ( 'C_tooltip' );
 
- 		
 
- 		$c_tooltip = new C_tooltip ();
 
- 		$longle = new longle ();
 
- 		$client = new client ();
 
- 		$category = new L_category ();
 
- 		$tagClient = new tag_client ();
 
- 		$district = new district ();
 
- 		$tag = new tag ();
 
- 		$client_staff = new client_staff ();
 
- 		
 
- 		$data ['tag'] = $tag->getAllBySid ( $this->staff [0] ['sid'] );
 
- 		$data ['district2'] = $district->get_lv ( 1 );
 
- 		$page_size = 200;
 
- 		$linfo = $category->getCategoryById ( $this->staff [0] ['cid'], $this->staff ['0'] ['othercid'] );
 
- 		$staffid = $condition = $a = "";
 
- 		
 
- 		// if ($this->staff [0] ['isadmin'] != 1) {
 
- 		// 加入办事处地区
 
- 		
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 5 );
 
- 		
 
- 		$didList = explode ( ',', $this->staff [0] ['did'] );
 
- 		$didList = array_filter ( $didList );
 
- 		$didListContont = array ();
 
- 		if (! empty ( $didList )) {
 
- 			foreach ( $didList as $key => $value ) {
 
- 				array_push ( $didListContont, $XDeode->decode ( $value ) );
 
- 			}
 
- 			
 
- 			$data ['district'] = $district->getDistrictInId ( implode ( ',', $didListContont ) ); // $district->get_lvByStaffid ( 1, $this->staff [0] ['sid'] );
 
- 		} else {
 
- 			$data ['district'] = array ();
 
- 		}
 
- 		
 
- 		if (! empty ( $search ))
 
- 			$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 . "%')";
 
- 		else {
 
- 			$a = '';
 
- 			$sqstr = '';
 
- 			if (! empty ( $didListContont )) {
 
- 				$a = '';
 
- 				foreach ( $didListContont as $key => $value ) {
 
- 					if ($key != 0) {
 
- 						$sqstr .= " or b.district like '" . $value . ",%'";
 
- 					}
 
- 				}
 
- 				$a = "and ( b.district like '" . $didListContont [0] . ",%'" . $sqstr . ')';
 
- 			}
 
- 			
 
- 			if (! empty ( $tooltip ))
 
- 				$sch = "";
 
- 			$staffid = $data ['staff'] [0] ['sid'];
 
- 		}
 
- 		
 
- 		$data ['htmllv2'] = $data ['htmllv3'] = array ();
 
- 		
 
- 		if ($districtLv == 1) {
 
- 			$a = "";
 
- 			$condition = "";
 
- 			if (! empty ( $lv1 )) {
 
- 				$condition .= " and district like '" . $lv1 . ",%'";
 
- 				$data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
 
- 			}
 
- 		}
 
- 		
 
- 		if ($districtLv == 2) {
 
- 			$a = "";
 
- 			if (! empty ( $lv2 ))
 
- 				$condition .= " and district like '" . $lv1 . "," . $lv2 . ",%'";
 
- 			else
 
- 				$condition .= " and district like '" . $lv1 . ",%'";
 
- 			
 
- 			$data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
 
- 			$data ['htmllv3'] = $district->get_lvByid ( 2, $lv2 );
 
- 		}
 
- 		
 
- 		if ($districtLv == 3) {
 
- 			$a = "";
 
- 			if (! empty ( $lv3 ))
 
- 				$condition .= " and district like '" . $lv1 . "," . $lv2 . "," . $lv3 . "'";
 
- 			else
 
- 				$condition .= " and district like '" . $lv1 . "," . $lv2 . ",%'";
 
- 			
 
- 			$data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
 
- 			$data ['htmllv3'] = $district->get_lvByid ( 2, $lv2 );
 
- 		}
 
- 		$condition .= $a;
 
- 		$districtCount = $condition;
 
- 		
 
- 		if (! empty ( $lv4 )) {
 
- 			$condition .= " and nature like '%" . $lv4 . "%'";
 
- 		}
 
- 		$tagSQL = false;
 
- 		if (! empty ( $tagList )) {
 
- 			$tagSQL = true;
 
- 			foreach ( $tagList as $value ) {
 
- 				$condition .= " and c.tag like '%" . $value . "%' ";
 
- 			}
 
- 			$search = "";
 
- 		}
 
- 		
 
- 		if (! empty ( $search ))
 
- 			$condition .= $sch;
 
- 			// if(!empty($tooltip))
 
- 			// $condition.=" and tooltip like '%".$tooltip."%'";
 
- 		$pageinfo = array (
 
- 				'lower' => 0,
 
- 				'total_page' => 0,
 
- 				'total_data' => 0 
 
- 		);
 
- 		if (! empty ( $didListContont ) || ! empty ( $search ))
 
- 			$pageinfo = $this->get_page ( "CLD_client_staff", $condition, $page, $page_size, "", "", "", $staffid, $search, $tooltip, $this->staff [0] ['cid'], $tagSQL );
 
- 		
 
- 		if ($sortV == "h") { // order by a.cid desc
 
- 			$limit = " order by cid desc limit " . $pageinfo ['lower'] . " , " . $page_size . " ";
 
- 		}
 
- 		if ($sortV == "g") { // order by updatetime desc
 
- 			$limit = "  limit " . $pageinfo ['lower'] . " , " . $page_size . " ";
 
- 		}
 
- 		if ($sortV == "f") { // order by updatetime desc
 
- 			$limit = "  limit " . $pageinfo ['lower'] . " , " . $page_size . " ";
 
- 		}
 
- 		if ($sortV == "i") { // order by servicetime desc
 
- 			$limit = "  limit " . $pageinfo ['lower'] . " , " . $page_size . " ";
 
- 		}
 
- 		// 检索是全局
 
- 		// echo $condition;
 
- 		$data ['clientInfo'] = array ();
 
- 		if (! empty ( $didListContont ) || ! empty ( $search ))
 
- 			$data ['clientInfo'] = $client_staff->getClientByStaff ( $condition, $limit, $staffid, $this->staff [0] ['sid'], $search, $tooltip, $this->staff [0] ['cid'], $tagSQL );
 
- 			
 
- 			// 获取其他办事处的客户
 
- 			// if(!empty($districtstr)){
 
- 			// $buclient=$client->getClientByDistrict($districtstr);
 
- 			//
 
- 			// foreach ($buclient as $key=>$vlaue){
 
- 			//
 
- 			// $falg=true;
 
- 			//
 
- 			// foreach ($data['clientInfo'] as $y=>$v){
 
- 			// if($vlaue['clientname']==$v['clientname']&&$vlaue['companyname']==$v['companyname'])
 
- 			// $falg=false;
 
- 			// }
 
- 			// if($falg)
 
- 			// array_push($data['clientInfo'], $vlaue);
 
- 			// }
 
- 			//
 
- 			// }
 
- 		
 
- 		$k = "";
 
- 		for($i = 1; $i <= $pageinfo ['total_page']; $i ++) {
 
- 			if ($page == $i)
 
- 				$k .= "<option value='" . $search . ":" . $i . ":" . $lv1 . ":" . $lv2 . ":" . $lv3 . "' selected>第" . $i . "页</option>";
 
- 			else
 
- 				$k .= "<option value='" . $search . ":" . $i . ":" . $lv1 . ":" . $lv2 . ":" . $lv3 . "'>第" . $i . "页</option>";
 
- 		}
 
- 		
 
- 		$data ['pageinfo'] = $k;
 
- 		Doo::loadModel ( 'product' );
 
- 		$product = new product ();
 
- 		$data ['nature'] = $this->nature;
 
- 		$data ['product'] = $product->getProudct ();
 
- 		
 
- 		// 获得标签
 
- 		$ClientTagList = $tagClient->getTagClientBySid ( $this->staff [0] ['sid'] );
 
- 		
 
- 		$toollist = $c_tooltip->find ( array (
 
- 				'where' => 'cateid=' . $this->staff [0] ['cid'],
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		// $ToolTipList=$
 
- 		
 
- 		foreach ( $ClientTagList as $key => $value ) {
 
- 			$ClientTagList [$key] ['taginfo'] = $tag->getTagByTidL ( $value ['tag'] );
 
- 		}
 
- 		
 
- 		foreach ( $data ['clientInfo'] as $key => $value ) {
 
- 			if (! empty ( $value ['cid'] )) {
 
- 				// $tinfo=$tagClient->getTagClientBySCid($value['cid'], $this->staff[0]['sid']);
 
- 				$data ['clientInfo'] [$key] ['taginfo'] = array ();
 
- 				$data ['clientInfo'] [$key] ['tag'] = "";
 
- 				
 
- 				foreach ( $ClientTagList as $k => $v ) {
 
- 					// $tag->getTagByTidL($value['tag']);$value['tag'];
 
- 					if ($value ['cid'] == $v ['client']) {
 
- 						$data ['clientInfo'] [$key] ['taginfo'] = $v ['taginfo'];
 
- 						$data ['clientInfo'] [$key] ['tag'] = $v ['tag'];
 
- 					}
 
- 				}
 
- 				// array_pop 可以优化数组
 
- 			}
 
- 			
 
- 			$data ['clientInfo'] [$key] ['tooltipList'] = array ();
 
- 			
 
- 			foreach ( $toollist as $k => $v ) {
 
- 				if ($v ['cid'] == $value ['cid']) {
 
- 					$data ['clientInfo'] [$key] ['tooltipList'] = explode ( ",", $v ['name'] );
 
- 					break;
 
- 				} // array_pop 可以优化数组
 
- 			}
 
- 			
 
- 			// $tl=array();
 
- 			// if(!empty($value['tooltip']))
 
- 			// $tl=explode(',', $value['tooltip']);
 
- 			// $data['clientInfo'][$key]['tooltipList']=$tl;
 
- 			
 
- 			$data ['clientInfo'] [$key] ['locount'] = 0; // $longle->count(array('where'=>'clientid='.$value['cid']));
 
- 		}
 
- 		$CC1 = "";
 
- 		$CC2 = "";
 
- 		$CC3 = "";
 
- 		if (! empty ( $districtCount )) {
 
- 			$clientCount = $client->find ( array (
 
- 					'select' => 'district',
 
- 					'where' => "district like '" . $lv1 . ",%'",
 
- 					'asArray' => TRUE 
 
- 			) );
 
- 			$CC1 = count ( $clientCount );
 
- 			if (! empty ( $clientCount ) && ! empty ( $lv2 )) {
 
- 				$CC2 = 0;
 
- 				foreach ( $clientCount as $key => $value ) {
 
- 					if (strpos ( $value ['district'], ','.$lv2.',' )) {
 
- 						//echo $value ['district'].'<br/>';
 
- 						$CC2 ++;
 
- 					}
 
- 				}
 
- 			}
 
- 			
 
- 			if (! empty ( $clientCount ) && ! empty ( $lv3 )) {
 
- 				$CC3 = 0;
 
- 				foreach ( $clientCount as $key => $value ) {
 
- 					if (strpos ( $value ['district'], ','.$lv3 )) {
 
- 						$CC3 ++;
 
- 					}
 
- 				}
 
- 			}
 
- 		}
 
- 		
 
- 		Doo::loadModel ( 'remind' );
 
- 		$remind = new remind ();
 
- 		// and date_add(time, INTERVAL day DAY) <= CURDATE()
 
- 		$remindList = $remind->find ( array (
 
- 				'where' => "staffID = '" . $this->staff [0] ['sid'] . "' and status=0 ",
 
- 				'asc' => 'date_add(time, INTERVAL day DAY)',
 
- 				'asArray' => TRUE 
 
- 		) );
 
- 		$rc = 0;
 
- 		foreach ( $remindList as $key => $value ) {
 
- 			$a = strtotime ( $value ['time'] . " +" . $value ['day'] . " days" );
 
- 			$b = strtotime ( date ( 'y-m-d' ) );
 
- 			if ($a <= $b) {
 
- 				$rc ++;
 
- 				$remindList [$key] ['isRemind'] = 1;
 
- 			} else
 
- 				$remindList [$key] ['isRemind'] = 0;
 
- 			$remindList [$key] ['Ctime'] = date ( 'm-d', strtotime ( $value ['time'] ) );
 
- 			$remindList [$key] ['Etime'] = date ( 'm-d', strtotime ( $value ['time'] . " +" . $value ['day'] . " days" ) );
 
- 		}
 
- 		
 
- 		$token = $this->set_token ();
 
- 		$tokenTime=time().rand(5, 15);
 
- 		$_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
 
- 		$data['tokenTime']=$tokenTime;
 
- 		$data ['token'] = $token;
 
- 		
 
- 		$data ['remindCount'] = $rc;
 
- 		$data ['remindList'] = $remindList;
 
- 		$data ['CC1'] = $CC1;
 
- 		$data ['CC2'] = $CC2;
 
- 		$data ['CC3'] = $CC3;
 
- 		$data ['lv1'] = $lv1;
 
- 		$data ['lv2'] = $lv2;
 
- 		$data ['lv3'] = $lv3;
 
- 		$data ['lv4'] = $lv4;
 
- 		$data ['districtLv'] = $districtLv;
 
- 		$data ['tagList'] = $tagList;
 
- 		$data ['tooltip'] = $this->tooltip;
 
- 		$data ['ttip'] = $tooltip;
 
- 		$data ['search'] = $search;
 
- 		$data ['totalData'] = $pageinfo ['total_data'];
 
- 		// $data['messagehtml']=$html;
 
- 		$this->render ( "/contacts_client", $data );
 
- 	}
 
- 	function remindCL() {
 
- 		$rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
 
- 		
 
- 		Doo::loadModel ( 'remind' );
 
- 		$remind = new remind ();
 
- 		
 
- 		$remind->status = 1;
 
- 		$remind->update ( array (
 
- 				'where' => "staffID = '" . $this->staff [0] ['sid'] . "' and rid=" . $rid,
 
- 				'asArray' => TRUE 
 
- 		) );
 
- 		
 
- 		return "/contacts";
 
- 	}
 
- 	function communication() {
 
- 		$data ['memu'] = "contacts";
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		$cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
 
- 		
 
- 		Doo::loadModel ( 'L_category' );
 
- 		$L_category = new L_category ();
 
- 		Doo::loadModel ( 'staff' );
 
- 		$staff = new staff ();
 
- 		Doo::loadModel ( 'staffDynamic' );
 
- 		$staffDynamic = new staffDynamic ();
 
- 		
 
- 		if (! empty ( $cid ))
 
- 			$data ['staffList'] = $staff->getStaffByCid ( $cid );
 
- 		else
 
- 			$data ['staffList'] = $staff->getStaff ( true );
 
- 		
 
- 		foreach ( $data ['staffList'] as $key => $value ) {
 
- 			if (! empty ( $value ['birthday'] )) {
 
- 				$dataD = date ( "d", strtotime ( $value ['birthday'] ) );
 
- 				if (date ( 'm' ) == date ( "m", strtotime ( $value ['birthday'] ) )) {
 
- 					$now = date ( 'd' );
 
- 					$post = $dataD - 7; // date("d",mktime(0,0,0,date("m"),date("d")+7,date("Y")));
 
- 					if ($now >= $post && $now <= $dataD) {
 
- 						$data ['staffList'] [$key] ['birthday'] = "birthday";
 
- 						$data ['staffList'] [$key] ['birthDAY'] = date ( "m-d", strtotime ( $value ['birthday'] ) );
 
- 					}
 
- 				}
 
- 			}
 
- 			$happy = date ( "m-d", strtotime ( $value ['birthday'] ) );
 
- 			if ($happy == date ( 'm-d' )) {
 
- 				$SBL = $staffDynamic->getStaffBirthday ( $happy, $value ['sid'] );
 
- 				if (empty ( $SBL )) {
 
- 					$staffDynamic->content = '<img src="/global/img/cake.gif"><span class="colOrange">今天过生日!</span>';
 
- 					$staffDynamic->cid = $value ['cid'];
 
- 					$staffDynamic->category = $value ['category'];
 
- 					$staffDynamic->time = time ();
 
- 					$staffDynamic->sid = $value ['sid'];
 
- 					$staffDynamic->staff = $value ['username'];
 
- 					$staffDynamic->insert ();
 
- 				}
 
- 			}
 
- 		}
 
- 		
 
- 		$sDynaimic = $staffDynamic->getStaffDynamic ();
 
- 		foreach ( $sDynaimic as $key => $value ) {
 
- 			$time = date ( "Y-m-d", $value ['time'] );
 
- 			$timeArray = explode ( '-', $time );
 
- 			$sDynaimic [$key] ['year'] = $timeArray [0];
 
- 			$sDynaimic [$key] ['month'] = $timeArray [1];
 
- 			$sDynaimic [$key] ['day'] = $timeArray [2];
 
- 		}
 
- 		
 
- 		$data ['sDynaimic'] = $sDynaimic;
 
- 		
 
- 		$data ['category'] = $L_category->getCategory ();
 
- 		$data ['cid'] = $cid;
 
- 		
 
- 		$this->render ( "/staff_contacts", $data );
 
- 	}
 
- 	function app() {
 
- 		$data ['memu'] = "app";
 
- 		$data ['staff'] = $this->staff;
 
- 		$this->render ( "/app", $data );
 
- 	}
 
- 	function synClient() {
 
- 		if ($this->staff [0] ['isadmin'] != 1) {
 
- 			
 
- 			Doo::loadModel ( 'L_category' );
 
- 			Doo::loadModel ( 'client_staff' );
 
- 			
 
- 			$client_staff = new client_staff ();
 
- 			$cate = new L_category ();
 
- 			
 
- 			$district = $cate->getOne ( array (
 
- 					'where' => 'cid=' . $this->staff [0] ['cid'],
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			$syn = $client_staff->synClient ( $this->staff [0] ['sid'], $district ['districtid'] );
 
- 			
 
- 			$bei = $client_staff->find ( array (
 
- 					'where' => "sid = " . $this->staff [0] ['sid'],
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			foreach ( $syn as $value ) {
 
- 				
 
- 				$falg = true;
 
- 				
 
- 				foreach ( $bei as $v ) {
 
- 					if (($v ['cid'] == $value ['cid']) && ($v ['sid'] == $this->staff [0] ['sid'])) {
 
- 						$falg = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 				if ($falg) {
 
- 					$client_staff = new client_staff ();
 
- 					
 
- 					$client_staff->sid = $this->staff [0] ['sid'];
 
- 					$client_staff->cid = $value ['cid'];
 
- 					$client_staff->insert ();
 
- 				}
 
- 			}
 
- 		}
 
- 		return "/contacts";
 
- 	}
 
- 	function DoAddTagCompany() {
 
- 		$cid = $this->get_args ( 'id' );
 
- 		
 
- 		$tid = $this->get_args ( 'tagALD' );
 
- 		Doo::loadModel ( 'tagCompanyNexus' );
 
- 		$strtid = implode ( ",", $tid );
 
- 		
 
- 		foreach ( $cid as $key => $value ) {
 
- 			$tagClient = new tagCompanyNexus ();
 
- 			$tagClientInfo = $tagClient->getTagClientBySCid ( $value, $this->staff [0] ['sid'] );
 
- 			$ar = explode ( ",", $strtid . ',' . $tagClientInfo ['tag'] );
 
- 			$re = array_filter ( array_unique ( $ar ) );
 
- 			$tagClient->tag = implode ( ",", $re );
 
- 			if (! empty ( $tagClientInfo )) {
 
- 				$tagClient->tcid = $tagClientInfo ['tcid'];
 
- 				$tagClient->update ();
 
- 			} else {
 
- 				$tagClient->sid = $this->staff [0] ['sid'];
 
- 				$tagClient->company = $value;
 
- 				$tagClient->insert ();
 
- 			}
 
- 		}
 
- 		header ( "Location: /mycompany" );
 
- 	}
 
- 	function DoAddTag() {
 
- 		$cid = $this->get_args ( 'id' );
 
- 		$tooltipAct = $this->get_args ( 'tooltipAct' ) ? $this->get_args ( 'tooltipAct' ) : "";
 
- 		Doo::loadModel ( 'client' );
 
- 		
 
- 		if (! empty ( $tooltipAct )) {
 
- 			
 
- 			$tid = $this->get_args ( 'tooltiplist' );
 
- 			$k = implode ( ",", $tid );
 
- 			
 
- 			Doo::loadModel ( 'C_tooltip' );
 
- 			
 
- 			$s = " and cateid=" . $this->staff [0] ['cid'];
 
- 			
 
- 			if (! empty ( $this->staff [0] ['othercid'] )) {
 
- 				$othercid = explode ( ",", $this->staff [0] ['othercid'] );
 
- 				foreach ( $othercid as $value ) {
 
- 					$s .= " or cateid=" . $value;
 
- 				}
 
- 			}
 
- 			
 
- 			foreach ( $cid as $key => $value ) {
 
- 				$C_tooltip = new C_tooltip ();
 
- 				$tooltip = $C_tooltip->getOne ( array (
 
- 						'where' => 'cid=' . $value . " " . $s,
 
- 						'asArray' => true 
 
- 				) );
 
- 				
 
- 				if (empty ( $tooltip )) {
 
- 					$C_tooltip->cid = $value;
 
- 					$C_tooltip->name = $k;
 
- 					$C_tooltip->cateid = $this->staff [0] ['cid'];
 
- 					$C_tooltip->insert ();
 
- 				} else {
 
- 					$C_tooltip->tip = $tooltip ['tip'];
 
- 					$C_tooltip->name = $k;
 
- 					$C_tooltip->update ();
 
- 				}
 
- 			}
 
- 		} else {
 
- 			
 
- 			$tid = $this->get_args ( 'tagALD' );
 
- 			Doo::loadModel ( 'tag_client' );
 
- 			$strtid = implode ( ",", $tid );
 
- 			
 
- 			foreach ( $cid as $key => $value ) {
 
- 				$tagClient = new tag_client ();
 
- 				$tagClientInfo = $tagClient->getTagClientBySCid ( $value, $this->staff [0] ['sid'] );
 
- 				$ar = explode ( ",", $strtid . ',' . $tagClientInfo ['tag'] );
 
- 				$re = array_filter ( array_unique ( $ar ) );
 
- 				$tagClient->tag = implode ( ",", $re );
 
- 				if (! empty ( $tagClientInfo )) {
 
- 					$tagClient->tcid = $tagClientInfo ['tcid'];
 
- 					$tagClient->update ();
 
- 				} else {
 
- 					$tagClient->sid = $this->staff [0] ['sid'];
 
- 					$tagClient->client = $value;
 
- 					$tagClient->insert ();
 
- 				}
 
- 			}
 
- 		}
 
- 		header ( "Location: /contacts" );
 
- 	}
 
- 	function ajaxDeleteTag() {
 
- 		$cid = $this->get_args ( 'cid' );
 
- 		$tid = $this->get_args ( 'tid' );
 
- 		
 
- 		Doo::loadModel ( 'tag_client' );
 
- 		$tagClient = new tag_client ();
 
- 		
 
- 		$tagInfo = $tagClient->getTagClientBySCid ( $cid, $this->staff [0] ['sid'] );
 
- 		$tag = str_replace ( $tid, "", $tagInfo ['tag'] );
 
- 		
 
- 		$ar = explode ( ',', $tag );
 
- 		$tag = implode ( ',', array_filter ( $ar ) );
 
- 		$tagClient->tcid = $tagInfo ['tcid'];
 
- 		$tagClient->tag = $tag;
 
- 		
 
- 		$tagClient->update ();
 
- 	}
 
- 	function ajaxDeleteTagCompany() {
 
- 		$cid = $this->get_args ( 'cid' );
 
- 		$tid = $this->get_args ( 'tid' );
 
- 		
 
- 		Doo::loadModel ( 'tagCompanyNexus' );
 
- 		$tagClient = new tagCompanyNexus ();
 
- 		
 
- 		$tagInfo = $tagClient->getTagClientBySCid ( $cid, $this->staff [0] ['sid'] );
 
- 		$tag = str_replace ( $tid, "", $tagInfo ['tag'] );
 
- 		
 
- 		$ar = explode ( ',', $tag );
 
- 		$tag = implode ( ',', array_filter ( $ar ) );
 
- 		$tagClient->tcid = $tagInfo ['tcid'];
 
- 		$tagClient->tag = $tag;
 
- 		
 
- 		$tagClient->update ();
 
- 	}
 
- 	function deleteToolTip() {
 
- 		$cid = $this->get_args ( 'cid' );
 
- 		
 
- 		$cateid = $this->get_args ( 'cateid' );
 
- 		$name = $this->get_args ( 'name' );
 
- 		
 
- 		Doo::loadModel ( "C_tooltip" );
 
- 		
 
- 		$tooltip = new C_tooltip ();
 
- 		
 
- 		if (! empty ( $cid ) && ! empty ( $cateid ) && ! empty ( $name )) {
 
- 			$tool = $tooltip->getOne ( array (
 
- 					'where' => 'cid=' . $cid . ' and cateid=' . $cateid,
 
- 					'asArray' => true 
 
- 			) );
 
- 			if (! empty ( $tool )) {
 
- 				$name = str_replace ( $name, "", $tool ['name'] );
 
- 				
 
- 				$name = explode ( ',', $name );
 
- 				
 
- 				$name = implode ( ',', array_filter ( $name ) );
 
- 				
 
- 				$tooltip->name = $name;
 
- 				
 
- 				$tooltip->tip = $tool ['tip'];
 
- 				
 
- 				$tooltip->update ();
 
- 			}
 
- 		}
 
- 	}
 
- 	function DoEdiTagCompany() {
 
- 		$tag_1 = $this->get_args ( 'tag_1' ) ? $this->get_args ( 'tag_1' ) : "";
 
- 		$tag_2 = $this->get_args ( 'tag_2' ) ? $this->get_args ( 'tag_2' ) : "";
 
- 		$tag_3 = $this->get_args ( 'tag_3' ) ? $this->get_args ( 'tag_3' ) : "";
 
- 		$tag_4 = $this->get_args ( 'tag_4' ) ? $this->get_args ( 'tag_4' ) : "";
 
- 		$tag_5 = $this->get_args ( 'tag_5' ) ? $this->get_args ( 'tag_5' ) : "";
 
- 		$tag_6 = $this->get_args ( 'tag_6' ) ? $this->get_args ( 'tag_6' ) : "";
 
- 		$tag_7 = $this->get_args ( 'tag_7' ) ? $this->get_args ( 'tag_7' ) : "";
 
- 		
 
- 		$tid_1 = $this->get_args ( 'tid_1' ) ? $this->get_args ( 'tid_1' ) : 0;
 
- 		$tid_2 = $this->get_args ( 'tid_2' ) ? $this->get_args ( 'tid_2' ) : 0;
 
- 		$tid_3 = $this->get_args ( 'tid_3' ) ? $this->get_args ( 'tid_3' ) : 0;
 
- 		$tid_4 = $this->get_args ( 'tid_4' ) ? $this->get_args ( 'tid_4' ) : 0;
 
- 		$tid_5 = $this->get_args ( 'tid_5' ) ? $this->get_args ( 'tid_5' ) : 0;
 
- 		$tid_6 = $this->get_args ( 'tid_6' ) ? $this->get_args ( 'tid_6' ) : 0;
 
- 		$tid_7 = $this->get_args ( 'tid_7' ) ? $this->get_args ( 'tid_7' ) : 0;
 
- 		
 
- 		Doo::loadModel ( 'tagCompany' );
 
- 		
 
- 		if (! empty ( $tag_1 ) && ! empty ( $tid_1 )) {
 
- 			
 
- 			$tag = new tagCompany ();
 
- 			
 
- 			$tag->tid = $tid_1;
 
- 			
 
- 			$tag->name = $tag_1;
 
- 			
 
- 			$tag->update ();
 
- 		}
 
- 		if (! empty ( $tag_2 ) && ! empty ( $tid_2 )) {
 
- 			$tag = new tagCompany ();
 
- 			
 
- 			$tag->tid = $tid_2;
 
- 			
 
- 			$tag->name = $tag_2;
 
- 			
 
- 			$tag->update ();
 
- 		}
 
- 		if (! empty ( $tag_3 ) && ! empty ( $tid_3 )) {
 
- 			$tag = new tagCompany ();
 
- 			
 
- 			$tag->tid = $tid_3;
 
- 			
 
- 			$tag->name = $tag_3;
 
- 			
 
- 			$tag->update ();
 
- 		}
 
- 		if (! empty ( $tag_4 ) && ! empty ( $tid_4 )) {
 
- 			$tag = new tagCompany ();
 
- 			
 
- 			$tag->tid = $tid_4;
 
- 			
 
- 			$tag->name = $tag_4;
 
- 			
 
- 			$tag->update ();
 
- 		}
 
- 		if (! empty ( $tag_5 ) && ! empty ( $tid_5 )) {
 
- 			$tag = new tagCompany ();
 
- 			
 
- 			$tag->tid = $tid_5;
 
- 			
 
- 			$tag->name = $tag_5;
 
- 			
 
- 			$tag->update ();
 
- 		}
 
- 		if (! empty ( $tag_6 ) && ! empty ( $tid_6 )) {
 
- 			$tag = new tagCompany ();
 
- 			
 
- 			$tag->tid = $tid_6;
 
- 			
 
- 			$tag->name = $tag_6;
 
- 			
 
- 			$tag->update ();
 
- 		}
 
- 		if (! empty ( $tag_7 ) && ! empty ( $tid_7 )) {
 
- 			$tag = new tagCompany ();
 
- 			
 
- 			$tag->tid = $tid_7;
 
- 			
 
- 			$tag->name = $tag_7;
 
- 			
 
- 			$tag->update ();
 
- 		}
 
- 		
 
- 		return "/mycompany";
 
- 	}
 
- 	function DoEdiTag() {
 
- 		$tag_1 = $this->get_args ( 'tag_1' ) ? $this->get_args ( 'tag_1' ) : "";
 
- 		$tag_2 = $this->get_args ( 'tag_2' ) ? $this->get_args ( 'tag_2' ) : "";
 
- 		$tag_3 = $this->get_args ( 'tag_3' ) ? $this->get_args ( 'tag_3' ) : "";
 
- 		$tag_4 = $this->get_args ( 'tag_4' ) ? $this->get_args ( 'tag_4' ) : "";
 
- 		$tag_5 = $this->get_args ( 'tag_5' ) ? $this->get_args ( 'tag_5' ) : "";
 
- 		$tag_6 = $this->get_args ( 'tag_6' ) ? $this->get_args ( 'tag_6' ) : "";
 
- 		$tag_7 = $this->get_args ( 'tag_7' ) ? $this->get_args ( 'tag_7' ) : "";
 
- 		
 
- 		$tid_1 = $this->get_args ( 'tid_1' ) ? $this->get_args ( 'tid_1' ) : 0;
 
- 		$tid_2 = $this->get_args ( 'tid_2' ) ? $this->get_args ( 'tid_2' ) : 0;
 
- 		$tid_3 = $this->get_args ( 'tid_3' ) ? $this->get_args ( 'tid_3' ) : 0;
 
- 		$tid_4 = $this->get_args ( 'tid_4' ) ? $this->get_args ( 'tid_4' ) : 0;
 
- 		$tid_5 = $this->get_args ( 'tid_5' ) ? $this->get_args ( 'tid_5' ) : 0;
 
- 		$tid_6 = $this->get_args ( 'tid_6' ) ? $this->get_args ( 'tid_6' ) : 0;
 
- 		$tid_7 = $this->get_args ( 'tid_7' ) ? $this->get_args ( 'tid_7' ) : 0;
 
- 		
 
- 		Doo::loadModel ( 'tag' );
 
- 		
 
- 		if (! empty ( $tag_1 ) && ! empty ( $tid_1 )) {
 
- 			
 
- 			$tag = new tag ();
 
- 			$tag->tid = $tid_1;
 
- 			$tag->name = $tag_1;
 
- 			$tag->update ();
 
- 		}
 
- 		if (! empty ( $tag_2 ) && ! empty ( $tid_2 )) {
 
- 			$tag = new tag ();
 
- 			$tag->tid = $tid_2;
 
- 			$tag->name = $tag_2;
 
- 			$tag->update ();
 
- 		}
 
- 		if (! empty ( $tag_3 ) && ! empty ( $tid_3 )) {
 
- 			$tag = new tag ();
 
- 			$tag->tid = $tid_3;
 
- 			$tag->name = $tag_3;
 
- 			$tag->update ();
 
- 		}
 
- 		if (! empty ( $tag_4 ) && ! empty ( $tid_4 )) {
 
- 			$tag = new tag ();
 
- 			$tag->tid = $tid_4;
 
- 			$tag->name = $tag_4;
 
- 			$tag->update ();
 
- 		}
 
- 		if (! empty ( $tag_5 ) && ! empty ( $tid_5 )) {
 
- 			$tag = new tag ();
 
- 			$tag->tid = $tid_5;
 
- 			$tag->name = $tag_5;
 
- 			$tag->update ();
 
- 		}
 
- 		if (! empty ( $tag_6 ) && ! empty ( $tid_6 )) {
 
- 			$tag = new tag ();
 
- 			$tag->tid = $tid_6;
 
- 			$tag->name = $tag_6;
 
- 			$tag->update ();
 
- 		}
 
- 		if (! empty ( $tag_7 ) && ! empty ( $tid_7 )) {
 
- 			$tag = new tag ();
 
- 			$tag->tid = $tid_7;
 
- 			$tag->name = $tag_7;
 
- 			$tag->update ();
 
- 		}
 
- 		
 
- 		return "/contacts";
 
- 	}
 
- 	function ajaxGetLv2() {
 
- 		$lv1 = $this->get_args ( 'lv1' ) ? $this->get_args ( 'lv1' ) : 0;
 
- 		$s = $this->get_args ( 's' ) ? $this->get_args ( 's' ) : 0;
 
- 		
 
- 		if ($lv1 == 0) {
 
- 			echo json_encode ( array (
 
- 					"success" => false,
 
- 					"info" => "" 
 
- 			) );
 
- 			die ();
 
- 		}
 
- 		
 
- 		if (! empty ( $lv1 )) {
 
- 			Doo::loadModel ( 'district' );
 
- 			$district = new district ();
 
- 			$district = $district->get_lvByid ( $s, $lv1 );
 
- 			echo json_encode ( array (
 
- 					"success" => true,
 
- 					"info" => $district 
 
- 			) );
 
- 		}
 
- 	}
 
- 	function keyonline() {
 
- 		$data ['memu'] = "keyonline";
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		$year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
 
- 		if (empty ( $year ))
 
- 			$year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( 'Y' );
 
- 		$cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
 
- 		if (empty ( $cid ))
 
- 			$cid = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : $this->staff [0] ['cid'];
 
- 		$staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
 
- 		if (empty ( $staff ))
 
- 			$staff = isset ( $this->params ['staff'] ) ? $this->params ['staff'] : "";
 
- 		$status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "";
 
- 		if (empty ( $status ))
 
- 			$status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 0;
 
- 		$search = $this->get_args ( 'search' ) ? $this->get_args ( 'search' ) : "";
 
- 		
 
- 		$productW = $this->get_args ( 'product' ) ? $this->get_args ( 'product' ) : "";
 
-         $lidKey = $this->get_args ( 'lid' ) ? $this->get_args ( 'lid' ) : "";
 
- 		Doo::loadModel ( 'longle' );
 
- 		$longle = new longle ();
 
-         Doo::loadClass ( 'XDeode' );
 
-         $XDeode = new XDeode ( 5 );
 
-         Doo::loadModel ( 'longle_log' );
 
-         $longle_log = new longle_log ();
 
-         $lid =0;
 
-         if(!empty($lidKey)){
 
-             $lid = $XDeode->decode ( $lidKey );
 
-         }
 
- 		$data ['longleArray'] = $longle->getLongleByStatus ( $year, $cid, $staff, $status, $search, $productW );
 
-         $longleDetail=$longle->getLongleByLid($lid);
 
-         $longleLogDetail=$longle_log->getLongleByLid ( $lid );
 
- 		// 获取接收锁信息
 
- 		// $longle->getLongleByRe($this->staff[0]['cid'],1);
 
- 		$othstr = "";
 
- 		if (! empty ( $this->staff [0] ['othercid'] ))
 
- 			$othstr = " cid in (" . $this->staff [0] ['cid'] . "," . $this->staff [0] ['othercid'] . ")";
 
- 		else
 
- 			$othstr = " cid in (" . $this->staff [0] ['cid'] . ")";
 
- 		
 
- 		$data ['reLongle'] = $longle->count ( array (
 
- 				'where' => $othstr . '  and status=1' 
 
- 		) );
 
-         $data['lidKey']=$lidKey;
 
-         if (isset($longleDetail[0])){
 
-             $data['longleDetail']=$longleDetail[0];
 
-             
 
-         }else{
 
-             $data['longleDetail']=array();
 
-         }
 
-         $data ['longleLogHtml'] = $this->_getLongleLogHtml ( $longleLogDetail );
 
- 		$data ['cid'] = $cid;
 
- 		$data ['year'] = $year;
 
- 		$data ['staff'] = $staff;
 
- 		$data ['status'] = $status;
 
- 		$data ['productName'] = $productW;
 
-         $data ['search'] =$search;
 
- 		
 
- 		Doo::loadModel ( 'L_category' );
 
- 		Doo::loadModel ( 'staff' );
 
- 		Doo::loadModel ( 'product' );
 
- 		
 
- 		$product = new product ();
 
- 		$staff = new staff ();
 
- 		
 
- 		$L_category = new L_category ();
 
- 		
 
- 		$data ['product'] = $product->getProudct ();
 
- 		
 
- 		$data ['staffu'] = $staff->getUserById ( $this->staff [0] ['sid'] );
 
- 		$data ['category'] = $L_category->getCategory ();
 
- 		$data ['staffList'] = $staff->getStaffByCid ( $cid );
 
- 		
 
- 		if ($cid == 1)
 
- 			$data ['cid'] = $data ['category'] [0] ['cid'];
 
- 		
 
- 		$dateHtml = "";
 
- 		$now = date ( "Y" );
 
- 		for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
 
- 			
 
- 			if ($YEARD <= $now) {
 
- 				$dateHtml .= '<option ';
 
- 				if ($data ['year'] == $YEARD) {
 
- 					$dateHtml .= 'selected ';
 
- 				}
 
- 				$dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
 
- 			}
 
- 		}
 
- 		
 
- 		$data ['dateHtml'] = $dateHtml;
 
- 		$this->render ( "/lock_look", $data );
 
- 	}
 
- 	function keyStatistics() {
 
- 		Doo::loadModel ( 'staff' );
 
- 		$staff = new staff ();
 
- 		Doo::loadModel ( 'longle' );
 
- 		$longle = new longle ();
 
- 		
 
- 		Doo::loadModel ( 'L_category' );
 
- 		$L_category = new L_category ();
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 5 );
 
- 		
 
- 		$cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
 
- 		
 
- 		
 
- 		$staffCondition = "";
 
- 		if ($this->staff [0] ['cid'] != 12){
 
- 			$staffCondition = " and cid=" . $this->staff [0] ['cid'];
 
- 			$cid=$this->staff [0] ['cid'];
 
- 		}else{
 
- 			$cid=$this->staff [0] ['cid'];
 
- 			if (!empty($cidKey)){
 
- 				$cid = $XDeode->decode ( $cidKey );
 
- 				if (! is_numeric ( $cid )){
 
- 					$cid=$this->staff [0] ['cid'];
 
- 				}
 
- 			}
 
- 			$staffCondition = " and cid=" . $cid;
 
- 		}
 
- 		
 
- 		$staffList = $staff->find ( array (
 
- 				'where' => "isadmin= 0 and nature !=4  " . $staffCondition,
 
- 				'asArray' => TRUE 
 
- 		) );
 
- 		
 
- 		
 
- 		
 
- 		
 
- 		//
 
- 		$sql = "select COUNT(*) as count,responsible
 
- 				from CLD_longle
 
- 				where status!= 1 and make_day >='2019-12-01'
 
- 				GROUP BY responsible";
 
- 		$query = Doo::db ()->query ( $sql );
 
- 		$resultSum = $query->fetchAll ();
 
- 		
 
- 		$sql = "select COUNT(*) as count,responsible
 
- 				from CLD_longle
 
- 				where status!= 2 and status!= 1 and make_day >='2019-12-01'
 
- 				GROUP BY responsible";
 
- 		$query = Doo::db ()->query ( $sql );
 
- 		$resultA = $query->fetchAll ();
 
- 		
 
- 		foreach ( $staffList as $key => $value ) {
 
- 			$sum=$a=0;
 
- 			foreach ($resultSum as $k=>$v){
 
- 				if($value ['username']==$v['responsible']){
 
- 					$sum=$v['count'];
 
- 					break;
 
- 				}
 
- 			}
 
- 			
 
- 			foreach ($resultA as $k=>$v){
 
- 				if($value ['username']==$v['responsible']){
 
- 					$a=$v['count'];
 
- 					break;
 
- 				}
 
- 			}
 
- 			
 
- 			$b = $sum - $a;
 
- 			$staffList [$key] ['sum'] = $sum;
 
- 			$staffList [$key] ['a'] = $a;
 
- 			$staffList [$key] ['b'] = $b;
 
- 		}
 
- 		
 
- 		
 
- 		
 
- 		
 
- 		
 
- 		
 
- 		
 
- 		
 
- 		
 
- 		
 
- 		
 
- 		
 
- 		
 
- 		/* Doo::db ()->beginTransaction ();
 
- 		foreach ( $staffList as $key => $value ) { // not in(1,2)
 
- 			$sum = $longle->count ( array (
 
- 					'where' => "status!= 1 and responsible ='" . $value ['username'] . "' and make_day >='2019-12-01'",
 
- 					'asArray' => TRUE 
 
- 			) );
 
- 			$a = $longle->count ( array (
 
- 					'where' => "status!= 2 and status!= 1 and responsible ='" . $value ['username'] . "' and make_day >='2019-12-01'",
 
- 					'asArray' => TRUE 
 
- 			) );
 
- 			
 
- 			$b = $sum - $a;
 
- 			$staffList [$key] ['sum'] = $sum;
 
- 			$staffList [$key] ['a'] = $a;
 
- 			$staffList [$key] ['b'] = $b;
 
- 		}
 
- 		Doo::db ()->commit (); */
 
- 		
 
- 		$data ['cid'] = $cid;
 
- 		
 
- 		$data ['category'] = $L_category->getCategory ();
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		$data ['staffList'] = $staffList;
 
- 		$data ['memu'] = "keyStatistics";
 
- 		$this->render ( "lock_count", $data );
 
- 	}
 
- 	function addDoLockLog() {
 
- 		Doo::loadModel ( 'longle_log' );
 
- 		Doo::loadModel ( 'longle' );
 
- 		Doo::loadModel ( "action_log" );
 
- 		Doo::loadModel ( 'client' );
 
- 		$clientobj = new client ();
 
- 		$longle = new longle ();
 
- 		$longle_log = new longle_log ();
 
- 		Doo::loadModel ( 'district' );
 
- 		$district = new district ();
 
- 		
 
- 		$status = $this->get_args ( 'longleStatus' ) ? $this->get_args ( 'longleStatus' ) : 0;
 
- 		$lidKey = $this->get_args ( 'klid' ) ? $this->get_args ( 'klid' ) : 0;
 
- 		$name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
 
- 		$company = $this->get_args ( 'company' ) ? $this->get_args ( 'company' ) : '';
 
-         $alloted_time = $this->get_args ( 'alloted_time' ) ? $this->get_args ( 'alloted_time' ) : '';
 
- 		
 
- 		if (empty ( $lidKey ))
 
- 			return "/keyonline/";
 
-         Doo::loadClass ( 'XDeode' );
 
-         $XDeode = new XDeode ( 5 );
 
-         $lid = $XDeode->decode ( $lidKey );
 
- 		$linfo = $longle->getLongleByLid ( $lid );
 
- 		
 
- 		if ($status == 0)
 
- 			return "/keyonline/" . $lid;
 
- 		elseif ($status == 3) {
 
- 			
 
- 			$clientname = $clientobj->getClientByName2 ( $name, $company );
 
- 			
 
- 			if (empty ( $clientname ))
 
- 				return "/keyonline/" . $lid;
 
- 			
 
- 			if ($name != "") {
 
- 				$longle->client = $name;
 
- 				$longle->clientid = $clientname [0] ['cid'];
 
- 			}
 
- 			// if($product!="")
 
- 			// $longle->product=$product;
 
- 			
 
- 			$longle->statusT = "借出";
 
- 			
 
- 			$longle_log->client = $name;
 
- 			$longle_log->clientid = $clientname [0] ['cid'];
 
- 			$longle_log->product = $linfo [0] ['product'];
 
- 			$longle_log->statusT = "借出";
 
- 			// 日常行为
 
- 			$action_log = new action_log ();
 
- 			
 
- 			$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'] . ')';
 
- 			$action_log->sid = $this->staff [0] ['sid'];
 
- 			$action_log->cid = $this->staff [0] ['cid'];
 
- 			$action_log->updatetime = date ( "Y-m-d" );
 
- 			$action_log->time = date ( "H:i" );
 
- 			$action_log->status = 4;
 
- 			$action_log->districtid = $clientname [0] ['district'];
 
- 			
 
- 			$local = $district->getbyidlist ( $clientname [0] ['district'] );
 
- 			$action_log->city = $local [0] ['name'];
 
- 			$action_log->province = $local [1] ['name'];
 
- 			$action_log->company = $clientname [0] ['companyname'];
 
- 			
 
- 			Doo::loadModel ( 'company' );
 
- 			$company = new company ();
 
- 			$companyInfo = $company->getOne ( array (
 
- 					'where' => ' companyname="' . $clientname [0] ['companyname'] . '"',
 
- 					'asArray' => true 
 
- 			) );
 
- 			$nature = explode ( ',', $companyInfo ['nature'] );
 
- 			$action_log->nature = $nature [0];
 
- 			
 
- 			$action_log->class = $action_log->iconBorrow;
 
- 			
 
- 			$action_log->insert ();
 
- 		} elseif ($status == 4) {
 
- 			
 
- 			$clientname = $clientobj->getClientByName2 ( $name, $company );
 
- 			
 
- 			if (empty ( $clientname ))
 
- 				return "/keyonline/" . $lid;
 
- 			
 
- 			if ($name != "") {
 
- 				$longle->client = $name;
 
- 				$longle->clientid = $clientname [0] ['cid'];
 
- 			}
 
- 			
 
- 			$longle->statusT = "销售";
 
- 			
 
- 			$longle_log->client = $name;
 
- 			$longle_log->clientid = $clientname [0] ['cid'];
 
- 			$longle_log->product = $linfo [0] ['product'];
 
- 			$longle_log->statusT = "销售";
 
- 			
 
- 			// 日常行为
 
- 			$action_log = new action_log ();
 
- 			
 
- 			$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'] . ')';
 
- 			$action_log->sid = $this->staff [0] ['sid'];
 
- 			$action_log->cid = $this->staff [0] ['cid'];
 
- 			$action_log->updatetime = date ( "Y-m-d" );
 
- 			$action_log->time = date ( "H:i" );
 
- 			$action_log->status = 5;
 
- 			$action_log->districtid = $clientname [0] ['district'];
 
- 			
 
- 			$local = $district->getbyidlist ( $clientname [0] ['district'] );
 
- 			$action_log->city = $local [0] ['name'];
 
- 			$action_log->province = $local [1] ['name'];
 
- 			$action_log->company = $clientname [0] ['companyname'];
 
- 			
 
- 			Doo::loadModel ( 'company' );
 
- 			$company = new company ();
 
- 			$companyInfo = $company->getOne ( array (
 
- 					'where' => ' companyname="' . $clientname [0] ['companyname'] . '"',
 
- 					'asArray' => true 
 
- 			) );
 
- 			$nature = explode ( ',', $companyInfo ['nature'] );
 
- 			$action_log->nature = $nature [0];
 
- 			
 
- 			$action_log->class = $action_log->iconSell;
 
- 			
 
- 			$action_log->insert ();
 
- 		} elseif ($status == 5) {
 
- 			
 
- 			$product = $this->get_args ( 'newProduct' ) ? $this->get_args ( 'newProduct' ) : "";
 
- 			
 
- 			if ($product != "")
 
- 				$longle->product = $linfo [0] ['product'] . "+" . $product;
 
- 			
 
- 			$longle->statusT = "升级";
 
- 			$longle_log->product = $linfo [0] ['product'] . "+" . $product;
 
- 			$longle_log->statusT = "升级";
 
- 			
 
- 			$longle_log->client = $linfo [0] ['client'];
 
- 			$longle_log->clientid = $linfo [0] ['clientid'];
 
- 			
 
- 			$clientname = $clientobj->getOne ( array (
 
- 					'where' => "cid= '" . $linfo [0] ['clientid'] . "'",
 
- 					'asArray' => TRUE 
 
- 			) );
 
- 			
 
- 			// 日常行为
 
- 			$action_log = new action_log ();
 
- 			
 
- 			$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>';
 
- 			$action_log->sid = $this->staff [0] ['sid'];
 
- 			$action_log->cid = $this->staff [0] ['cid'];
 
- 			$action_log->updatetime = date ( "Y-m-d" );
 
- 			$action_log->time = date ( "H:i" );
 
- 			$action_log->class = $action_log->iconUpdate;
 
- 			$action_log->sid = $this->staff [0] ['sid'];
 
- 			$action_log->cid = $this->staff [0] ['cid'];
 
- 			$action_log->status = 7;
 
- 			
 
- 			$action_log->insert ();
 
- 		} elseif ($status == 6) {
 
- 			
 
- 			$key_num = $this->get_args ( 'key_num' ) ? $this->get_args ( 'key_num' ) : "";
 
- 			
 
- 			$key_num2 = explode ( "-", $key_num );
 
- 			
 
- 			$key_num = $key_num2 [0] . "-" . $key_num2 [1];
 
- 			
 
- 			// if($key_num!="")
 
- 			// $longle->key_num=$key_num;
 
- 			
 
- 			// 新锁拷贝记录
 
- 			
 
- 			$newLongle = new longle ();
 
- 			// $newLongle->product=$linfo[0]['product'];
 
- 			$newLongle->statusT = "更换";
 
- 			$newLongle->status = 6;
 
- 			$newLongle->client = $linfo [0] ['client'];
 
- 			$newLongle->clientid = $linfo [0] ['clientid'];
 
- 			
 
- 			$newlid = $newLongle->update ( array (
 
- 					'where' => ' key_num= \'' . $key_num . "'" 
 
- 			) );
 
- 			$longleinfo = $longle->getOne ( array (
 
- 					'where' => ' key_num =\'' . $key_num . "'",
 
- 					'asArray' => true 
 
- 			) );
 
- 			$longleLog = $longle_log->getOne ( array (
 
- 					'where' => ' lid =' . $linfo [0] ['lid'],
 
- 					'desc' => 'logid',
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			// 新记录日志
 
- 			$newlongle_log = new longle_log ();
 
- 			$newlongle_log->statusT = "更换";
 
- 			$newlongle_log->status = 6;
 
- 			$newlongle_log->client = $linfo [0] ['client'];
 
- 			$newlongle_log->new_key_num = $linfo [0] ['key_num'];
 
- 			$newlongle_log->product = $linfo [0] ['product'];
 
- 			$newlongle_log->category = $this->staff [0] ['category'];
 
- 			$newlongle_log->dateline = date ( "Y-m-d" );
 
- 			$newlongle_log->operator = $this->staff [0] ['username'];
 
- 			$newlongle_log->lid = $longleinfo ['lid'];
 
- 			$newlongle_log->insert ();
 
- 			
 
- 			$newlongle_log = new longle_log ();
 
- 			$newlongle_log->statusT = $longleLog ['statusT'];
 
- 			$newlongle_log->status = $longleLog ['status'];
 
- 			$newlongle_log->client = $longleLog ['client'];
 
- 			$newlongle_log->new_key_num = $longleLog ['new_key_num'];
 
- 			$newlongle_log->product = $longleLog ['product'];
 
- 			$newlongle_log->category = $longleLog ['category'];
 
- 			$newlongle_log->dateline = $longleLog ['dateline'];
 
- 			$newlongle_log->operator = $longleLog ['operator'];
 
- 			$newlongle_log->lid = $longleinfo ['lid'];
 
- 			$newlongle_log->insert ();
 
- 			
 
- 			$newLongle = new longle ();
 
- 			
 
- 			$newLongle->statusT = $longleLog ['statusT'];
 
- 			$newLongle->status = $longleLog ['status'];
 
- 			
 
- 			$newlid = $newLongle->update ( array (
 
- 					'where' => ' key_num= \'' . $key_num . "'" 
 
- 			) );
 
- 			
 
- 			// 新锁状态拷贝
 
- 			$longle->statusT = "更换";
 
- 			
 
- 			$longle_log->new_key_num = $key_num;
 
- 			$longle_log->statusT = "更换";
 
- 			
 
- 			$longle_log->client = $linfo [0] ['client'];
 
- 			
 
- 			$clientname = $clientobj->getOne ( array (
 
- 					'where' => "cid= '" . $linfo [0] ['clientid'] . "'",
 
- 					'asArray' => TRUE 
 
- 			) );
 
- 			
 
- 			// 日常行为
 
- 			$action_log = new action_log ();
 
- 			
 
- 			$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'] . ')';
 
- 			$action_log->sid = $this->staff [0] ['sid'];
 
- 			$action_log->cid = $this->staff [0] ['cid'];
 
- 			$action_log->updatetime = date ( "Y-m-d" );
 
- 			$action_log->time = date ( "H:i" );
 
- 			$action_log->class = $action_log->iconReplace;
 
- 			$action_log->sid = $this->staff [0] ['sid'];
 
- 			$action_log->cid = $this->staff [0] ['cid'];
 
- 			$action_log->status = 8;
 
- 			
 
- 			$action_log->insert ();
 
- 		} elseif ($status == 7) {
 
- 			
 
- 			$longle->statusT = "收回";
 
- 			$longle_log->statusT = "收回";
 
- 			$longle_log->responsible = $linfo [0] ['responsible'];
 
- 			
 
- 			// 日常行为
 
- 			$action_log = new action_log ();
 
- 			
 
- 			$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>';
 
- 			$action_log->sid = $this->staff [0] ['sid'];
 
- 			$action_log->cid = $this->staff [0] ['cid'];
 
- 			$action_log->updatetime = date ( "Y-m-d" );
 
- 			$action_log->time = date ( "H:i" );
 
- 			$action_log->class = $action_log->iconRecycle;
 
- 			$action_log->sid = $this->staff [0] ['sid'];
 
- 			$action_log->cid = $this->staff [0] ['cid'];
 
- 			$action_log->status = 9;
 
- 			
 
- 			$action_log->insert ();
 
- 		} elseif ($status == 8) {
 
- 			$mark = $this->get_args ( 'mark' ) ? $this->get_args ( 'mark' ) : "";
 
- 			
 
- 			if (empty ( $mark )) {
 
- 				echo json_encode ( array (
 
- 						'msg' => 2 
 
- 				) );
 
- 				die ();
 
- 			}
 
- 			
 
- 			$longle_log->mark = $mark;
 
- 			// 日常行为
 
- 			$action_log = new action_log ();
 
- 			
 
- 			$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>添加新备注。';
 
- 			$action_log->sid = $this->staff [0] ['sid'];
 
- 			$action_log->cid = $this->staff [0] ['cid'];
 
- 			$action_log->updatetime = date ( "Y-m-d" );
 
- 			$action_log->time = date ( "H:i" );
 
- 			$action_log->sid = $this->staff [0] ['sid'];
 
- 			$action_log->cid = $this->staff [0] ['cid'];
 
- 			$action_log->status = 10;
 
- 			
 
- 			$action_log->class = $action_log->iconLock;
 
- 			
 
- 			$action_log->insert ();
 
- 		} elseif ($status == 9) {
 
- 			$longle->statusT = "赠送";
 
- 			$longle_log->statusT = "赠送";
 
- 			
 
- 			$clientname = $clientobj->getClientByName2 ($name, $company );
 
- 			
 
- 			if (empty ( $clientname ))
 
- 				return "/keyonline/" . $lid;
 
- 			
 
- 			if ($name != "") {
 
- 				$longle->client = $name;
 
- 				$longle->clientid = $clientname [0] ['cid'];
 
- 			}
 
- 			$longle_log->client = $name;
 
- 			$longle_log->clientid = $clientname [0] ['cid'];
 
- 			
 
- 			// 日常行为
 
- 			$action_log = new action_log ();
 
- 			$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'] . ')';
 
- 			$action_log->updatetime = date ( "Y-m-d" );
 
- 			$action_log->time = date ( "H:i" );
 
- 			$action_log->class = $action_log->iconRecycle;
 
- 			$action_log->sid = $this->staff [0] ['sid'];
 
- 			$action_log->cid = $this->staff [0] ['cid'];
 
- 			$action_log->status = 6;
 
- 			
 
- 			$action_log->districtid = $clientname [0] ['district'];
 
- 			
 
- 			$local = $district->getbyidlist ( $clientname [0] ['district'] );
 
- 			$action_log->city = $local [0] ['name'];
 
- 			$action_log->province = $local [1] ['name'];
 
- 			$action_log->company = $clientname [0] ['companyname'];
 
- 			
 
- 			Doo::loadModel ( 'company' );
 
- 			$company = new company ();
 
- 			$companyInfo = $company->getOne ( array (
 
- 					'where' => ' companyname="' . $clientname [0] ['companyname'] . '"',
 
- 					'asArray' => true 
 
- 			) );
 
- 			$nature = explode ( ',', $companyInfo ['nature'] );
 
- 			$action_log->nature = $nature [0];
 
- 			
 
- 			$action_log->insert ();
 
- 		}elseif($status == 10){
 
-             $longle->alloted_time = $alloted_time;
 
-             $longle_log->mark ='由'.$linfo[0]['alloted_time'].'延期至'.$alloted_time;
 
-             // 日常行为
 
-             $action_log = new action_log ();
 
-             $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;
 
-             $action_log->sid = $this->staff [0] ['sid'];
 
-             $action_log->cid = $this->staff [0] ['cid'];
 
-             $action_log->updatetime = date ( "Y-m-d" );
 
-             $action_log->time = date ( "H:i" );
 
-             $action_log->sid = $this->staff [0] ['sid'];
 
-             $action_log->cid = $this->staff [0] ['cid'];
 
-             $action_log->status = 12;
 
-             $action_log->class = $action_log->iconLock;
 
-             $action_log->insert ();
 
-         }
 
- 		
 
- 		// 记录使用过的状态
 
- 		$statuslog = $status . "," . $linfo [0] ['statuslog'];
 
- 		$ar = explode ( ',', $statuslog );
 
- 		$statuslog = implode ( ',', array_unique ( array_filter ( $ar ) ) );
 
- 		$longle->statuslog = $statuslog;
 
- 		
 
- 		if ($linfo [0] ['status'] <= 2) {
 
- 			if ($status >= 4 && $status <= 2) {
 
- 				return "/keyonline/" . $lid;
 
- 			}
 
- 		}
 
- 		
 
- 		if ($lid != 0) {
 
- 			
 
- 			$longle->lid = $lid;
 
- 			if (!($status == 8||$status == 10))
 
- 				$longle->status = $status;
 
- 				
 
- 				// if($status!=8)
 
- 			$longle->responsible = $this->staff [0] ['username'];
 
- 			
 
- 			$longle->update ();
 
- 		}
 
- 		
 
- 		$longle_log->lid = $lid;
 
- 		$longle_log->status = $status;
 
- 		$longle_log->operator = $this->staff [0] ['username'];
 
- 		
 
- 		// 责任人
 
- 		$longle_log->category = $this->staff [0] ['category'];
 
- 		$longle_log->dateline = date ( "Y-m-d" );
 
- 		$longle_log->insert ();
 
- 		
 
- 		echo json_encode ( array (
 
- 				'msg' => 1 
 
- 		) );
 
- 		die ();
 
- 		// return "/keyonline/".$lid;
 
- 	}
 
- 	function ajaxGetLongleByName() {
 
- 		Doo::loadModel ( 'longle_log' );
 
- 		Doo::loadModel ( 'longle' );
 
- 		
 
- 		$longle = new longle ();
 
- 		$longle_log = new longle_log ();
 
- 		
 
- 		$name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
 
- 		
 
- 		if (empty ( $name )) {
 
- 			echo json_encode ( array (
 
- 					"success" => false 
 
- 			) );
 
- 			die ();
 
- 		}
 
- 		
 
- 		$ky = $longle->getLongleBykeynum ( $name );
 
- 		$t = $longle_log->getLongleByLid ( $ky [0] ['lid'] );
 
- 		
 
- 		if (isset ( $t [0] ))
 
- 			$tk = $t [0];
 
- 		else
 
- 			$tk = array ();
 
- 		
 
- 		$longleLog = $tk;
 
- 		$longleLog ['klid'] = $t [0] ['lid'];
 
- 		$longleLog ['longle'] = $ky [0];
 
- 		$longleLog ['longleLogHtml'] = $this->_getLongleLogHtml ( $t );
 
- 		
 
- 		echo json_encode ( $longleLog );
 
- 	}
 
- 	function ajaxGetLongleN() {
 
- 		Doo::loadModel ( 'longle_log' );
 
- 		Doo::loadModel ( 'longle' );
 
- 		
 
- 		$longle = new longle ();
 
- 		$longle_log = new longle_log ();
 
- 		
 
- 		$keynum = $this->get_args ( 'keynum' ) ? $this->get_args ( 'keynum' ) : "";
 
- 		
 
- 		if (empty ( $keynum )) {
 
- 			echo json_encode ( array (
 
- 					"success" => false 
 
- 			) );
 
- 			die ();
 
- 		}
 
- 		
 
- 		$ky = $longle->getLongleBykeynum ( $keynum );
 
- 		
 
- 		if (! empty ( $ky )) {
 
- 			
 
- 			$t = $longle_log->getLongleByLid ( $ky [0] ['lid'] );
 
- 			
 
- 			if (isset ( $t [0] ))
 
- 				$tk = $t [0];
 
- 			else
 
- 				$tk = array ();
 
- 			
 
- 			$longleLog = $tk;
 
- 			
 
- 			$longleLog ['klid'] = $ky [0] ['lid'];
 
- 			
 
- 			$longleLog ['longle'] = $ky [0];
 
- 			
 
- 			$longleLog ['longleLogHtml'] = $this->_getLongleLogHtml ( $t );
 
- 			
 
- 			echo json_encode ( $longleLog );
 
- 		}
 
- 	}
 
- 	function ajaxGetLongle() {
 
- 		Doo::loadModel ( 'longle_log' );
 
- 		Doo::loadModel ( 'longle' );
 
- 		$longle = new longle ();
 
- 		$longle_log = new longle_log ();
 
-         Doo::loadClass ( 'XDeode' );
 
-         $XDeode = new XDeode ( 5 );
 
- 		$lid = $this->get_args ( 'lid' ) ? $this->get_args ( 'lid' ) : 0;
 
- 		
 
- 		if ($lid == 0) {
 
- 			echo json_encode ( array (
 
- 					"success" => false 
 
- 			) );
 
- 			die ();
 
- 		}
 
- 		
 
- 		$t = $longle_log->getLongleByLid ( $lid );
 
- 		if (isset ( $t [0] ))
 
- 			$tk = $t [0];
 
- 		else
 
- 			$tk = array ();
 
- 		
 
- 		$longleLog = $tk;
 
- 		$longleLog ['klid'] = $lid;
 
-         $longleLog ['lidKey'] =$XDeode->encode ( $lid );
 
- 		$ky = $longle->getLongleByLid ( $lid );
 
- 		$longleLog ['longle'] = $ky [0];
 
- 		$longleLog ['longleLogHtml'] = $this->_getLongleLogHtml ( $t );
 
- 		
 
- 		echo json_encode ( $longleLog );
 
- 	}
 
- 	function ajaxGetStaffInfo() {
 
- 		$username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
 
- 		
 
- 		if ($username == "") {
 
- 			echo json_encode ( array (
 
- 					"success" => false 
 
- 			) );
 
- 			die ();
 
- 		}
 
- 		
 
- 		Doo::loadModel ( 'staff' );
 
- 		
 
- 		$staff = new staff ();
 
- 		
 
- 		$staffInfo = $staff->getOne ( array (
 
- 				'where' => ' username like "' . $username . '"',
 
- 				'asArray' => TRUE 
 
- 		) );
 
- 		
 
- 		if (empty ( $staffInfo )) {
 
- 			echo json_encode ( array (
 
- 					"success" => false,
 
- 					'html' => '' 
 
- 			) );
 
- 			die ();
 
- 		}
 
- 		
 
- 		$staffHtml = array (
 
- 				'html' => '<div class="contactPanel"><h1>' . $staffInfo ['username'] . '</h1>
 
- 		  				<table><tbody><tr><th>性别</th><td>' . $staffInfo ['gender'] . '</td><th>办事处</th><td>' . $staffInfo ['category'] . '</td></tr>
 
- 		  					<tr><th>手机</th><td>' . $staffInfo ['telephone'] . '</td><th>电话</th><td>' . $staffInfo ['phone'] . '</td></tr>
 
- 		  					<tr><th>QQ</th><td>' . $staffInfo ['qq'] . '</td><th>邮箱</th><td>' . $staffInfo ['email'] . '</td></tr>
 
- 		  				</tbody></table>
 
- 		  			</div>' 
 
- 		);
 
- 		
 
- 		echo json_encode ( $staffHtml );
 
- 	}
 
- 	function ajaxGetCompanyByAdd() {
 
- 		session_start ();
 
- 		$cidKey = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
 
- 		
 
- 		if (empty($cidKey)){
 
- 			echo json_encode ( array (
 
- 					"success" => false,
 
- 					'data' => ''
 
- 			) );
 
- 		}
 
- 		
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 5 );
 
- 		$cid = $XDeode->decode ( $cidKey );
 
- 		
 
- 		if (! empty ( $cid )) {
 
- 			Doo::loadModel ( 'company' );
 
- 			$company = new company ();
 
- 			Doo::loadModel ( 'client' );
 
- 			Doo::loadModel ( 'district' );
 
- 			$district = new district ();
 
- 			$client = new client ();
 
- 			
 
- 			$districtInfo = $district->get_lv ( 1 );
 
- 			
 
- // 			$companyInfo = $client->getClientByCompanyId ( $cid );
 
- // 			$companyInfo = $companyInfo [0];
 
- 			
 
- 			$companyInfo = $company->getOne ( array (
 
- 					'where' => "cid = " . $cid,
 
- 					'asArray' => TRUE 
 
- 			) );
 
- 			
 
- 			$companyInfo ['companyKey'] = $XDeode->encode ( $companyInfo ['cid'] );
 
- 			
 
- // 			$companyInfo ['companyname'] = $cInfo ['companyname'];
 
- // 			$companyInfo ['address'] = $cInfo ['address'];
 
- // 			$companyInfo ['ride'] = $cInfo ['ride'];
 
- // 			$companyInfo ['landmarks'] = $cInfo ['landmarks'];
 
- // 			$companyInfo ['stay'] = $cInfo ['stay'];
 
- 			
 
- 			$artld = explode ( ',', $companyInfo ['local'] );
 
- 			$districtid = explode ( ',', $companyInfo ['district'] );
 
- 			
 
- 			$html = "";
 
- 			$html .= '<select  name="lv21" id="lv31" onchange="dislv(\'lv31\',\'32\');"><option value="' . $districtid [0] . '">' . $artld [0] . '</option>';
 
- 			
 
- 			// foreach ($districtInfo as $key=>$value){
 
- 			//
 
- 			// $html.='<option selected value="'.$value['id'].'">'.$value['name'].'</option>';
 
- 			// }
 
- 			
 
- 			$html .= '</select> ';
 
- 			$html .= '<span id="mlv32">
 
- 		  					<select  id="lv32" name="lv22">
 
- 		  					<option selected value="' . $districtid [1] . '" >' . $artld [1] . '</option>
 
- 		  					</select>
 
- 		  					</span>';
 
- 			
 
- 			$html .= '<span id="mlv33">
 
- 	  					<select  id="lv33" name="lv23">
 
- 	  					<option selected value="' . $districtid [2] . '" >' . $artld [2] . '</option>
 
- 	  					</select> 
 
- 	  					</span>';
 
- 			
 
- 			$companyInfo ['dishtml'] = $html;
 
- 			$companyInfo ['natureAr'] = $this->nature;
 
- 			$companyInfo ['natureArlenght'] = 12;
 
- 			
 
- 			$token = $this->set_token ();
 
- 			
 
- 			$_SESSION ['token_' . $this->staff [0] ['sidKey']] = $token;
 
- 			$companyInfo ['token'] = $token;
 
- 			
 
- 			echo json_encode ( array (
 
- 					"success" => true,
 
- 					'data' => $companyInfo 
 
- 			) );
 
- 			die ();
 
- 		} else
 
- 			echo json_encode ( array (
 
- 					"success" => false,
 
- 					'data' => '' 
 
- 			) );
 
- 		die ();
 
- 	}
 
- 	function doEditCompanyD() {
 
- 		$cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
 
- 		$companyname = $this->get_args ( 'companyname' ) ? $this->get_args ( 'companyname' ) : "";
 
- 		$lv21 = $this->get_args ( 'lv21' ) ? $this->get_args ( 'lv21' ) : 0;
 
- 		$lv22 = $this->get_args ( 'lv22' ) ? $this->get_args ( 'lv22' ) : 0;
 
- 		$lv23 = $this->get_args ( 'lv23' ) ? $this->get_args ( 'lv23' ) : 0;
 
- 		
 
- 		$nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
 
- 		
 
- 		$fax = $this->get_args ( 'fax' ) ? $this->get_args ( 'fax' ) : "";
 
- 		$webservice = $this->get_args ( 'webservice' ) ? $this->get_args ( 'webservice' ) : "";
 
- 		
 
- 		$address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
 
- 		$ride = $this->get_args ( 'ride' ) ? $this->get_args ( 'ride' ) : "";
 
- 		$stay = $this->get_args ( 'stay' ) ? $this->get_args ( 'stay' ) : "";
 
- 		$landmarks = $this->get_args ( 'landmarks' ) ? $this->get_args ( 'landmarks' ) : "";
 
- 		
 
- 		if (empty ( $cid ) || empty ( $companyname )) {
 
- 			echo json_encode ( array (
 
- 					"success" => false 
 
- 			) );
 
- 			die ();
 
- 		}
 
- 		
 
- 		Doo::loadModel ( "company" );
 
- 		Doo::loadModel ( "client" );
 
- 		
 
- 		$client = new client ();
 
- 		$company = new company ();
 
- 		
 
- 		$company->cid = $cid;
 
- 		
 
- 		if (! empty ( $lv21 ) && ! empty ( $lv22 ) && ! empty ( $lv23 )) {
 
- 			
 
- 			Doo::loadModel ( 'district' );
 
- 			$district = new district ();
 
- 			
 
- 			// 更新公司信息
 
- 			$lv1 = $district->getbyid ( $lv21 );
 
- 			$lv2 = $district->getbyid ( $lv22 );
 
- 			$lv3 = $district->getbyid ( $lv23 );
 
- 			
 
- 			$company->district = $lv21 . "," . $lv22 . "," . $lv23;
 
- 			
 
- 			$company->local = $lv1 [0] ['name'] . "," . $lv2 [0] ['name'] . "," . $lv3 [0] ['name'];
 
- 		}
 
- 		
 
- 		if (! empty ( $nature )) {
 
- 			$nature = implode ( ",", $nature );
 
- 			
 
- 			$company->nature = $nature;
 
- 		}
 
- 		
 
- 		if (! empty ( $companyname )) {
 
- 			$company->companyname = $companyname;
 
- 			$client->companyname = $companyname;
 
- 		}
 
- 		
 
- 		if (! empty ( $fax ))
 
- 			$company->fax = $fax;
 
- 		
 
- 		if (! empty ( $webservice ))
 
- 			$company->webservice = $webservice;
 
- 		
 
- 		$company->address = $address;
 
- 		$company->ride = $ride;
 
- 		$company->stay = $stay;
 
- 		$company->landmarks = $landmarks;
 
- 		
 
- 		$company->update ();
 
- 		
 
- 		$client->update ( array (
 
- 				'where' => ' companyid =' . $cid 
 
- 		) );
 
- 		
 
- 		echo json_encode ( array (
 
- 				"success" => true 
 
- 		) );
 
- 		die ();
 
- 	}
 
- 	function ajaxEditCompany() {
 
- 		$companyname = $this->get_args ( 'companyId' ) ? $this->get_args ( 'companyId' ) : 0;
 
- 		
 
- 		if (! empty ( $companyname )) {
 
- 			
 
- 			Doo::loadModel ( 'company' );
 
- 			
 
- 			$company = new company ();
 
- 			
 
- 			$companyInfo = $company->getOne ( array (
 
- 					'where' => "cid = '" . $companyname . "'",
 
- 					'asArray' => TRUE 
 
- 			) );
 
- 			if (! empty ( $companyInfo )) {
 
- 				
 
- 				Doo::loadModel ( 'district' );
 
- 				
 
- 				$district = new district ();
 
- 				
 
- 				$districtinfo = $district->get_lv ( 1 );
 
- 				
 
- 				$dinfo = $district->getbyidlist ( $companyInfo ['district'] );
 
- 				
 
- 				$html = '
 
- 				<div class="contactInfo clearfix">
 
- 		  			<div class="header">
 
- 	  				<h1 class="companyName">' . $companyInfo ['companyname'] . '</h1>
 
- 	  				</div>
 
- 	  			</div>
 
- 				<div class="lockRecord">
 
- 		  			<div class="contactPanel">
 
- 		  				<table>
 
- 		  					<tbody><tr><th>单位全称</th><td colspan="3"><input type="text" name="companyname" id="companyname" value="' . $companyInfo ['companyname'] . '"></td></tr>
 
- 		  					<tr><th>地区</th><td colspan="3">
 
- 		  					<select name="lv21" id="lv21" onchange="dislv(\'lv21\',22);">
 
- 		  					<option value="0">请选择</option>';
 
- 				foreach ( $districtinfo as $key => $value ) {
 
- 					if ($value ['id'] == $dinfo [0] ['id'])
 
- 						$html .= '<option selected value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
 
- 					else
 
- 						$html .= '<option value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
 
- 				}
 
- 				$html .= '</select>
 
- 		  					<span id="mlv22">
 
- 		  					<select id="lv22">
 
- 		  					<option value="' . $dinfo [1] ['id'] . '">' . $dinfo [1] ['name'] . '</option>
 
- 		  					</select>
 
- 		  					</span>
 
- 		  					<span id="mlv23">
 
- 		  					<select id="lv23">
 
- 		  					<option value="' . $dinfo [2] ['id'] . '">' . $dinfo [2] ['name'] . '</option>
 
- 		  					</select> 
 
- 		  					</span>
 
- 		  					</td></tr>
 
- 		  		';
 
- 				$html .= '<tr><th>性质</th><td colspan="3">';
 
- 				
 
- 				$ntre = explode ( ",", $companyInfo ['nature'] );
 
- 				
 
- 				foreach ( $this->nature as $key => $value ) {
 
- 					$falg = true;
 
- 					
 
- 					foreach ( $ntre as $k => $v ) {
 
- 						if ($value == $v) {
 
- 							$falg = false;
 
- 							$html .= '<label><input type="checkbox" checked name="nature[]" value="' . $value . '">' . $value . '</label> ';
 
- 						}
 
- 					}
 
- 					if ($falg)
 
- 						$html .= '<label><input type="checkbox"  name="nature[]" value="' . $value . '">' . $value . '</label> ';
 
- 				}
 
- 				
 
- 				$html .= '	</td></tr>
 
- 		  					<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>
 
- 		  					<tr><th>单位地址</th><td colspan="3"><input type="text" name="address" id="address" value="' . $companyInfo ['address'] . '"> </td></tr>
 
- 		  					<tr><th>乘车路线</th><td colspan="3"><input type="text" name="ride" id="ride" value="' . $companyInfo ['ride'] . '"> </td></tr>
 
- 		  					<tr><th>地标建筑</th><td colspan="3"><input type="text" name="landmarks" id="landmarks" value="' . $companyInfo ['landmarks'] . '"> </td></tr>
 
- 		  					<tr><th>住宿参考</th><td colspan="3"><input type="text" name="stay" id="stay" value="' . $companyInfo ['stay'] . '"> </td></tr>
 
- 		  					<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>
 
- 		  				</tbody></table>
 
- 		  				<div class="bsAlert bsInfo">单位全称将与该单位已存在的客户进行同步;其他单位信息不会进行同步;<br>单位信息随该单位第一位客户录入,并作为“在这添加客户”的基础数据</div>
 
- 		  			</div>
 
- 	  			</div>
 
- 				';
 
- 				
 
- 				echo json_encode ( array (
 
- 						"success" => true,
 
- 						'html' => $html 
 
- 				) );
 
- 				die ();
 
- 			}
 
- 		} else
 
- 			echo json_encode ( array (
 
- 					"success" => false,
 
- 					'html' => '' 
 
- 			) );
 
- 		die ();
 
- 	}
 
- 	function ajaxGetCompany() {
 
- 		$companyIdKey = $this->get_args ( 'companyId' ) ? $this->get_args ( 'companyId' ) : 0;
 
- 		
 
- 		if (empty($companyIdKey)){
 
- 			echo json_encode ( array (
 
- 					"success" => false,
 
- 					'html' => ''
 
- 			) );
 
- 		}
 
- 		
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 5 );
 
- 		
 
- 		$companyname = $XDeode->decode ( $companyIdKey );
 
- 		
 
- 		if (! empty ( $companyname )) {
 
- 			
 
- 			Doo::loadModel ( 'company' );
 
- 			$company = new company ();
 
- 			
 
- 			$companyInfo = $company->getOne ( array (
 
- 					'where' => "cid = '" . $companyname . "'",
 
- 					'asArray' => TRUE 
 
- 			) );
 
- 			if (! empty ( $companyInfo )) {
 
- 				
 
- 				Doo::loadModel ( 'client' );
 
- 				Doo::loadModel ( 'staff' );
 
- 				Doo::loadModel ( 'client_staff' );
 
- 				Doo::loadModel ( 'longle' );
 
- 				
 
- 				$longle = new longle ();
 
- 				$client_staff = new client_staff ();
 
- 				$staff = new staff ();
 
- 				$client = new client ();
 
- 				Doo::loadModel ( 'district' );
 
- 				$district = new district ();
 
- 				
 
- 				$clientlist = $client->getClientByCompanyId ( $companyInfo ['cid'] );
 
- 				$department = $client->getDepartment ( $companyInfo ['cid'] );
 
- 				
 
- 				Doo::loadModel ( "tagCompanyNexus" );
 
- 				Doo::loadModel ( "tagCompany" );
 
- 				$tag = new tagCompany ();
 
- 				$tag_client = new tagCompanyNexus ();
 
- 				
 
- 				$tagId = $tag_client->getTagClientBySCid ( $companyInfo ['cid'], $this->staff [0] ['sid'] );
 
- 				$taginfo = $tag->getTagByTidL ( $tagId ['tag'] );
 
- 				$taghtml = "";
 
- 				
 
- 				foreach ( $taginfo as $key => $value ) {
 
- 					$taghtml .= '<span class="contactsTag tagCol-0' . $value ['colorid'] . '">' . $value ['name'] . '</span>';
 
- 				}
 
- 				
 
- 				$html = '<div class="header">
 
- 				<h1 class="companyName"><div class="fR">
 
- 						<a class="icon- add" node-syn="show" href="javascript:void(0)" title="同步地址信息">S</a>
 
- 						<a href="javascript:void(0)"  title="编辑单位" class="icon- edit" onclick="editByCompany(' . $companyInfo ['cid'] . ')" >I</a> | 
 
- <a title="在这个单位下添加客户"  href="javascript:void(0)"  class="icon- add" onclick="addClientByCompany(\'' . $companyIdKey . '\')" >H</a></div>' . $companyInfo ['companyname'] . '</h1>
 
- 				<div class="contactPanel">
 
- 		  				<table>
 
- 		  					<tbody>
 
- 		  					<tr><th>单位地区</th><td><span>' . $companyInfo ['local'] . '</span></td><th>单位性质</th><td>' . $companyInfo ['nature'] . '</td></tr>
 
- 		  					<tr><th>单位地址</th><td colspan="3">' . $companyInfo ['address'] . '</td></tr>
 
- 		  					<tr><th>单位乘车</th><td colspan="3">' . $companyInfo ['ride'] . '</td></tr>
 
- 		  					<tr><th>单位地标</th><td colspan="3">' . $companyInfo ['landmarks'] . '</td></tr>
 
- 		  					<tr><th>单位住宿</th><td colspan="3">' . $companyInfo ['stay'] . '</td></tr>
 
- 		  					<tr><td colspan="4">
 
- 		  					' . $taghtml . '
 
- 		  					</td></tr>
 
- 		  					<tr><td colspan="4" >
 
- 		  						<a class="button" style="display:none" node-synadd="true" href="javascript:void(0)">确定同步</a>
 
- 		  							<span node-synAdd="msg" class="bsAlert bsSuccess fL hide"></span>
 
- 		  							<span class="hide" id="skop">已选择 <span id="tl">0</span>/<span id="bl">' . sizeof ( $clientlist ) . '</span>
 
- 		  							<input type="checkbox" name="CASYN[]" cas-all="TR" class="hide" value="19595" style="display: inline-block;">全选客户		
 
- 		  						</td>
 
- 		  					</tr>		
 
- 		  							
 
- 		  				</tbody></table></div>
 
- 		  				<h2 class="cate">';
 
- 				$html .= '<a  href="javascript:void(0)" onclick="departmentC()" class="now">不限</a>';
 
- 				foreach ( $department as $key => $value ) {
 
- 					if ($value != "")
 
- 						$html .= '<a href="javascript:void(0)" onclick="departmentC(\'' . $value ['department'] . '\')">' . $value ['department'] . '</a>';
 
- 				}
 
- 				$html .= '</h2></div><script>$(".header .cate a").click(function(){
 
-   $(this).addClass("now").siblings("a").removeClass("now");
 
- });
 
- 		  		</script>';
 
- 				
 
- 				$html .= '<div class="lockRecord autoHeightR2" >';
 
- 				
 
- 				foreach ( $clientlist as $key => $value ) {
 
- 					
 
- 					$scinfo = $client_staff->getClientByCid ( $value ['cid'] );
 
- 					
 
- 					$staffinfo = $staff->getUserById ( $scinfo ['sid'] );
 
- 					// 客户信息
 
- 					$html .= '<div class="contactPanel" id="PART_' . $value ['department'] . '">
 
- 						<h1><p class="fR">' . $staffinfo [0] ['category'] . '-<a href="javascript:void(0)" onclick="getStaffInfo(\'' . $staffinfo [0] ['username'] . '\')" >
 
- 							' . $staffinfo [0] ['username'] . '</a></p>
 
- 									
 
- 			<input type="checkbox" name="CASYN[]" CAS-NUM="TR" class="hide" value="' . $value ['cid'] . '">
 
- 			<a href="javascript:void(0)" onclick="getClientInfo(\'' . $value ['cid'] . '\')" class="clientName">' . $value ['clientname'] . '   </a>
 
- 			
 
- 					
 
- 			<i class="icon- sport">' . $value ['priority'] . '</i><a class="icon- edit" title="编辑客户" href="javascript:clientEdit(' . $value ['cid'] . ')">I</a></h1><table>
 
- 											
 
- 											
 
- 							<tbody><tr><th>性别</th><td>' . $value ['gender'] . '</td><th>昵称</th><td>' . $value ['nicename'] . '</td></tr>
 
- 							<tr><th>部门</th><td>' . $value ['department'] . '</td><th>办公室</th><td>' . $value ['office'] . '</td></tr>
 
- 							<tr><th>手机</th><td>' . $value ['telephone'] . '</td><th>电话</th><td>' . $value ['phone'] . '</td></tr>
 
- 							<tr><th>QQ</th><td>' . $value ['qq'] . '</td><th>邮箱</th><td>' . $value ['email'] . '</td></tr>
 
- 							
 
- 							<tr node-ck=fz ><th>备注</th><td >' . $value ['mark'] . '</td>
 
- 							</tr>';
 
- 					
 
- 					$longleinfo = $longle->getLongleByClientid ( $value ['cid'] );
 
- 					if (empty ( $longleinfo )) {
 
- 						$longleinfo = array (
 
- 								0 => array (
 
- 										'lid' => '',
 
- 										'key_num' => '',
 
- 										'product' => '',
 
- 										'statusT' => '' 
 
- 								) 
 
- 						);
 
- 					}
 
- 					$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>';
 
- 					
 
- 					$districtList = $district->getbyidlist ( $value ['district'] );
 
- 					
 
- 					$localdis = '';
 
- 					foreach ( $districtList as $lov ) {
 
- 						$localdis .= ' ' . $lov ['name'];
 
- 					}
 
- 					
 
- 					$html .= '
 
- 					<tr node-synCom=pany style="display:none" ><th>客户地区</th><td colspan="4">' . $localdis . '</td></tr>
 
- 					<tr node-synCom=pany style="display:none" ><th>客户地址</th><td colspan="4">' . $value ['address'] . '</td></tr>
 
- 					<tr node-synCom=pany style="display:none" ><th>客户乘车</th><td colspan="4">' . $value ['ride'] . '</td></tr>
 
- 					<tr node-synCom=pany style="display:none" ><th>客户地标</th><td colspan="4">' . $value ['landmarks'] . '</td></tr>
 
- 					<tr node-synCom=pany style="display:none" ><th>客户住宿</th><td colspan="4">' . $value ['stay'] . '</td></tr>';
 
- 					
 
- 					$html .= '</tbody></table></div>';
 
- 				}
 
- 				$html .= "</div><script type='text/javascript'>
 
- 						
 
- 		
 
- 		
 
- 		$(\"a[node-syn=show]\").click(function() {
 
- 			$(\"a[node-synadd='true']\").show();
 
- 			$('input[CAS-NUM=TR]').show();
 
- 			$('#skop').show();
 
- 			$('tr[node-ck=fz]').hide();
 
- 			$('tr[node-synCom=pany]').show();
 
- 		});
 
- 				
 
- 						
 
- 						
 
- 		$(\"input[cas-all='TR']\").click(function() {
 
- 						
 
- 			if (this.checked) {
 
- 				$(\"input[CAS-NUM=TR]:checkbox\").each(function() { 
 
- 							$(this).attr(\"checked\", true);
 
- 						})
 
- 			}else{
 
- 			$(\"input[CAS-NUM=TR]:checkbox\").each(function() { 
 
- 							$(this).attr(\"checked\", false);
 
- 						})
 
- 			}
 
- 						
 
- 						
 
- 			$('#tl').html($('input[CAS-NUM=TR]:checked').length);
 
- 		});
 
- 								
 
- 				
 
- 		$(\"input[CAS-NUM='TR']\").click(function() {
 
- 			$('#tl').html($('input[CAS-NUM=TR]:checked').length);
 
- 		});
 
- 		$(\"a[node-synadd='true']\").click(function() {
 
- 						
 
- 			var id_array=new Array();  
 
- 			$('input[CAS-NUM=TR]:checked').each(function(){  
 
-     			id_array.push($(this).val());
 
- 			});  
 
- 			if(id_array.length==0){
 
- 				alert('未选中客户');
 
- 			}else{
 
- 				var idstr=id_array.join(',');
 
- 				var url='/ajaxSetCompanyAddress';
 
- 		
 
- 				$.ajax({
 
- 					url:url,
 
- 			type: 'post',
 
- 			cache: false,
 
- 			dataType: 'json',
 
- 			data: {
 
- 				cidString:idstr,
 
- 				company:" . $companyInfo ['cid'] . "
 
- 			},
 
- 			global: true,
 
- 			success: function(data){
 
- 				if(data.status>0){
 
- 					$(\"span[node-synAdd=msg]\").html('同步成功');
 
- 					for(var i=0;i<id_array.length;i++){
 
- 						$(\"td[node-address=company_\"+id_array[i]+\"]\").html('" . $companyInfo ['address'] . "');
 
- 					}
 
- 					$(\"a[node-synadd='true']\").hide();
 
- 					$('input[CAS-NUM=TR]').hide();
 
- 					$('#skop').hide();
 
- 					$(\"span[node-synAdd=msg]\").show().delay(2000).fadeOut();
 
- 					
 
- 				}else if(data.status==-1){
 
- 					$(\"span[node-synAdd=msg]\").html('操作不成功');	
 
- 					$(\"span[node-synAdd=msg]\").show().delay(2000).fadeOut();
 
- 				}else if(data.status==0){
 
- 					$(\"span[node-synAdd=msg]\").html('地址已同步过');	
 
- 					$(\"span[node-synAdd=msg]\").show().delay(2000).fadeOut();
 
- 				}
 
- 			},
 
- 			error:function(err){
 
- 			}
 
- 			});		
 
- 				
 
- 			}
 
- 			
 
- 		});		
 
- 		autoFlashHeight();
 
- 		</script>";
 
- 				echo json_encode ( array (
 
- 						"success" => true,
 
- 						'html' => $html 
 
- 				) );
 
- 				die ();
 
- 			}
 
- 		} 
 
- 		die ();
 
- 	}
 
- 	function ajaxSetCompanyAddress() {
 
- 		$cidString = $this->get_args ( 'cidString' ) ? $this->get_args ( 'cidString' ) : "";
 
- 		$companyId = $this->get_args ( 'company' ) && is_numeric ( $this->get_args ( 'company' ) ) ? $this->get_args ( 'company' ) : 0;
 
- 		
 
- 		if (! empty ( $cidString ) && ! empty ( $companyId )) {
 
- 			Doo::loadModel ( 'client' );
 
- 			$client = new client ();
 
- 			Doo::loadModel ( 'company' );
 
- 			$company = new company ();
 
- 			
 
- 			$cidList = explode ( ',', $cidString );
 
- 			
 
- 			foreach ( $cidList as $value ) {
 
- 				if (! is_numeric ( $value ))
 
- 					die ( 'illegal request3' );
 
- 			}
 
- 			
 
- 			$companyInfo = $company->getOne ( array (
 
- 					'where' => "cid = '" . $companyId . "'",
 
- 					'asArray' => TRUE 
 
- 			) );
 
- 			
 
- 			$client->address = $companyInfo ['address'];
 
- 			$client->ride = $companyInfo ['ride'];
 
- 			$client->landmarks = $companyInfo ['landmarks'];
 
- 			$client->stay = $companyInfo ['stay'];
 
- 			$client->local = $companyInfo ['local'];
 
- 			$client->district = $companyInfo ['district'];
 
- 			
 
- 			$falg = $client->update ( array (
 
- 					'where' => 'companyid =' . $companyInfo ['cid'] . ' and cid in (' . $cidString . ')' 
 
- 			) );
 
- 			
 
- 			echo json_encode ( array (
 
- 					'status' => $falg,
 
- 					'msg' => 'illegal request2' 
 
- 			) );
 
- 			die ();
 
- 		}
 
- 		echo json_encode ( array (
 
- 				'status' => - 1,
 
- 				'msg' => 'illegal request' 
 
- 		) );
 
- 		die ();
 
- 	}
 
- 	function checkclicomname() { // 地区区分
 
- 		$companyname = $this->get_args ( 'companyname' ) ? $this->get_args ( 'companyname' ) : "";
 
- 		$clientname = $this->get_args ( 'clientname' ) ? $this->get_args ( 'clientname' ) : "";
 
- 		
 
- 		$district1 = $this->get_args ( 'district1' ) ? $this->get_args ( 'district1' ) : 0;
 
- 		$district2 = $this->get_args ( 'district2' ) ? $this->get_args ( 'district2' ) : 0;
 
- 		$district3 = $this->get_args ( 'district3' ) ? $this->get_args ( 'district3' ) : 0;
 
- 		
 
- 		Doo::loadModel ( 'client' );
 
- 		$client = new client ();
 
- 		
 
- 		$local = $district1 . "," . $district2 . "," . $district3;
 
- 		
 
- 		$companyname = trim ( $companyname );
 
- 		
 
- 		$clientname = trim ( $clientname );
 
- 		
 
- 		$clientinfo = $client->getClientToName ( $clientname, $companyname, $local );
 
- 		
 
- 		if (! empty ( $clientinfo )) {
 
- 			echo json_encode ( array (
 
- 					'success' => false 
 
- 			) );
 
- 		} else {
 
- 			echo json_encode ( array (
 
- 					'success' => true 
 
- 			) );
 
- 		}
 
- 	}
 
- 	function ajaxGetClientInfoN() {
 
- 		$clientname = $this->get_args ( 'client' ) ? $this->get_args ( 'client' ) : "";
 
- 		
 
- 		if ($clientname == "") {
 
- 			echo json_encode ( array (
 
- 					"success" => false 
 
- 			) );
 
- 			die ();
 
- 		}
 
- 		
 
- 		Doo::loadModel ( 'client' );
 
- 		Doo::loadModel ( 'client_staff' );
 
- 		Doo::loadModel ( 'longle' );
 
- 		Doo::loadModel ( 'company' );
 
- 		
 
- 		Doo::loadModel ( 'service_log' );
 
- 		$service_log = new service_log ();
 
- 		
 
- 		$company = new company ();
 
- 		$longle = new longle ();
 
- 		$client = new client ();
 
- 		$client_staff = new client_staff ();
 
- 		
 
- 		$clientInfo = $client->getOne ( array (
 
- 				"where" => ' cid like "' . $clientname . '"',
 
- 				'asArray' => TRUE 
 
- 		) );
 
- 		
 
- 		if (empty ( $clientInfo )) {
 
- 			echo json_encode ( array (
 
- 					"success" => false,
 
- 					'html' => '' 
 
- 			) );
 
- 			die ();
 
- 		}
 
- 		
 
- 		// 获取锁
 
- 		$longleInfo = $longle->getLongleByClientid ( $clientname );
 
- 		$k = "";
 
- 		foreach ( $longleInfo as $key => $value ) {
 
- 			if ($value ['status'] == 6 || $value ['status'] == 7)
 
- 				$k .= '<a href="javascript:void(0)" class="disenable" onclick="getLock(' . $value ['lid'] . ')" >' . $value ['key_num'] . '/' . $value ['product'] . '/' . $value ['statusT'] . '</a>  ';
 
- 			else
 
- 				$k .= '<a href="javascript:void(0)" onclick="getLock(' . $value ['lid'] . ')" >' . $value ['key_num'] . '/' . $value ['product'] . '/' . $value ['statusT'] . '</a>  ';
 
- 		}
 
- 		
 
- 		// 获取办事人
 
- 		$staffInfo = $client_staff->getClientByCid ( $clientInfo ['cid'] );
 
- 		// 获取公司信息
 
- 		$companyInfo = $company->getCompanyByCid ( $clientInfo ['companyid'] );
 
- 		$serviceLog = $service_log->getServiceByClientid ( $clientInfo ['cid'] );
 
- 		
 
- 		$u = "";
 
- 		
 
- 		$order = array (
 
- 				"\r\n",
 
- 				"\n",
 
- 				"\r" 
 
- 		);
 
- 		$replace = '</br>';
 
- 		
 
- 		foreach ( $serviceLog as $key => $value ) {
 
- 			
 
- 			$datetime = explode ( "-", $value ['date'] );
 
- 			
 
- 			$u .= '<div class="infoFlowList">
 
- 						<div class="dateTitle">
 
- 							<em class="month"><span class="num">' . $datetime ['1'] . '</span><span class="text">-' . $datetime ['2'] . '</span></em>
 
- 							<span class="year">' . $datetime ['0'] . '</span>
 
- 						</div>
 
- 						<ul class="flowList">';
 
- 			if ($value ['status'] == 1)
 
- 				$u .= '<li class="item iconService">上门服务</li>';
 
- 			elseif ($value ['status'] == 2)
 
- 				$u .= '<li class="item iconPhone">电话拜访</li>';
 
- 			elseif ($value ['status'] == 3)
 
- 				$u .= '<li class="item iconOther">其他</li>';
 
- 			
 
- 			$u .= '
 
- 							<li class="item">' . $value ['category'] . '<a href="javascript:void(0)" onclick="getStaffInfo(\'' . $value ['staffname'] . '\')"  >' . $value ['staffname'] . '</a></li>
 
- 							<li class="item">
 
- 								' . str_replace ( $order, $replace, $value ['mark'] ) . '
 
- 							</li>
 
- 						</ul>
 
- 					</div>';
 
- 		}
 
- 		
 
- 		Doo::loadModel ( "tag_client" );
 
- 		Doo::loadModel ( "tag" );
 
- 		
 
- 		$tag = new tag ();
 
- 		$tag_client = new tag_client ();
 
- 		
 
- 		$tagId = $tag_client->getTagClientBySCid ( $clientInfo ['cid'], $this->staff [0] ['sid'] );
 
- 		
 
- 		$taginfo = $tag->getTagByTidL ( $tagId ['tag'] );
 
- 		
 
- 		// $taghtml="";
 
- 		//
 
- 		// foreach ($taginfo as $key=>$value){
 
- 		// $taghtml.='<span class="contactsTag tagCol-0'.$value['colorid'].'">'.$value['name'].'</span>';
 
- 		// }
 
- 		
 
- 		$mhtml = "";
 
- 		$dhtml = "";
 
- 		
 
- 		for($month = 1; $month <= 12; $month ++) {
 
- 			if (date ( "m" ) == $month)
 
- 				$mhtml .= '<option selected value="' . $month . '">' . $month . '月</option>';
 
- 			else
 
- 				$mhtml .= '<option value="' . $month . '">' . $month . '月</option>';
 
- 		}
 
- 		
 
- 		for($day = 1; $day <= 31; $day ++) {
 
- 			if (date ( "d" ) == $day)
 
- 				$dhtml .= '<option selected value="' . $day . '">' . $day . '日</option>';
 
- 			else
 
- 				$dhtml .= '<option value="' . $day . '">' . $day . '日</option>';
 
- 		}
 
- 		
 
- 		// $b="";
 
- 		// if(!empty($staffInfo))
 
- 		// $b='<p class="fR">'.$staffInfo['category'].'-<a href="javascript:void(0)" onclick="getStaffInfo(\''.$staffInfo['username'].'\')" >'.$staffInfo['username'].'</a></p>'.$clientInfo['clientname'].' ';
 
- 		//
 
- 		
 
- 		$m = "";
 
- 		if (! empty ( $companyInfo )) {
 
- 			$m = '
 
- 		  		<table width="100%">
 
- 		  			<tbody>
 
- 		  			<tr><th>单位全称</th><td colspan="3"><a href="javascript:void(0)" >' . $companyInfo [0] ['companyname'] . '</a></td></tr>
 
- 		  			<tr><th>地区</th><td>' . $companyInfo [0] ['local'] . '</td><th>部门/职位</th><td>' . $clientInfo ['department'] . '/' . $clientInfo ['position'] . '</td></tr>
 
- 		  			<tr><th>传真</th><td>' . $companyInfo [0] ['fax'] . '</td><th>办公室</th><td>' . $clientInfo ['office'] . '</td></tr>
 
- 		  			<tr><th>单位地址</th><td colspan="3">' . $companyInfo [0] ['address'] . '</td></tr>
 
- 		  			<tr><th>乘车路线</th><td colspan="3">' . $companyInfo [0] ['ride'] . '</td></tr>
 
- 		  			<tr><th>地标建筑</th><td colspan="3">' . $companyInfo [0] ['landmarks'] . '</td></tr>
 
- 		  			<tr><th>参考住宿</th><td colspan="3">' . $clientInfo ['stay'] . '</td></tr>
 
- 		  			<tr><th>单位主页</th><td colspan="3">' . $clientInfo ['webservice'] . '</td></tr>
 
- 		  		</tbody></table>
 
- 		  	';
 
- 		}
 
- 		
 
- 		$clientHtml = array (
 
- 				'html' => '
 
- 		<div class="modal-dialog ">
 
- 		<div class="modal-content">
 
- 		<div class="modal-header">
 
- 					    <h3><span class="fR"><a>' . $staffInfo ['category'] . ' ' . $staffInfo ['username'] . '</a></span>' . $clientInfo ['clientname'] . '</h3>
 
- 					    </div>
 
- 					    <div class="modal-body">
 
- 	    <div class="modalClientTable">
 
- 			<table width="100%">
 
- 				<tbody><tr><th>性别</th><td>' . $clientInfo ['gender'] . '</td><th>昵称</th><td>' . $clientInfo ['nicename'] . '</td></tr>
 
- 				<tr><th>手机</th><td>' . $clientInfo ['telephone'] . '</td><th>QQ</th><td>' . $clientInfo ['qq'] . '</td></tr>
 
- 				<tr><th>电话</th><td>' . $clientInfo ['phone'] . '</td><th>邮箱</th><td>' . $clientInfo ['email'] . '</td></tr>
 
- 				<tr><th>软件锁</th><td colspan="3"> <div class="lockContent">' . $k . '</div></td></tr>
 
- 				<tr><td colspan="4">
 
- 				</td></tr>
 
- 				</tbody>
 
- 			</table>
 
- 			' . $m . '
 
- 	  		<div class="clearfix">
 
- 		  		' . $u . '
 
- 			</div>
 
- 	    </div>
 
-     </div>
 
- 			<div class="modal-footer">
 
- 	    <a href="javascript:void(0)" onclick="closeClick()" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a>
 
- 	</div>
 
- </div></div>'
 
- 		);
 
- 		echo json_encode ( $clientHtml );
 
- 	}
 
- 	function ajaxGetClientInfo() {
 
- 		$clientname = $this->get_args ( 'client' )&&is_numeric($this->get_args ( 'client' )) ? $this->get_args ( 'client' ) : "";
 
- 		if ($clientname == "") {
 
- 			echo json_encode ( array (
 
- 					"success" => false 
 
- 			) );
 
- 			die ();
 
- 		}
 
- 		
 
- 		Doo::loadModel ( 'client' );
 
- 		Doo::loadModel ( 'client_staff' );
 
- 		Doo::loadModel ( 'longle' );
 
- 		Doo::loadModel ( 'company' );
 
- 		Doo::loadModel ( 'service_log' );
 
- 		Doo::loadModel ( "district" );
 
- 		
 
- 		$district = new district ();
 
- 		$service_log = new service_log ();
 
- 		
 
- 		$company = new company ();
 
- 		$longle = new longle ();
 
- 		$client = new client ();
 
- 		$client_staff = new client_staff ();
 
- 		
 
-         $clientInfo = $client->getOne ( array (
 
- 					"where" => ' cid = "' . $clientname . '"',
 
- 					'asArray' => TRUE
 
-         ) );
 
- 		
 
- 		if (empty ( $clientInfo )) {
 
- 			echo json_encode ( array (
 
- 					"success" => false,
 
- 					'html' => '' 
 
- 			) );
 
- 			die ();
 
- 		}
 
- 		
 
- 		// 获取锁
 
- 		$longleInfo = $longle->getLongleByClientid ( $clientInfo ['cid'] );
 
- 		
 
- 		$k = "";
 
- 		foreach ( $longleInfo as $key => $value ) {
 
- 			if ($value ['status'] == 6 || $value ['status'] == 7)
 
- 				$k .= '<a href="javascript:void(0)" class="disenable" onclick="getLock(' . $value ['lid'] . ')" >' . $value ['key_num'] . '/' . $value ['product'] . '/' . $value ['statusT'] . '</a>  ';
 
- 			else
 
- 				$k .= '<a href="javascript:void(0)" onclick="getLock(' . $value ['lid'] . ')" >' . $value ['key_num'] . '/' . $value ['product'] . '/' . $value ['statusT'] . '</a>  ';
 
- 		}
 
- 		
 
- 		// 获取办事人
 
- 		$staffInfo = $client_staff->getClientByCid ( $clientInfo ['cid'] );
 
- 		
 
- 		$b = "";
 
- 		if (! empty ( $staffInfo ))
 
- 			$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>';
 
- 			
 
- 			// 获取公司信息
 
- 		$companyInfo = $company->getCompanyByCid ( $clientInfo ['companyid'] );
 
- 		
 
- 		$serviceLog = $service_log->getServiceByClientid ( $clientInfo ['cid'] );
 
- 		
 
- 		$local = $district->getbyidlist ( $clientInfo ['district'] );
 
- 		
 
- 		if (! isset ( $local [1] ))
 
- 			$local [1] ['name'] = "";
 
- 		if (! isset ( $local [2] ))
 
- 			$local [2] ['name'] = "";
 
- 		
 
- 		$m = "";
 
- 		if (! empty ( $companyInfo )) {
 
- 			$m = '<div class="contactPanel">
 
- 		  		<table>
 
- 		  			<tbody>
 
- 		  			<tr><th>单位全称</th><td colspan="3"><a href="javascript:void(0)" onclick="getCompany(\'' . $companyInfo [0] ['cidKey'] . '\')">' . $companyInfo [0] ['companyname'] . '</a></td></tr>
 
- 		  			<tr><th>单位主页</th><td colspan="3">' . $clientInfo ['webservice'] . '</td></tr>
 
- 		  			<tr><th>客户地区</th><td>' . $local [0] ['name'] . ',' . $local [1] ['name'] . ',' . $local [2] ['name'] . '</td><th>部门/职位</th><td>' . $clientInfo ['department'] . '/' . $clientInfo ['position'] . '</td></tr>
 
- 		  			<tr><th>客户传真</th><td>' . $clientInfo ['fax'] . '</td><th>办公室</th><td>' . $clientInfo ['office'] . '</td></tr>
 
- 		  			<tr><th>客户地址</th><td colspan="3">' . $clientInfo ['address'] . '</td></tr>
 
- 		  			<tr><th>客户乘车</th><td colspan="3">' . $clientInfo ['ride'] . '</td></tr>
 
- 		  			<tr><th>客户地标</th><td colspan="3">' . $clientInfo ['landmarks'] . '</td></tr>
 
- 		  			<tr><th>客户住宿</th><td colspan="3">' . $clientInfo ['stay'] . '</td></tr>
 
- 		  		</tbody></table>
 
- 		  	</div>';
 
- 		}
 
- 		
 
- 		$u = "";
 
- 		
 
- 		$order = array (
 
- 				"\r\n",
 
- 				"\n",
 
- 				"\r" 
 
- 		);
 
- 		$replace = '</br>';
 
- 		
 
- 		foreach ( $serviceLog as $key => $value ) {
 
- 			
 
- 			$datetime = explode ( "-", $value ['date'] );
 
- 			
 
- 			$u .= '<div class="infoFlowList">
 
- 						<div class="dateTitle">
 
- 							<em class="month"><span class="num">' . $datetime ['1'] . '</span><span class="text">-' . $datetime ['2'] . '</span></em>
 
- 							<span class="year">' . $datetime ['0'] . '</span>
 
- 						</div>
 
- 						<ul class="flowList">';
 
- 			if ($value ['status'] == 1)
 
- 				$u .= '<li class="item iconService">上门服务<';
 
- 			elseif ($value ['status'] == 2)
 
- 				$u .= '<li class="item iconPhone">电话拜访<';
 
- 			elseif ($value ['status'] == 3)
 
- 				$u .= '<li class="item iconOther">其他<';
 
- 			
 
- 			$u .= $value ['category'] . '<a href="javascript:void(0)" onclick="getStaffInfo(\'' . $value ['staffname'] . '\')"  >' . $value ['staffname'] . '</a></li>
 
- 							<li class="item">
 
- 								' . str_replace ( $order, $replace, $value ['mark'] ) . '
 
- 							</li>
 
- 						</ul>
 
- 					</div>';
 
- 		}
 
- 		
 
- 		Doo::loadModel ( "tag_client" );
 
- 		Doo::loadModel ( "tag" );
 
- 		
 
- 		$tag = new tag ();
 
- 		$tag_client = new tag_client ();
 
- 		
 
- 		$tagId = $tag_client->getTagClientBySCid ( $clientInfo ['cid'], $this->staff [0] ['sid'] );
 
- 		
 
- 		$taginfo = $tag->getTagByTidL ( $tagId ['tag'] );
 
- 		
 
- 		$taghtml = "";
 
- 		
 
- 		foreach ( $taginfo as $key => $value ) {
 
- 			$taghtml .= '<span class="contactsTag tagCol-0' . $value ['colorid'] . '">' . $value ['name'] . '</span>';
 
- 		}
 
- 		
 
- 		$mhtml = "";
 
- 		$dhtml = "";
 
- 		$yhtml = "";
 
- 		
 
- 		for($year = 2020; $year >= 2004; $year --) {
 
- 			if (date ( "Y" ) == $year)
 
- 				$yhtml .= '<option selected value="' . $year . '">' . $year . '年</option>';
 
- 			else
 
- 				$yhtml .= '<option value="' . $year . '">' . $year . '年</option>';
 
- 		}
 
- 		
 
- 		for($month = 1; $month <= 12; $month ++) {
 
- 			if (date ( "m" ) == $month)
 
- 				$mhtml .= '<option selected value="' . $month . '">' . $month . '月</option>';
 
- 			else
 
- 				$mhtml .= '<option value="' . $month . '">' . $month . '月</option>';
 
- 		}
 
- 		
 
- 		for($day = 1; $day <= 31; $day ++) {
 
- 			if (date ( "d" ) == $day)
 
- 				$dhtml .= '<option selected value="' . $day . '">' . $day . '日</option>';
 
- 			else
 
- 				$dhtml .= '<option value="' . $day . '">' . $day . '日</option>';
 
- 		}
 
- 		
 
- 		$clientHtml = array (
 
- 				'html' => '<div class="contactInfo clearfix">
 
- 		  			<div class="contactPanel">
 
- 		  				<h1>' . $b . '<a data-original-title="编辑客户" data-toggle="ctooltip" data-placement="right" href="javascript:clientEdit(' . $clientInfo ['cid'] . ')" class="icon- edit">I</a></h1>
 
- 		  				<table>
 
- 		  					<tbody><tr><th>性别</th><td>' . $clientInfo ['gender'] . '</td><th>昵称</th><td>' . $clientInfo ['nicename'] . '</td></tr>
 
- 		  					<tr><th>手机</th><td>' . $clientInfo ['telephone'] . '</td><th>QQ</th><td>' . $clientInfo ['qq'] . '</td></tr>
 
- 		  					<tr><th>电话</th><td>' . $clientInfo ['phone'] . '</td><th>邮箱</th><td>' . $clientInfo ['email'] . '</td></tr>
 
- 		  					<tr><th>软件锁</th><td colspan="3"><div class="lockContent">' . $k . '</div></td></tr>
 
- 		  					<tr><th>备注</th><td colspan="3">' . $clientInfo ['mark'] . '</td></tr>
 
- 		  					<tr><td colspan="4">
 
- 		  					' . $taghtml . '
 
- 		  					</td></tr>
 
- 		  				</tbody></table>
 
- 		  			</div>
 
- 		  			' . $m . '
 
- 	  				</div>
 
- 		  			<div class="lockRecord autoHeightR1" >
 
- 	  				<!--添加记录按钮-->
 
- 	  				<div class="addRecord addRecordButton clearfix" >
 
- 	  					<a  href="#" onclick="slideupInfo(this)">+ 打开添加服务记录</a>
 
- 	  				</div>
 
- 	  				<!--添加记录-->
 
- 	  				<div class="addRecord addRecordForm clearfix hide">
 
- 						<a onclick="slidedownInfo(this)" class="fR slidedownInfo">- 关闭添加记录</a>
 
- 	  				<form name="lk" action="/addServiceLog" method="post" >
 
- 						  <div class="control-group">
 
- 						    <div class="controls">
 
- 							    <label class="radio inline">
 
- 							    	<input type="radio" name="logstatus" id="status" checked value="2">电话拜访
 
- 							    </label>
 
- 							    <label class="radio inline">
 
- 							    	<input type="radio" name="logstatus" id="status" value="1" >上门服务
 
- 							    </label>
 
- 							    <label class="radio inline">
 
- 							    	<input type="radio" name="logstatus" id="status" value="3">其他
 
- 							    </label>
 
- 						    </div>
 
- 						  </div>
 
- 						  <div class="control-group">
 
- 						    <div class="controls">时间:
 
- 						      <select name="y" id="y">
 
- 						      	' . $yhtml . '
 
- 						      </select>
 
- 						      <select name="m" id="m">
 
- 						      	' . $mhtml . '
 
- 						      </select>
 
- 						      <select name="d" id="d">
 
- 						      	' . $dhtml . '
 
- 						      </select>
 
- 						    </div>
 
- 						  </div>
 
- 	
 
-     <link href="' . WEB_SITE_GLOBAL . 'css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
 
- 	  				<!--添加记录-备注-->
 
- 						  <!--<div class="control-group">
 
- 						    <div class="controls">
 
- 						      <select name="date" id="date">
 
- 						      <option value="2013">2013</option>
 
- 						      </select>
 
- 						    </div>
 
- 						  </div>-->
 
- 						  <div class="control-group">
 
- 						    <div class="controls" onclick="slideupInfo()">
 
- 						      <textarea name="mark" id="mark" style="width:95%" rows="5"></textarea>
 
- 						      
 
- 						      <div class="bsAlert bsWarning"><b>含泪告知:</b>客户记录暂时无法修改!删除!,添加时请谨慎。点击确定添加成功后,信息会立即出现在下方!注意咯,别猛戳‘确定添加’导致重复添加了哦~</div>
 
- 						    </div>
 
- 						  </div>
 
- 						  
 
- 						  <div class="control-group">
 
- 						    <div class="controls">
 
- 						      <div style="display:inline-block;margin-right:10px"><label><input name="Remind" onclick="reFK()" type="checkbox" value="1"> 添加提醒</label></div>
 
- 						      <span id="reHL"  class="hide">
 
- 								<div>
 
-                  	限期:
 
- 									<input type="date" name="time" id="dtp_input2" value="" class="hide"/>
 
- 	              </div>
 
- 								<div>
 
- 							    备注:<input id="remark" name="remark" type="text"></span>
 
- 	            	</div> 
 
- 						  </div>
 
- 						  
 
- 						  <div class="control-group">
 
- 						    <div class="controls clearfix">
 
- 	  					<input type="button" value="确定添加" id="conSer" onclick="aServiceLog(\'' . $this->staff [0] ['category'] . '\',\'' . $this->staff [0] ['username'] . '\',' . $clientInfo ['cid'] . ')" class="button"></input>
 
- 	  					<div id="load"></div>
 
- 	  					</div>
 
- 	  				</div>
 
- 	  				</div>
 
- 	  				</form>
 
- 	  				</div>
 
- 	  				<!--添加记录按钮-->
 
- 	  				<!--记录列表-->
 
- 	  				<div id="kl"></div>
 
- 					' . $u . '
 
- 					
 
- 					
 
- 	  	<script type="text/javascript">autoFlashHeight();</script>	</div>' 
 
- 		);
 
- 		echo json_encode ( $clientHtml );
 
- 	}
 
- 	function ajaxGetCompanyInfo() {
 
- 	}
 
- 	function checkClient() {
 
- 		$name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
 
- 		$company = $this->get_args ( 'company' ) ? $this->get_args ( 'company' ) : "";
 
- 		
 
- 		
 
- 		
 
- 		if (! empty ( $name )&&! empty ( $company )) {
 
- 			
 
- 			Doo::loadModel ( 'client' );
 
- 			
 
- 			$client = new client ();
 
- 			
 
- 			$clientInfo = $client->getClientByName2 ( $name, $company );
 
- 			if (! empty ( $clientInfo ))
 
- 				echo json_encode ( array (
 
- 						"success" => true 
 
- 				) );
 
- 			else
 
- 				echo json_encode ( array (
 
- 						"success" => false 
 
- 				) );
 
- 		} else {
 
- 			echo json_encode ( array (
 
- 					"success" => false 
 
- 			) );
 
- 		}
 
- 	}
 
- 	function searchClient() {
 
- 		$searchDbInforItem = $this->get_args ( 'searchDbInforItem' ) ? $this->get_args ( 'searchDbInforItem' ) : "";
 
- 		
 
- 		if (! empty ( $searchDbInforItem )) {
 
- 			
 
- 			Doo::loadModel ( 'client' );
 
- 			
 
- 			$client = new client ();
 
- 			
 
- 			$clientInfo = $client->getClientByName ( $searchDbInforItem );
 
- 			
 
- 			echo json_encode ( $clientInfo );
 
- 		} else {
 
- 			echo json_encode ( array (
 
- 					0 => array (
 
- 							'clientname' => '' 
 
- 					) 
 
- 			) );
 
- 		}
 
- 	}
 
- 	function searchCompany() {
 
- 		$searchDbInforItem = $this->get_args ( 'searchDbInforItem' ) ? $this->get_args ( 'searchDbInforItem' ) : "";
 
- 		
 
- 		if (! empty ( $searchDbInforItem )) {
 
- 			
 
- 			Doo::loadModel ( 'company' );
 
- 			
 
- 			$company = new company ();
 
- 			
 
- 			$clientInfo = $company->searchCompany ( $searchDbInforItem );
 
- 			
 
- 			echo json_encode ( $clientInfo );
 
- 		} else {
 
- 			echo json_encode ( array (
 
- 					0 => array (
 
- 							'companyname' => '',
 
- 							'local' => '' 
 
- 					) 
 
- 			) );
 
- 		}
 
- 	}
 
- 	function checkCompany() {
 
- 		$searchDbInforItem = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
 
- 		
 
- 		$searchDbInforItem = explode ( '-', $searchDbInforItem );
 
- 		
 
- 		$this->nature ['naturelenght'] = 15;
 
- 		
 
- 		Doo::loadModel ( 'district' );
 
- 		
 
- 		$district = new district ();
 
- 		
 
- 		$d = $district->get_lv ( 1 );
 
- 		
 
- 		$html = '<option vlaue="0">请选择</option>';
 
- 		
 
- 		foreach ( $d as $key => $value ) {
 
- 			$html .= '<option value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
 
- 		}
 
- 		
 
- 		$this->nature ['district'] = $html;
 
- 		
 
- 		if (! empty ( $searchDbInforItem )) {
 
- 			
 
- 			Doo::loadModel ( 'company' );
 
- 			
 
- 			$company = new company ();
 
- 			if (! isset ( $searchDbInforItem [1] )) {
 
- 				echo json_encode ( array (
 
- 						"success" => false,
 
- 						'nature' => $this->nature 
 
- 				) );
 
- 				die ();
 
- 			}
 
- 			$clientInfo = $company->getCompanyByName ( $searchDbInforItem [0], $searchDbInforItem [1] );
 
- 			
 
- 			if (! empty ( $clientInfo ))
 
- 				echo json_encode ( array (
 
- 						"success" => true,
 
- 						'data' => $clientInfo 
 
- 				) );
 
- 			else
 
- 				echo json_encode ( array (
 
- 						"success" => false,
 
- 						'nature' => $this->nature 
 
- 				) );
 
- 		} else {
 
- 			
 
- 			echo json_encode ( array (
 
- 					"success" => false,
 
- 					'nature' => $this->nature 
 
- 			) );
 
- 		}
 
- 	}
 
- 	function checkLongle() {
 
- 		$searchDbInforItem = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
 
- 		
 
- 		$searchDbInforItem = explode ( ' ', $searchDbInforItem );
 
- 		
 
- 		if (! empty ( $searchDbInforItem )) {
 
- 			
 
- 			Doo::loadModel ( 'longle' );
 
- 			
 
- 			$longle = new longle ();
 
- 			
 
- 			$clientInfo = $longle->getLongleBykeynum ( $searchDbInforItem [0] );
 
- 			if (! empty ( $clientInfo ))
 
- 				echo json_encode ( array (
 
- 						"success" => true 
 
- 				) );
 
- 			else
 
- 				echo json_encode ( array (
 
- 						"success" => false 
 
- 				) );
 
- 		} else {
 
- 			echo json_encode ( array (
 
- 					"success" => false 
 
- 			) );
 
- 		}
 
- 	}
 
- 	function searchLongle() {
 
- 		$searchDbInforItem = $this->get_args ( 'searchDbInforItem' ) ? $this->get_args ( 'searchDbInforItem' ) : "";
 
- 		
 
- 		if (! empty ( $searchDbInforItem )) {
 
- 			
 
- 			Doo::loadModel ( 'longle' );
 
- 			
 
- 			$longle = new longle ();
 
- 			
 
- 			$longleInfo = $longle->getLongleBykeynum2 ( $searchDbInforItem );
 
- 			
 
- 			echo json_encode ( $longleInfo );
 
- 		} else {
 
- 			echo json_encode ( array (
 
- 					0 => array (
 
- 							'clientname' => '' 
 
- 					) 
 
- 			) );
 
- 		}
 
- 	}
 
- 	function updateChangeCompany() {
 
- 		$cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
 
- 		
 
- 		$clientID = $this->get_args ( 'clientID' ) ? $this->get_args ( 'clientID' ) : 0;
 
- 		
 
- 		$companyname = $this->get_args ( 'companyname' ) ? $this->get_args ( 'companyname' ) : "";
 
- 		
 
- 		Doo::loadModel ( 'company' );
 
- 		Doo::loadModel ( 'client' );
 
- 		
 
- 		$client = new client ();
 
- 		$company = new company ();
 
- 		
 
- 		$companyname = explode ( "-", $companyname );
 
- 		
 
- 		if (isset ( $companyname [1] ))
 
- 			$k = $company->getCompanyByName ( $companyname [0], $companyname [1] );
 
- 		else
 
- 			$k = array ();
 
- 		
 
- 		if (! empty ( $cid ) && ! empty ( $k ) && ! empty ( $clientID )) {
 
- 			
 
- 			$client->cid = $clientID;
 
- 			
 
- 			$client->companyid = $cid;
 
- 			
 
- 			$client->companyname = $companyname [0];
 
- 			
 
- 			$client->update ();
 
- 		} else {
 
- 			
 
- 			$local1 = $this->get_args ( 'lv21' ) ? $this->get_args ( 'lv21' ) : 0;
 
- 			$local2 = $this->get_args ( 'lv22' ) ? $this->get_args ( 'lv22' ) : 0;
 
- 			$local3 = $this->get_args ( 'lv23' ) ? $this->get_args ( 'lv23' ) : 0;
 
- 			
 
- 			Doo::loadModel ( 'district' );
 
- 			$district = new district ();
 
- 			
 
- 			// 更新公司信息
 
- 			$lv1 = $district->getbyid ( $local1 );
 
- 			$lv2 = $district->getbyid ( $local2 );
 
- 			$lv3 = $district->getbyid ( $local3 );
 
- 			
 
- 			if (empty ( $local1 ) || empty ( $local2 ))
 
- 				return "/";
 
- 			
 
- 			if (! empty ( $local1 ) && ! empty ( $local2 ))
 
- 				$company->local = $lv1 [0] ['name'] . "," . $lv2 [0] ['name'] . "," . $lv3 [0] ['name'];
 
- 			
 
- 			if (! empty ( $local1 ) && ! empty ( $local2 ))
 
- 				$company->district = $local1 . "," . $local2 . "," . $local3;
 
- 			
 
- 			$nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
 
- 			$fax = $this->get_args ( 'fax' ) ? $this->get_args ( 'fax' ) : "";
 
- 			$webservice = $this->get_args ( 'webservice' ) ? $this->get_args ( 'webservice' ) : "";
 
- 			$address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
 
- 			$landmarks = $this->get_args ( 'landmarks' ) ? $this->get_args ( 'landmarks' ) : "";
 
- 			$stay = $this->get_args ( 'stay' ) ? $this->get_args ( 'stay' ) : "";
 
- 			$ride = $this->get_args ( 'ride' ) ? $this->get_args ( 'ride' ) : "";
 
- 			
 
- 			$nature = implode ( ",", $nature );
 
- 			
 
- 			$company->companyname = $companyname [0];
 
- 			$company->ride = $ride;
 
- 			$company->fax = $fax;
 
- 			
 
- 			$company->webservice = $webservice;
 
- 			
 
- 			$company->address = $address;
 
- 			$company->landmarks = $landmarks;
 
- 			$company->stay = $stay;
 
- 			
 
- 			$company->nature = $nature;
 
- 			$cid = $company->insert ();
 
- 			
 
- 			$client->cid = $clientID;
 
- 			
 
- 			$client->companyid = $cid;
 
- 			
 
- 			$client->companyname = $companyname [0];
 
- 			
 
- 			$client->update ();
 
- 		}
 
- 		return "/contacts";
 
- 	}
 
- 	function AddClientInfo() { // 不编辑公司
 
- 		$cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
 
- 		$clientname = $this->get_args ( 'clientname' ) ? $this->get_args ( 'clientname' ) : "";
 
- 		$gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : "";
 
- 		$nicename = $this->get_args ( 'nicename' ) ? $this->get_args ( 'nicename' ) : "";
 
- 		$telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : "";
 
- 		$phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
 
- 		$email = $this->get_args ( 'email' ) ? $this->get_args ( 'email' ) : "";
 
- 		$unit = $this->get_args ( 'unit' ) ? $this->get_args ( 'unit' ) : "";
 
- 		$fax = $this->get_args ( 'fax' ) ? $this->get_args ( 'fax' ) : "";
 
- 		$webservice = $this->get_args ( 'webservice' ) ? $this->get_args ( 'webservice' ) : "";
 
- 		$department = $this->get_args ( 'department' ) ? $this->get_args ( 'department' ) : "";
 
- 		$position = $this->get_args ( 'position' ) ? $this->get_args ( 'position' ) : "";
 
- 		$office = $this->get_args ( 'office' ) ? $this->get_args ( 'office' ) : "";
 
- 		$address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
 
- 		$ride = $this->get_args ( 'ride' ) ? $this->get_args ( 'ride' ) : "";
 
- 		$landmarks = $this->get_args ( 'landmarks' ) ? $this->get_args ( 'landmarks' ) : "";
 
- 		$qq = $this->get_args ( 'qq' ) ? $this->get_args ( 'qq' ) : "";
 
- 		$priority = $this->get_args ( 'priority' ) ? $this->get_args ( 'priority' ) : 5;
 
- 		$stay = $this->get_args ( 'stay' ) ? $this->get_args ( 'stay' ) : "";
 
- 		$mark = $this->get_args ( 'mark' ) ? $this->get_args ( 'mark' ) : "";
 
- 		
 
- 		$lv21 = $this->get_args ( 'lv21' ) ? $this->get_args ( 'lv21' ) : "";
 
- 		$lv22 = $this->get_args ( 'lv22' ) ? $this->get_args ( 'lv22' ) : "";
 
- 		$lv23 = $this->get_args ( 'lv23' ) ? $this->get_args ( 'lv23' ) : "";
 
- 		
 
- 		if (! empty ( $cid ) && ! empty ( $clientname )) {
 
- 			
 
- 			Doo::loadModel ( 'client' );
 
- 			Doo::loadModel ( 'district' );
 
- 			$district = new district ();
 
- 			$client = new client ();
 
- 			
 
- 			$client->cid = $cid;
 
- 			$client->clientname = $clientname;
 
- 			$client->gender = $gender;
 
- 			$client->nicename = $nicename;
 
- 			$client->telephone = $telephone;
 
- 			$client->phone = $phone;
 
- 			$client->email = $email;
 
- 			// if(!empty($unit)){
 
- 			// $client->unit=$unit;
 
- 			// $client->companyname=$unit;
 
- 			// }
 
- 			if (! empty ( $lv21 ) && ! empty ( $lv22 ) && ! empty ( $lv23 )) {
 
- 				$client->district = $lv21 . "," . $lv22 . "," . $lv23;
 
- 			}
 
- 			
 
- 			if (! empty ( $client->district )) {
 
- 				$districtList = $district->find ( array (
 
- 						'where' => 'id in(' . $client->district . ')',
 
- 						'asArray' => true 
 
- 				) );
 
- 				$jsonString = array ();
 
- 				foreach ( $districtList as $value ) {
 
- 					array_push ( $jsonString, $value ['name'] );
 
- 				}
 
- 				$jsonString = implode ( ",", $jsonString );
 
- 				if (! empty ( $jsonString ))
 
- 					$client->local = $jsonString;
 
- 			}
 
- 			
 
- 			$client->fax = $fax;
 
- 			$client->webservice = $webservice;
 
- 			$client->department = $department;
 
- 			$client->position = $position;
 
- 			$client->office = $office;
 
- 			$client->address = $address;
 
- 			$client->ride = $ride;
 
- 			$client->landmarks = $landmarks;
 
- 			$client->qq = $qq;
 
- 			$client->stay = $stay;
 
- 			$client->priority = $priority;
 
- 			$client->mark = $mark;
 
- 			$client->updatetime = time ();
 
- 			$client->update ();
 
- 			
 
- 			// Doo::loadModel ( 'company' );
 
- 			// $company = new company();
 
- 			// $companyid=$client->getOne(array('where'=>' cid='.$cid,'asArray'=>true));
 
- 			// $company->office=$office;
 
- 			// $company->fax=$fax;
 
- 			// $company->address=$address;
 
- 			// $company->ride=$ride;
 
- 			// $company->landmarks=$landmarks;
 
- 			// $company->cid=$companyid['companyid'];
 
- 			// if(!empty($unit)){
 
- 			// $company->companyname=$unit;
 
- 			// }
 
- 			// $company->update();
 
- 			
 
- 			$clientInfo = $client->getOne ( array (
 
- 					'where' => ' cid=' . $cid,
 
- 					'asArray' => true 
 
- 			) );
 
- 			// 日常行为
 
- 			Doo::loadModel ( "action_log" );
 
- 			$action_log = new action_log ();
 
- 			
 
- 			$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'] . ')';
 
- 			$action_log->sid = $this->staff [0] ['sid'];
 
- 			$action_log->cid = $this->staff [0] ['cid'];
 
- 			$action_log->updatetime = date ( "Y-m-d" );
 
- 			$action_log->time = date ( "H:i" );
 
- 			$action_log->class = $action_log->iconContacts;
 
- 			
 
- 			$action_log->status = 2;
 
- 			
 
- 			$action_log->districtid = $clientInfo ['district'];
 
- 			
 
- 			$local = $district->getbyidlist ( $clientInfo ['district'] );
 
- 			$action_log->city = $local [0] ['name'];
 
- 			$action_log->province = $local [1] ['name'];
 
- 			
 
- 			$action_log->company = $clientInfo ['companyname'];
 
- 			
 
- 			Doo::loadModel ( 'company' );
 
- 			$company = new company ();
 
- 			$companyInfo = $company->getOne ( array (
 
- 					'where' => ' companyname="' . $clientInfo ['companyname'] . '"',
 
- 					'asArray' => true 
 
- 			) );
 
- 			$nature = explode ( ',', $companyInfo ['nature'] );
 
- 			$action_log->nature = $nature [0];
 
- 			
 
- 			$action_log->insert ();
 
- 			
 
- 			echo json_encode ( array (
 
- 					"success" => true 
 
- 			) );
 
- 			die ();
 
- 		} else
 
- 			echo json_encode ( array (
 
- 					"success" => false 
 
- 			) );
 
- 		die ();
 
- 	}
 
- 	function ajaxClientInfo() {
 
- 		$cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
 
- 		
 
- 		if (! empty ( $cid )) {
 
- 			Doo::loadModel ( 'client' );
 
- 			Doo::loadModel ( 'company' );
 
- 			
 
- 			$company = new company ();
 
- 			$client = new client ();
 
- 			
 
- 			$info = $client->getOne ( array (
 
- 					'where' => ' cid=' . $cid,
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			$cinfo = $company->getOne ( array (
 
- 					'where' => ' cid=' . $info ['companyid'],
 
- 					'asArray' => true 
 
- 			) );
 
-             Doo::loadClass ( 'XDeode' );
 
-             $XDeode = new XDeode ( 5 );
 
-             $cinfo['cidKey']=$XDeode->encode ( $cinfo['cid'] );
 
- 			Doo::loadModel ( 'district' );
 
- 			$district = new district ();
 
- 			$districtLv1 = $district->get_lv ( 1 );
 
- 			
 
- 			$info ['districtList'] = $district->getbyidlist ( $info ['district'] );
 
- 			$optionHtml = '<option vlaue="0">请选择</option>';
 
- 			foreach ( $districtLv1 as $key => $value ) {
 
- 				if ($value ['name'] == $info ['districtList'] [0] ['name']) {
 
- 					$optionHtml .= '<option selected value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
 
- 				} else
 
- 					$optionHtml .= '<option value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
 
- 			}
 
- 			
 
- 			$districtLv2 = $district->get_lvByid ( 2, $info ['districtList'] [0] ['id'] );
 
- 			$optionHtml2 = '';
 
- 			foreach ( $districtLv2 as $key => $value ) {
 
- 				if ($value ['name'] == $info ['districtList'] [1] ['name'])
 
- 					$optionHtml2 .= '<option selected value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
 
- 				else
 
- 					$optionHtml2 .= '<option value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
 
- 			}
 
- 			$districtLv3 = $district->get_lvByid ( 2, $info ['districtList'] [1] ['id'] );
 
- 			$optionHtml3 = '';
 
- 			foreach ( $districtLv3 as $key => $value ) {
 
- 				if ($value ['name'] == $info ['districtList'] [2] ['name'])
 
- 					$optionHtml3 .= '<option selected value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
 
- 				else
 
- 					$optionHtml3 .= '<option value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
 
- 			}
 
- 			
 
- 			$info ['districtLv1'] = $optionHtml;
 
- 			$info ['districtLv2'] = $optionHtml2;
 
- 			$info ['districtLv3'] = $optionHtml3;
 
- 			
 
- 			$info ['companyInfo'] = $cinfo;
 
- 			
 
- 			echo json_encode ( array (
 
- 					"success" => true,
 
- 					'html' => $info 
 
- 			) );
 
- 			die ();
 
- 		} else
 
- 			echo json_encode ( array (
 
- 					"success" => false,
 
- 					'html' => '' 
 
- 			) );
 
- 		die ();
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 为客户添加服务日志
 
- 	 */
 
- 	function ajaxAddServiceLog() {
 
- 		$status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "";
 
- 		$clientid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
 
- 		$mark = $this->get_args ( 'mark' ) ? $this->get_args ( 'mark' ) : "";
 
- 		$m = $this->get_args ( 'm' ) ? $this->get_args ( 'm' ) : "";
 
- 		$d = $this->get_args ( 'd' ) ? $this->get_args ( 'd' ) : "";
 
- 		$y = $this->get_args ( 'y' ) ? $this->get_args ( 'y' ) : date ( "Y" );
 
- 		
 
- 		$Remind = $this->get_args ( 'Remind' ) ? $this->get_args ( 'Remind' ) : 0;
 
- 		$time = $this->get_args ( 'time' ) ? $this->get_args ( 'time' ) : 0;
 
- 		$remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
 
- 		
 
- 		if (! empty ( $status ) && ! empty ( $clientid )) {
 
- 			Doo::loadModel ( 'service_log' );
 
- 			Doo::loadModel ( 'client_staff' );
 
- 			Doo::loadModel ( 'client' );
 
- 			Doo::loadModel ( 'district' );
 
- 			$district = new district ();
 
- 			$client = new client ();
 
- 			$clientStaff = new client_staff ();
 
- 			$service_log = new service_log ();
 
- 			
 
- 			$service_log->status = $status;
 
- 			$service_log->clientid = $clientid;
 
- 			$service_log->mark = htmlspecialchars ( $mark );
 
- 			$service_log->date = $y . "-" . $m . "-" . $d;
 
- 			$service_log->category = $this->staff [0] ['category'];
 
- 			$service_log->staffname = $this->staff [0] ['username'];
 
- 			$service_log->staffid = $this->staff [0] ['sid'];
 
- 			
 
- 			$service_log->insert ();
 
- 			
 
- 			// 日常行为
 
- 			Doo::loadModel ( "action_log" );
 
- 			Doo::loadModel ( "client" );
 
- 			$client = new client ();
 
- 			
 
- 			// 记录服务时间
 
- 			$client->cid = $clientid;
 
- 			$client->servicetime = time ();
 
- 			$client->update ();
 
- 			$action_log = new action_log ();
 
- 			
 
- 			$clientInfo = $client->getOne ( array (
 
- 					'where' => ' cid=' . $clientid,
 
- 					'asArray' => TRUE 
 
- 			) );
 
- 			
 
- 			$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'] . ')添加新客户记录。';
 
- 			$action_log->sid = $this->staff [0] ['sid'];
 
- 			$action_log->cid = $this->staff [0] ['cid'];
 
- 			$action_log->updatetime = date ( "Y-m-d" );
 
- 			$action_log->time = date ( "H:i" );
 
- 			$action_log->status = 3;
 
- 			
 
- 			$action_log->districtid = $clientInfo ['district'];
 
- 			
 
- 			$local = $district->getbyidlist ( $clientInfo ['district'] );
 
- 			$action_log->city = $local [0] ['name'];
 
- 			$action_log->province = $local [1] ['name'];
 
- 			
 
- 			$action_log->company = $clientInfo ['companyname'];
 
- 			
 
- 			Doo::loadModel ( 'company' );
 
- 			$company = new company ();
 
- 			$companyInfo = $company->getOne ( array (
 
- 					'where' => ' companyname="' . $clientInfo ['companyname'] . '"',
 
- 					'asArray' => true 
 
- 			) );
 
- 			$nature = explode ( ',', $companyInfo ['nature'] );
 
- 			$action_log->nature = $nature [0];
 
- 			
 
- 			$action_log->class = $action_log->iconContacts;
 
- 			$action_log->insert ();
 
- 			
 
- 			// 更新信息中心服务日志统计数量
 
- 			$redis = new Redis ();
 
- 			$redis->connect ( '127.0.0.1', '6379' );
 
- 			
 
- 			$categoryCondition = " and cid=" . $this->staff [0] ['cid'];
 
- 			$sidCondition = " and sid=" . $this->staff [0] ['sid'];
 
- 			// actionlog免查询值 $alCondition='';
 
- 			$alCondition = ' aid>' . REMIT . ' and ';
 
- 			
 
- 			// 个人服务日志数量redis值
 
- 			$redisKeyCS = date ( 'Y-m-d' ) . 'SL_' . $this->staff [0] ['cid'] . '_' . $this->staff [0] ['sid'];
 
- 			$action_log = new action_log ();
 
- 			
 
- 			$actionLogLongle = $action_log->find ( array (
 
- 					'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
 
- 					'where' => $alCondition . " status=3 " . $categoryCondition . $sidCondition . " and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)  ",
 
- 					'groupby' => 'date_format(updatetime,"%m-%d")',
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			$statisticsLongle = array ();
 
- 			for($d = 0; $d <= 29; $d ++) {
 
- 				$MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
 
- 				$falgLongle = true;
 
- 				
 
- 				foreach ( $actionLogLongle as $value ) {
 
- 					if ($value ['updatetime'] == $MD) {
 
- 						array_push ( $statisticsLongle, $value ['count'] );
 
- 						$falgLongle = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 				if ($falgLongle)
 
- 					array_push ( $statisticsLongle, 0 );
 
- 			}
 
- 			$statisticsLongle = array_reverse ( $statisticsLongle );
 
- 			$jsl = json_encode ( $statisticsLongle );
 
- 			$redis->set ( $redisKeyCS, $jsl );
 
- 			
 
- 			// 办事处服务日志数量reids值
 
- 			$redisKeyC = date ( 'Y-m-d' ) . 'SL_' . $this->staff [0] ['cid'] . '_';
 
- 			$action_log = new action_log ();
 
- 			$actionLogLongle = $action_log->find ( array (
 
- 					'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
 
- 					'where' => $alCondition . " status=3 " . $categoryCondition . " and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)  ",
 
- 					'groupby' => 'date_format(updatetime,"%m-%d")',
 
- 					'asArray' => true 
 
- 			) );
 
- 			$statisticsLongle = array ();
 
- 			for($d = 0; $d <= 29; $d ++) {
 
- 				$MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
 
- 				$falgLongle = true;
 
- 				
 
- 				foreach ( $actionLogLongle as $value ) {
 
- 					if ($value ['updatetime'] == $MD) {
 
- 						array_push ( $statisticsLongle, $value ['count'] );
 
- 						$falgLongle = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 				if ($falgLongle)
 
- 					array_push ( $statisticsLongle, 0 );
 
- 			}
 
- 			$statisticsLongle = array_reverse ( $statisticsLongle );
 
- 			$jsl = json_encode ( $statisticsLongle );
 
- 			$redis->set ( $redisKeyC, $jsl );
 
- 			
 
- 			// 全员处服务日志数量的redis值
 
- 			$redisKey = date ( 'Y-m-d' ) . 'SL__';
 
- 			$action_log = new action_log ();
 
- 			$actionLogLongle = $action_log->find ( array (
 
- 					'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
 
- 					'where' => $alCondition . " status=3  and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)  ",
 
- 					'groupby' => 'date_format(updatetime,"%m-%d")',
 
- 					'asArray' => true 
 
- 			) );
 
- 			$statisticsLongle = array ();
 
- 			for($d = 0; $d <= 29; $d ++) {
 
- 				$MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
 
- 				$falgLongle = true;
 
- 				
 
- 				foreach ( $actionLogLongle as $value ) {
 
- 					if ($value ['updatetime'] == $MD) {
 
- 						array_push ( $statisticsLongle, $value ['count'] );
 
- 						$falgLongle = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 				if ($falgLongle)
 
- 					array_push ( $statisticsLongle, 0 );
 
- 			}
 
- 			$statisticsLongle = array_reverse ( $statisticsLongle );
 
- 			$jsl = json_encode ( $statisticsLongle );
 
- 			$redis->set ( $redisKey, $jsl );
 
- 			
 
- 			if (! empty ( $Remind )) {
 
- 				Doo::loadModel ( 'remind' );
 
- 				$remindObj = new remind ();
 
- 				
 
- 				$datetime1 = new DateTime ( date ( 'Y-m-d' ) );
 
- 				$datetime2 = new DateTime ( $time );
 
- 				$interval = $datetime1->diff ( $datetime2 );
 
- 				
 
- 				$remindObj->day = $interval->format ( '%a' );
 
- 				$remindObj->remark = $remark;
 
- 				$remindObj->time = date ( "Y-m-d" );
 
- 				$remindObj->clientName = $clientInfo ['clientname'];
 
- 				$remindObj->clientID = $clientid;
 
- 				$remindObj->companyName = $clientInfo ['companyname'];
 
- 				$remindObj->companyID = $companyInfo ['cid'];
 
- 				$remindObj->staffID = $this->staff [0] ['sid'];
 
- 				if ($status == 1)
 
- 					$remindObj->class = "iconService";
 
- 				if ($status == 2)
 
- 					$remindObj->class = "iconPhone";
 
- 				if ($status == 3)
 
- 					$remindObj->class = "iconOther";
 
- 				$remindObj->insert ();
 
- 			}
 
- 			
 
- 			echo json_encode ( array (
 
- 					"success" => true,
 
- 					'html' => '' 
 
- 			) );
 
- 			die ();
 
- 		} else
 
- 			echo json_encode ( array (
 
- 					"success" => false,
 
- 					'html' => '' 
 
- 			) );
 
- 		die ();
 
- 	}
 
- 	function _getLongleLogHtml($longleLog = array()) {
 
- 		$html = "";
 
- 		
 
- 		foreach ( $longleLog as $key => $value ) {
 
- 			$dateline = explode ( "-", $value ['dateline'] );
 
- 			
 
- 			$html .= '<div class="infoFlowList">
 
- 						<div class="dateTitle">
 
- 							<em class="month"><span class="num">' . $dateline [1] . '</span><span class="text">-' . $dateline [2] . '</span></em>
 
- 							<span class="year">' . $dateline [0] . '</span>
 
- 						</div>
 
- 						';
 
- 			// 备注
 
- 			if ($value ['status'] == 8) {
 
- 				$html .= '
 
- 						<ul class="flowList">
 
- 							<li class="item iconLock">备注<' . $value ['category'] . '<a href="javascript:void(0);"  onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
 
- 							<li class="item">' . $value ['mark'] . '</li>
 
- 						</ul>';
 
- 			} elseif ($value ['status'] == 10) {
 
-                 $html .= '
 
- 						<ul class="flowList">
 
- 							<li class="item iconLock">延期<' . $value ['category'] . '<a href="javascript:void(0);"  onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
 
- 							<li class="item">' . $value ['mark'] . '</li>
 
- 						</ul>';
 
-                 // 生成
 
-             }elseif ($value ['status'] == 1) {
 
- 				$html .= '<ul class="flowList">
 
- 							<li class="item iconGenerate">生成<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
 
- 						</ul>';
 
- 				// 接收
 
- 			} elseif ($value ['status'] == 2) {
 
- 				$html .= '<ul class="flowList">
 
- 							<li class="item iconReceive">接收<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
 
- 						</ul>';
 
- 				// 借出
 
- 			} elseif ($value ['status'] == 3) {
 
- 				$html .= '<ul class="flowList">
 
- 							<li class="item iconBorrow">借出<' . $value ['category'] . '<a  href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
 
- 							<li class="item">' . $value ['product'] . '</li>
 
- 							<li class="item"><a href="javascript:void(0);" onclick="getClientInfo(\'' . $value ['clientid'] .'\')"  >' . $value ['client'] . '</a></li>
 
- 						</ul>';
 
- 				// 销售
 
- 			} elseif ($value ['status'] == 4) {
 
- 				$html .= '<ul class="flowList">
 
- 							<li class="item iconSell">销售<' . $value ['category'] . '<a  href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
 
- 							<li class="item">' . $value ['product'] . '</li>
 
- 							<li class="item"><a href="javascript:void(0);" onclick="getClientInfo(\'' . $value ['clientid'] .  '\')" >' . $value ['client'] . '</a></li>
 
- 						</ul>';
 
- 				// 升级
 
- 			} elseif ($value ['status'] == 5) {
 
- 				$html .= '<ul class="flowList">
 
- 							<li class="item iconUpdate">升级<' . $value ['category'] . '<a  href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
 
- 							<li class="item">' . $value ['product'] . '</li>
 
- 							<li class="item"><a href="javascript:void(0);" onclick="getClientInfo(\'' . $value ['clientid'] .  '\')" >' . $value ['client'] . '</a></li>
 
- 						</ul>';
 
- 				// 更换
 
- 			} elseif ($value ['status'] == 6) {
 
- 				
 
- 				$html .= '<ul class="flowList">
 
- 							<li class="item iconReplace">更换<' . $value ['category'] . '<a  href="javascript:void(0);"  onclick="getStaffInfo(\'' . $value ['operator'] . '\')">' . $value ['operator'] . '</a></li>
 
- 							<li class="item"><a href="javascript:void(0);" onclick="getLockByName(\'' . $value ['new_key_num'] . '\')">' . $value ['new_key_num'] . '</a>
 
- 							<li class="item"><a href="javascript:void(0);" onclick="getClientInfo(\'' . $value ['clientid'] .  '\')" >' . $value ['client'] . '</a></li>
 
- 						</ul>';
 
- 				// 回收
 
- 			} elseif ($value ['status'] == 7) {
 
- 				Doo::loadModel ( 'staff' );
 
- 				$staff = new staff ();
 
- 				$staffinfo = $staff->getOne ( array (
 
- 						'where' => ' username like "' . $value ['responsible'] . '"',
 
- 						'asArray' => true 
 
- 				) );
 
- 				if (empty ( $staffinfo ))
 
- 					$staffinfo ['category'] = "";
 
- 				$html .= '<ul class="flowList">
 
- 							<li class="item iconRecycle">收回<' . $value ['category'] . '<a  href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')">' . $value ['operator'] . '</a></li>
 
- 							<li class="item">' . $staffinfo ['category'] . '<a  href="javascript:void(0);" id="ajaxStaff" data="' . $value ['responsible'] . '">' . $value ['responsible'] . '</a></li>
 
- 						</ul>';
 
- 			} elseif ($value ['status'] == 9) {
 
- 				$html .= '<ul class="flowList">
 
- 							<li class="item iconGif">赠送 < ' . $value ['category'] . '<a  href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')">' . $value ['operator'] . '</a></li>
 
- 							<li class="item"><a href="javascript:void(0);" onclick="getClientInfo(\'' . $value ['clientid'] .  '\')" >' . $value ['client'] . '</a></li>
 
- 						</ul>';
 
- 			}
 
- 			$html .= '</div>';
 
- 		}
 
- 		
 
- 		return $html;
 
- 	}
 
- 	function adminLock() {
 
- 		$emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
 
- 		$data ['emsg'] = "";
 
- 		
 
- 		if ($emsg != "")
 
- 			$data ['emsg'] = "请填写完整的数据";
 
- 		
 
- 		$data ['memu'] = "keyonline";
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		if ($this->staff [0] ['isadmin'] != 1)
 
- 			return "/adminmyinfo";
 
- 		
 
- 		Doo::loadModel ( 'L_category' );
 
- 		$L_category = new L_category ();
 
- 		$data ['category'] = $L_category->getCategory ();
 
- 		$data ['time'] = time ();
 
- 		$this->render ( "/admin/admin_addlock", $data );
 
- 	}
 
- 	function adminAddLock() {
 
- 		$cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
 
- 		$path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
 
- 		
 
- 		if ($cid != 0 && $path != "") {
 
- 			Doo::loadModel ( 'longle' );
 
- 			Doo::loadModel ( 'L_category' );
 
- 			$L_category = new L_category ();
 
- 			Doo::loadModel ( 'longle_log' );
 
- 			
 
- 			$exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/" . iconv ( "UTF-8", "GB2312", $path ) );
 
- 			// print_r($exlArray);die;
 
- 			// echo json_encode($exlArray);die;
 
- 			$category = $L_category->getCategoryById ( $cid );
 
- 			
 
- 			foreach ( $exlArray as $key => $value ) {
 
- 				// 锁记录
 
- 				$longle = new longle ();
 
- 				$longle->key_num = str_replace ( "'", "", $value ['key_num'] );
 
- 				$longle->product = str_replace ( "'", "", $value ['product'] );
 
- 				$longle->make_day = $value ['make_day'];
 
- 				$longle->alloted_time = $value ['alloted_time'];
 
- 				$longle->status = 1;
 
- 				$longle->statusT = "生成";
 
- 				$longle->cid = $cid;
 
- 				$longle->category = $category [0] ['title'];
 
- 				$longle->SerialNumber = $value ['SerialNumber'];
 
- 				$longle->version = $value ['version'];
 
- 				$lid = $longle->insert ();
 
- 				
 
- 				// 锁日志记录
 
- 				$longle_log = new longle_log ();
 
- 				$longle_log->lid = $lid;
 
- 				$longle_log->status = 1;
 
- 				$longle_log->statusT = "生成";
 
- 				$longle_log->operator = $this->staff [0] ['username'];
 
- 				$longle_log->product = $longle->product;
 
- 				$longle_log->category = $this->staff [0] ['category'];
 
- 				$longle_log->dateline = date ( "Y-m-d" );
 
- 				$id = $longle_log->insert ();
 
- 			}
 
- 			// 记录日常行为
 
- 			Doo::loadModel ( "action_log" );
 
- 			$action_log = new action_log ();
 
- 			$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>个锁';
 
- 			$action_log->sid = $this->staff [0] ['sid'];
 
- 			$action_log->cid = $this->staff [0] ['cid'];
 
- 			$action_log->class = $action_log->iconGenerate;
 
- 			$action_log->updatetime = date ( "Y-m-d" );
 
- 			$action_log->time = date ( "H:i" );
 
- 			$action_log->status = 11;
 
- 			
 
- 			$action_log->insert ();
 
- 			
 
- 			return "/keyonline";
 
- 		} else
 
- 			return "/adminlock/error";
 
- 	}
 
- 	function avatarCM() {
 
- 		$vid = isset ( $this->params ['vid'] ) ? $this->params ['vid'] : 0;
 
- 		
 
- 		if (! empty ( $vid )) {
 
- 			Doo::loadModel ( "verify" );
 
- 			$verify = new verify ();
 
- 			Doo::loadModel ( 'staff' );
 
- 			$staff = new staff ();
 
- 			
 
- 			$list = $verify->getOne ( array (
 
- 					'where' => 'vid=' . $vid,
 
- 					'asArray' => true 
 
- 			) );
 
- 			if (empty ( $list ))
 
- 				return "/adminverify";
 
- 			
 
- 			$avatar = json_decode ( $list ['staff'] );
 
- 			foreach ( $avatar as $key => $value ) {
 
- 				$uinfo = $staff->getOne ( array (
 
- 						'where' => 'sid=' . $value [0],
 
- 						'asArray' => true 
 
- 				) );
 
- 				$avatar [$key] ['2'] = $uinfo ['avatar'];
 
- 			}
 
- 			
 
- 			$verify->staff = json_encode ( $avatar );
 
- 			$verify->update ( array (
 
- 					'where' => 'vid=' . $vid 
 
- 			) );
 
- 		}
 
- 		return "/adminverify";
 
- 	}
 
- 	function adminmyinfo() {
 
- 		$data ['memu'] = "adminmyinfo";
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		$birArray = explode ( '-', $this->staff [0] ['birthday'] );
 
- 		
 
- 		$data ['year'] = $birArray [0];
 
- 		
 
- 		$year = date ( 'Y' );
 
- 		$yearHtml = "";
 
- 		for(; $year >= 1900; $year --) {
 
- 			$yearHtml .= '<option ';
 
- 			if ($data ['year'] == $year)
 
- 				$yearHtml .= 'selected';
 
- 			$yearHtml .= ' value="' . $year . '">' . $year . '</option>';
 
- 		}
 
- 		$data ['yearHtml'] = $yearHtml;
 
- 		$data ['month'] = 01;
 
- 		$data ['day'] = 01;
 
- 		if (isset ( $birArray [1] )) {
 
- 			$data ['month'] = $birArray [1];
 
- 			$data ['day'] = $birArray [2];
 
- 		}
 
- 		$data ['msg'] = urldecode ( $this->params ['msg'] );
 
- 		
 
- 		$this->render ( "/admin/admin_myinfo", $data );
 
- 	}
 
- 	function updateMyinfo() {
 
- 		$telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : 0;
 
- 		
 
- 		$phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : 0;
 
- 		$email = $this->get_args ( 'email' ) ? $this->get_args ( 'email' ) : "";
 
- 		
 
- 		$qq = is_numeric ( $this->get_args ( 'qq' ) ) ? $_POST ['qq'] : 0;
 
- 		$year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
 
- 		$month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
 
- 		$day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : "";
 
- 		$position = $this->get_args ( 'position' ) ? $this->get_args ( 'position' ) : "";
 
- 		$gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : "男";
 
- 		
 
- 		$oldpassword = $this->get_args ( 'oldpassword' ) ? $this->get_args ( 'oldpassword' ) : "";
 
- 		$newpassword = $this->get_args ( 'newpassword' ) ? $this->get_args ( 'newpassword' ) : "";
 
- 		$rnewpassword = $this->get_args ( 'rnewpassword' ) ? $this->get_args ( 'rnewpassword' ) : "";
 
- 		
 
- 		$remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
 
- 		$bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
 
- 		$bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
 
- 		$coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
 
- 		
 
- 		Doo::loadModel ( 'staff' );
 
- 		$staff = new staff ();
 
- 		Doo::loadModel ( 'staffDynamic' );
 
- 		$staffDynamic = new staffDynamic ();
 
- 		
 
- 		$staff->sid = $this->staff [0] ['sid'];
 
- 		
 
- 		if (! empty ( $remittanceName ))
 
- 			$staff->remittanceName = $remittanceName;
 
- 		if (! empty ( $bankName ))
 
- 			$staff->bankName = $bankName;
 
- 		if (! empty ( $bankNumber ))
 
- 			$staff->bankNumber = $bankNumber;
 
- 		if (! empty ( $coupletNumber ))
 
- 			$staff->coupletNumber = $coupletNumber;
 
- 		
 
- 		$content = "";
 
- 		$ext = "更新了他的";
 
- 		if ($telephone != 0 && $this->staff [0] ['telephone'] != $telephone) {
 
- 			$staff->telephone = $telephone;
 
- 			$content .= "<b>手机</b> ";
 
- 		}
 
- 		if ($phone != 0 && $this->staff [0] ['phone'] != $phone) {
 
- 			$staff->phone = $phone;
 
- 			$content .= "<b>电话</b> ";
 
- 		}
 
- 		
 
- 		if ($qq != 0 && $this->staff [0] ['qq'] != $qq) {
 
- 			$staff->qq = $qq;
 
- 			$content .= "<b>QQ</b> ";
 
- 		}
 
- 		if ($year != 2014) {
 
- 			$staff->birthday = $year . "-" . $month . "-" . $day;
 
- 			$content .= "<b>生日</b> ";
 
- 		}
 
- 		if ($email != "" && filter_var ( $email, FILTER_VALIDATE_EMAIL ) && $this->staff [0] ['email'] != $email) {
 
- 			$staff->email = $email;
 
- 			$content .= "<b>邮箱</b> ";
 
- 		}
 
- 		if (! empty ( $position )) {
 
- 			$staff->position = $position;
 
- 			$content .= "<b>职位</b> ";
 
- 		}
 
- 		
 
- 		$staff->gender = $gender;
 
- 		
 
- 		$msg = "更新成功";
 
- 		
 
- 		if ($this->staff [0] ['passwork'] == md5 ( $oldpassword )) {
 
- 			if ($newpassword == $rnewpassword && (! empty ( $newpassword )))
 
- 				$staff->passwork = md5 ( $newpassword );
 
- 			else
 
- 				$msg = "密码不一致";
 
- 		} else {
 
- 			if ($oldpassword != "")
 
- 				$msg = "密码错误";
 
- 		}
 
- 		
 
- 		if (! empty ( $content )) {
 
- 			$staffDynamic->content = $ext . $content;
 
- 			$staffDynamic->cid = $this->staff [0] ['cid'];
 
- 			$staffDynamic->category = $this->staff [0] ['category'];
 
- 			$staffDynamic->time = time ();
 
- 			$staffDynamic->sid = $this->staff [0] ['sid'];
 
- 			$staffDynamic->staff = $this->staff [0] ['username'];
 
- 			$staffDynamic->insert ();
 
- 		}
 
- 		
 
- 		$staff->update ( array (
 
- 				'where' => ' sid=' . $this->staff [0] ['sid'] 
 
- 		) );
 
- 		
 
- 		return "/adminmyinfo/" . $msg;
 
- 	}
 
- 	function admincontacts() {
 
- 		$data ['memu'] = "admincontacts";
 
- 		
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		Doo::loadModel ( 'L_category' );
 
- 		Doo::loadModel ( 'staff' );
 
- 		
 
- 		$staff = new staff ();
 
- 		$L_category = new L_category ();
 
- 		
 
- 		$this->render ( "/admin/admin_addContacts", $data );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 微信通知设置
 
- 	 */
 
- 	// function notificationConf() {
 
- 	// Doo::loadModel ( "notificationConf" );
 
- 	// $notificationConf = new notificationConf ();
 
- 	
 
- 	// $detail = $notificationConf->getNotificationConfBySid ( $this->staff [0] ['sid'] );
 
- 	
 
- 	// $rule = json_decode ( $detail ['conf'], true );
 
- 	
 
- 	// $data ['rule'] = $rule;
 
- 	// $data ['memu'] = "notificationConf";
 
- 	// $data ['staff'] = $this->staff;
 
- 	
 
- 	// $this->render ( "/admin/invoiceNotificationConf", $data );
 
- 	// }
 
- 	// function ajaxSetNotificationConf() {
 
- 	// $notificationType = $this->get_args ( 'notificationType' ) ? $this->get_args ( 'notificationType' ) : "";
 
- 	// $notificationValue = $this->get_args ( 'notificationValue' ) ? $this->get_args ( 'notificationValue' ) : '';
 
- 	
 
- 	// if (! empty ( $notificationType ) && ! empty ( $notificationValue ) && ! empty ( $this->staff [0] ['sid'] )) {
 
- 	// Doo::loadModel ( "notificationConf" );
 
- 	// $notificationConf = new notificationConf ();
 
- 	
 
- 	// $detail = $notificationConf->getNotificationConfBySid ( $this->staff [0] ['sid'] );
 
- 	
 
- 	// if (empty ( $detail )) {
 
- 	// $rule = array (
 
- 	// $notificationType => $notificationValue
 
- 	// );
 
- 	// $rule = json_encode ( $rule );
 
- 	// $item = array (
 
- 	// 'sid' => $this->staff [0] ['sid'],
 
- 	// 'conf' => $rule
 
- 	// );
 
- 	
 
- 	// $notificationConf->addNotification ( $item );
 
- 	// } else {
 
- 	// $rule = json_decode ( $detail ['conf'], true );
 
- 	// $rule [$notificationType] = $notificationValue;
 
- 	// $rule = json_encode ( $rule );
 
- 	// $item = array (
 
- 	// 'nid' => $detail ['nid'],
 
- 	// 'conf' => $rule
 
- 	// );
 
- 	// $notificationConf->setNotificationByCondition ( $item );
 
- 	// }
 
- 	// echo json_encode ( array (
 
- 	// 'status' => 1,
 
- 	// 'msgType' => $notificationType,
 
- 	// 'msg' => ''
 
- 	// ) );
 
- 	// die ();
 
- 	// }
 
- 	// echo json_encode ( array (
 
- 	// 'status' => 2,
 
- 	// 'msgType' => $notificationType,
 
- 	// 'msg' => 'illegal request'
 
- 	// ) );
 
- 	// die ();
 
- 	// }
 
- 	function eMailTask() {
 
- 		Doo::loadModel ( 'tag' );
 
- 		$tag = new tag ();
 
- 		Doo::loadModel ( 'district' );
 
- 		$district = new district ();
 
- 		
 
- 		$tagList = $tag->getAllBySid ( $this->staff [0] ['sid'] );
 
- 		$districtList = $district->get_lv ( 1 );
 
-         $districtlv2List=$district->get_lvByid(2,$districtList[0]['id']);
 
- 		$data ['tagList'] = $tagList;
 
- 		$data ['districtList'] = $districtList;
 
-         $data ['districtlv2List'] = $districtlv2List;
 
- 		$data ['memu'] = "eMailTask";
 
- 		$data ['staff'] = $this->staff;
 
- 		$data ['mailMemu'] = 'eMailTask';
 
- 		$data ['nature'] = $this->nature;
 
- 		
 
- 		$this->render ( "/mail_create", $data );
 
- 	}
 
- 	function eMialCenter() {
 
- 		$year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
 
- 		$month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : 0;
 
- 		
 
- 		Doo::loadModel ( 'eMailList' );
 
- 		$eMailList = new eMailList ();
 
- 		Doo::loadModel ( 'tag' );
 
- 		$tag = new tag ();
 
- 		Doo::loadModel ( 'staff' );
 
- 		$staff = new staff ();
 
- 		
 
- 		$dateCondition = "status!=2 and Year(date) =" . $year;
 
- 		if (! empty ( $month ))
 
- 			$dateCondition = "Year(date) =" . $year . " and Month(date) = " . $month;
 
- 		$mailList = $eMailList->find ( array (
 
- 				'where' => $dateCondition,
 
- 				'asc' => 'status',
 
- 				'desc' => 'elid',
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		foreach ( $mailList as $key => $value ) {
 
- 			
 
- 			$mailList [$key] ['clientName2'] = $mailList [$key] ['clientName3'] = array ();
 
- 			$mailList [$key] ['clientName'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName'] ) ), true );
 
- 			if (! empty ( $value ['clientName2'] ))
 
- 				$mailList [$key] ['clientName2'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName2'] ) ), true );
 
- 			if (! empty ( $value ['clientName3'] ))
 
- 				$mailList [$key] ['clientName3'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName3'] ) ), true );
 
- 			
 
- 			$mailList [$key] ['illegalEmail'] = json_decode ( $value ['illegalEmail'], true );
 
- 			$mailList [$key] ['sendEmail'] = json_decode ( $value ['sendEmail'], true );
 
- 			$mailList [$key] ['clientCount'] = count ( $mailList [$key] ['clientName'] ) + count ( $mailList [$key] ['clientName2'] ) + count ( $mailList [$key] ['clientName3'] );
 
- 			$mailList [$key] ['tag'] = array ();
 
- 			$kks = $staff->getOne ( array (
 
- 					'where' => 'username like "' . $value ['staffName'] . '"',
 
- 					'asArray' => true 
 
- 			) );
 
- 			$mailList [$key] ['category'] = $kks ['category'];
 
- 			if (! empty ( $value ['tag'] ))
 
- 				$mailList [$key] ['tag'] = $tag->find ( array (
 
- 						'where' => 'tid in ( ' . $value ['tag'] . ') ',
 
- 						'asArray' => true 
 
- 				) );
 
- 		}
 
- 		
 
- 		$dateHtml = "";
 
- 		$now = date ( "Y" );
 
- 		for($YEARD = 2014; $YEARD <= 2050; $YEARD ++) {
 
- 			if ($YEARD <= $now) {
 
- 				$dateHtml .= '<option ';
 
- 				if ($year == $YEARD)
 
- 					$dateHtml .= ' selected ';
 
- 				$dateHtml .= ' value="' . $YEARD . '">' . $YEARD . '</option>';
 
- 			}
 
- 		}
 
- 		$monthHtml = '<option value="0">所有月份</option>';
 
- 		for($i = 1; $i <= 12; $i ++) {
 
- 			$monthHtml .= '<option ';
 
- 			if ($i == $month)
 
- 				$monthHtml .= ' selected ';
 
- 			$monthHtml .= ' value="' . $i . '">' . $i . '</option>';
 
- 		}
 
- 		
 
- 		$data ['monthHtml'] = $monthHtml;
 
- 		$data ['dateHtml'] = $dateHtml;
 
- 		$data ['mailList'] = $mailList;
 
- 		$data ['memu'] = "eMailTask";
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		$data ['mailMemu'] = 'eMialCenter';
 
- 		$data ['nature'] = $this->nature;
 
- 		
 
- 		$this->render ( "/mailCenter", $data );
 
- 	}
 
- 	function authMail() {
 
- 		$elid = isset ( $this->params ['elid'] ) ? $this->params ['elid'] : 0;
 
- 		if (! empty ( $elid )) {
 
- 			Doo::loadModel ( 'eMailList' );
 
- 			$eMailList = new eMailList ();
 
- 			
 
- 			$eMailList->examine = 2;
 
- 			
 
- 			$eMailList->mark = $this->staff [0] ['username'] . "已同意";
 
- 			$eMailList->update ( array (
 
- 					'where' => 'elid=' . $elid,
 
- 					'asArray' => true 
 
- 			) );
 
- 		}
 
- 		return '/eMialCenter';
 
- 	}
 
- 	function editMailView() {
 
- 		$elid = isset ( $this->params ['elid'] ) ? $this->params ['elid'] : 0;
 
- 		
 
- 		Doo::loadModel ( 'tag' );
 
- 		$tag = new tag ();
 
- 		Doo::loadModel ( 'district' );
 
- 		$district = new district ();
 
- 		Doo::loadModel ( 'eMailList' );
 
- 		$eMList = new eMailList ();
 
- 		
 
- 		$mail = $eMList->getOne ( array (
 
- 				'where' => 'elid =' . $elid . '',
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		if (empty ( $mail ))
 
- 			return "/eMailList";
 
- 		$mail ['tagList'] = explode ( ",", $mail ['tag'] );
 
- 		$tagList = $tag->getAllBySid ( $this->staff [0] ['sid'] );
 
- 		$districtList = $district->get_lv ( 1 );
 
- 		
 
- 		$tagHtml = '';
 
- 		foreach ( $tagList as $key => $value ) {
 
- 			$tagHtml .= '<label><span data-original-title="' . $value ['name'] . '" data-toggle="ctooltip" data-placement="right" class="contactsTag tagCol-0' . $value ['colorid'] . '">
 
- 			  			<input type="checkbox" name="tagId[]"';
 
- 			foreach ( $mail ['tagList'] as $k => $v ) {
 
- 				if ($value ['tid'] == $v) {
 
- 					$tagHtml .= ' checked ';
 
- 					break;
 
- 				}
 
- 			}
 
- 			$tagHtml .= ' value="' . $value ['tid'] . '"></span></label>';
 
- 		}
 
- 		
 
- 		$districtHtml = '';
 
- 		foreach ( $districtList as $key => $value ) {
 
- 			$districtHtml .= '<option value="' . $value ['id'] . '"';
 
- 			if ($value ['id'] == $mail ['districtId'])
 
- 				$districtHtml .= 'selected';
 
- 			
 
- 			$districtHtml .= '>' . $value ['name'] . '</option>';
 
- 		}
 
- 		
 
- 		$natureHtml = '';
 
- 		$natList = explode ( ",", $mail ['nature'] );
 
- 		foreach ( $this->nature as $key => $value ) {
 
- 			
 
- 			$natureHtml .= '<label><input type="checkbox" name="nature[]" ';
 
- 			foreach ( $natList as $k => $v ) {
 
- 				if ($value == $v) {
 
- 					$natureHtml .= ' checked ';
 
- 					break;
 
- 				}
 
- 			}
 
- 			$natureHtml .= 'value="' . $value . '">' . $value . '</label>';
 
- 		}
 
- 		
 
- 		$data ['natureHtml'] = $natureHtml;
 
- 		$data ['districtHtml'] = $districtHtml;
 
- 		$data ['tagHtml'] = $tagHtml;
 
- 		$data ['mail'] = $mail;
 
- 		$data ['tagList'] = $tagList;
 
- 		$data ['districtList'] = $districtList;
 
- 		$data ['memu'] = "eMailTask";
 
- 		$data ['staff'] = $this->staff;
 
- 		$data ['mailMemu'] = 'eMailList';
 
- 		$data ['nature'] = $this->nature;
 
- 		
 
- 		$this->render ( "/mailEdit", $data );
 
- 	}
 
- 	function editEmail() {
 
- 		$title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
 
- 		$skin = $this->get_args ( 'skin' ) ? $this->get_args ( 'skin' ) : "";
 
- 		$content = isset ( $_POST ['content'] ) ? $_POST ['content'] : "";
 
- 		$tagId = $this->get_args ( 'tagId' ) ? $this->get_args ( 'tagId' ) : array ();
 
- 		$nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : array ();
 
- 		$natureNULL = $this->get_args ( 'natureNULL' ) ? $this->get_args ( 'natureNULL' ) : "";
 
- 		
 
- 		$did = $this->get_args ( 'did' ) ? $this->get_args ( 'did' ) : "";
 
- 		$stype = $this->get_args ( 'stype' ) ? $this->get_args ( 'stype' ) : "";
 
- 		
 
- 		$elid = $this->get_args ( 'elid' ) ? $this->get_args ( 'elid' ) : "";
 
- 		
 
- 		if (! empty ( $title ) && ! empty ( $elid ) && (! empty ( $tagId ) || ! empty ( $did ))) {
 
- 			
 
- 			Doo::loadModel ( 'eMailList' );
 
- 			$eMailList = new eMailList ();
 
- 			$etid = $eMailList->getOne ( array (
 
- 					'select' => 'etid,annexName,annex',
 
- 					'where' => 'elid=' . $elid,
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			Doo::loadModel ( 'eMailTemplate' );
 
- 			$eMailTemplate = new eMailTemplate ();
 
- 			Doo::loadModel ( 'eMailJournal' );
 
- 			$eMailJournal = new eMailJournal ();
 
- 			
 
- 			if ($natureNULL != 'NULL') {
 
- 				if (empty ( $tagId ) && ! empty ( $did ) && empty ( $nature ))
 
- 					die ( '请选择性质' );
 
- 			}
 
- 			// annex
 
- 			$annexPath = "";
 
- 			$annexEXT = $this->_GetFileEXT ( $_FILES ["annex"] ["name"] );
 
- 			$annexName = "";
 
- 			if (isset ( $_FILES ['annex'] ['name'] )) {
 
- 				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)) {
 
- 					$path = DOO::conf ()->SITE_PATH . "upload/emailAnnex/";
 
- 					if (! file_exists ( $path . $_FILES ["annex"] ["name"] )) {
 
- 						$fileName = time () . "." . $annexEXT;
 
- 						$annexName = $_FILES ['annex'] ['name'];
 
- 						$annexPath = $path . $fileName;
 
- 						move_uploaded_file ( $_FILES ["annex"] ["tmp_name"], $annexPath );
 
- 						$annexPath = $this->webPath . $fileName;
 
- 					}
 
- 				}
 
- 			}
 
- 			if (! empty ( $annexPath )) {
 
- 				$annexHtml = '<table style="width:100%;margin:10px 0">
 
- 										<thead>
 
- 											<tr>
 
- 												<th align="left" colspan="2" style="background-color:ff6501;color:#fff;font-size:16px;padding:5px">下载附件:</th>
 
- 											</tr>
 
- 										</thead>
 
- 										<tbody>
 
- 											<tr>
 
- 												<td style="padding:5px"><a href="' . $annexPath . '" target="_blank" style="font-size:16px">' . $annexName . '</a></td>
 
- 												<td> </td>
 
- 											</tr>
 
- 										</tbody>
 
- 									</table>';
 
- 			} elseif (! empty ( $etid ['annexName'] ) && empty ( $annexPath ))
 
- 				$annexHtml = $etid ['annex'];
 
- 			
 
- 			$smartcostMail = 'smartcost_mail_1';
 
- 			$info = "";
 
- 			// html template
 
- 			if ($skin == 1) {
 
- 				$html = '<div><table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
 
- 				   <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">
 
- 					<tbody><tr>
 
- 					<td style="background-color:#ff6501;padding:20px 0 25px;" align="center">
 
- 					<span style="vertical-align:bottom;font-size:20px;color:#fff;">' . $title . '</span>
 
- 					</td></tr><tr><td>
 
- 					<table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;border-top:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
 
- 					<tbody><tr><td style="padding: 0 40px;" align="left">
 
- 					<p style="margin-top:40px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;"><b>CLIENTNAME</b>,您好</p>
 
- 					</td></tr><tr><td style="padding: 0 40px;" align="left">
 
- 					<p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;">我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
 
- 					<p style="margin-top:0px;margin-bottom:20px;color:#383838;font-size:16px;line-height:32px;">
 
- 					' . $content . '</p>
 
- 					</td></tr>
 
- 					<tr><td align="left" style="padding: 0 40px;background:#fff">
 
- 						' . $annexHtml . '
 
- 					</td></tr>
 
- 					<tr> <td style="padding: 20px 40px;border-top:1px dashed #ddd" align="left">
 
- 					<p style="margin-bottom:10px;color:#383838;font-size:16px;line-height:22px;border-left:2px solid #FF6501;padding-left:5px">
 
- 					纵横公路造价软件' . $this->staff [0] ['category'] . '办事处</p>
 
- 					 <table>
 
- 					<tr><th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td></tr>
 
- 					<tr><th align="right">联系人:</th><td>' . $this->staff [0] ['username'] . '</td></tr>
 
- 					<tr><th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr>
 
- 					<tr><th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td></tr>
 
- 					<tr><th align="right">邮箱:</th><td>' . $this->staff [0] ['email'] . '</td></tr>
 
- 					</table></td></tr></tbody></table></td></tr><tr>
 
- 					<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>
 
- 					</tr></tbody></table></td></tr></tbody></table></div>';
 
- 				$info = '<table><tr><th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td></tr>
 
- 					<tr><th align="right">联系人:</th><td>' . $this->staff [0] ['username'] . '</td></tr>
 
- 					<tr><th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr>
 
- 					<tr><th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td></tr>
 
- 					<tr><th align="right">邮箱:</th><td>' . $this->staff [0] ['email'] . '</td></tr></table>';
 
- 			} elseif ($skin == 2) {
 
- 				$smartcostMail = 'smartcost_mail_2';
 
- 				$html = '<table cellspacing="0" cellpadding="0" style="background-color:#e4e4e4; width:100%;"><tbody><tr><td>
 
- 					<table align="center" cellspacing="0" cellpadding="0" style="background-color:#f8f8f8; width:640px;margin-bottom:20px">
 
- 					<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;">
 
- 					<b><span name="titleHtml">' . $title . '</span></b></p></td>
 
- 					</tr><tr><td><table align="center" cellspacing="0" cellpadding="0" style="border:1px solid #ddd;"><tbody><tr>
 
- 					<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>
 
- 					</tr><tr><td align="center" style="background-color:#fff;"><img width="640" height="191" src="http://zonghengvideo.qiniudn.com/hero.jpg"></td>
 
- 					</tr><tr><td align="left" style="background-color:#fff;padding:40px;border-bottom:1px solid #ddd;">
 
- 					<p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;"><b>CLIENTNAME</b>,您好</p>
 
- 					<p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;">我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
 
- 					<p name="contentHtml" style="margin-top:0px;margin-bottom:15px;color:#383838;font-size:16px;line-height:32px;">' . $content . '</p></td>
 
- 					</tr>
 
- 					<tr><td align="left" style="padding: 0 40px;background:#fff">
 
- 						' . $annexHtml . '
 
- 					</td></tr>
 
- 					<tr><td style="padding: 10px 0;background:#EEF2F5"><table><tbody><tr>
 
- 					<td style="font-size:14pxl;color:#333;padding:0 20px"><b>纵横公路造价软件' . $this->staff [0] ['category'] . '办事处</b><br>' . $this->staff [0] ['username'] . '</td>
 
- 					<td><table><tbody><tr style="font-size:12px;color:#666">
 
- 					<th align="right">电话:</th><td style="padding:0 20px 0 0">' . $this->staff [0] ['phone'] . '</td>
 
- 					<th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#666">
 
- 					<th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
 
- 					<th align="right">邮箱:	</th><td>' . $this->staff [0] ['email'] . '</td>
 
- 					</tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr>
 
- 					<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>
 
- 					</tr></tbody></table></td></tr></tbody> </table>';
 
- 				
 
- 				$info = '<table><tbody><tr style="font-size:12px;color:#666">
 
- 					<th align="right">电话:</th><td style="padding:0 20px 0 0">' . $this->staff [0] ['phone'] . '</td>
 
- 					<th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#666">
 
- 					<th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
 
- 					<th align="right">邮箱:	</th><td>' . $this->staff [0] ['email'] . '</td>
 
- 					</tr></tbody></table>';
 
- 			} else {
 
- 				$smartcostMail = 'smartcost_mail_3';
 
- 				
 
- 				$html = '<table cellspacing="0" cellpadding="0" style="background-color:#ECF0E1; width:100%">
 
- 				   <tbody>
 
- 				    <tr>
 
- 				     <td>
 
- 				      <table align="center" cellspacing="0" cellpadding="0" style="width:698px;margin-bottom:30px;margin-top:30px;">
 
- 				       <tbody>
 
- 				        <tr>
 
- 				         <td>
 
- 				          <table align="center" cellspacing="0" cellpadding="0" style="border:1px solid #ccc;width:100%;border-top:none">
 
- 				           <tbody>
 
- 				            <tr>
 
- 				             <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;">
 
- 				             	<div style="position:relative;text-align:right">
 
- 				              <b style="font-size:24px;color:#8A9F98;z-index:999"><span name="titleHtml">' . $title . '</span></b>
 
- 				              <div style="width:80px;height:80px;position:absolute;top:0;left:0"><img src="http://zonghengvideo.qiniudn.com/zonghenglogo.png"></div>
 
- 				              </div>
 
- 				             </td>
 
- 				            </tr>
 
- 				            <tr>
 
- 				             <td align="left" style="background-color:#fff;padding:40px;border-bottom:1px solid #ddd;">
 
- 				             <p style="margin-top:0px;margin-bottom:10px;color:#666;font-size:16px;line-height:32px;"><b>CLIENTNAME</b>,您好</p>
 
- 				             <p style="margin-top:0px;margin-bottom:10px;color:#666;font-size:16px;line-height:32px;">我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
 
- 				             <p name="contentHtml" style="margin-top:0px;margin-bottom:15px;color:#666;font-size:16px;line-height:32px;">' . $content . '</p></td>
 
- 				            </tr>
 
- 				            <tr><td align="left" style="padding: 0 40px;background:#fff">
 
- 						' . $annexHtml . '
 
- 					</td></tr>
 
- 				            <tr>
 
- 				             <td style="padding: 10px 0 0;background:#F6F6F6;">
 
- 				              <table>
 
- 				                <tbody><tr>
 
- 				                  <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>
 
- 				                  <td>
 
- 				                    <table style="width:100%">
 
- 				             				<tbody><tr style="font-size:12px;color:#496781">
 
- 				             					<th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td>
 
- 				             					<th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td>
 
- 				             				</tr>
 
- 				             				<tr style="font-size:12px;color:#496781">
 
- 				             					<th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
 
- 				             					<th align="right">邮箱:	</th><td>' . $this->staff [0] ['email'] . '</td>
 
- 				             					</tr>
 
- 				             			</tbody></table>
 
- 				                  </td>
 
- 				                </tr>
 
- 				              </tbody></table>
 
- 				             </td>
 
- 				            </tr>
 
- 				        <tr>
 
- 				          <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>
 
- 				        </tr>
 
- 				           </tbody>
 
- 				          </table></td>
 
- 				        </tr>
 
- 				       </tbody>
 
- 				      </table></td>
 
- 				    </tr>
 
- 				   </tbody>
 
- 				  </table>';
 
- 				
 
- 				$info = '<table><tr style="font-size:12px;color:#496781"><th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td>
 
- 				   <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#496781">
 
- 				   <th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
 
- 				   <th align="right">邮箱:	</th><td>' . $this->staff [0] ['email'] . '</td></tr></table>
 
- 		  	';
 
- 			}
 
- 			
 
- 			Doo::loadModel ( 'tag_client' );
 
- 			$tagClient = new tag_client ();
 
- 			Doo::loadModel ( 'client' );
 
- 			$client = new client ();
 
- 			
 
- 			Doo::loadModel ( 'company' );
 
- 			$company = new company ();
 
- 			
 
- 			$eMailTemplate->title = $title;
 
- 			$eMailTemplate->skin = $skin;
 
- 			$eMailTemplate->content = $content;
 
- 			if (! empty ( $tagId ))
 
- 				$eMailTemplate->tag = implode ( ",", $tagId );
 
- 			$eMailTemplate->staffId = $this->staff [0] ['sid'];
 
- 			$eMailTemplate->staffName = $this->staff [0] ['username'];
 
- 			$eMailTemplate->status = 0;
 
- 			$eMailTemplate->html = $html;
 
- 			if (! empty ( $annexPath )) {
 
- 				$eMailTemplate->annex = $annexPath;
 
- 				$eMailTemplate->annexName = $annexName;
 
- 			}
 
- 			
 
- 			$etid = $eMailTemplate->update ( array (
 
- 					'where' => 'etid=' . $etid ['etid'] 
 
- 			) );
 
- 			
 
- 			// create email list
 
- 			
 
- 			$tagCondition = "";
 
- 			$tagArray = array ();
 
- 			foreach ( $tagId as $value ) {
 
- 				array_push ( $tagArray, " tag like '%" . $value . "%' " );
 
- 			}
 
- 			
 
- 			if (! empty ( $tagArray ))
 
- 				$tagCondition = ' and (' . implode ( " or ", $tagArray ) . ')';
 
- 			$clientList = $tagClient->find ( array (
 
- 					'select' => 'client',
 
- 					'where' => 'sid=' . $this->staff [0] ['sid'] . $tagCondition,
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			$clientArray = array ();
 
- 			foreach ( $clientList as $value ) {
 
- 				array_push ( $clientArray, $value ['client'] );
 
- 			}
 
- 			$clientEmailList = array ();
 
- 			if (! empty ( $clientArray ))
 
- 				$clientEmailList = $client->find ( array (
 
- 						'select' => 'email,cid,nicename as clientname,companyname',
 
- 						'where' => 'cid in (' . implode ( ",", $clientArray ) . ')',
 
- 						'asArray' => true 
 
- 				) );
 
- 				
 
- 				//
 
- 			if ($stype == 2) {
 
- 				// 获取性质相关数据
 
- 				$cidList = '';
 
- 				if ($natureNULL == '') {
 
- 					$nD = array ();
 
- 					foreach ( $nature as $key => $value ) {
 
- 						array_push ( $nD, ' nature like "' . $value . '"' );
 
- 						// $nD=' nature like "'.$value.'"';
 
- 					}
 
- 					$nD = implode ( ' or ', $nD );
 
- 					
 
- 					$companycid = $company->find ( array (
 
- 							'select' => 'cid',
 
- 							'where' => $nD,
 
- 							'asArray' => true 
 
- 					) );
 
- 					$cidList = array ();
 
- 					foreach ( $companycid as $key => $value ) {
 
- 						array_push ( $cidList, $value ['cid'] );
 
- 					}
 
- 					$cidList = implode ( ',', $cidList );
 
- 					if (! empty ( $cidList ))
 
- 						$cidList = ' and companyid in (' . $cidList . ')';
 
- 					else
 
- 						$cidList = '';
 
- 				}
 
- 				// 'select'=>'email,cid,nicename as clientname,companyname,district'
 
- 				$clientEmailList = $client->find ( array (
 
- 						'select' => 'email,cid,nicename as clientname,companyname,district',
 
- 						'where' => 'district like "' . $did . ',%" ' . $cidList,
 
- 						'asArray' => true 
 
- 				) );
 
- 			}
 
- 			
 
- 			// ;datediff(curdate(), 'date')>=10
 
- 			$eMailJournal->delete ( array (
 
- 					'where' => "datediff(curdate(), date)>=7" 
 
- 			) );
 
- 			$eMailJournal->delete ( array (
 
- 					'where' => 'DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(date)' 
 
- 			) );
 
- 			
 
- 			$checkMail = $eMailJournal->find ( array (
 
- 					'where' => 'DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(date)',
 
- 					' groupby' => 'email',
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			$emailNameList = $emailArray = $illegalEmail = $sendEmail = array ();
 
- 			Doo::db ()->beginTransaction ();
 
- 			foreach ( $clientEmailList as $value ) {
 
- 				if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
 
- 					if (! empty ( $checkMail )) {
 
- 						$falg = true;
 
- 						foreach ( $checkMail as $v ) {
 
- 							if ($v ['email'] == $value ['email']) {
 
- 								$Bdate = strtotime ( $v ['date'] ) + 7 * 24 * 3600;
 
- 								if ($Bdate <= time ()) {
 
- 									array_push ( $emailArray, $value ['email'] );
 
- 									array_push ( $emailNameList, $value );
 
- 									$eMailJournal->date = date ( "Y-m-d" );
 
- 									$eMailJournal->update ( array (
 
- 											'where' => 'ejid=' . $v ['ejid'] 
 
- 									) );
 
- 								} else {
 
- 									array_push ( $sendEmail, $value );
 
- 								}
 
- 								$falg = false;
 
- 								break;
 
- 							}
 
- 						}
 
- 						if ($falg) {
 
- 							array_push ( $emailArray, $value ['email'] );
 
- 							array_push ( $emailNameList, $value );
 
- 							
 
- 							$eMailJournal->clientId = $value ['cid'];
 
- 							$eMailJournal->status = 1;
 
- 							$eMailJournal->email = $value ['email'];
 
- 							$eMailJournal->date = date ( "Y-m-d" );
 
- 							$eMailJournal->insert ();
 
- 						}
 
- 					} else {
 
- 						array_push ( $emailArray, $value ['email'] );
 
- 						array_push ( $emailNameList, $value );
 
- 						
 
- 						$eMailJournal->clientId = $value ['cid'];
 
- 						$eMailJournal->status = 1;
 
- 						$eMailJournal->email = $value ['email'];
 
- 						$eMailJournal->date = date ( "Y-m-d" );
 
- 						$eMailJournal->insert ();
 
- 					}
 
- 				} else {
 
- 					array_push ( $illegalEmail, $value );
 
- 				}
 
- 			}
 
- 			Doo::db ()->commit ();
 
- 			
 
- 			// echo json_encode($illegalEmail);
 
- 			// json_encode(array_slice($illegalEmail,0,100))
 
- 			
 
- 			// $kk=gzcompress();
 
- 			// $ll=gzuncompress($kk);
 
- 			// ."</br>".strlen($kk)."</br>".strlen($ll);die;
 
- 			
 
- 			$size = floor ( count ( $emailArray ) / 3 );
 
- 			
 
- 			if (! empty ( $emailArray )) {
 
- 				if (count ( $emailArray ) < 3) {
 
- 					$list = array (
 
- 							0 => $emailArray,
 
- 							1 => array (),
 
- 							2 => array () 
 
- 					);
 
- 				} else
 
- 					$list = array_chunk ( $emailArray, $size );
 
- 			} else
 
- 				$list = array (
 
- 						0 => array (),
 
- 						1 => array (),
 
- 						2 => array () 
 
- 				);
 
- 			$emailJson = array ();
 
- 			foreach ( $list as $value ) {
 
- 				$em = array ();
 
- 				foreach ( $value as $v ) {
 
- 					array_push ( $em, $v );
 
- 				}
 
- 				array_push ( $emailJson, $em );
 
- 			}
 
- 			
 
- 			$size = floor ( count ( $emailNameList ) / 3 );
 
- 			
 
- 			if (! empty ( $emailNameList )) {
 
- 				if (count ( $emailNameList ) < 3) {
 
- 					$list = array (
 
- 							0 => $emailNameList,
 
- 							1 => array (),
 
- 							2 => array () 
 
- 					);
 
- 				} else
 
- 					$list = array_chunk ( $emailNameList, $size );
 
- 			} else
 
- 				$list = array (
 
- 						0 => array (),
 
- 						1 => array (),
 
- 						2 => array () 
 
- 				);
 
- 			$emailNameJson = array ();
 
- 			foreach ( $list as $value ) {
 
- 				$em = array ();
 
- 				foreach ( $value as $v ) {
 
- 					array_push ( $em, $v );
 
- 				}
 
- 				array_push ( $emailNameJson, $em );
 
- 			}
 
- 			
 
- 			//
 
- 			$eMailList->date = date ( "Y-m-d" );
 
- 			$eMailList->clientEmail = base64_encode ( gzcompress ( json_encode ( $emailJson [0] ) ) );
 
- 			$eMailList->clientEmail2 = base64_encode ( gzcompress ( json_encode ( $emailJson [1] ) ) );
 
- 			$eMailList->clientEmail3 = base64_encode ( gzcompress ( json_encode ( $emailJson [2] ) ) );
 
- 			$eMailList->clientName = base64_encode ( gzcompress ( json_encode ( $emailNameJson [0] ) ) );
 
- 			$eMailList->clientName2 = base64_encode ( gzcompress ( json_encode ( $emailNameJson [1] ) ) );
 
- 			$eMailList->clientName3 = base64_encode ( gzcompress ( json_encode ( $emailNameJson [2] ) ) );
 
- 			$eMailList->illegalEmail = json_encode ( array_slice ( $illegalEmail, 0, 100 ) ); // json_encode($illegalEmail);
 
- 			$eMailList->sendEmail = json_encode ( $sendEmail );
 
- 			
 
- 			$eMailList->templateName = $smartcostMail;
 
- 			$eMailList->eTitle = $title;
 
- 			$eMailList->html = $html;
 
- 			$eMailList->content = $content;
 
- 			$eMailList->info = $info;
 
- 			if (! empty ( $annexName )) {
 
- 				$eMailList->annex = $annexHtml;
 
- 				$eMailList->annexName = $annexName;
 
- 			}
 
- 			if ($stype == 1) {
 
- 				$eMailList->tag = implode ( ",", $tagId );
 
- 				$eMailList->districtId = "";
 
- 				$eMailList->nature = "";
 
- 			}
 
- 			if ($stype == 2) {
 
- 				$eMailList->districtId = $did;
 
- 				$eMailList->nature = implode ( ",", $nature );
 
- 				$eMailList->tag = "";
 
- 			}
 
- 			$eMailList->update ( array (
 
- 					'where' => 'elid=' . $elid 
 
- 			) );
 
- 			
 
- 			return "/eMailList";
 
- 		}
 
- 		return "/eMailTask";
 
- 	}
 
- 	function createEmail() {
 
- 		
 
- 		// include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
 
- 		$title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
 
- 		$skin = $this->get_args ( 'skin' ) ? $this->get_args ( 'skin' ) : "";
 
- 		$content = isset ( $_POST ['content'] ) ? $_POST ['content'] : "";
 
- 		$tagId = $this->get_args ( 'tagId' ) ? $this->get_args ( 'tagId' ) : array ();
 
- 		$nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : array ();
 
- 		$natureNULL = $this->get_args ( 'natureNULL' ) ? $this->get_args ( 'natureNULL' ) : "";
 
- 		
 
- 		$did = $this->get_args ( 'did' ) ? $this->get_args ( 'did' ) : "";
 
-         $didCity = $this->get_args ( 'didCity' ) ? $this->get_args ( 'didCity' ) : "";
 
- 		$stype = $this->get_args ( 'stype' ) ? $this->get_args ( 'stype' ) : "";
 
- 		
 
- 		if (! empty ( $title ) && (! empty ( $tagId ) || ! empty ( $did ))) {
 
- 			Doo::loadModel ( 'eMailTemplate' );
 
- 			$eMailTemplate = new eMailTemplate ();
 
- 			Doo::loadModel ( 'eMailJournal' );
 
- 			$eMailJournal = new eMailJournal ();
 
- 			
 
- 			if ($natureNULL != 'NULL') {
 
- 				if (empty ( $tagId ) && ! empty ( $did ) && empty ( $nature )) {
 
- 					header ( 'Content-Type:text/html;charset=utf-8' );
 
- 					die ( '请选择性质' );
 
- 				}
 
- 			}
 
- 			// annex
 
- 			$annexPath = "";
 
- 			$annexEXT = $this->_GetFileEXT ( $_FILES ["annex"] ["name"] );
 
- 			$annexName = "";
 
- 			if (isset ( $_FILES ['annex'] ['name'] )) {
 
- 				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)) {
 
- 					$path = DOO::conf ()->SITE_PATH . "upload/emailAnnex/";
 
- 					if (! file_exists ( $path . $_FILES ["annex"] ["name"] )) {
 
- 						$fileName = time () . "." . $annexEXT;
 
- 						$annexName = $_FILES ['annex'] ['name'];
 
- 						$annexPath = $path . $fileName;
 
- 						move_uploaded_file ( $_FILES ["annex"] ["tmp_name"], $annexPath );
 
- 						$annexPath = $this->webPath . $fileName;
 
- 					}
 
- 				}
 
- 			}
 
- 			$annexHtml = '<table style="width:100%;margin:10px 0">
 
- 										<thead>
 
- 											<tr>
 
- 												<th align="left" colspan="2">下载附件:</th>
 
- 											</tr>
 
- 										</thead>
 
- 										<tbody>
 
- 											<tr>
 
- 												<td><a href="' . $annexPath . '" target="_blank">' . $annexName . '</a></td>
 
- 												<td> </td>
 
- 											</tr>
 
- 										</tbody>
 
- 									</table>';
 
- 			
 
- 			$smartcostMail = 'smartcost_mail_1';
 
- 			$info = "";
 
- 			// html template
 
- 			if ($skin == 1) {
 
- 				$html = '<div><table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
 
- 				   <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">
 
- 					<tbody><tr>
 
- 					<td style="background-color:#ff6501;padding:20px 0 25px;" align="center">
 
- 					<span style="vertical-align:bottom;font-size:20px;color:#fff;">' . $title . '</span>
 
- 					</td></tr><tr><td>
 
- 					<table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;border-top:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
 
- 					<tbody><tr><td style="padding: 0 40px;" align="left">
 
- 					<p style="margin-top:40px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;"><b>CLIENTNAME</b></p>
 
- 					</td></tr><tr><td style="padding: 0 40px;" align="left">
 
- 					<p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;">您好,我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
 
- 					<p style="margin-top:0px;margin-bottom:20px;color:#383838;font-size:16px;line-height:32px;">
 
- 					' . $content . '</p>
 
- 					</td></tr>
 
- 					<tr><td align="left" style="padding: 0 40px;background:#fff">
 
- 						' . $annexHtml . '
 
- 					</td></tr>
 
- 					<tr> 
 
- 								<td style="padding: 10px 0 0;background:#F6F6F6;">
 
- 								
 
- 								
 
- <table>
 
-                 <tr>
 
-                   <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>
 
-                   <td>
 
-                     <table>
 
-                     <tr style="font-size:12px;color:#666">
 
-                       <th align="right">电话:</th><td style="padding:0 20px 0 0">' . $this->staff [0] ['phone'] . '</td>
 
-                       <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td>
 
-                     </tr>
 
-                     <tr style="font-size:12px;color:#666">
 
-                       <th align="right">Q Q:</th><td>' . $this->staff [0] ['qq'] . '</td>
 
-                       <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td>
 
-                       </tr>
 
-                   </table>
 
-                   </td>
 
-                 </tr>
 
-               </table>
 
- 								
 
- 								
 
- 								
 
- 								
 
- 					
 
- 					 </td></tr></tbody></table></td></tr><tr>
 
- 					<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>
 
- 					</tr></tbody></table></td></tr></tbody></table></div>';
 
- 				$info = '<table><tr><th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td></tr>
 
- 					<tr><th align="right">联系人:</th><td>' . $this->staff [0] ['username'] . '</td></tr>
 
- 					<tr><th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr>
 
- 					<tr><th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td></tr>
 
- 					<tr><th align="right">邮箱:</th><td>' . $this->staff [0] ['email'] . '</td></tr></table>';
 
- 			} elseif ($skin == 2) {
 
- 				$smartcostMail = 'smartcost_mail_2';
 
- 				$html = '<table cellspacing="0" cellpadding="0" style="background-color:#e4e4e4; width:100%;"><tbody><tr><td>
 
- 					<table align="center" cellspacing="0" cellpadding="0" style="background-color:#f8f8f8; width:640px;margin-bottom:20px">
 
- 					<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;">
 
- 					<b><span name="titleHtml">' . $title . '</span></b></p></td>
 
- 					</tr><tr><td><table align="center" cellspacing="0" cellpadding="0" style="border:1px solid #ddd;"><tbody><tr>
 
- 					<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>
 
- 					</tr><tr><td align="center" style="background-color:#fff;"><img width="640" height="191" src="http://zonghengvideo.qiniudn.com/hero.jpg"></td>
 
- 					</tr><tr><td align="left" style="background-color:#fff;padding:40px;border-bottom:1px solid #ddd;">
 
- 					<p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;"><b>CLIENTNAME</b></p>
 
- 					<p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;">您好,我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
 
- 					<p name="contentHtml" style="margin-top:0px;margin-bottom:15px;color:#383838;font-size:16px;line-height:32px;">' . $content . '</p></td>
 
- 					</tr>
 
- 					<tr><td align="left" style="padding: 0 40px;background:#fff">
 
- 						' . $annexHtml . '
 
- 					</td></tr>
 
- 					<tr>
 
- 					<td style="padding: 10px 0;background:#F6F6F6">
 
- 								
 
- 								<table>
 
- 								<tbody>
 
- 								<tr>
 
- 					<td style="font-size:14pxl;color:#333;padding:0 20px">
 
- 								
 
- 								<b>纵横公路造价软件' . $this->staff [0] ['category'] . '服务中心</b><br>' . $this->staff [0] ['username'] . '</td>
 
- 					<td>
 
- 										<table>
 
- 										<tbody>
 
- 										<tr style="font-size:12px;color:#666">
 
- 					<th align="right">电话:</th><td style="padding:0 20px 0 0">' . $this->staff [0] ['phone'] . '</td>
 
- 					<th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#666">
 
- 					<th align="right">Q Q:</th><td>' . $this->staff [0] ['qq'] . '</td>
 
- 					<th align="right">邮箱:	</th><td>' . $this->staff [0] ['email'] . '</td>
 
- 					</tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr>
 
- 					<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>
 
- 					</tr></tbody></table></td></tr></tbody> </table>';
 
- 				
 
- 				$info = '<table><tbody><tr style="font-size:12px;color:#666">
 
- 					<th align="right">电话:</th><td style="padding:0 20px 0 0">' . $this->staff [0] ['phone'] . '</td>
 
- 					<th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#666">
 
- 					<th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
 
- 					<th align="right">邮箱:	</th><td>' . $this->staff [0] ['email'] . '</td>
 
- 					</tr></tbody></table>';
 
- 			} else {
 
- 				$smartcostMail = 'smartcost_mail_3';
 
- 				
 
- 				$html = '<table cellspacing="0" cellpadding="0" style="background-color:#ECF0E1; width:100%">
 
- 				   <tbody>
 
- 				    <tr>
 
- 				     <td>
 
- 				      <table align="center" cellspacing="0" cellpadding="0" style="width:698px;margin-bottom:30px;margin-top:30px;">
 
- 				       <tbody>
 
- 				        <tr>
 
- 				         <td>
 
- 				          <table align="center" cellspacing="0" cellpadding="0" style="border:1px solid #ccc;width:100%;border-top:none">
 
- 				           <tbody>
 
- 				            <tr>
 
- 				             <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;">
 
- 				             	<div style="position:relative;text-align:right">
 
- 				              <b style="font-size:24px;color:#8A9F98;z-index:999"><span name="titleHtml">' . $title . '</span></b>
 
- 				              <div style="width:80px;height:80px;position:absolute;top:0;left:0"><img src="http://zonghengvideo.qiniudn.com/zonghenglogo.png"></div>
 
- 				              </div>
 
- 				             </td>
 
- 				            </tr>
 
- 				            <tr>
 
- 				             <td align="left" style="background-color:#fff;padding:40px;border-bottom:1px solid #ddd;">
 
- 				             <p style="margin-top:0px;margin-bottom:10px;color:#666;font-size:16px;line-height:32px;"><b>CLIENTNAME</b></p>
 
- 				             <p style="margin-top:0px;margin-bottom:10px;color:#666;font-size:16px;line-height:32px;">您好,我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
 
- 				             <p name="contentHtml" style="margin-top:0px;margin-bottom:15px;color:#666;font-size:16px;line-height:32px;">' . $content . '</p></td>
 
- 				            </tr>
 
- 				            <tr><td align="left" style="padding: 0 40px;background:#fff">
 
- 						' . $annexHtml . '
 
- 					</td></tr>
 
- 				            <tr>
 
- 				             <td style="padding: 10px 0 0;background:#F6F6F6;">
 
- 				              <table>
 
- 				                <tbody><tr>
 
- 				                  <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>
 
- 				                  <td>
 
- 				                    <table style="width:100%">
 
- 				             				<tbody><tr style="font-size:12px;color:#496781">
 
- 				             					<th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td>
 
- 				             					<th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td>
 
- 				             				</tr>
 
- 				             				<tr style="font-size:12px;color:#496781">
 
- 				             					<th align="right">Q Q:</th><td>' . $this->staff [0] ['qq'] . '</td>
 
- 				             					<th align="right">邮箱:	</th><td>' . $this->staff [0] ['email'] . '</td>
 
- 				             					</tr>
 
- 				             			</tbody></table>
 
- 				                  </td>
 
- 				                </tr>
 
- 				              </tbody></table>
 
- 				             </td>
 
- 				            </tr>
 
- 				        <tr>
 
- 				          <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>
 
- 				        </tr>
 
- 				           </tbody>
 
- 				          </table></td>
 
- 				        </tr>
 
- 				       </tbody>
 
- 				      </table></td>
 
- 				    </tr>
 
- 				   </tbody>
 
- 				  </table>';
 
- 				
 
- 				$info = '<table><tr style="font-size:12px;color:#496781"><th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td>
 
- 				   <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#496781">
 
- 				   <th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
 
- 				   <th align="right">邮箱:	</th><td>' . $this->staff [0] ['email'] . '</td></tr></table>
 
- 		  	';
 
- 			}
 
- 			$eMailTemplate->title = $title;
 
- 			$eMailTemplate->skin = $skin;
 
- 			$eMailTemplate->content = $content;
 
- 			if (! empty ( $tagId ))
 
- 				$eMailTemplate->tag = implode ( ",", $tagId );
 
- 			$eMailTemplate->staffId = $this->staff [0] ['sid'];
 
- 			$eMailTemplate->staffName = $this->staff [0] ['username'];
 
- 			$eMailTemplate->status = 0;
 
- 			$eMailTemplate->html = $html;
 
- 			$eMailTemplate->annex = $annexPath;
 
- 			$eMailTemplate->annexName = $annexName;
 
- 			
 
- 			$etid = $eMailTemplate->insert ();
 
- 			
 
- 			// create email list
 
- 			Doo::loadModel ( 'tag_client' );
 
- 			$tagClient = new tag_client ();
 
- 			Doo::loadModel ( 'client' );
 
- 			$client = new client ();
 
- 			Doo::loadModel ( 'eMailList' );
 
- 			$eMailList = new eMailList ();
 
- 			Doo::loadModel ( 'company' );
 
- 			$company = new company ();
 
- 			
 
- 			$tagCondition = "";
 
- 			$tagArray = array ();
 
- 			foreach ( $tagId as $value ) {
 
- 				array_push ( $tagArray, " tag like '%" . $value . "%' " );
 
- 			}
 
- 			
 
- 			if (! empty ( $tagArray ))
 
- 				$tagCondition = ' and (' . implode ( " or ", $tagArray ) . ')';
 
- 			$clientList = $tagClient->find ( array (
 
- 					'select' => 'client',
 
- 					'where' => 'sid=' . $this->staff [0] ['sid'] . $tagCondition,
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			$clientArray = array ();
 
- 			foreach ( $clientList as $value ) {
 
- 				array_push ( $clientArray, $value ['client'] );
 
- 			}
 
- 			$clientEmailList = array ();
 
- 			if (! empty ( $clientArray ))
 
- 				$clientEmailList = $client->find ( array (
 
- 						'select' => 'email,cid,nicename as clientname,companyname',
 
- 						'where' => 'cid in (' . implode ( ",", $clientArray ) . ')',
 
- 						'asArray' => true 
 
- 				) );
 
- 				
 
- 				//
 
- 			if ($stype == 2) {
 
- 				// 获取性质相关数据
 
- 				$cidList = '';
 
- 				if ($natureNULL == '') {
 
- 					$nD = array ();
 
- 					foreach ( $nature as $key => $value ) {
 
- 						array_push ( $nD, ' nature like "' . $value . '"' );
 
- 						// $nD=' nature like "'.$value.'"';
 
- 					}
 
- 					$nD = implode ( ' or ', $nD );
 
- 					
 
- 					$companycid = $company->find ( array (
 
- 							'select' => 'cid',
 
- 							'where' => $nD,
 
- 							'asArray' => true 
 
- 					) );
 
- 					$cidList = array ();
 
- 					foreach ( $companycid as $key => $value ) {
 
- 						array_push ( $cidList, $value ['cid'] );
 
- 					}
 
- 					$cidList = implode ( ',', $cidList );
 
- 					if (! empty ( $cidList ))
 
- 						$cidList = ' and companyid in (' . $cidList . ')';
 
- 					else
 
- 						$cidList = '';
 
- 				}
 
- 				// 'select'=>'email,cid,nicename as clientname,companyname,district'
 
-                 $where='district like "' . $did . ',%" ' . $cidList;
 
-                 if ($didCity!="ALL"){
 
-                     Doo::loadClass ( 'XDeode' );
 
-                     $XDeode = new XDeode ( 5 );
 
-                     $didCity = $XDeode->decode ( $didCity );
 
-                     $where='district like "' . $did . ','.$didCity.',%" ' . $cidList;
 
-                 }
 
- 				$clientEmailList = $client->find ( array (
 
- 						'select' => 'email,cid,nicename as clientname,companyname,district',
 
- 						'where' => $where,
 
- 						'asArray' => true 
 
- 				) );
 
- 			}
 
- 			
 
- 			// ;datediff(curdate(), 'date')>=10
 
- 			$eMailJournal->delete ( array (
 
- 					'where' => "datediff(curdate(), date)>=7" 
 
- 			) );
 
- 			
 
- 			$checkMail = $eMailJournal->find ( array (
 
- 					'where' => 'DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(date)',
 
- 					' groupby' => 'email',
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			$emailNameList = $emailArray = $illegalEmail = $sendEmail = array ();
 
- 			Doo::db ()->beginTransaction ();
 
- 			foreach ( $clientEmailList as $value ) {
 
- 				if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
 
- 					if (! empty ( $checkMail )) {
 
- 						$falg = true;
 
- 						foreach ( $checkMail as $v ) {
 
- 							if ($v ['email'] == $value ['email']) {
 
- 								$Bdate = strtotime ( $v ['date'] ) + 7 * 24 * 3600;
 
- 								if ($Bdate <= time ()) {
 
- 									array_push ( $emailArray, $value ['email'] );
 
- 									array_push ( $emailNameList, $value );
 
- 									$eMailJournal->date = date ( "Y-m-d" );
 
- 									$eMailJournal->update ( array (
 
- 											'where' => 'ejid=' . $v ['ejid'] 
 
- 									) );
 
- 								} else {
 
- 									array_push ( $sendEmail, $value );
 
- 								}
 
- 								$falg = false;
 
- 								break;
 
- 							}
 
- 						}
 
- 						if ($falg) {
 
- 							array_push ( $emailArray, $value ['email'] );
 
- 							array_push ( $emailNameList, $value );
 
- 							
 
- 							$eMailJournal->clientId = $value ['cid'];
 
- 							$eMailJournal->status = 1;
 
- 							$eMailJournal->email = $value ['email'];
 
- 							$eMailJournal->date = date ( "Y-m-d" );
 
- 							// $eMailJournal->insert();
 
- 						}
 
- 					} else {
 
- 						array_push ( $emailArray, $value ['email'] );
 
- 						array_push ( $emailNameList, $value );
 
- 						
 
- 						$eMailJournal->clientId = $value ['cid'];
 
- 						$eMailJournal->status = 1;
 
- 						$eMailJournal->email = $value ['email'];
 
- 						$eMailJournal->date = date ( "Y-m-d" );
 
- 						// $eMailJournal->insert();
 
- 					}
 
- 				} else {
 
- 					array_push ( $illegalEmail, $value );
 
- 				}
 
- 			}
 
- 			Doo::db ()->commit ();
 
- 			
 
- 			// echo json_encode($illegalEmail);
 
- 			// json_encode(array_slice($illegalEmail,0,100))
 
- 			
 
- 			// $kk=gzcompress();
 
- 			// $ll=gzuncompress($kk);
 
- 			// ."</br>".strlen($kk)."</br>".strlen($ll);die;
 
- 			
 
- 			$size = floor ( count ( $emailArray ) / 3 );
 
- 			
 
- 			if (! empty ( $emailArray )) {
 
- 				if (count ( $emailArray ) < 3) {
 
- 					$list = array (
 
- 							0 => $emailArray,
 
- 							1 => array (),
 
- 							2 => array () 
 
- 					);
 
- 				} else
 
- 					$list = array_chunk ( $emailArray, $size );
 
- 			} else
 
- 				$list = array (
 
- 						0 => array (),
 
- 						1 => array (),
 
- 						2 => array () 
 
- 				);
 
- 			$emailJson = array ();
 
- 			foreach ( $list as $value ) {
 
- 				$em = array ();
 
- 				foreach ( $value as $v ) {
 
- 					array_push ( $em, $v );
 
- 				}
 
- 				array_push ( $emailJson, $em );
 
- 			}
 
- 			
 
- 			$size = floor ( count ( $emailNameList ) / 3 );
 
- 			
 
- 			if (! empty ( $emailNameList )) {
 
- 				if (count ( $emailNameList ) < 3) {
 
- 					$list = array (
 
- 							0 => $emailNameList,
 
- 							1 => array (),
 
- 							2 => array () 
 
- 					);
 
- 				} else
 
- 					$list = array_chunk ( $emailNameList, $size );
 
- 			} else
 
- 				$list = array (
 
- 						0 => array (),
 
- 						1 => array (),
 
- 						2 => array () 
 
- 				);
 
- 			$emailNameJson = array ();
 
- 			foreach ( $list as $value ) {
 
- 				$em = array ();
 
- 				foreach ( $value as $v ) {
 
- 					array_push ( $em, $v );
 
- 				}
 
- 				array_push ( $emailNameJson, $em );
 
- 			}
 
- 			
 
- 			//
 
- 			$eMailList->date = date ( "Y-m-d" );
 
- 			$eMailList->clientEmail = base64_encode ( gzcompress ( json_encode ( $emailJson [0] ) ) );
 
- 			$eMailList->clientEmail2 = base64_encode ( gzcompress ( json_encode ( $emailJson [1] ) ) );
 
- 			$eMailList->clientEmail3 = base64_encode ( gzcompress ( json_encode ( $emailJson [2] ) ) );
 
- 			$eMailList->clientName = base64_encode ( gzcompress ( json_encode ( $emailNameJson [0] ) ) );
 
- 			$eMailList->clientName2 = base64_encode ( gzcompress ( json_encode ( $emailNameJson [1] ) ) );
 
- 			$eMailList->clientName3 = base64_encode ( gzcompress ( json_encode ( $emailNameJson [2] ) ) );
 
- 			$eMailList->illegalEmail = json_encode ( array_slice ( $illegalEmail, 0, 100 ) ); // json_encode($illegalEmail);
 
- 			$eMailList->sendEmail = json_encode ( $sendEmail );
 
- 			$eMailList->etid = $etid;
 
- 			$eMailList->templateName = $smartcostMail;
 
- 			$eMailList->eTitle = $title;
 
- 			$eMailList->html = $html;
 
- 			$eMailList->content = $content;
 
- 			$eMailList->info = $info;
 
- 			if (! empty ( $annexName ))
 
- 				$eMailList->annex = $annexHtml;
 
- 			$eMailList->annexName = $annexName;
 
- 			$eMailList->staffId = $this->staff [0] ['sid'];
 
- 			$eMailList->staffName = $this->staff [0] ['username'];
 
- 			if ($stype == 1)
 
- 				$eMailList->tag = implode ( ",", $tagId );
 
- 			if ($stype == 2) {
 
- 				$eMailList->districtId = $did;
 
- 				$eMailList->nature = implode ( ",", $nature );
 
- 			}
 
- 			$eMailList->insert ();
 
- 			
 
- 			// 创建邮件地址
 
- 			// 'http://sendcloud.sohu.com/webapi/list_member.add.json';
 
- 			// print_r($emailJson);
 
- 			
 
- 			// die;
 
- 			return "/eMailList";
 
- 		}
 
- 		return "/eMailTask";
 
- 	}
 
- 	function eMailList() {
 
- 		Doo::loadModel ( 'eMailList' );
 
- 		$eMailList = new eMailList ();
 
- 		Doo::loadModel ( 'tag' );
 
- 		$tag = new tag ();
 
- 		
 
- 		$mailList = $eMailList->find ( array (
 
- 				'where' => 'staffId=' . $this->staff [0] ['sid'],
 
- 				'desc' => 'elid',
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		foreach ( $mailList as $key => $value ) {
 
- 			$mailList [$key] ['clientName2'] = $mailList [$key] ['clientName3'] = array ();
 
- 			$mailList [$key] ['clientName'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName'] ) ), true );
 
- 			
 
- 			if (! empty ( $value ['clientName2'] ))
 
- 				$mailList [$key] ['clientName2'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName2'] ) ), true );
 
- 			if (! empty ( $value ['clientName3'] ))
 
- 				$mailList [$key] ['clientName3'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName3'] ) ), true );
 
- 			$mailList [$key] ['illegalEmail'] = json_decode ( $value ['illegalEmail'], true );
 
- 			$mailList [$key] ['sendEmail'] = json_decode ( $value ['sendEmail'], true );
 
- 			$mailList [$key] ['clientCount'] = count ( $mailList [$key] ['clientName'] ) + count ( $mailList [$key] ['clientName2'] ) + count ( $mailList [$key] ['clientName3'] );
 
- 			$mailList [$key] ['tag'] = array ();
 
- 			if (! empty ( $value ['tag'] ))
 
- 				$mailList [$key] ['tag'] = $tag->find ( array (
 
- 						'where' => 'tid in ( ' . $value ['tag'] . ') ',
 
- 						'asArray' => true 
 
- 				) );
 
- 		}
 
- 		
 
- 		$data ['mailList'] = $mailList;
 
- 		
 
- 		$data ['memu'] = "eMailTask";
 
- 		$data ['staff'] = $this->staff;
 
- 		$data ['mailMemu'] = 'eMailList';
 
- 		
 
- 		$this->render ( "/mail_list", $data );
 
- 	}
 
- 	function showEmailContent() {
 
- 		$elid = isset ( $this->params ['elid'] ) ? $this->params ['elid'] : 0;
 
- 		
 
- 		Doo::loadModel ( 'eMailList' );
 
- 		$eMList = new eMailList ();
 
- 		
 
- 		$isSend = $eMList->getOne ( array (
 
- 				'where' => 'elid =' . $elid . '',
 
- 				'asArray' => true 
 
- 		) );
 
- 		echo htmlspecialchars ( $isSend ['content'] );
 
- 	}
 
- 	function postEmail() {
 
- 		
 
- 		// include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
 
- 		$elid = isset ( $this->params ['elid'] ) ? $this->params ['elid'] : 0;
 
- 		$send = isset ( $this->params ['send'] ) ? $this->params ['send'] : 0;
 
- 		
 
- 		Doo::loadModel ( 'eMailList' );
 
- 		$eMList = new eMailList ();
 
- 		
 
- 		if (! empty ( $elid )) {
 
- 			
 
- 			$isSend = $eMList->getOne ( array (
 
- 					'select' => 'send' . $send,
 
- 					'where' => 'elid =' . $elid . ' and status=0 and send' . $send . '=1',
 
- 					'asArray' => true 
 
- 			) );
 
- 			if (! empty ( $isSend ))
 
- 				die ( '这批邮件已经发送' );
 
- 			
 
- 			if ($send == 1)
 
- 				$send = '';
 
- 			
 
- 			$eMailList = $eMList->getOne ( array (
 
- 					'select' => 'eTitle,staffName,clientName' . $send . ' as clientName,clientEmail' . $send . ' as clientEmail,annex,info,content,templateName',
 
- 					'where' => 'elid =' . $elid . ' and status=0',
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			if ($send == "")
 
- 				$send = 1;
 
- 			$sql = "update `CLD_eMailList` set  send" . $send . "='1' where elid = '" . $elid . "'";
 
- 			Doo::db ()->query ( $sql );
 
- 			
 
- 			$isSend = $eMList->getOne ( array (
 
- 					'where' => 'elid =' . $elid . ' and status=0 and send1=1 and send2=1 and send3=1',
 
- 					'asArray' => true 
 
- 			) );
 
- 			if (! empty ( $isSend )) {
 
- 				$sql = "update `CLD_eMailList` set  status='2' where elid = '" . $elid . "'";
 
- 				Doo::db ()->query ( $sql );
 
- 			}
 
- 			
 
- 			$toFormatMail = array ();
 
- 			$sub = array ();
 
- 			
 
- 			// file_put_contents("test.txt", "This is another something.<br/>", FILE_APPEND);
 
- 			
 
- 			// sleep(4);
 
- 			// die;
 
- 			$toMail = json_decode ( gzuncompress ( base64_decode ( $eMailList ['clientEmail'] ) ), true );
 
- 			// $toMailCount=count($toMail);
 
- 			
 
- 			$subMail = json_decode ( gzuncompress ( base64_decode ( $eMailList ['clientName'] ) ), true );
 
- 			
 
- 			$chunkMail = array_chunk ( $toMail, 80 );
 
- 			$chunkSubMail = array_chunk ( $subMail, 80 );
 
- 			$vii = 0;
 
- 			foreach ( $chunkMail as $key => $value ) {
 
- 				$l = $s = $c = $i = $cate = $con = $annex = array ();
 
- 				$toFormatMail ['to'] = $value;
 
- 				$cn = $chunkSubMail [$key];
 
- 				foreach ( $cn as $v ) {
 
- 					array_push ( $l, $eMailList ['eTitle'] );
 
- 					array_push ( $s, $eMailList ['staffName'] );
 
- 					array_push ( $c, $v ['clientname'] );
 
- 					array_push ( $annex, $eMailList ['annex'] );
 
- 					array_push ( $i, $eMailList ['info'] );
 
- 					// array_push($con, $eMailList['content']);
 
- 					array_push ( $cate, $this->staff [0] ['category'] );
 
- 				}
 
- 				$sub ['%eTitle%'] = $l;
 
- 				$sub ['%staffName%'] = $s;
 
- 				$sub ['%clientName%'] = $c;
 
- 				$sub ['%category%'] = $cate;
 
- 				$sub ['%info%'] = $i;
 
- 				// $sub['%content%']=$con;
 
- 				$sub ['%annex%'] = $annex;
 
- 				$toFormatMail ['sub'] = $sub;
 
- 				
 
- 				$url = 'http://sendcloud.sohu.com/webapi/mail.send_template.xml';
 
- 				
 
- 				$param = array (
 
- 						'api_user' => 'cldmail',
 
- 						'api_key' => 'cDO1GjtY1seH',
 
- 						'template_invoke_name' => $eMailList ['templateName'],
 
- 						'from' => $this->staff [0] ['email'],
 
- 						'fromname' => '纵横' . $eMailList ['staffName'],
 
- 						'subject' => $eMailList ['eTitle'],
 
- 						'substitution_vars' => json_encode ( $toFormatMail ) 
 
- 				);
 
- 				
 
- 				$post_data = http_build_query ( $param );
 
- 				
 
- 				$ch = curl_init ();
 
- 				curl_setopt ( $ch, CURLOPT_POST, 1 );
 
- 				curl_setopt ( $ch, CURLOPT_URL, $url );
 
- 				curl_setopt ( $ch, CURLOPT_HEADER, false ); // 设定是否输出页面内容
 
- 				curl_setopt ( $ch, CURLOPT_NOBODY, false );
 
- 				curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_data );
 
- 				
 
- 				$result = curl_exec ( $ch );
 
- 				curl_close ( $ch );
 
- 				
 
- 				/*
 
- 				 * if($result=='success'){ $eM=new eMailList(); $eM->status='2'; $eM->update(array('where'=>'elid=?','param'=>array($elid))); }
 
- 				 */
 
- 			}
 
- 			
 
- 			// die;
 
- 			return '/eMailList';
 
- 		}
 
- 	}
 
- 	function a() {
 
- 		$substitution_vars = $this->get_args ( 'substitution_vars' );
 
- 		file_put_contents ( DOO::conf ()->SITE_PATH . 'upload/' . "_" . time () . "_" . rand ( 100, 999 ) . ".log", $substitution_vars );
 
- 	}
 
- 	function deleteEmail() {
 
- 		$elid = isset ( $this->params ['elid'] ) ? $this->params ['elid'] : 0;
 
- 		
 
- 		if (! empty ( $elid )) {
 
- 			$sql = "DELETE FROM `CLD_eMailList` where elid = '" . $elid . "'";
 
- 			Doo::db ()->query ( $sql );
 
- 			return '/eMailList';
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 发送post请求
 
- 	 * @param string $url 请求地址
 
- 	 * @param array $post_data post键值对数据
 
- 	 * @return string
 
- 	 */
 
- 	function sendPost($url, $post_data) {
 
- 		$postdata = http_build_query ( $post_data );
 
- 		// X-Amzn-Authorization: AWS3 AWSAccessKeyId=AKIAIDSE5VYNX5ERJHXQ,Signature=lBP67vCvGlDMBQ=dofZxg8E8SUEXAMPLE,Algorithm=HmacSHA256,SignedHeaders=qG1BdSh9QyYPlWLnjqvjDXjyPdFjl7fUSkfs0Hk2
 
- 		$options = array (
 
- 				'http' => array (
 
- 						'method' => 'POST',
 
- 						'header' => '
 
- 				Content-Type: application/x-www-form-urlencoded
 
- ',
 
- 						'content' => $postdata,
 
- 						'timeout' => 15 * 60 
 
- 				) 
 
- 		); // 超时时间(单位:s)
 
- 		
 
- 		$context = stream_context_create ( $options );
 
- 		$result = file_get_contents ( $url, false, $context );
 
- 		
 
- 		return $result;
 
- 	}
 
- 	function avatar() {
 
- 		$result = array ();
 
- 		$result ['success'] = false;
 
- 		$successNum = 0;
 
- 		// 定义一个变量用以储存当前头像的序号
 
- 		$avatarNumber = 1;
 
- 		$i = 0;
 
- 		$msg = '';
 
- 		// 上传目录
 
- 		$dir = DOO::conf ()->SITE_PATH . "global/avatar";
 
- 		// 遍历所有文件域
 
- 		while ( list ( $key, $val ) = each ( $_FILES ) ) {
 
- 			if ($_FILES [$key] ['error'] > 0)
 
- 				$msg .= $_FILES [$key] ['error'];
 
- 			else {
 
- 				$fileName = 'avatar_' . $this->staff [0] ['sid'];
 
- 				// 原始图片(file 域的名称:__source,如果客户端定义可以上传的话,可在此处理)。
 
- 				if ($key == '__source') { // 当前头像基于原图的初始化参数,用于修改头像时保证界面的视图跟保存头像时一致。帮助提升用户体验度。修改头像时设置默认加载的原图的url为此图片的url+该参数即可。
 
- 					$initParams = $_POST ["__initParams"];
 
- 					$virtualPath = $dir . "/" . $fileName . "_" . $avatarNumber . ".jpg";
 
- 					$result ['sourceUrl'] = '/' . $virtualPath . $initParams;
 
- 					move_uploaded_file ( $_FILES [$key] ["tmp_name"], $virtualPath );
 
- 					$successNum ++;
 
- 				} else if (strpos ( $key, '__avatar' ) === 0) { // 头像图片(file 域的名称:__avatar1,2,3...)。
 
- 					$virtualPath = $dir . "/" . $fileName . "_" . $avatarNumber . ".jpg";
 
- 					$result ['avatarUrls'] [$i] = '/' . $virtualPath;
 
- 					move_uploaded_file ( $_FILES [$key] ["tmp_name"], $virtualPath );
 
- 					$avatarNumber ++;
 
- 					$successNum ++;
 
- 					$i ++;
 
- 				}
 
- 			}
 
- 		}
 
- 		$result ['msg'] = $msg;
 
- 		if ($successNum > 0)
 
- 			$result ['success'] = true;
 
- 			// 返回图片的保存结果(返回内容为json字符串)
 
- 		
 
- 		Doo::loadModel ( 'staff' );
 
- 		$staff = new staff ();
 
- 		
 
- 		$staff->sid = $this->staff [0] ['sid'];
 
- 		$staff->avatar = "/global/avatar/" . $fileName;
 
- 		$staff->update ();
 
- 		
 
- 		echo json_encode ( $result );
 
- 	}
 
- 	function lockUpload() {
 
- 		// move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
 
- 		if (isset ( $_FILES ['Filedata'] ['name'] )) {
 
- 			
 
- 			$file = $_FILES ['Filedata'] ['tmp_name'];
 
- 			
 
- 			$error = false;
 
- 			
 
- 			if (! is_uploaded_file ( $file )) {
 
- 				
 
- 				$error = '400 Bad Request';
 
- 			}
 
- 			
 
- 			if ($error) {
 
- 				
 
- 				header ( 'HTTP/1.0 ' . $error );
 
- 				
 
- 				die ( 'Error ' . $error );
 
- 			} else {
 
- 				
 
- 				include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
 
- 				$this->IoHandler = new IoHandler ();
 
- 				
 
- 				$pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
 
- 				
 
- 				// $filedir=$_POST['time'];
 
- 				
 
- 				// 调用定义物理路径
 
- 				$t = DOO::conf ()->SITE_PATH . "upload/";
 
- 				
 
- 				$this->IoHandler->MakeDir ( $t );
 
- 				
 
- 				$filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
 
- 				
 
- 				if ($filename != 'xlsx')
 
- 					return "";
 
- 					// $upload_dir = $t."/".time().rand(10,100).".".$filename;
 
- 				
 
- 				$upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
 
- 				
 
- 				$upload_dir = $t . "/" . $upload_file;
 
- 				$k = move_uploaded_file ( $file, $upload_dir );
 
- 				
 
- 				if ($k) {
 
- 					// "series/".$filedir."/".
 
- 					
 
- 					$m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
 
- 					
 
- 					echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
 
- 				}
 
- 			}
 
- 		}
 
- 	}
 
- 	function getAuthentication() {
 
- 	}
 
- 	function loadCVS() {
 
- 		Doo::loadModel ( 'longle' );
 
- 		$longle = new longle ();
 
- 		$list = $longle->find ( array (
 
- 				'select' => 'key_num',
 
- 				'asArray' => TRUE 
 
- 		) );
 
- 		
 
- 		$file = fopen ( DOO::conf ()->SITE_PATH . "upload/key2.csv", 'r' );
 
- 		
 
- 		while ( $data = fgetcsv ( $file ) ) {
 
- 			$goods_list [$data [0]] = $data [1];
 
- 		}
 
- 		fclose ( $file );
 
- 		
 
- 		$sqlArray = array ();
 
- 		$sql = 'UPDATE CLD_longle SET SerialNumber = CASE key_num ';
 
- 		foreach ( $list as $key => $value ) {
 
- 			
 
- 			if (array_key_exists ( $value ['key_num'], $goods_list )) {
 
- 				// echo $value['key_num'].'-'.$goods_list[$value['key_num']].'<br/>';
 
- 				// $longle->SerialNumber=$goods_list[$value['key_num']];
 
- 				// $longle->update(array('where'=>'key_num="'.$value['key_num'].'"'));
 
- 				$sql .= ' WHEN "' . $value ['key_num'] . '" THEN "' . $goods_list [$value ['key_num']] . '" ';
 
- 				
 
- 				array_push ( $sqlArray, '"' . $value ['key_num'] . '"' );
 
- 				unset ( $goods_list [$value ['key_num']] );
 
- 			}
 
- 		}
 
- 		$sql .= 'END WHERE key_num IN (' . implode ( ',', $sqlArray ) . ')';
 
- 		echo $sql . '<br/>--------------------------------<br/>';
 
- 		foreach ( $goods_list as $key => $value ) {
 
- 			echo $key . ',' . $value . '<br/>';
 
- 		}
 
- 	}
 
- 	private function getRandChar($length) {
 
- 		$str = null;
 
- 		$strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
 
- 		$max = strlen ( $strPol ) - 1;
 
- 		
 
- 		for($i = 0; $i < $length; $i ++) {
 
- 			$str .= $strPol [rand ( 0, $max )]; // rand($min,$max)生成介于min和max两个数之间的一个随机整数
 
- 		}
 
- 		
 
- 		return $str;
 
- 	}
 
- 	
 
- 	// private function getReceiptCount(){
 
- 	
 
- 	// $status=2;
 
- 	// $year=date('Y');
 
- 	
 
- 	// Doo::loadModel('receipt');
 
- 	// $receipt=new receipt();
 
- 	
 
- 	// $dateCondition=" and Year(date) =".$year;
 
- 	
 
- 	// $approvalCondition=' and nowStaff like "%'.$this->staff[0]['sid'].'%" ';
 
- 	// $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
 
- 	
 
- 	// return count($receiptList);
 
- 	// }
 
- 	
 
- 	// private function getExeCount(){
 
- 	// Doo::loadModel('receipt');
 
- 	// $receipt=new receipt();
 
- 	// $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));
 
- 	
 
- 	// return count($receiptList);
 
- 	// }
 
- 	
 
- 	/**
 
- 	 * 格式化excel文件为数组
 
- 	 * @param unknown_type $file_url
 
- 	 * @param unknown_type $mcid
 
- 	 */
 
- 	function _format_excel_to_array($file_url = "") {
 
- 		if (! file_exists ( $file_url ))
 
- 			return array ();
 
- 		
 
- 		Doo::loadClass ( 'PHPExcel' );
 
- 		
 
- 		$PHPExcel = new PHPExcel ();
 
- 		
 
- 		$PHPReader = new PHPExcel_Reader_Excel2007 ();
 
- 		
 
- 		if (! $PHPReader->canRead ( $file_url )) {
 
- 			$PHPReader = new PHPExcel_Reader_Excel5 ();
 
- 			if (! $PHPReader->canRead ( $file_url )) {
 
- 				
 
- 				echo 'no Excel';
 
- 				return;
 
- 			}
 
- 		}
 
- 		
 
- 		$PHPExcel = $PHPReader->load ( $file_url );
 
- 		/**
 
- 		 * 读取excel文件中的第一个工作表
 
- 		 */
 
- 		$currentSheet = $PHPExcel->getSheet ( 0 );
 
- 		/**
 
- 		 * 取得最大的列号
 
- 		 */
 
- 		$allColumn = $currentSheet->getHighestColumn ();
 
- 		/**
 
- 		 * 取得一共有多少行
 
- 		 */
 
- 		$allRow = $currentSheet->getHighestRow ();
 
- 		
 
- 		$excel_array = array ();
 
- 		
 
- 		for($currentRow = 2; $currentRow <= $allRow; $currentRow ++) {
 
- 			
 
- 			$excel_column = array ();
 
- 			
 
- 			// 后期改进
 
- 			if ($allColumn == 'AM')
 
- 				$allColumn = 'Z';
 
- 			
 
- 			/**
 
- 			 * 从第A列开始输出
 
- 			 */
 
- 			for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
 
- 				
 
- 				$val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
 
- 				
 
- 				/**
 
- 				 * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312',
 
- 				 */
 
- 				$val = "'" . addslashes ( $val ) . "'";
 
- 				if ($currentColumn == 'A')
 
- 					$excel_column ['key_num'] = $val;
 
- 				elseif ($currentColumn == 'C')
 
- 					$excel_column ['product'] = $val;
 
- 				elseif ($currentColumn == 'D') {
 
- 					
 
- 					$val = str_replace ( "'", "", $val );
 
- 					
 
- 					$excel_column ['make_day'] = $this->excelTime ( $val );
 
- 				} elseif ($currentColumn == 'E') {
 
- 					$val = str_replace ( "'", "", $val );
 
- 					
 
- 					$excel_column ['alloted_time'] = $this->excelTime ( $val );
 
- 				} elseif ($currentColumn == 'F') {
 
- 					$val = str_replace ( "'", "", $val );
 
- 					
 
- 					$excel_column ['version'] = $val;
 
- 				} elseif ($currentColumn == 'B') {
 
- 					$val = str_replace ( "'", "", $val );
 
- 					$excel_column ['SerialNumber'] = $val;
 
- 				}
 
- 			}
 
- 			array_push ( $excel_array, $excel_column );
 
- 		}
 
- 		
 
- 		return $excel_array;
 
- 	}
 
- 	function excelTime($date, $time = false) {
 
- 		if (function_exists ( 'GregorianToJD' )) {
 
- 			if (is_numeric ( $date )) {
 
- 				$jd = GregorianToJD ( 1, 1, 1970 );
 
- 				$gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
 
- 				$date = explode ( '/', $gregorian );
 
- 				$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" : '');
 
- 				return $date_str;
 
- 			}
 
- 		} else {
 
- 			$date = $date > 25568 ? $date + 1 : 25569;
 
- 			/* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
 
- 			$ofs = (70 * 365 + 17 + 2) * 86400;
 
- 			$date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
 
- 		}
 
- 		return $date;
 
- 	}
 
- 	function _GetFileEXT($filename) {
 
- 		$pics = explode ( '.', $filename );
 
- 		
 
- 		$num = count ( $pics );
 
- 		
 
- 		return $pics [$num - 1];
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 获取get或者POST值
 
- 	 * @param string $name 属性名称
 
- 	 * @return fixed 值
 
- 	 */
 
- 	function get_args($name) {
 
- 		if (isset ( $_GET [$name] )) {
 
- 			if (is_array ( $_GET [$name] ))
 
- 				return $_GET [$name];
 
- 			else {
 
- 				return addslashes ( $_GET [$name] );
 
- 			}
 
- 		} elseif (isset ( $_POST [$name] )) {
 
- 			if (is_array ( $_POST [$name] ))
 
- 				return $_POST [$name];
 
- 			else {
 
- 				return addslashes ( $_POST [$name] );
 
- 			}
 
- 		} else {
 
- 			return false;
 
- 		}
 
- 	}
 
- 	function get_previous($on_page = 1) {
 
- 		return $on_page != 0 ? $on_page - 1 : $on_page;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 获得分页数据
 
- 	 * @param unknown_type $table
 
- 	 * @param unknown_type $condition
 
- 	 * @param unknown_type $on_page
 
- 	 * @param unknown_type $page_size
 
- 	 */
 
- 	function get_Tpage($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $tagSQL) {
 
- 		$page_c = "";
 
- 		$page ['previous'] = $this->get_previous ( $on_page );
 
- 		$page ['on_page'] = $on_page;
 
- 		$total_count = $this->get_table_Tcount ( $table, $condition, $tagSQL );
 
- 		$total = intval ( $total_count / $page_size );
 
- 		$page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
 
- 		$page ['total_data'] = $total_count;
 
- 		$page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
 
- 		$i = 1;
 
- 		$page_max = 1;
 
- 		if ($on_page > 10) {
 
- 			$page_max = intval ( $on_page / 10 ) + 1;
 
- 			$i = intval ( $on_page / 10 ) * 10 - 1;
 
- 		}
 
- 		$page ['page'] = $page_c;
 
- 		$page ['lower'] = (-- $on_page) * $page_size;
 
- 		return $page;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 获得分页数据
 
- 	 * @param unknown_type $table
 
- 	 * @param unknown_type $condition
 
- 	 * @param unknown_type $on_page
 
- 	 * @param unknown_type $page_size
 
- 	 */
 
- 	function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page", $staffid = "", $search, $tooltip, $cateid, $tagSQL) {
 
- 		$page_c = "";
 
- 		
 
- 		$page ['previous'] = $this->get_previous ( $on_page );
 
- 		
 
- 		$page ['on_page'] = $on_page;
 
- 		
 
- 		$total_count = $this->get_table_count ( $table, $condition, $staffid, $search, $tooltip, $cateid, $tagSQL );
 
- 		
 
- 		$total = intval ( $total_count / $page_size );
 
- 		
 
- 		$page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
 
- 		
 
- 		$page ['total_data'] = $total_count;
 
- 		
 
- 		$page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
 
- 		
 
- 		$i = 1;
 
- 		
 
- 		$page_max = 1;
 
- 		
 
- 		if ($on_page > 10) {
 
- 			$page_max = intval ( $on_page / 10 ) + 1;
 
- 			$i = intval ( $on_page / 10 ) * 10 - 1;
 
- 		}
 
- 		
 
- 		for(; $i <= $page ['total_page']; $i ++) {
 
- 			
 
- 			if ($i == $on_page) {
 
- 				if ($other == "page")
 
- 					$page_c .= '<a href="javascript:void(0);" class="current">' . $i . '</a>';
 
- 				else
 
- 					$page_c .= ' <span class="current">' . $i . '</span> ';
 
- 			} else if ($other == "page")
 
- 				$page_c .= '<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>';
 
- 			else
 
- 				$page_c .= ' <a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a> ';
 
- 			if ($i == (10 * $page_max))
 
- 				break;
 
- 		}
 
- 		
 
- 		$page ['page'] = $page_c;
 
- 		
 
- 		$page ['lower'] = (-- $on_page) * $page_size;
 
- 		
 
- 		return $page;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 获取总页数
 
- 	 * @param unknown_type $table
 
- 	 * @param unknown_type $condition
 
- 	 */
 
- 	public function get_table_Tcount($table = "", $condition = "", $tagSQL) {
 
- 		if ($tagSQL)
 
- 			$sql = "select count(*) as count from CLD_tagCompanyNexus as a left join CLD_company as b on (a.company=b.cid )  where " . $condition;
 
- 		else
 
- 			$sql = "select count(*) as count from  CLD_company where " . $condition;
 
- 		
 
- 		$query = Doo::db ()->query ( $sql );
 
- 		$result = $query->fetch ();
 
- 		return $result ['count'];
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 获取总页数
 
- 	 * @param unknown_type $table
 
- 	 * @param unknown_type $condition
 
- 	 */
 
- 	public function get_table_count($table = "", $condition = "", $staffid = "", $search, $tooltip, $cateid, $tagSQL) {
 
- 		// $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
 
- 		// echo $staffid;die;
 
- 		//
 
- 		if (! empty ( $staffid )) {
 
- 			// $staffid="and a.sid= '".$staffid."'"; " . $table . " as a left join on (a.cid=b.cid ".$staffid.")
 
- 			$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;
 
- 		} else {
 
- 			if (strlen ( $condition ) == 1 || empty ( $condition ))
 
- 				$sql = "select count(*) as count from  CLD_client as a  " . $condition;
 
- 			else
 
- 				$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;
 
- 		}
 
- 		
 
- 		if (! empty ( $search ))
 
- 			$sql = "select count(*) as count from  CLD_client as a where 1 " . $condition;
 
- 		
 
- 		if (! empty ( $tooltip )) {
 
- 			$condition = str_replace ( "a.", "c.", $condition );
 
- 			if ($tagSQL)
 
- 				$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;
 
- 			else
 
- 				$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;
 
- 		}
 
- 		// echo $sql;
 
- 		$query = Doo::db ()->query ( $sql );
 
- 		
 
- 		$result = $query->fetch ();
 
- 		
 
- 		return $result ['count'];
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 生成token
 
- 	 * @return string
 
- 	 */
 
- 	function set_token() {
 
- 		$str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
 
- 		$str = sha1 ( $str ); // 加密
 
- 		return $str;
 
- 	}
 
- 	
 
- }
 
- ?>
 
 
  |