MainController.php 265 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class MainController extends DooController {
  6. public $staff;
  7. public $nature = array (
  8. '1' => '设计',
  9. '2' => '造价管理',
  10. '3' => '业主',
  11. '4' => '交通局',
  12. '5' => '公路局',
  13. '6' => '审计',
  14. '7' => '财政',
  15. '8' => '审核',
  16. '9' => '施工',
  17. '10' => '咨询',
  18. '11' => '招标代理',
  19. '12' => '监理',
  20. '13' => '学校',
  21. '14' => '个人',
  22. '15' => '合作伙伴'
  23. );
  24. public $tooltip = array (
  25. '1' => array (
  26. 'L',
  27. '点击筛选标签'
  28. ),
  29. '2' => array (
  30. 'M',
  31. '点击筛选标签'
  32. ),
  33. '3' => array (
  34. 'N',
  35. '点击筛选标签'
  36. ),
  37. '4' => array (
  38. 'O',
  39. '点击筛选标签'
  40. ),
  41. '5' => array (
  42. 'P',
  43. '点击筛选标签'
  44. ),
  45. '6' => array (
  46. 'Q',
  47. '点击筛选标签'
  48. ),
  49. '7' => array (
  50. 'R',
  51. '点击筛选标签'
  52. )
  53. );
  54. public $webPath = "http://cld.smartcost.com.cn/upload/emailAnnex/";
  55. public function beforeRun($resource, $action) {
  56. // 主权限获得与判断
  57. Doo::loadModel ( 'staff' );
  58. $staff = new staff ();
  59. $detail = array ();
  60. if (isset ( $_COOKIE ["staff"] ))
  61. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  62. else
  63. $detail ['sid'] = 0;
  64. $flag = false;
  65. $accessModular = 'EMAIL';
  66. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  67. $flag = true;
  68. } else {
  69. $flag = false;
  70. }
  71. if ($flag === false) {
  72. $accessModular = 'INFORMATION';
  73. if (empty ( $detail ['cldAccessArray'] ))
  74. return '/settingEmployeeInfo';
  75. else {
  76. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  77. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  78. $flag = true;
  79. } else {
  80. $flag = false;
  81. }
  82. } else {
  83. $flag = false;
  84. }
  85. }
  86. }
  87. if ($flag === false) {
  88. $accessModular = 'DIRECTORIES';
  89. if (empty ( $detail ['cldAccessArray'] ))
  90. die ( 'illegal request' );
  91. else {
  92. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  93. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  94. $flag = true;
  95. } else {
  96. $flag = false;
  97. }
  98. } else {
  99. $flag = false;
  100. }
  101. }
  102. }
  103. if ($flag === false) {
  104. $accessModular = 'LOCK';
  105. if (empty ( $detail ['cldAccessArray'] ))
  106. die ( 'illegal request' );
  107. else {
  108. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  109. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  110. $flag = true;
  111. } else {
  112. $flag = false;
  113. }
  114. } else {
  115. $flag = false;
  116. }
  117. }
  118. }
  119. if ($detail ['sid'] == superHR && ! $flag)
  120. return '/settingEmployeeInfo';
  121. elseif (! $flag && $action == 'logStatistics')
  122. return '/settingEmployeeInfo';
  123. elseif (! $flag)
  124. die ( 'illegal request' );
  125. }
  126. function __construct() {
  127. // phpinfo();die;
  128. // include './protected/config/common.conf.php';
  129. // include $config['BASE_PATH'].'diagnostic/debug.php';
  130. if (isset ( $_COOKIE ["staff"] )) {
  131. if (! empty ( $_COOKIE ["staff"] )) {
  132. Doo::loadModel ( 'staff' );
  133. $staff = new staff ();
  134. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  135. return "";
  136. }
  137. }
  138. Doo::loadCore ( 'uri/DooUriRouter' );
  139. $router = new DooUriRouter ();
  140. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  141. if ($routeRs ['1'] != "login") {
  142. header ( 'Content-Type:text/html;charset=utf-8' );
  143. @header ( "Location: /login" );
  144. }
  145. }
  146. /**
  147. * 优化actionLog表
  148. */
  149. function backUpActionLog() {
  150. Doo::loadModel ( 'action_log' );
  151. $action_log = new action_log ();
  152. $date = date ( "Y" );
  153. $tableName = 'CLD_action_log' . $date;
  154. $action_log->copyActionLogToBakTable ( $tableName );
  155. $action_log = new action_log ();
  156. $aid = 0;
  157. $action_log->delActionLogByAid ( $aid );
  158. }
  159. function login() {
  160. $passwork = $this->get_args ( 'passwork' ) ? $this->get_args ( 'passwork' ) : 0;
  161. $uid = $this->get_args ( 'user' ) ? $this->get_args ( 'user' ) : 0;
  162. Doo::loadModel ( 'staff' );
  163. $staff = new staff ();
  164. Doo::loadClass ( 'XDeode' );
  165. $XDeode = new XDeode ( 5 );
  166. if (! empty ( $passwork )) {
  167. $userinfo = $staff->checkUser ( $uid, $passwork );
  168. if (! empty ( $userinfo )) {
  169. setcookie ( "staff", $XDeode->encode ( $userinfo [0] ['sid'] ), time () + 36000, "/" );
  170. // $text = 'CLDV2_CP';
  171. // $algorithm = 'aes192';
  172. // $password = '1234567890abcdef1234567890abcdef'; //node js required 32 byte length key
  173. // $iv = '1234567890abcdef'; //must be 16 byte length OPENSSL_RAW_DATA
  174. // $staffV2= bin2hex(openssl_encrypt($userinfo [0] ['sid'] , $algorithm, $text ));
  175. Doo::loadClass ( 'crypto' );
  176. $crypto = new crypto ( );
  177. $staffV2=$crypto->encrypt( $userinfo [0] ['sid'],'CLDV2_CP');
  178. setcookie ( "staffV2", $staffV2, time () + 36000, "/" );
  179. //工会动态密匙
  180. Doo::loadClass ( 'auth' );
  181. $auth = new auth ( );
  182. $staffGH=$auth->yundanran_auth($userinfo [0] ['sid'],'',"GH");
  183. setcookie ( "staffGH", $staffGH, time () + 36000, "/" );
  184. return "/";
  185. }
  186. }
  187. // 检测员工状态
  188. $data ['application'] = 0;
  189. $detail = $staff->getStaffByName ( $uid );
  190. if (! empty ( $detail )) {
  191. if ($detail ['pendStatus'] == 1) {
  192. $data ['application'] = 1;
  193. } elseif ($detail ['pendStatus'] == 2) {
  194. $data ['application'] = 2;
  195. }
  196. }
  197. $data ['staff'] = $detail; // $staff->getUser ();
  198. $data ['login'] = "";
  199. if (! empty ( $passwork ))
  200. $data ['login'] = "inputErrow";
  201. $this->render ( "/login", $data );
  202. }
  203. function out() {
  204. setcookie ( "staff", "", time () - 3600, "/" );
  205. setcookie ( "staffV2", "", time () - 3600, "/" );
  206. return "/";
  207. }
  208. function test() {
  209. // 实例化redis
  210. }
  211. function index2() {
  212. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  213. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  214. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  215. $page = $this->get_args ( 'page' ) ? $this->get_args ( 'page' ) : 1;
  216. Doo::loadModel ( 'action_log' );
  217. $action_log = new action_log ();
  218. Doo::loadModel ( 'staff' );
  219. $staff = new staff ();
  220. Doo::loadModel ( 'client_staff' );
  221. $client_staff = new client_staff ();
  222. Doo::loadModel ( 'longle' );
  223. $longle = new longle ();
  224. Doo::loadModel ( 'L_category' );
  225. $lcategory = new L_category ();
  226. $limit = 50;
  227. $p = $page;
  228. if ($page != 1)
  229. $page = $page * $limit - 1;
  230. else
  231. $page --;
  232. $condition = "";
  233. // if (!empty($cid) && $cid != 12) {
  234. // $condition = " and cid=" . $cid . " and sid=" . $sid;
  235. // }
  236. $staffCondition = "";
  237. $categorylist2 = array ();
  238. if ($this->staff [0] ['cid'] != 12) {
  239. $staffCondition = " and cid=" . $this->staff [0] ['cid'];
  240. array_push ( $categorylist2, array (
  241. 'cid' => $this->staff [0] ['cid'],
  242. 'title' => $this->staff [0] ['category']
  243. ) );
  244. if (! empty ( $sid ))
  245. $condition = " and cid=" . $this->staff [0] ['cid'] . " and sid=" . $sid;
  246. else
  247. $condition = " and cid=" . $this->staff [0] ['cid'];
  248. } else {
  249. $sql = 'SELECT `CLD_L_category`.cid,`CLD_L_category`.title,count(`CLD_staff`.sid) as count FROM `CLD_L_category` left join `CLD_staff` on `CLD_L_category`.cid=`CLD_staff`.cid group by `CLD_staff`.cid HAVING count(`CLD_staff`.sid)>0 order by count(`CLD_staff`.sid) desc';
  250. $query = Doo::db ()->query ( $sql );
  251. $result = $query->fetchAll ();
  252. $categorylist2 = $result;
  253. }
  254. // 有待优化
  255. Doo::loadModel ( 'department' );
  256. $department = new department ();
  257. $categorylist3 = $categorylist2;
  258. $bakCategory = array ();
  259. foreach ( $categorylist3 as $key => $value ) {
  260. $departList = $department->getDepartmentBycid ( $value ['cid'] );
  261. if (! empty ( $departList )) {
  262. // $bakCategory=$categorylist2[$key];
  263. array_unshift ( $bakCategory, $value );
  264. unset ( $categorylist2 [$key] );
  265. foreach ( $departList as $v ) {
  266. array_unshift ( $bakCategory, array (
  267. 'cid' => $v ['cid'],
  268. 'title' => $value ['title'],
  269. 'count' => $value ['count'],
  270. 'did' => $v ['did'],
  271. 'departmentName' => $v ['departmentName']
  272. ) );
  273. }
  274. }
  275. }
  276. foreach ( $bakCategory as $value ) {
  277. array_unshift ( $categorylist2, $value );
  278. }
  279. $data ['did'] = '';
  280. if (! empty ( $cid )) {
  281. $staffCondition = " and cid=" . $cid;
  282. if (! is_numeric ( $cid )) {
  283. $cdid = explode ( '-', $cid );
  284. $cid = $cdid [0];
  285. $data ['did'] = $cdid [1];
  286. $staffCondition = " and cid=" . $cid . " and departmentID=" . $cdid [1];
  287. }
  288. if (! empty ( $sid ))
  289. $condition = " and cid=" . $cid . " and sid=" . $sid;
  290. else
  291. $condition = " and cid=" . $cid;
  292. }
  293. /*
  294. * $itemCategoryList=$action_log->find(array('select'=>'updatetime,COUNT(*)', 'where'=>" Year(updatetime)=2014",'groupby'=>'Month(updatetime)','asArray'=>true)); print_r($itemCategoryList);die;
  295. */
  296. $staffList = $staff->find ( array (
  297. 'where' => ' username!="admin" ' . $staffCondition . $staffCondition . ' and nature!=4 and pendStatus!=4 and pendStatus!=1 and pendStatus!=2 ',
  298. 'asArray' => true
  299. ) );
  300. $alCondition = ' aid>' . REMIT . ' ';
  301. $actionLogList = $action_log->find ( array (
  302. 'where' => $alCondition . $condition,
  303. 'limit' => $page . ',' . $limit,
  304. 'desc' => 'aid',
  305. 'asArray' => true
  306. ) );
  307. // echo $condition;
  308. // 抽取日期 ,'groupby'=>'updatetime'
  309. $dateLog = $action_log->find ( array (
  310. 'select' => 'updatetime',
  311. 'where' => $alCondition . $condition,
  312. 'limit' => $limit,
  313. 'desc' => 'aid',
  314. 'asArray' => true
  315. ) );
  316. $dl = array ();
  317. foreach ( $dateLog as $value ) {
  318. array_push ( $dl, $value ['updatetime'] );
  319. }
  320. $dateLog = array_unique ( $dl );
  321. $log = array ();
  322. foreach ( $dateLog as $key => $value ) {
  323. $log [$value] = array ();
  324. foreach ( $actionLogList as $k => $v ) {
  325. if ($value == $v ['updatetime']) {
  326. array_push ( $log [$value], $v );
  327. unset ( $actionLogList [$k] );
  328. }
  329. }
  330. }
  331. $max = array ();
  332. foreach ( $staffList as $key => $value ) {
  333. $staffList [$key] ['count'] = $client_staff->count ( array (
  334. 'where' => 'sid=' . $value ['sid'],
  335. 'asArray' => true
  336. ) );
  337. array_push ( $max, $staffList [$key] ['count'] . ':' . $value ['username'] );
  338. }
  339. rsort ( $max, SORT_NUMERIC );
  340. $sum = 0;
  341. foreach ( $max as $key => $value ) {
  342. $max [$key] = explode ( ":", $value );
  343. $sum += $max [$key] [0];
  344. }
  345. $max2 = $max;
  346. array_shift ( $max2 );
  347. array_shift ( $max2 );
  348. array_shift ( $max2 );
  349. $lcategoryList = $lcategory->find ( array (
  350. 'asArray' => true
  351. ) );
  352. $useL = array ();
  353. $Rsum = $Ssum = 0;
  354. foreach ( $lcategoryList as $key => $value ) {
  355. $longleR = $longle->count ( array (
  356. 'where' => 'cid=' . $value ['cid'],
  357. 'asArray' => true
  358. ) );
  359. $longleS = $longle->count ( array (
  360. 'where' => 'cid=' . $value ['cid'] . ' and status!=1 and status!=2',
  361. 'asArray' => true
  362. ) );
  363. $Rsum += $longleR;
  364. $Ssum += $longleS;
  365. if (! empty ( $longleS ))
  366. array_push ( $useL, round ( ($longleS / $longleR) * 100 ) . '% :' . $value ['title'] );
  367. else
  368. array_push ( $useL, '0% :' . $value ['title'] );
  369. }
  370. rsort ( $useL, SORT_NUMERIC ); // $sum=0;
  371. foreach ( $useL as $key => $value ) {
  372. $useL [$key] = explode ( ":", $value );
  373. // $sum+=$max[$key][0];
  374. }
  375. $useL2 = $useL;
  376. array_shift ( $useL2 );
  377. array_shift ( $useL2 );
  378. array_shift ( $useL2 );
  379. $data ['Ssum'] = round ( ($Ssum / $Rsum) * 100 ) . '%';
  380. $data ['Rsum'] = $Rsum;
  381. $data ['useL2'] = $useL2;
  382. $data ['useL'] = $useL;
  383. $data ['sum'] = $sum;
  384. $data ['max'] = $max;
  385. $data ['max2'] = $max2;
  386. $data ['log'] = $log;
  387. $data ['page'] = $p;
  388. $data ['staffList'] = $staffList;
  389. $data ['categorylist2'] = $categorylist2;
  390. $data ['cid'] = $cid;
  391. $data ['sid'] = $sid;
  392. $data ['memu'] = "index";
  393. $data ['staff'] = $this->staff;
  394. $this->render ( "index2", $data );
  395. }
  396. function indexPage() {
  397. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  398. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  399. $page = $this->get_args ( 'page' ) ? $this->get_args ( 'page' ) : 1;
  400. Doo::loadModel ( 'action_log' );
  401. $action_log = new action_log ();
  402. $limit = 50;
  403. $p = $page;
  404. // if ($page!=1)
  405. // $page=$page*$limit-1;
  406. // else
  407. // $page--;
  408. $page = (-- $p) * $limit;
  409. /*
  410. * $condition=""; if (!empty($cid)&&$cid!=12){ $condition=" and cid=".$cid; } $staffCondition=""; if($this->staff[0]['cid']!=12){ $staffCondition=" and cid=".$this->staff[0]['cid']; $condition=" and cid=".$this->staff[0]['cid']; }
  411. */
  412. $condition = "";
  413. if (! empty ( $cid ) && $cid != 12) {
  414. $condition = " and cid=" . $cid . " and sid=" . $sid;
  415. }
  416. $staffCondition = "";
  417. if ($this->staff [0] ['cid'] != 12) {
  418. $staffCondition = " and cid=" . $this->staff [0] ['cid'];
  419. if (! empty ( $sid ))
  420. $condition = " and cid=" . $this->staff [0] ['cid'] . " and sid=" . $sid;
  421. else
  422. $condition = " and cid=" . $this->staff [0] ['cid'];
  423. }
  424. $actionLogList = $action_log->find ( array (
  425. 'where' => ' 1 ' . $condition,
  426. 'limit' => $page . ',' . $limit,
  427. 'desc' => 'aid',
  428. 'asArray' => true
  429. ) );
  430. // 抽取日期 ,'groupby'=>'updatetime'
  431. $dateLog = $action_log->find ( array (
  432. 'select' => 'updatetime',
  433. 'where' => ' 1 ' . $condition,
  434. 'limit' => $page . ',' . $limit,
  435. 'desc' => 'aid',
  436. 'asArray' => true
  437. ) );
  438. $dl = array ();
  439. foreach ( $dateLog as $value ) {
  440. array_push ( $dl, $value ['updatetime'] );
  441. }
  442. $dateLog = array_unique ( $dl );
  443. $log = array ();
  444. foreach ( $dateLog as $key => $value ) {
  445. $log [$value] = array ();
  446. foreach ( $actionLogList as $k => $v ) {
  447. if ($value == $v ['updatetime']) {
  448. array_push ( $log [$value], $v );
  449. unset ( $actionLogList [$k] );
  450. }
  451. }
  452. }
  453. $html = '';
  454. foreach ( $log as $key => $value ) {
  455. $html .= '<div class="item">
  456. <div class="date">' . $key . '</div>
  457. <dl class="recordList clearfix">';
  458. foreach ( $value as $k => $v ) {
  459. $html .= '<dd class="' . $v ['class'] . '"><span class="fR">' . $v ['time'] . '</span>' . $v ['action'] . '</dd>';
  460. }
  461. $html .= '</dl></div>';
  462. }
  463. echo $html;
  464. }
  465. function logStatistics() {
  466. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  467. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  468. Doo::loadModel ( 'action_log' );
  469. $action_log = new action_log ();
  470. Doo::loadModel ( 'staff' );
  471. $staff = new staff ();
  472. Doo::loadModel ( 'client_staff' );
  473. $client_staff = new client_staff ();
  474. Doo::loadModel ( 'longle' );
  475. $longle = new longle ();
  476. Doo::loadModel ( 'L_category' );
  477. $lcategory = new L_category ();
  478. Doo::loadModel ( 'department' );
  479. $department = new department ();
  480. $redis = new Redis ();
  481. $redis->connect ( '127.0.0.1', '6379' ); // 120.27.200.79
  482. $staffCondition = "";
  483. $categorylist2 = array ();
  484. if ($this->staff [0] ['cid'] != 12) {
  485. $staffCondition = " and cid=" . $this->staff [0] ['cid'];
  486. // array_push ( $categorylist2, array (
  487. // 'cid' => $this->staff [0] ['cid'],
  488. // 'title' => $this->staff [0] ['category']
  489. // ) );
  490. $otherC = $lcategory->getCategoryById ( $this->staff [0] ['cid'], $this->staff [0] ['othercid'] );
  491. foreach ( $otherC as $value ) {
  492. array_push ( $categorylist2, array (
  493. 'cid' => $value ['cid'],
  494. 'title' => $value ['title']
  495. ) );
  496. }
  497. } else {
  498. $sql = 'SELECT `CLD_L_category`.cid,`CLD_L_category`.title,count(`CLD_staff`.sid) as count FROM `CLD_L_category`
  499. 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';
  500. //echo $sql;
  501. $query = Doo::db ()->query ( $sql );
  502. $result = $query->fetchAll ();
  503. $categorylist2 = $result;
  504. // $otherC=$lcategory->getCategoryById($this->staff [0] ['cid'],$this->staff [0] ['othercid']);
  505. }
  506. // print_r($categorylist2);
  507. // 有待优化
  508. $categorylist3 = $categorylist2;
  509. $bakCategory = array ();
  510. foreach ( $categorylist3 as $key => $value ) {
  511. $departList = $department->getDepartmentBycid ( $value ['cid'] );
  512. if (! empty ( $departList )) {
  513. // $bakCategory=$categorylist2[$key];
  514. array_unshift ( $bakCategory, $value );
  515. unset ( $categorylist2 [$key] );
  516. foreach ( $departList as $v ) {
  517. array_unshift ( $bakCategory, array (
  518. 'cid' => $v ['cid'],
  519. 'title' => $value ['title'],
  520. 'count' => @$value ['count'],
  521. 'did' => $v ['did'],
  522. 'departmentName' => $v ['departmentName']
  523. ) );
  524. }
  525. }
  526. }
  527. foreach ( $bakCategory as $value ) {
  528. array_unshift ( $categorylist2, $value );
  529. }
  530. // array_unshift($categorylist2,$bakCategory);
  531. // print_r($categorylist2);
  532. $did = $data ['did'] = '';
  533. $othercateSql = '';
  534. if (! empty ( $this->staff [0] ['othercid'] ))
  535. $othercateSql = " or (othercid like '" . $this->staff [0] ['othercid'] . "')";
  536. if (! empty ( $cid )) { //
  537. if (is_numeric ( $cid ))
  538. $staffCondition = " and cid=" . $cid . $othercateSql;
  539. else {
  540. $cdid = explode ( '-', $cid );
  541. $cid = $cdid [0];
  542. $data ['did'] = $did = $cdid [1];
  543. $staffCondition = " and cid=" . $cdid [0] . " and departmentID=" . $cdid [1] . $othercateSql;
  544. }
  545. }
  546. // echo $staffCondition;
  547. // echo $staffCondition;
  548. // Doo::db()->beginTransaction();
  549. $staffList = $staff->find ( array (
  550. 'where' => ' username !="admin"' . $staffCondition . ' and nature!=4 and pendStatus!=4 and pendStatus!=1 and pendStatus!=2 ',
  551. 'asArray' => true
  552. ) );
  553. $max = array ();
  554. $sum = 0;
  555. // 客户总数
  556. $redisKey = date ( 'Y-m-d' ) . '_logStatisticsCSum_' . $this->staff [0] ['cid'];
  557. $redisValue = $redis->lrange ( $redisKey, 0, - 1 );
  558. if (empty ( $redisValue )) {
  559. $kkk = array ();
  560. foreach ( $staffList as $key => $value ) {
  561. $staffList [$key] ['count'] = $client_staff->count ( array (
  562. 'where' => 'sid=' . $value ['sid'],
  563. 'asArray' => true
  564. ) );
  565. array_push ( $max, $staffList [$key] ['count'] . ':' . $value ['username'] );
  566. if ($this->staff [0] ['cid'] == 12)
  567. array_push ( $kkk, $staffList [$key] ['count'] );
  568. if ($this->staff [0] ['cid'] == $value ['cid'] && $this->staff [0] ['cid'] != 12) {
  569. array_push ( $kkk, $staffList [$key] ['count'] );
  570. }
  571. }
  572. foreach ( $kkk as $key => $value ) {
  573. $sum += $value;
  574. }
  575. $sortMaxStr = json_encode ( $max );
  576. $redis->lpush ( $redisKey, $sum );
  577. $redis->lpush ( $redisKey, $sortMaxStr );
  578. } else {
  579. $sum = $redisValue [1];
  580. $max = json_decode ( $redisValue [0], true );
  581. }
  582. rsort ( $max, SORT_NUMERIC );
  583. foreach ( $max as $key => $value ) {
  584. $max [$key] = explode ( ":", $value );
  585. // $sum+=$max[$key][0];
  586. }
  587. $max2 = $max;
  588. array_shift ( $max2 );
  589. array_shift ( $max2 );
  590. array_shift ( $max2 );
  591. $lcategoryList = $lcategory->find ( array (
  592. 'asArray' => true
  593. ) );
  594. $useL = array ();
  595. $Rsum = $Ssum = 0;
  596. $redisKey = date ( 'Y-m-d' ) . '_logStatisticsLongle';
  597. $redisValue = $redis->lrange ( $redisKey, 0, - 1 );
  598. if (empty ( $redisValue )) {
  599. foreach ( $lcategoryList as $key => $value ) {
  600. $longleR = $longle->count ( array (
  601. 'where' => 'cid=' . $value ['cid'],
  602. 'asArray' => true
  603. ) );
  604. $longleS = $longle->count ( array (
  605. 'where' => 'cid=' . $value ['cid'] . ' and status!=1 and status!=2',
  606. 'asArray' => true
  607. ) );
  608. $Rsum += $longleR;
  609. $Ssum += $longleS;
  610. if (! empty ( $longleS ))
  611. array_push ( $useL, round ( ($longleS / $longleR) * 100 ) . '% :' . $value ['title'] );
  612. else
  613. array_push ( $useL, '0% :' . $value ['title'] );
  614. }
  615. $useLStr = json_encode ( $useL );
  616. $redis->lpush ( $redisKey, $Rsum );
  617. $redis->lpush ( $redisKey, $Ssum );
  618. $redis->lpush ( $redisKey, $useLStr );
  619. } else {
  620. $useL = $redisValue [0];
  621. $useL = json_decode ( $useL, true );
  622. $Ssum = $redisValue [1];
  623. $Rsum = $redisValue [2];
  624. }
  625. rsort ( $useL, SORT_NUMERIC );
  626. foreach ( $useL as $key => $value ) {
  627. $useL [$key] = explode ( ":", $value );
  628. }
  629. $useL2 = $useL;
  630. array_shift ( $useL2 );
  631. array_shift ( $useL2 );
  632. array_shift ( $useL2 );
  633. // statistics
  634. // 30天操作日志数
  635. $categoryCondition = " and cid=" . $this->staff [0] ['cid'];
  636. $redisCid = $this->staff [0] ['cid'];
  637. $sidCondition = $redisSid = "";
  638. if (! empty ( $cid )) {
  639. $categoryCondition = " and cid=" . $cid;
  640. $redisCid = $cid;
  641. }
  642. if (! empty ( $sid )) {
  643. $redisSid = $sid;
  644. $sidCondition = " and sid=" . $sid;
  645. }
  646. if ($this->staff [0] ['cid'] == 12 && empty ( $cid )) {
  647. $categoryCondition = "";
  648. $redisCid = '';
  649. }
  650. // if(!empty($did))
  651. // $categoryCondition=$categoryCondition.' and departmentID='.$did;
  652. $redisKey = date ( 'Y-m-d' ) . 'SL_' . $redisCid . '_' . $redisSid;
  653. $redisValue = $redis->get ( $redisKey );
  654. if (empty ( $redisValue )) {
  655. $actionLogLongle = $action_log->find ( array (
  656. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  657. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=3" . $categoryCondition . $sidCondition,
  658. 'groupby' => 'date_format(updatetime,"%m-%d")',
  659. 'asArray' => true
  660. ) );
  661. $statisticsLongle = array ();
  662. for($d = 0; $d <= 29; $d ++) {
  663. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  664. $falgLongle = true;
  665. foreach ( $actionLogLongle as $value ) {
  666. if ($value ['updatetime'] == $MD) {
  667. array_push ( $statisticsLongle, $value ['count'] );
  668. $falgLongle = false;
  669. break;
  670. }
  671. }
  672. if ($falgLongle)
  673. array_push ( $statisticsLongle, 0 );
  674. }
  675. $statisticsLongle = array_reverse ( $statisticsLongle );
  676. $jsl = json_encode ( $statisticsLongle );
  677. $redis->set ( $redisKey, $jsl );
  678. $data ['statisticsLongle'] = $jsl;
  679. } else {
  680. $data ['statisticsLongle'] = $redisValue;
  681. }
  682. // 添加客户 数30天
  683. $redisKey = date ( 'Y-m-d' ) . 'SC_' . $redisCid . '_' . $redisSid;
  684. // echo $redisKey;
  685. // echo "<br/> date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=1" . $categoryCondition . $sidCondition;
  686. $redisValue = $redis->get ( $redisKey );
  687. if (empty ( $redisValue )) {
  688. $actionLogClient = $action_log->find ( array (
  689. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  690. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=1" . $categoryCondition . $sidCondition,
  691. 'groupby' => 'date_format(updatetime,"%m-%d")',
  692. 'asArray' => true
  693. ) );
  694. $statisticsClient = array ();
  695. for($d = 0; $d <= 29; $d ++) {
  696. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  697. $falgClient = true;
  698. foreach ( $actionLogClient as $value ) {
  699. if ($value ['updatetime'] == $MD) {
  700. array_push ( $statisticsClient, $value ['count'] );
  701. $falgClient = false;
  702. break;
  703. }
  704. }
  705. if ($falgClient)
  706. array_push ( $statisticsClient, 0 );
  707. }
  708. $statisticsClient = array_reverse ( $statisticsClient );
  709. $jsc = json_encode ( $statisticsClient );
  710. $redis->set ( $redisKey, $jsc );
  711. $data ['statisticsClient'] = $jsc;
  712. } else {
  713. $data ['statisticsClient'] = $redisValue;
  714. }
  715. $statisticsDay = array ();
  716. for($d = 0; $d <= 29; $d ++) {
  717. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  718. array_push ( $statisticsDay, $MD );
  719. }
  720. $statisticsDay = array_reverse ( $statisticsDay );
  721. // / Year(updatetime)=".date('Y')." and Month(updatetime)=".date('m')." and
  722. $categoryList = $lcategory->find ( array (
  723. 'asArray' => true
  724. ) );
  725. // 最近30天区域分布图
  726. $redisKey = date ( 'Y-m-d' ) . 'SCCT_' . $redisCid . '_' . $redisSid;
  727. $redisValue = $redis->lrange ( $redisKey, 0, - 1 );
  728. if (empty ( $redisValue )) {
  729. $CategoryClient = $action_log->find ( array (
  730. 'select' => 'cid,COUNT(*) as count,city',
  731. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=1" . $categoryCondition . $sidCondition,
  732. 'groupby' => 'cid',
  733. 'asArray' => true
  734. ) );
  735. $CategoryCompany = $action_log->find ( array (
  736. 'select' => 'cid, COUNT(*) as count,company,districtid',
  737. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and (status=1 )" . $categoryCondition . $sidCondition,
  738. 'groupby' => 'cid,districtid,company',
  739. 'asArray' => true
  740. ) );
  741. $statisticsCategory = array ();
  742. $statisticsCompany = array ();
  743. foreach ( $categoryList as $value ) {
  744. $falgClient = $falgLongle = true;
  745. foreach ( $CategoryClient as $v ) {
  746. if ($value ['cid'] == $v ['cid'] && $v ['cid'] != 12) {
  747. array_push ( $statisticsCategory, array (
  748. 'value' => $v ['count'],
  749. 'name' => str_replace ( "办", "省", $value ['title'] )
  750. ) );
  751. $falgClient = false;
  752. break;
  753. }
  754. }
  755. if ($falgClient) {
  756. array_push ( $statisticsCategory, array (
  757. 'value' => 0,
  758. 'name' => str_replace ( "办", "省", $value ['title'] )
  759. ) );
  760. }
  761. // company statistics
  762. $i = 0;
  763. foreach ( $CategoryCompany as $v ) {
  764. if ($value ['cid'] == $v ['cid'] && $v ['cid'] != 12) {
  765. $i ++;
  766. }
  767. }
  768. array_push ( $statisticsCompany, array (
  769. 'value' => $i,
  770. 'name' => str_replace ( "办", "省", $value ['title'] )
  771. ) );
  772. }
  773. $scctA = json_encode ( $statisticsCompany );
  774. $scctB = json_encode ( $statisticsCategory );
  775. $redis->lpush ( $redisKey, $scctA );
  776. $redis->lpush ( $redisKey, $scctB );
  777. $data ['statisticsCompany'] = $scctA;
  778. $data ['statisticsCategory'] = $scctB;
  779. } else {
  780. $data ['statisticsCompany'] = $redisValue [1];
  781. $data ['statisticsCategory'] = $redisValue [0];
  782. }
  783. // print_r($CategoryClient);
  784. $redisKey = date ( 'Y-m-d' ) . 'SN_' . $redisCid . '_' . $redisSid;
  785. $redisValue = $redis->get ( $redisKey );
  786. if (empty ( $redisValue )) {
  787. $natureList = $action_log->find ( array (
  788. 'select' => 'cid, COUNT(*) as count,nature',
  789. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=1 and nature !=''" . $categoryCondition . $sidCondition,
  790. 'groupby' => 'nature',
  791. 'asArray' => true
  792. ) );
  793. $statisticsNature = array ();
  794. foreach ( $this->nature as $value ) {
  795. $flagNature = true;
  796. foreach ( $natureList as $v ) {
  797. if ($value == $v ['nature']) {
  798. array_push ( $statisticsNature, array (
  799. 'value' => $v ['count'],
  800. 'name' => $value
  801. ) );
  802. $flagNature = false;
  803. break;
  804. }
  805. }
  806. if ($flagNature)
  807. array_push ( $statisticsNature, array (
  808. 'value' => 0,
  809. 'name' => $value
  810. ) );
  811. }
  812. $jsn = json_encode ( $statisticsNature );
  813. $redis->set ( $redisKey, $jsn );
  814. $data ['statisticsNature'] = $jsn;
  815. } else {
  816. $data ['statisticsNature'] = $redisValue;
  817. }
  818. $data ['statisticsDay'] = json_encode ( $statisticsDay );
  819. $data ['categorylist2'] = $categorylist2;
  820. $data ['Ssum'] = round ( ($Ssum / $Rsum) * 100 ) . '%';
  821. $data ['Rsum'] = $Rsum;
  822. $data ['useL2'] = $useL2;
  823. $data ['useL'] = $useL;
  824. $data ['sum'] = $sum;
  825. $data ['max'] = $max;
  826. $data ['max2'] = $max2;
  827. $data ['staffList'] = $staffList;
  828. $data ['cid'] = $cid;
  829. $data ['sid'] = $sid;
  830. $data ['memu'] = "index";
  831. $data ['staff'] = $this->staff;
  832. $this->render ( "/indexStat", $data );
  833. }
  834. function longleStatistics() {
  835. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  836. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  837. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 4;
  838. $districtH = $this->get_args ( 'district' ) ? $this->get_args ( 'district' ) : 0;
  839. Doo::loadModel ( 'action_log' );
  840. $action_log = new action_log ();
  841. Doo::loadModel ( 'staff' );
  842. $staff = new staff ();
  843. Doo::loadModel ( 'client_staff' );
  844. $client_staff = new client_staff ();
  845. Doo::loadModel ( 'longle' );
  846. $longle = new longle ();
  847. Doo::loadModel ( 'L_category' );
  848. $lcategory = new L_category ();
  849. Doo::loadModel ( 'district' );
  850. $district = new district ();
  851. $staffCondition = "";
  852. $categorylist2 = array ();
  853. if ($this->staff [0] ['cid'] != 12) {
  854. $staffCondition = " and cid=" . $this->staff [0] ['cid'];
  855. array_push ( $categorylist2, array (
  856. 'cid' => $this->staff [0] ['cid'],
  857. 'title' => $this->staff [0] ['category']
  858. ) );
  859. } else {
  860. $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';
  861. $query = Doo::db ()->query ( $sql );
  862. $result = $query->fetchAll ();
  863. $categorylist2 = $result;
  864. }
  865. // 有待优化
  866. Doo::loadModel ( 'department' );
  867. $department = new department ();
  868. $categorylist3 = $categorylist2;
  869. $bakCategory = array ();
  870. foreach ( $categorylist3 as $key => $value ) {
  871. $departList = $department->getDepartmentBycid ( $value ['cid'] );
  872. if (! empty ( $departList )) {
  873. // $bakCategory=$categorylist2[$key];
  874. array_unshift ( $bakCategory, $value );
  875. unset ( $categorylist2 [$key] );
  876. foreach ( $departList as $v ) {
  877. array_unshift ( $bakCategory, array (
  878. 'cid' => $v ['cid'],
  879. 'title' => $value ['title'],
  880. 'count' => $value ['count'],
  881. 'did' => $v ['did'],
  882. 'departmentName' => $v ['departmentName']
  883. ) );
  884. }
  885. }
  886. }
  887. foreach ( $bakCategory as $value ) {
  888. array_unshift ( $categorylist2, $value );
  889. }
  890. $data ['did'] = '';
  891. if (! empty ( $cid )) {
  892. if (is_numeric ( $cid ))
  893. $staffCondition = " and cid=" . $cid;
  894. else {
  895. $cdid = explode ( '-', $cid );
  896. $cid = $cdid [0];
  897. $data ['did'] = $cdid [1];
  898. $staffCondition = " and cid=" . $cdid [0] . " and departmentID=" . $cdid [1];
  899. }
  900. // $staffCondition = " and cid=" . $cid;
  901. }
  902. $staffList = $staff->find ( array (
  903. 'where' => ' username!="admin"' . $staffCondition . ' and nature!=4 and pendStatus!=4 and pendStatus!=1 and pendStatus!=2 ',
  904. 'asArray' => true
  905. ) );
  906. $max = array ();
  907. foreach ( $staffList as $key => $value ) {
  908. $staffList [$key] ['count'] = $client_staff->count ( array (
  909. 'where' => 'sid=' . $value ['sid'],
  910. 'asArray' => true
  911. ) );
  912. array_push ( $max, $staffList [$key] ['count'] . ':' . $value ['username'] );
  913. }
  914. rsort ( $max, SORT_NUMERIC );
  915. $sum = 0;
  916. foreach ( $max as $key => $value ) {
  917. $max [$key] = explode ( ":", $value );
  918. $sum += $max [$key] [0];
  919. }
  920. $max2 = $max;
  921. array_shift ( $max2 );
  922. array_shift ( $max2 );
  923. array_shift ( $max2 );
  924. $lcategoryList = $lcategory->find ( array (
  925. 'asArray' => true
  926. ) );
  927. $useL = array ();
  928. $Rsum = $Ssum = 0;
  929. foreach ( $lcategoryList as $key => $value ) {
  930. $longleR = $longle->count ( array (
  931. 'where' => 'cid=' . $value ['cid'],
  932. 'asArray' => true
  933. ) );
  934. $longleS = $longle->count ( array (
  935. 'where' => 'cid=' . $value ['cid'] . ' and status!=1 and status!=2',
  936. 'asArray' => true
  937. ) );
  938. $Rsum += $longleR;
  939. $Ssum += $longleS;
  940. if (! empty ( $longleS ))
  941. array_push ( $useL, round ( ($longleS / $longleR) * 100 ) . '% :' . $value ['title'] );
  942. else
  943. array_push ( $useL, '0% :' . $value ['title'] );
  944. }
  945. rsort ( $useL, SORT_NUMERIC ); // $sum=0;
  946. foreach ( $useL as $key => $value ) {
  947. $useL [$key] = explode ( ":", $value );
  948. // $sum+=$max[$key][0];
  949. }
  950. $useL2 = $useL;
  951. array_shift ( $useL2 );
  952. array_shift ( $useL2 );
  953. array_shift ( $useL2 );
  954. // statistics
  955. $categoryCondition = " and cid=" . $this->staff [0] ['cid'];
  956. $sidCondition = "";
  957. if (! empty ( $cid ))
  958. $categoryCondition = " and cid=" . $cid;
  959. if (! empty ( $sid ))
  960. $sidCondition = " and sid=" . $sid;
  961. if ($this->staff [0] ['cid'] == 12 && empty ( $cid )) {
  962. $categoryCondition = "";
  963. }
  964. // Year(updatetime)=".date('Y')." and Month(updatetime)=".date('m')." date_format(updatetime,"%m-%d") Day(updatetime)
  965. $actionLogClient = $action_log->find ( array (
  966. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  967. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=4" . $categoryCondition . $sidCondition,
  968. 'groupby' => 'Day(updatetime)',
  969. 'asArray' => true
  970. ) );
  971. $actionLogLongle = $action_log->find ( array (
  972. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  973. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=5" . $categoryCondition . $sidCondition,
  974. 'groupby' => 'Day(updatetime)',
  975. 'asArray' => true
  976. ) );
  977. $actionLogGet = $action_log->find ( array (
  978. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  979. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=6" . $categoryCondition . $sidCondition,
  980. 'groupby' => 'Day(updatetime)',
  981. 'asArray' => true
  982. ) );
  983. $statisticsDay = array ();
  984. $statisticsClient = $statisticsLongle = $statisticsGet = array ();
  985. /**
  986. * for ($d=1;$d<=date("t");$d++){ $MD=date('m')."-".$d;
  987. */
  988. for($d = 0; $d <= 29; $d ++) {
  989. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  990. $falgClient = $falgLongle = $falgGet = true;
  991. array_push ( $statisticsDay, $MD );
  992. foreach ( $actionLogClient as $value ) {
  993. if ($value ['updatetime'] == $MD) {
  994. array_push ( $statisticsClient, $value ['count'] );
  995. $falgClient = false;
  996. break;
  997. }
  998. }
  999. if ($falgClient)
  1000. array_push ( $statisticsClient, 0 );
  1001. foreach ( $actionLogLongle as $value ) {
  1002. if ($value ['updatetime'] == $MD) {
  1003. array_push ( $statisticsLongle, $value ['count'] );
  1004. $falgLongle = false;
  1005. break;
  1006. }
  1007. }
  1008. if ($falgLongle)
  1009. array_push ( $statisticsLongle, 0 );
  1010. foreach ( $actionLogGet as $value ) {
  1011. if ($value ['updatetime'] == $MD) {
  1012. array_push ( $statisticsGet, $value ['count'] );
  1013. $falgGet = false;
  1014. break;
  1015. }
  1016. }
  1017. if ($falgGet)
  1018. array_push ( $statisticsGet, 0 );
  1019. }
  1020. $statisticsClient = array_reverse ( $statisticsClient );
  1021. $statisticsLongle = array_reverse ( $statisticsLongle );
  1022. $statisticsGet = array_reverse ( $statisticsGet );
  1023. $statisticsDay = array_reverse ( $statisticsDay );
  1024. // /
  1025. $districtCondition = "";
  1026. $topDistrict = $district->get_lvByid ( 0, 0 );
  1027. if (! empty ( $sid )) {
  1028. $s = $staff->getOne ( array (
  1029. 'where' => ' sid=' . $sid,
  1030. 'asArray' => true
  1031. ) );
  1032. $l = $lcategory->find ( array (
  1033. 'where' => ' cid in(' . $s ['cid'] . ')',
  1034. 'asArray' => true
  1035. ) );
  1036. if (! empty ( $s ['othercid'] ))
  1037. $l = $lcategory->find ( array (
  1038. 'where' => ' cid in(' . $s ['cid'] . ',' . $s ['othercid'] . ')',
  1039. 'asArray' => true
  1040. ) );
  1041. if (! empty ( $districtH )) {
  1042. $districtCondition = " and districtid like '" . $districtH . ",%'";
  1043. $sidCondition = "";
  1044. $topDistrict = $district->find ( array (
  1045. 'where' => ' upid=' . $districtH,
  1046. 'asArray' => true
  1047. ) );
  1048. } else {
  1049. $districtCondition = " and districtid like '" . $l [0] ['districtid'] . ",%'";
  1050. $sidCondition = "";
  1051. $topDistrict = $district->find ( array (
  1052. 'where' => ' upid=' . $l [0] ['districtid'],
  1053. 'asArray' => true
  1054. ) );
  1055. }
  1056. $str = array ();
  1057. foreach ( $l as $value ) {
  1058. array_push ( $str, $value ['districtid'] );
  1059. }
  1060. $str = implode ( ",", $str );
  1061. $data ['districtHtml'] = $district->find ( array (
  1062. 'where' => ' id in (' . $str . ')',
  1063. 'asArray' => true
  1064. ) );
  1065. $data ['districtH'] = $l [0] ['districtid'];
  1066. if (! empty ( $districtH ))
  1067. $data ['districtH'] = $districtH;
  1068. }
  1069. // Year(updatetime)=".date('Y')." and Month(updatetime)=".date('m')." and
  1070. if (! empty ( $sid ))
  1071. $districtClient = $action_log->find ( array (
  1072. 'select' => 'city,province,COUNT(*) as count',
  1073. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=" . $status . $categoryCondition . $sidCondition . $districtCondition,
  1074. 'groupby' => 'province',
  1075. 'asArray' => true
  1076. ) );
  1077. else
  1078. $districtClient = $action_log->find ( array (
  1079. 'select' => 'city,province,COUNT(*) as count',
  1080. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=" . $status . $categoryCondition . $sidCondition . $districtCondition,
  1081. 'groupby' => 'city',
  1082. 'asArray' => true
  1083. ) );
  1084. $statisticsLend = array ();
  1085. $statisticsCompany = array ();
  1086. if (! empty ( $sid )) {
  1087. foreach ( $topDistrict as $value ) {
  1088. $falgLend = $falgLongle = true;
  1089. foreach ( $districtClient as $v ) {
  1090. if ($value ['name'] == $v ['province']) {
  1091. array_push ( $statisticsLend, array (
  1092. 'value' => $v ['count'],
  1093. 'name' => $value ['name']
  1094. ) );
  1095. $falgLend = false;
  1096. break;
  1097. }
  1098. }
  1099. if ($falgLend)
  1100. array_push ( $statisticsLend, array (
  1101. 'value' => 0,
  1102. 'name' => $value ['name']
  1103. ) );
  1104. }
  1105. } else {
  1106. foreach ( $topDistrict as $value ) {
  1107. $falgLend = $falgLongle = true;
  1108. foreach ( $districtClient as $v ) {
  1109. if ($value ['name'] == $v ['city']) {
  1110. array_push ( $statisticsLend, array (
  1111. 'value' => $v ['count'],
  1112. 'name' => $value ['name']
  1113. ) );
  1114. $falgLend = false;
  1115. break;
  1116. }
  1117. }
  1118. if ($falgLend)
  1119. array_push ( $statisticsLend, array (
  1120. 'value' => 0,
  1121. 'name' => $value ['name']
  1122. ) );
  1123. }
  1124. }
  1125. // print_r($statisticsLend);die;
  1126. $natureList = $action_log->find ( array (
  1127. 'select' => 'cid, COUNT(*) as count,nature',
  1128. 'where' => " date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) and status=" . $status . " and nature !=''" . $categoryCondition . $sidCondition . $districtCondition,
  1129. 'groupby' => 'nature',
  1130. 'asArray' => true
  1131. ) );
  1132. $statisticsNature = array ();
  1133. foreach ( $this->nature as $value ) {
  1134. $flagNature = true;
  1135. foreach ( $natureList as $v ) {
  1136. if ($value == $v ['nature']) {
  1137. array_push ( $statisticsNature, array (
  1138. 'value' => $v ['count'],
  1139. 'name' => $value
  1140. ) );
  1141. $flagNature = false;
  1142. break;
  1143. }
  1144. }
  1145. if ($flagNature)
  1146. array_push ( $statisticsNature, array (
  1147. 'value' => 0,
  1148. 'name' => $value
  1149. ) );
  1150. }
  1151. $data ['statisticsNature'] = json_encode ( $statisticsNature );
  1152. // print_r($statisticsLend);die;
  1153. $data ['statisticsLend'] = json_encode ( $statisticsLend );
  1154. $data ['status'] = $status;
  1155. $data ['statisticsDay'] = json_encode ( $statisticsDay );
  1156. $data ['statisticsClient'] = json_encode ( $statisticsClient );
  1157. $data ['statisticsLongle'] = json_encode ( $statisticsLongle );
  1158. $data ['statisticsGet'] = json_encode ( $statisticsGet );
  1159. $data ['categorylist2'] = $categorylist2;
  1160. $data ['Ssum'] = round ( ($Ssum / $Rsum) * 100 ) . '%';
  1161. $data ['Rsum'] = $Rsum;
  1162. $data ['useL2'] = $useL2;
  1163. $data ['useL'] = $useL;
  1164. $data ['sum'] = $sum;
  1165. $data ['max'] = $max;
  1166. $data ['max2'] = $max2;
  1167. $data ['staffList'] = $staffList;
  1168. $data ['cid'] = $cid;
  1169. $data ['sid'] = $sid;
  1170. $data ['memu'] = "index";
  1171. $data ['staff'] = $this->staff;
  1172. $this->render ( "/indexLongle", $data );
  1173. }
  1174. function index() {
  1175. die ( 'dd' );
  1176. $data ['memu'] = "index";
  1177. $data ['staff'] = $this->staff;
  1178. Doo::loadModel ( 'action_log' );
  1179. $action_log = new action_log ();
  1180. $data ['today'] = explode ( "-", date ( "Y-m-d" ) );
  1181. $str = "";
  1182. if ($this->staff [0] ['isadmin'] != 1) {
  1183. $str = " and (action like '%" . $this->staff [0] ['category'] . "%'";
  1184. $khql = explode ( ",", $this->staff [0] ['othercategory'] );
  1185. if (! empty ( $khql [0] )) {
  1186. foreach ( $khql as $key => $value ) {
  1187. $str .= " or action like '%" . $value . "%'";
  1188. }
  1189. $str .= ")";
  1190. } else
  1191. $str .= ")";
  1192. }
  1193. $data ['actionListNow'] = $action_log->find ( array (
  1194. 'where' => ' updatetime=\'' . date ( "Y-m-d" ) . "'" . $str,
  1195. 'desc' => 'aid',
  1196. 'asArray' => TRUE
  1197. ) );
  1198. $d2 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 1, date ( "Y" ) );
  1199. $strdate = date ( "Y-m-d", $d2 );
  1200. $data ['day2'] = explode ( "-", $strdate );
  1201. $data ['actionListNow2'] = $action_log->find ( array (
  1202. 'where' => ' updatetime=\'' . $strdate . "'" . $str,
  1203. 'desc' => 'aid',
  1204. 'asArray' => TRUE
  1205. ) );
  1206. $d3 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 2, date ( "Y" ) );
  1207. $strdate = date ( "Y-m-d", $d3 );
  1208. $data ['day3'] = explode ( "-", $strdate );
  1209. $data ['actionListNow3'] = $action_log->find ( array (
  1210. 'where' => ' updatetime=\'' . $strdate . "'" . $str,
  1211. 'desc' => 'aid',
  1212. 'asArray' => TRUE
  1213. ) );
  1214. $d4 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 3, date ( "Y" ) );
  1215. $strdate = date ( "Y-m-d", $d4 );
  1216. $data ['day4'] = explode ( "-", $strdate );
  1217. $data ['actionListNow4'] = $action_log->find ( array (
  1218. 'where' => ' updatetime=\'' . $strdate . "'" . $str,
  1219. 'asArray' => TRUE
  1220. ) );
  1221. $d5 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 4, date ( "Y" ) );
  1222. $strdate = date ( "Y-m-d", $d5 );
  1223. $data ['day5'] = explode ( "-", $strdate );
  1224. $data ['actionListNow5'] = $action_log->find ( array (
  1225. 'where' => ' updatetime=\'' . $strdate . "'" . $str,
  1226. 'asArray' => TRUE
  1227. ) );
  1228. $d6 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 5, date ( "Y" ) );
  1229. $strdate = date ( "Y-m-d", $d6 );
  1230. $data ['day6'] = explode ( "-", $strdate );
  1231. $data ['actionListNow6'] = $action_log->find ( array (
  1232. 'where' => ' updatetime=\'' . $strdate . "'" . $str,
  1233. 'asArray' => TRUE
  1234. ) );
  1235. $d7 = mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 6, date ( "Y" ) );
  1236. $strdate = date ( "Y-m-d", $d7 );
  1237. $data ['day7'] = explode ( "-", $strdate );
  1238. $data ['actionListNow7'] = $action_log->find ( array (
  1239. 'where' => ' updatetime=\'' . $strdate . "'" . $str,
  1240. 'asArray' => TRUE
  1241. ) );
  1242. Doo::loadModel ( 'staff' );
  1243. Doo::loadModel ( 'client_staff' );
  1244. $client_staff = new client_staff ();
  1245. $staff = new staff ();
  1246. $st = $staff->find ( array (
  1247. 'where' => '1',
  1248. 'asArray' => true
  1249. ) );
  1250. foreach ( $st as $key => $value ) {
  1251. $st [$key] ['count'] = $client_staff->count ( array (
  1252. 'where' => 'sid=' . $value ['sid'],
  1253. 'asArray' => true
  1254. ) );
  1255. }
  1256. $data ['staffCount'] = $st;
  1257. $this->render ( "/index", $data );
  1258. }
  1259. function receive() {
  1260. $data ['memu'] = "keyonline";
  1261. $data ['staff'] = $this->staff;
  1262. Doo::loadModel ( 'longle' );
  1263. $longle = new longle ();
  1264. $data ['arrayReceive'] = $longle->getLongleReceive ( $this->staff [0] ['cid'], 1, $this->staff [0] ['othercid'] );
  1265. $this->render ( "/look_receive", $data );
  1266. }
  1267. function doLongleReceive() {
  1268. $arrLid = $this->get_args ( 'lid' ) ? $this->get_args ( 'lid' ) : array ();
  1269. Doo::loadModel ( 'longle_log' );
  1270. Doo::loadModel ( 'longle' );
  1271. foreach ( $arrLid as $key => $value ) {
  1272. $ky = explode ( "-", $value );
  1273. $longle = new longle ();
  1274. $longle_log = new longle_log ();
  1275. $longle->lid = $ky [0];
  1276. $longle->status = 2;
  1277. $longle->statusT = '接收';
  1278. $longle->responsible = $this->staff [0] ['username'];
  1279. // 记录锁状态
  1280. //$longle->statuslog = "1,2";
  1281. $longle->update ();
  1282. $longle_log->lid = $ky [0];
  1283. $longle_log->status = 2;
  1284. $longle_log->statusT = '接收';
  1285. $longle_log->responsible = $this->staff [0] ['username'];
  1286. $longle_log->operator = $this->staff [0] ['username'];
  1287. $longle_log->category = $ky [1];
  1288. $longle_log->dateline = date ( "Y-m-d" );
  1289. $longle_log->insert ();
  1290. }
  1291. return "/receive";
  1292. }
  1293. function addClient() {
  1294. $companyKey = $this->get_args ( 'companyKey' ) ? $this->get_args ( 'companyKey' ) : "";
  1295. $clientname = $this->get_args ( 'clientname' ) ? $this->get_args ( 'clientname' ) : "";
  1296. $gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : "";
  1297. $nicename = $this->get_args ( 'nicename' ) ? $this->get_args ( 'nicename' ) : "";
  1298. $telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : "";
  1299. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1300. $email = $this->get_args ( 'email' ) ? $this->get_args ( 'email' ) : "";
  1301. $qq = $this->get_args ( 'qq' ) ? $this->get_args ( 'qq' ) : "";
  1302. $tid = $this->get_args ( 'tid' ) ? $this->get_args ( 'tid' ) : "";
  1303. $companyname = $this->get_args ( 'companyname' ) ? $this->get_args ( 'companyname' ) : "";
  1304. $local1 = $this->get_args ( 'lv21' ) ? $this->get_args ( 'lv21' ) : "";
  1305. $local2 = $this->get_args ( 'lv22' ) ? $this->get_args ( 'lv22' ) : "";
  1306. $local3 = $this->get_args ( 'lv23' ) ? $this->get_args ( 'lv23' ) : "";
  1307. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  1308. $fax = $this->get_args ( 'fax' ) ? $this->get_args ( 'fax' ) : "";
  1309. $webservice = $this->get_args ( 'webservice' ) ? $this->get_args ( 'webservice' ) : "";
  1310. $department = $this->get_args ( 'department' ) ? $this->get_args ( 'department' ) : "";
  1311. $position = $this->get_args ( 'position' ) ? $this->get_args ( 'position' ) : "";
  1312. $office = $this->get_args ( 'office' ) ? $this->get_args ( 'office' ) : "";
  1313. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1314. $ride = $this->get_args ( 'ride' ) ? $this->get_args ( 'ride' ) : "";
  1315. $landmarks = $this->get_args ( 'landmarks' ) ? $this->get_args ( 'landmarks' ) : "";
  1316. $priority = $this->get_args ( 'priority' ) ? $this->get_args ( 'priority' ) : "";
  1317. $stay = $this->get_args ( 'stay' ) ? $this->get_args ( 'stay' ) : "";
  1318. $mark = $this->get_args ( 'mark' ) ? $this->get_args ( 'mark' ) : "";
  1319. $clientname = trim ( $clientname );
  1320. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  1321. $tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
  1322. if (empty ( $token )) {
  1323. die ( 'illegal request-token' );
  1324. } else {
  1325. session_start ();
  1326. $sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
  1327. header ( 'Content-Type:text/html;charset=utf-8' );
  1328. if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
  1329. die ( '请重新刷新页面' );
  1330. }elseif($_SESSION [$sessionKey]=='repeat'){
  1331. die ( '请勿重复提交客户信息' );
  1332. }else{
  1333. if ($_SESSION [$sessionKey] != $token){
  1334. die ( '请勿重复提交客户信息' );
  1335. } else {
  1336. $_SESSION [$sessionKey] = 'repeat';
  1337. }
  1338. }
  1339. }
  1340. // $companyname = trim ( $companyname );
  1341. if (empty ( $companyname ))
  1342. return "/contacts";
  1343. if (empty ( $this->staff [0] ['sid'] ))
  1344. return "/contacts";
  1345. if (! empty ( $clientname )) {
  1346. // 相同的公司和客户
  1347. Doo::loadModel ( 'company' );
  1348. $company = new company ();
  1349. Doo::loadModel ( 'client' );
  1350. $client = new client ();
  1351. $redis = new Redis ();
  1352. $redis->connect ( '127.0.0.1', '6379' );
  1353. $cinfo = $client->getClientByNameT ( $clientname );
  1354. if (! empty ( $cinfo )) {
  1355. $ninfo = $company->getCompanyByCompanyname ( $companyname );
  1356. if (! empty ( $ninfo )) {
  1357. foreach ( $cinfo as $key => $value ) { // 问题
  1358. if ($value ['companyid'] == $ninfo [0] ['cid'])
  1359. return "/contacts";
  1360. }
  1361. }
  1362. }
  1363. Doo::loadModel ( 'district' );
  1364. $district = new district ();
  1365. // 修改
  1366. Doo::loadClass ( 'XDeode' );
  1367. $XDeode = new XDeode ( 5 );
  1368. //$comId = $XDeode->decode ( $companyKey );
  1369. $companyInfo = $company->getOne ( array (
  1370. 'where' => "companyname like '" . $companyname . "'",
  1371. "asArray" => true
  1372. ) );
  1373. // 更新公司信息
  1374. $lv1 = $district->getbyid ( $local1 );
  1375. $lv2 = $district->getbyid ( $local2 );
  1376. $lv3 = $district->getbyid ( $local3 );
  1377. if (empty ( $lv1 ))
  1378. $lv1 [0] ['name'] = "";
  1379. if (empty ( $lv2 ))
  1380. $lv2 [0] ['name'] = "";
  1381. if (empty ( $lv3 ))
  1382. $lv3 [0] ['name'] = "";
  1383. if (! empty ( $local1 ) && ! empty ( $local2 ))
  1384. $company->local = $lv1 [0] ['name'] . "," . $lv2 [0] ['name'] . "," . $lv3 [0] ['name'];
  1385. if (! empty ( $nature ))
  1386. $company->nature = implode ( ',', $nature );
  1387. if (! empty ( $fax ))
  1388. $company->fax = $fax;
  1389. if (! empty ( $webservice ))
  1390. $company->webservice = $webservice;
  1391. if (! empty ( $address ))
  1392. $company->address = $address;
  1393. if (! empty ( $ride ))
  1394. $company->ride = $ride;
  1395. if (! empty ( $landmarks ))
  1396. $company->landmarks = $landmarks;
  1397. if (! empty ( $office ))
  1398. $company->office = $office;
  1399. if (! empty ( $local1 ) && ! empty ( $local2 ))
  1400. $company->district = $local1 . "," . $local2 . "," . $local3;
  1401. if (! empty ( $stay ))
  1402. $company->stay = $stay;
  1403. if (empty ( $companyInfo )) {
  1404. $company->companyname = $companyname;
  1405. $company->staffid = $this->staff [0] ['sid'];
  1406. $cid = $company->insert ();
  1407. } else { // 不编辑公司,地区判断,作为新公司
  1408. // $cid=$companyInfo['cid'];
  1409. //
  1410. // $companyname=$companyInfo['companyname'];
  1411. //
  1412. // $company->cid=$cid;
  1413. //
  1414. // $company->update();
  1415. $diqu = $local1 . "," . $local2 . "," . $local3;
  1416. $cid = $companyInfo ['cid'];
  1417. $company2 = new company ();
  1418. $companyList = $company2->find ( array (
  1419. 'where' => " companyname like '" . $companyname . "'",
  1420. "asArray" => true
  1421. ) );
  1422. $falg = false;
  1423. // print_r($companyList);
  1424. foreach ( $companyList as $key => $value ) {
  1425. if ($value ['district'] != $diqu) {
  1426. $falg = true;
  1427. } elseif ($value ['district'] == $diqu) {
  1428. $falg = false;
  1429. $cid = $value ['cid'];
  1430. break;
  1431. }
  1432. }
  1433. if ($falg) {
  1434. $company->companyname = $companyname;
  1435. $company->staffid = $this->staff [0] ['sid'];
  1436. $cid = $company->insert ();
  1437. }
  1438. }
  1439. Doo::loadModel ( 'client_staff' );
  1440. $client_staff = new client_staff ();
  1441. $client->clientname = $clientname;
  1442. $client->gender = $gender;
  1443. $client->priority = $priority;
  1444. if (! empty ( $nicename ))
  1445. $client->nicename = $nicename;
  1446. if (! empty ( $telephone ))
  1447. $client->telephone = $telephone;
  1448. if (! empty ( $phone ))
  1449. $client->phone = $phone;
  1450. if (! empty ( $email ))
  1451. $client->email = $email;
  1452. if (! empty ( $qq ) && is_numeric ( $qq ))
  1453. $client->qq = $qq;
  1454. $client->companyid = $cid;
  1455. $client->companyname = $companyname;
  1456. $client->district = $local1 . "," . $local2 . "," . $local3;
  1457. // echo $client->district;
  1458. // die;
  1459. if (! empty ( $tid ))
  1460. $client->tag = implode ( ',', $tid );
  1461. if (! empty ( $fax ))
  1462. $client->fax = $fax;
  1463. if (! empty ( $webservice ))
  1464. $client->webservice = $webservice;
  1465. if (! empty ( $department ))
  1466. $client->department = $department;
  1467. if (! empty ( $position ))
  1468. $client->position = $position;
  1469. if (! empty ( $office ))
  1470. $client->office = $office;
  1471. if (! empty ( $address ))
  1472. $client->address = $address;
  1473. if (! empty ( $ride ))
  1474. $client->ride = $ride;
  1475. if (! empty ( $landmarks ))
  1476. $client->landmarks = $landmarks;
  1477. if (! empty ( $stay ))
  1478. $client->stay = $stay;
  1479. if (! empty ( $mark ))
  1480. $client->mark = $mark;
  1481. $id = $client->insert ();
  1482. $client_staff->cid = $id;
  1483. $client_staff->sid = $this->staff [0] ['sid'];
  1484. $client_staff->insert ();
  1485. // 加入地区记录
  1486. Doo::loadModel ( "district_staff" );
  1487. $district_staff = new district_staff ();
  1488. $district_staff->did = $lv1 [0] ['id'];
  1489. $district_staff->sid = $this->staff [0] ['sid'];
  1490. $district_staff->insert ();
  1491. // 日常行为
  1492. Doo::loadModel ( "action_log" );
  1493. $action_log = new action_log ();
  1494. $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 . ')';
  1495. $action_log->sid = $this->staff [0] ['sid'];
  1496. $action_log->cid = $this->staff [0] ['cid'];
  1497. $action_log->updatetime = date ( "Y-m-d" );
  1498. $action_log->time = date ( "H:i" );
  1499. $action_log->status = 1;
  1500. $action_log->districtid = $local1 . "," . $local2 . "," . $local3;
  1501. $action_log->city = $lv1 [0] ['name'];
  1502. $action_log->province = $lv2 [0] ['name'];
  1503. if (isset ( $nature [0] ))
  1504. $action_log->nature = $nature [0];
  1505. $action_log->company = $companyname;
  1506. $action_log->class = $action_log->iconContacts;
  1507. $action_log->insert ();
  1508. // 事实更新信息中心记录数量 需要更新3个redis 内的值
  1509. $categoryCondition = " and cid=" . $this->staff [0] ['cid'];
  1510. $sidCondition = " and sid=" . $this->staff [0] ['sid'];
  1511. // actionlog免查询值 $alCondition='';
  1512. $alCondition = ' aid>' . REMIT . ' and ';
  1513. // 个人添加数量redis值
  1514. $redisKeyCS = date ( 'Y-m-d' ) . 'SC_' . $this->staff [0] ['cid'] . '_' . $this->staff [0] ['sid'];
  1515. $action_log = new action_log ();
  1516. $actionLogClient = $action_log->find ( array (
  1517. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  1518. 'where' => $alCondition . " status=1" . $sidCondition . $categoryCondition . ' and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
  1519. 'groupby' => 'date_format(updatetime,"%m-%d")',
  1520. 'asArray' => true
  1521. ) );
  1522. $statisticsClient = array ();
  1523. for($d = 0; $d <= 29; $d ++) {
  1524. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  1525. $falgClient = true;
  1526. foreach ( $actionLogClient as $value ) {
  1527. if ($value ['updatetime'] == $MD) {
  1528. array_push ( $statisticsClient, $value ['count'] );
  1529. $falgClient = false;
  1530. break;
  1531. }
  1532. }
  1533. if ($falgClient)
  1534. array_push ( $statisticsClient, 0 );
  1535. }
  1536. $statisticsClient = array_reverse ( $statisticsClient );
  1537. $jsc = json_encode ( $statisticsClient );
  1538. $redis->set ( $redisKeyCS, $jsc );
  1539. // 办事处添加数量reids值
  1540. $redisKeyC = date ( 'Y-m-d' ) . 'SC_' . $this->staff [0] ['cid'] . '_';
  1541. $action_log = new action_log ();
  1542. $actionLogClient = $action_log->find ( array (
  1543. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  1544. 'where' => $alCondition . " status=1" . $categoryCondition . ' and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
  1545. 'groupby' => 'date_format(updatetime,"%m-%d")',
  1546. 'asArray' => true
  1547. ) );
  1548. $statisticsClient = array ();
  1549. for($d = 0; $d <= 29; $d ++) {
  1550. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  1551. $falgClient = true;
  1552. foreach ( $actionLogClient as $value ) {
  1553. if ($value ['updatetime'] == $MD) {
  1554. array_push ( $statisticsClient, $value ['count'] );
  1555. $falgClient = false;
  1556. break;
  1557. }
  1558. }
  1559. if ($falgClient)
  1560. array_push ( $statisticsClient, 0 );
  1561. }
  1562. $statisticsClient = array_reverse ( $statisticsClient );
  1563. $jsc = json_encode ( $statisticsClient );
  1564. $redis->set ( $redisKeyC, $jsc );
  1565. // 全员添加数量的redis值
  1566. $redisKey = date ( 'Y-m-d' ) . 'SC__';
  1567. $action_log = new action_log ();
  1568. $actionLogClient = $action_log->find ( array (
  1569. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  1570. 'where' => $alCondition . ' status=1 and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
  1571. 'groupby' => 'date_format(updatetime,"%m-%d")',
  1572. 'asArray' => true
  1573. ) );
  1574. $statisticsClient = array ();
  1575. for($d = 0; $d <= 29; $d ++) {
  1576. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  1577. $falgClient = true;
  1578. foreach ( $actionLogClient as $value ) {
  1579. if ($value ['updatetime'] == $MD) {
  1580. array_push ( $statisticsClient, $value ['count'] );
  1581. $falgClient = false;
  1582. break;
  1583. }
  1584. }
  1585. if ($falgClient)
  1586. array_push ( $statisticsClient, 0 );
  1587. }
  1588. $statisticsClient = array_reverse ( $statisticsClient );
  1589. $jsc = json_encode ( $statisticsClient );
  1590. $redis->set ( $redisKey, $jsc );
  1591. }
  1592. return "/contacts";
  1593. }
  1594. function addClientByCompany() {
  1595. $companyKey = $this->get_args ( 'companyKey' ) ? $this->get_args ( 'companyKey' ) : "";
  1596. $clientname = $this->get_args ( 'clientname' ) ? $this->get_args ( 'clientname' ) : "";
  1597. $gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : "";
  1598. $nicename = $this->get_args ( 'nicename' ) ? $this->get_args ( 'nicename' ) : "";
  1599. $telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : "";
  1600. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1601. $email = $this->get_args ( 'email' ) ? $this->get_args ( 'email' ) : "";
  1602. $qq = $this->get_args ( 'qq' ) ? $this->get_args ( 'qq' ) : "";
  1603. $tid = $this->get_args ( 'tid' ) ? $this->get_args ( 'tid' ) : "";
  1604. //$companyname = $this->get_args ( 'companyname' ) ? $this->get_args ( 'companyname' ) : "";
  1605. $local1 = $this->get_args ( 'lv21' ) ? $this->get_args ( 'lv21' ) : "";
  1606. $local2 = $this->get_args ( 'lv22' ) ? $this->get_args ( 'lv22' ) : "";
  1607. $local3 = $this->get_args ( 'lv23' ) ? $this->get_args ( 'lv23' ) : "";
  1608. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  1609. $fax = $this->get_args ( 'fax' ) ? $this->get_args ( 'fax' ) : "";
  1610. $webservice = $this->get_args ( 'webservice' ) ? $this->get_args ( 'webservice' ) : "";
  1611. $department = $this->get_args ( 'department' ) ? $this->get_args ( 'department' ) : "";
  1612. $position = $this->get_args ( 'position' ) ? $this->get_args ( 'position' ) : "";
  1613. $office = $this->get_args ( 'office' ) ? $this->get_args ( 'office' ) : "";
  1614. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1615. $ride = $this->get_args ( 'ride' ) ? $this->get_args ( 'ride' ) : "";
  1616. $landmarks = $this->get_args ( 'landmarks' ) ? $this->get_args ( 'landmarks' ) : "";
  1617. $priority = $this->get_args ( 'priority' ) ? $this->get_args ( 'priority' ) : "";
  1618. $stay = $this->get_args ( 'stay' ) ? $this->get_args ( 'stay' ) : "";
  1619. $mark = $this->get_args ( 'mark' ) ? $this->get_args ( 'mark' ) : "";
  1620. $clientname = trim ( $clientname );
  1621. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  1622. if (empty ( $token )) {
  1623. die ( 'illegal request-token' );
  1624. } else {
  1625. session_start ();
  1626. if ($_SESSION ['token_' . $this->staff [0] ['sidKey']] != $token) {
  1627. header ( 'Content-Type:text/html;charset=utf-8' );
  1628. die ( '请勿重复填写客户资料' );
  1629. } else {
  1630. $_SESSION ['token_' . $this->staff [0] ['sidKey']] = '';
  1631. }
  1632. }
  1633. if (empty ( $this->staff [0] ['sid'] ))
  1634. return "/contacts";
  1635. if (! empty ( $clientname )) {
  1636. // 相同的公司和客户
  1637. Doo::loadModel ( 'company' );
  1638. $company = new company ();
  1639. Doo::loadModel ( 'client' );
  1640. $client = new client ();
  1641. $redis = new Redis ();
  1642. $redis->connect ( '127.0.0.1', '6379' );
  1643. $cinfo = $client->getClientByNameT ( $clientname );
  1644. Doo::loadModel ( 'district' );
  1645. $district = new district ();
  1646. // 修改
  1647. Doo::loadClass ( 'XDeode' );
  1648. $XDeode = new XDeode ( 5 );
  1649. $comId = $XDeode->decode ( $companyKey );
  1650. $companyInfo = $company->getOne ( array (
  1651. 'where' => "cid = '" . $comId . "'",
  1652. "asArray" => true
  1653. ) );
  1654. // 更新公司信息
  1655. $lv1 = $district->getbyid ( $local1 );
  1656. $lv2 = $district->getbyid ( $local2 );
  1657. $lv3 = $district->getbyid ( $local3 );
  1658. if (empty ( $lv1 ))
  1659. $lv1 [0] ['name'] = "";
  1660. if (empty ( $lv2 ))
  1661. $lv2 [0] ['name'] = "";
  1662. if (empty ( $lv3 ))
  1663. $lv3 [0] ['name'] = "";
  1664. // if (! empty ( $local1 ) && ! empty ( $local2 ))
  1665. // $company->local = $lv1 [0] ['name'] . "," . $lv2 [0] ['name'] . "," . $lv3 [0] ['name'];
  1666. // if (! empty ( $nature ))
  1667. // $company->nature = implode ( ',', $nature );
  1668. // if (! empty ( $fax ))
  1669. // $company->fax = $fax;
  1670. // if (! empty ( $webservice ))
  1671. // $company->webservice = $webservice;
  1672. // if (! empty ( $address ))
  1673. // $company->address = $address;
  1674. // if (! empty ( $ride ))
  1675. // $company->ride = $ride;
  1676. // if (! empty ( $landmarks ))
  1677. // $company->landmarks = $landmarks;
  1678. // if (! empty ( $office ))
  1679. // $company->office = $office;
  1680. // if (! empty ( $local1 ) && ! empty ( $local2 ))
  1681. // $company->district = $local1 . "," . $local2 . "," . $local3;
  1682. // if (! empty ( $stay ))
  1683. // $company->stay = $stay;
  1684. $cid = $companyInfo ['cid'];
  1685. if (empty ( $companyInfo )) {
  1686. } else { // 不编辑公司,地区判断,作为新公司
  1687. // $cid=$companyInfo['cid'];
  1688. //
  1689. // $companyname=$companyInfo['companyname'];
  1690. //
  1691. // $company->cid=$cid;
  1692. //
  1693. // $company->update();
  1694. // $diqu = $local1 . "," . $local2 . "," . $local3;
  1695. // $cid = $companyInfo ['cid'];
  1696. // $company2 = new company ();
  1697. // $companyList = $company2->find ( array (
  1698. // 'where' => " companyname like '" . $companyname . "'",
  1699. // "asArray" => true
  1700. // ) );
  1701. // $falg = false;
  1702. // // print_r($companyList);
  1703. // foreach ( $companyList as $key => $value ) {
  1704. // if ($value ['district'] != $diqu) {
  1705. // $falg = true;
  1706. // } elseif ($value ['district'] == $diqu) {
  1707. // $falg = false;
  1708. // $cid = $value ['cid'];
  1709. // break;
  1710. // }
  1711. // }
  1712. // if ($falg) {
  1713. // $company->companyname = $companyname;
  1714. // $company->staffid = $this->staff [0] ['sid'];
  1715. // $cid = $company->insert ();
  1716. // }
  1717. }
  1718. Doo::loadModel ( 'client_staff' );
  1719. $client_staff = new client_staff ();
  1720. $client->clientname = $clientname;
  1721. $client->gender = $gender;
  1722. $client->priority = $priority;
  1723. if (! empty ( $nicename ))
  1724. $client->nicename = $nicename;
  1725. if (! empty ( $telephone ))
  1726. $client->telephone = $telephone;
  1727. if (! empty ( $phone ))
  1728. $client->phone = $phone;
  1729. if (! empty ( $email ))
  1730. $client->email = $email;
  1731. if (! empty ( $qq ) && is_numeric ( $qq ))
  1732. $client->qq = $qq;
  1733. $client->companyid = $cid;
  1734. $client->companyname = $companyInfo['companyname'];
  1735. $client->district = $local1 . "," . $local2 . "," . $local3;
  1736. // echo $client->district;
  1737. // die;
  1738. if (! empty ( $tid ))
  1739. $client->tag = implode ( ',', $tid );
  1740. if (! empty ( $fax ))
  1741. $client->fax = $fax;
  1742. if (! empty ( $webservice ))
  1743. $client->webservice = $webservice;
  1744. if (! empty ( $department ))
  1745. $client->department = $department;
  1746. if (! empty ( $position ))
  1747. $client->position = $position;
  1748. if (! empty ( $office ))
  1749. $client->office = $office;
  1750. if (! empty ( $address ))
  1751. $client->address = $address;
  1752. if (! empty ( $ride ))
  1753. $client->ride = $ride;
  1754. if (! empty ( $landmarks ))
  1755. $client->landmarks = $landmarks;
  1756. if (! empty ( $stay ))
  1757. $client->stay = $stay;
  1758. if (! empty ( $mark ))
  1759. $client->mark = $mark;
  1760. $id = $client->insert ();
  1761. $client_staff->cid = $id;
  1762. $client_staff->sid = $this->staff [0] ['sid'];
  1763. $client_staff->insert ();
  1764. // 加入地区记录
  1765. Doo::loadModel ( "district_staff" );
  1766. $district_staff = new district_staff ();
  1767. $district_staff->did = $lv1 [0] ['id'];
  1768. $district_staff->sid = $this->staff [0] ['sid'];
  1769. $district_staff->insert ();
  1770. // 日常行为
  1771. Doo::loadModel ( "action_log" );
  1772. $action_log = new action_log ();
  1773. $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'] . ')';
  1774. $action_log->sid = $this->staff [0] ['sid'];
  1775. $action_log->cid = $this->staff [0] ['cid'];
  1776. $action_log->updatetime = date ( "Y-m-d" );
  1777. $action_log->time = date ( "H:i" );
  1778. $action_log->status = 1;
  1779. $action_log->districtid = $local1 . "," . $local2 . "," . $local3;
  1780. $action_log->city = $lv1 [0] ['name'];
  1781. $action_log->province = $lv2 [0] ['name'];
  1782. if (isset ( $nature [0] ))
  1783. $action_log->nature = $nature [0];
  1784. $action_log->company = $companyInfo['companyname'];
  1785. $action_log->class = $action_log->iconContacts;
  1786. $action_log->insert ();
  1787. // 事实更新信息中心记录数量 需要更新3个redis 内的值
  1788. $categoryCondition = " and cid=" . $this->staff [0] ['cid'];
  1789. $sidCondition = " and sid=" . $this->staff [0] ['sid'];
  1790. // actionlog免查询值 $alCondition='';
  1791. $alCondition = ' aid>' . REMIT . ' and ';
  1792. // 个人添加数量redis值
  1793. $redisKeyCS = date ( 'Y-m-d' ) . 'SC_' . $this->staff [0] ['cid'] . '_' . $this->staff [0] ['sid'];
  1794. $action_log = new action_log ();
  1795. $actionLogClient = $action_log->find ( array (
  1796. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  1797. 'where' => $alCondition . " status=1" . $sidCondition . $categoryCondition . ' and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
  1798. 'groupby' => 'date_format(updatetime,"%m-%d")',
  1799. 'asArray' => true
  1800. ) );
  1801. $statisticsClient = array ();
  1802. for($d = 0; $d <= 29; $d ++) {
  1803. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  1804. $falgClient = true;
  1805. foreach ( $actionLogClient as $value ) {
  1806. if ($value ['updatetime'] == $MD) {
  1807. array_push ( $statisticsClient, $value ['count'] );
  1808. $falgClient = false;
  1809. break;
  1810. }
  1811. }
  1812. if ($falgClient)
  1813. array_push ( $statisticsClient, 0 );
  1814. }
  1815. $statisticsClient = array_reverse ( $statisticsClient );
  1816. $jsc = json_encode ( $statisticsClient );
  1817. $redis->set ( $redisKeyCS, $jsc );
  1818. // 办事处添加数量reids值
  1819. $redisKeyC = date ( 'Y-m-d' ) . 'SC_' . $this->staff [0] ['cid'] . '_';
  1820. $action_log = new action_log ();
  1821. $actionLogClient = $action_log->find ( array (
  1822. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  1823. 'where' => $alCondition . " status=1" . $categoryCondition . ' and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
  1824. 'groupby' => 'date_format(updatetime,"%m-%d")',
  1825. 'asArray' => true
  1826. ) );
  1827. $statisticsClient = array ();
  1828. for($d = 0; $d <= 29; $d ++) {
  1829. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  1830. $falgClient = true;
  1831. foreach ( $actionLogClient as $value ) {
  1832. if ($value ['updatetime'] == $MD) {
  1833. array_push ( $statisticsClient, $value ['count'] );
  1834. $falgClient = false;
  1835. break;
  1836. }
  1837. }
  1838. if ($falgClient)
  1839. array_push ( $statisticsClient, 0 );
  1840. }
  1841. $statisticsClient = array_reverse ( $statisticsClient );
  1842. $jsc = json_encode ( $statisticsClient );
  1843. $redis->set ( $redisKeyC, $jsc );
  1844. // 全员添加数量的redis值
  1845. $redisKey = date ( 'Y-m-d' ) . 'SC__';
  1846. $action_log = new action_log ();
  1847. $actionLogClient = $action_log->find ( array (
  1848. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  1849. 'where' => $alCondition . ' status=1 and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime)',
  1850. 'groupby' => 'date_format(updatetime,"%m-%d")',
  1851. 'asArray' => true
  1852. ) );
  1853. $statisticsClient = array ();
  1854. for($d = 0; $d <= 29; $d ++) {
  1855. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  1856. $falgClient = true;
  1857. foreach ( $actionLogClient as $value ) {
  1858. if ($value ['updatetime'] == $MD) {
  1859. array_push ( $statisticsClient, $value ['count'] );
  1860. $falgClient = false;
  1861. break;
  1862. }
  1863. }
  1864. if ($falgClient)
  1865. array_push ( $statisticsClient, 0 );
  1866. }
  1867. $statisticsClient = array_reverse ( $statisticsClient );
  1868. $jsc = json_encode ( $statisticsClient );
  1869. $redis->set ( $redisKey, $jsc );
  1870. }
  1871. return "/contacts";
  1872. }
  1873. function mycompany() {
  1874. $search = $this->get_args ( 'search' ) ? $this->get_args ( 'search' ) : "";
  1875. $districtLv = $this->get_args ( 'districtLv' ) ? $this->get_args ( 'districtLv' ) : 0;
  1876. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  1877. $lv1 = $this->get_args ( 'lv1' ) ? $this->get_args ( 'lv1' ) : 0;
  1878. $lv2 = $this->get_args ( 'lv2' ) ? $this->get_args ( 'lv2' ) : 0;
  1879. $lv3 = $this->get_args ( 'lv3' ) ? $this->get_args ( 'lv3' ) : 0;
  1880. $tagList = $this->get_args ( 'tag' ) ? $this->get_args ( 'tag' ) : array ();
  1881. if ($lv1 == 0) {
  1882. $lv1 = isset ( $this->params ['lv1'] ) && is_numeric ( $this->params ['lv1'] ) ? $this->params ['lv1'] : 0;
  1883. if ($lv1 != 0)
  1884. $districtLv = 1;
  1885. }
  1886. if ($lv2 == 0) {
  1887. $lv2 = isset ( $this->params ['lv2'] ) && is_numeric ( $this->params ['lv2'] ) ? $this->params ['lv2'] : 0;
  1888. if ($lv2 != 0)
  1889. $districtLv = 2;
  1890. }
  1891. if ($lv3 == 0) {
  1892. $lv3 = isset ( $this->params ['lv3'] ) && is_numeric ( $this->params ['lv3'] ) ? $this->params ['lv3'] : 0;
  1893. if ($lv2 != 0)
  1894. $districtLv = 3;
  1895. }
  1896. if (empty ( $search ))
  1897. $search = urldecode ( isset ( $this->params ['search'] ) ? $this->params ['search'] : "" );
  1898. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1899. $data['search']=$search;
  1900. $data ['memu'] = "contacts";
  1901. $data ['staff'] = $this->staff;
  1902. //Doo::loadModel ( 'tag' );
  1903. //$tag = new tag ();
  1904. Doo::loadModel ( 'district' );
  1905. Doo::loadModel ( 'company' );
  1906. Doo::loadModel ( 'client' );
  1907. Doo::loadModel ( 'L_category' );
  1908. $lcategory = new L_category ();
  1909. $client = new client ();
  1910. $company = new company ();
  1911. $district = new district ();
  1912. Doo::loadModel ( 'tagCompany' );
  1913. $tagCompany = new tagCompany ();
  1914. Doo::loadModel ( 'tagCompanyNexus' );
  1915. $tagCompanyNexus = new tagCompanyNexus ();
  1916. $data ['district2'] = $district->get_lv ( 1 );
  1917. //$category = $lcategory->getCategoryById ( $this->staff [0] ['cid'], $this->staff [0] ['othercid'] );
  1918. $cateStr = " cid =0 ";
  1919. Doo::loadClass ( 'XDeode' );
  1920. $XDeode = new XDeode ( 5 );
  1921. $didList = explode ( ',', $this->staff [0] ['did'] );
  1922. $didList = array_filter ( $didList );
  1923. $didListContont = array ();
  1924. if (! empty ( $didList )) {
  1925. foreach ( $didList as $key => $value ) {
  1926. array_push ( $didListContont, $XDeode->decode ( $value ) );
  1927. }
  1928. $data ['district'] = $district->getDistrictInId ( implode ( ',', $didListContont ) ); // $district->get_lvByStaffid ( 1, $this->staff [0] ['sid'] );
  1929. } else {
  1930. $data ['district'] = array ();
  1931. }
  1932. $sqstr = '';
  1933. if (! empty ( $didListContont )) {
  1934. foreach ( $didListContont as $key => $value ) {
  1935. if ($key != 0) {
  1936. $sqstr .= " or district like '" . $value . ",%'";
  1937. }
  1938. }
  1939. $cateStr = " ( district like '" . $didListContont [0] . ",%'" . $sqstr . ')';
  1940. }
  1941. // $list = array ();
  1942. // foreach ( $category as $key => $value ) {
  1943. // array_push ( $list, " district like '" . $value ['districtid'] . ",%' " );
  1944. // }
  1945. // if ($this->staff [0] ['isadmin'] != 1)
  1946. // $cateStr = implode ( " or ", $list );
  1947. // else
  1948. // $cateStr = " 1";
  1949. //
  1950. // if (! empty ( $nature ))
  1951. // $cateStr = " 1";
  1952. $size = 300;
  1953. $data ['htmllv2'] = array ();
  1954. $data ['htmllv3'] = array ();
  1955. $condition = "";
  1956. if ($districtLv == 1) {
  1957. $condition = "";
  1958. if (! empty ( $lv1 )) {
  1959. $condition = " district like '" . $lv1 . ",%'";
  1960. $data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
  1961. }
  1962. }
  1963. if ($districtLv == 2) {
  1964. if (! empty ( $lv2 ))
  1965. $condition = " district like '" . $lv1 . "," . $lv2 . ",%'";
  1966. else
  1967. $condition = " district like '" . $lv1 . ",%'";
  1968. $data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
  1969. $data ['htmllv3'] = $district->get_lvByid ( 2, $lv2 );
  1970. }
  1971. if ($districtLv == 3) {
  1972. if (! empty ( $lv3 ))
  1973. $condition = " district like '" . $lv1 . "," . $lv2 . "," . $lv3 . "'";
  1974. else
  1975. $condition = " district like '" . $lv1 . "," . $lv2 . ",%'";
  1976. $data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
  1977. $data ['htmllv3'] = $district->get_lvByid ( 2, $lv2 );
  1978. }
  1979. $districtCount = $condition;
  1980. if (! empty ( $condition ))
  1981. $cateStr = $condition;
  1982. if (!empty($search)){
  1983. $cateStr.=" and companyname like '%".$search."%' ";
  1984. }
  1985. if (! empty ( $nature ))
  1986. $cateStr .= " and nature like '%" . $nature . "%'";
  1987. // echo "<div style='display:none'>".$cateStr."</div><br/>";
  1988. $tagSQL = false;
  1989. if (! empty ( $tagList )) {
  1990. $tagSQL = true;
  1991. foreach ( $tagList as $value ) {
  1992. $cateStr .= " and a.tag like '%" . $value . "%' ";
  1993. }
  1994. }
  1995. if ($this->staff [0] ['isadmin'] != 1) {
  1996. $pageinfo = $this->get_Tpage ( "CLD_company", $cateStr, $page, $size, "", $tagSQL );
  1997. } else {
  1998. if ($tagSQL)
  1999. $pageinfo = $this->get_Tpage ( "CLD_company", $cateStr, $page, $size, "", $tagSQL );
  2000. else {
  2001. $total_page = $company->count ( array () );
  2002. $total = intval ( $total_page / $size );
  2003. $pageinfo ['total_page'] = ($total_page % $size) == 0 ? $total : $total + 1;
  2004. }
  2005. }
  2006. $k = "";
  2007. for($i = 1; $i <= $pageinfo ['total_page']; $i ++) {
  2008. if ($page == $i)
  2009. $k .= "<option value='" . $search . ":" . $i . ":" . $lv1 . ":" . $lv2 . ":" . $lv3 . "' selected>第" . $i . "页</option>";
  2010. else
  2011. $k .= "<option value='" . $search . ":" . $i . ":" . $lv1 . ":" . $lv2 . ":" . $lv3 . "'>第" . $i . "页</option>";
  2012. }
  2013. $data ['pageinfo'] = $k;
  2014. $data ['company'] = $company->getCompanyByDistrict ( $this->staff [0] ['sid'], $cateStr, $this->staff [0] ['isadmin'], $page, $size, $tagSQL );
  2015. // if ($this->staff [0] ['isadmin'] != 1) {
  2016. // $data ['district'] = $district->get_lvByStaffid ( 1, $this->staff [0] ['sid'] );
  2017. // } else {
  2018. // $data ['district'] = $data ['district2'];
  2019. // }
  2020. // 获得标签
  2021. $ClientTagList = $tagCompanyNexus->getTagClientBySid ( $this->staff [0] ['sid'] );
  2022. foreach ( $ClientTagList as $key => $value ) {
  2023. $ClientTagList [$key] ['taginfo'] = $tagCompany->getTagByTidL ( $value ['tag'] );
  2024. }
  2025. foreach ( $data ['company'] as $key => $value ) {
  2026. if (! empty ( $value ['cid'] )) {
  2027. $data ['company'] [$key] ['taginfo'] = array ();
  2028. $data ['company'] [$key] ['tag'] = "";
  2029. foreach ( $ClientTagList as $k => $v ) {
  2030. if ($value ['cid'] == $v ['company']) {
  2031. $data ['company'] [$key] ['taginfo'] = $v ['taginfo'];
  2032. $data ['company'] [$key] ['tag'] = $v ['tag'];
  2033. }
  2034. }
  2035. }
  2036. }
  2037. $comcid = $countL = array ();
  2038. foreach ( $data ['company'] as $key => $value ) {
  2039. array_push ( $comcid, $value ['cid'] );
  2040. }
  2041. $comcid = implode ( ",", $comcid );
  2042. if (! empty ( $comcid ))
  2043. $countL = $client->getCountByCompany ( $comcid );
  2044. foreach ( $data ['company'] as $key => $value ) {
  2045. $data ['company'] [$key] ['count'] = 0;
  2046. foreach ( $countL as $k => $v ) {
  2047. if ($value ['cid'] == $v ['companyid']) {
  2048. $data ['company'] [$key] ['count'] = $v ['count'];
  2049. break;
  2050. }
  2051. }
  2052. }
  2053. $CC1 = "";
  2054. $CC2 = "";
  2055. $CC3 = "";
  2056. $natureHtml = '';
  2057. if (! empty ( $districtCount )) {
  2058. $clientCount = $company->find ( array (
  2059. 'select' => 'district',
  2060. 'where' => "district like '" . $lv1 . ",%'",
  2061. 'asArray' => TRUE
  2062. ) );
  2063. $CC1 = count ( $clientCount );
  2064. if (! empty ( $clientCount ) && ! empty ( $lv2 )) {
  2065. $CC2 = 0;
  2066. foreach ( $clientCount as $key => $value ) {
  2067. if (strpos ( $value ['district'], $lv2 )) {
  2068. $CC2 ++;
  2069. }
  2070. }
  2071. }
  2072. if (! empty ( $clientCount ) && ! empty ( $lv3 )) {
  2073. $CC3 = 0;
  2074. foreach ( $clientCount as $key => $value ) {
  2075. if (strpos ( $value ['district'], $lv3 )) {
  2076. $CC3 ++;
  2077. }
  2078. }
  2079. }
  2080. $clientCount = $company->find ( array (
  2081. 'select' => 'district,nature',
  2082. 'where' => $districtCount,
  2083. 'asArray' => TRUE
  2084. ) );
  2085. $natureCount = array ();
  2086. foreach ( $this->nature as $value ) {
  2087. $natureCount [$value] = 0;
  2088. foreach ( $clientCount as $v ) {
  2089. $ak = explode ( ",", $v ['nature'] );
  2090. foreach ( $ak as $a ) {
  2091. if ($value == $a) {
  2092. $natureCount [$value] ++;
  2093. }
  2094. }
  2095. }
  2096. }
  2097. }
  2098. $natureHtml = '';
  2099. foreach ( $this->nature as $value ) {
  2100. $natureHtml .= '<a href="javascript:void(0)" ';
  2101. if ($value == $nature)
  2102. $natureHtml .= 'class="now"';
  2103. if (isset ( $natureCount [$value] ))
  2104. $natureHtml .= 'onclick="showNature(\'' . $value . '\',this)">' . $value . '(' . $natureCount [$value] . ')</a>';
  2105. else
  2106. $natureHtml .= 'onclick="showNature(\'' . $value . '\',this)">' . $value . '</a>';
  2107. }
  2108. $taglist = $tagCompany->find ( array (
  2109. 'where' => 'sid=' . $this->staff [0] ['sid'],
  2110. 'asArray' => TRUE
  2111. ) );
  2112. if (empty ( $taglist )) {
  2113. for($i = 1; $i <= 7; $i ++) {
  2114. $tag = new tagCompany ();
  2115. $tag->name = "个人标签";
  2116. $tag->sid = $this->staff [0] ['sid'];
  2117. $tag->colorid = $i;
  2118. $tag->insert ();
  2119. }
  2120. }
  2121. $data ['product'] = array ();
  2122. $data ['tagList'] = $tagList;
  2123. $data ['tag'] = $tagCompany->getAllBySid ( $this->staff [0] ['sid'] );
  2124. $data ['natureHtml'] = $natureHtml;
  2125. $data ['CC1'] = $CC1;
  2126. $data ['CC2'] = $CC2;
  2127. $data ['CC3'] = $CC3;
  2128. $data ['lv1'] = $lv1;
  2129. $data ['lv2'] = $lv2;
  2130. $data ['lv3'] = $lv3;
  2131. $data ['districtLv'] = $districtLv;
  2132. $data ['Hnature'] = $nature;
  2133. $data ['nature'] = $this->nature;
  2134. $this->render ( "/contacts_company", $data );
  2135. }
  2136. function contacts() {
  2137. session_start ();
  2138. $data ['memu'] = "contacts";
  2139. $data ['staff'] = $this->staff;
  2140. $search = $this->get_args ( 'search' ) ? trim ( $this->get_args ( 'search' ) ) : "";
  2141. if (empty ( $search ))
  2142. $search = urldecode ( isset ( $this->params ['search'] ) ? $this->params ['search'] : "" );
  2143. $lv1 = $this->get_args ( 'lv1' ) ? $this->get_args ( 'lv1' ) : 0;
  2144. $lv2 = $this->get_args ( 'lv2' ) ? $this->get_args ( 'lv2' ) : 0;
  2145. $lv3 = $this->get_args ( 'lv3' ) ? $this->get_args ( 'lv3' ) : 0;
  2146. $lv4 = $this->get_args ( 'lv4' ) ? $this->get_args ( 'lv4' ) : "";
  2147. $tagList = $this->get_args ( 'tag' ) ? $this->get_args ( 'tag' ) : array ();
  2148. $tooltip = $this->get_args ( 'tooltip' ) ? $this->get_args ( 'tooltip' ) : "";
  2149. $districtLv = $this->get_args ( 'districtLv' ) ? $this->get_args ( 'districtLv' ) : 0;
  2150. if ($lv1 == 0) {
  2151. $lv1 = isset ( $this->params ['lv1'] ) && is_numeric ( $this->params ['lv1'] ) ? $this->params ['lv1'] : 0;
  2152. if ($lv1 != 0)
  2153. $districtLv = 1;
  2154. }
  2155. if ($lv2 == 0) {
  2156. $lv2 = isset ( $this->params ['lv2'] ) && is_numeric ( $this->params ['lv2'] ) ? $this->params ['lv2'] : 0;
  2157. if ($lv2 != 0)
  2158. $districtLv = 2;
  2159. }
  2160. if ($lv3 == 0) {
  2161. $lv3 = isset ( $this->params ['lv3'] ) && is_numeric ( $this->params ['lv3'] ) ? $this->params ['lv3'] : 0;
  2162. if ($lv2 != 0)
  2163. $districtLv = 3;
  2164. }
  2165. $sortV = $this->get_args ( 'sortV' ) ? $this->get_args ( 'sortV' ) : "h";
  2166. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2167. Doo::loadModel ( 'client_staff' );
  2168. Doo::loadModel ( 'client' );
  2169. Doo::loadModel ( 'tag' );
  2170. Doo::loadModel ( 'district' );
  2171. Doo::loadModel ( 'tag_client' );
  2172. Doo::loadModel ( 'L_category' );
  2173. Doo::loadModel ( 'longle' );
  2174. Doo::loadModel ( 'C_tooltip' );
  2175. $c_tooltip = new C_tooltip ();
  2176. $longle = new longle ();
  2177. $client = new client ();
  2178. $category = new L_category ();
  2179. $tagClient = new tag_client ();
  2180. $district = new district ();
  2181. $tag = new tag ();
  2182. $client_staff = new client_staff ();
  2183. $data ['tag'] = $tag->getAllBySid ( $this->staff [0] ['sid'] );
  2184. $data ['district2'] = $district->get_lv ( 1 );
  2185. $page_size = 200;
  2186. $linfo = $category->getCategoryById ( $this->staff [0] ['cid'], $this->staff ['0'] ['othercid'] );
  2187. $staffid = $condition = $a = "";
  2188. // if ($this->staff [0] ['isadmin'] != 1) {
  2189. // 加入办事处地区
  2190. Doo::loadClass ( 'XDeode' );
  2191. $XDeode = new XDeode ( 5 );
  2192. $didList = explode ( ',', $this->staff [0] ['did'] );
  2193. $didList = array_filter ( $didList );
  2194. $didListContont = array ();
  2195. if (! empty ( $didList )) {
  2196. foreach ( $didList as $key => $value ) {
  2197. array_push ( $didListContont, $XDeode->decode ( $value ) );
  2198. }
  2199. $data ['district'] = $district->getDistrictInId ( implode ( ',', $didListContont ) ); // $district->get_lvByStaffid ( 1, $this->staff [0] ['sid'] );
  2200. } else {
  2201. $data ['district'] = array ();
  2202. }
  2203. if (! empty ( $search ))
  2204. $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 . "%')";
  2205. else {
  2206. $a = '';
  2207. $sqstr = '';
  2208. if (! empty ( $didListContont )) {
  2209. $a = '';
  2210. foreach ( $didListContont as $key => $value ) {
  2211. if ($key != 0) {
  2212. $sqstr .= " or b.district like '" . $value . ",%'";
  2213. }
  2214. }
  2215. $a = "and ( b.district like '" . $didListContont [0] . ",%'" . $sqstr . ')';
  2216. }
  2217. if (! empty ( $tooltip ))
  2218. $sch = "";
  2219. $staffid = $data ['staff'] [0] ['sid'];
  2220. }
  2221. $data ['htmllv2'] = $data ['htmllv3'] = array ();
  2222. if ($districtLv == 1) {
  2223. $a = "";
  2224. $condition = "";
  2225. if (! empty ( $lv1 )) {
  2226. $condition .= " and district like '" . $lv1 . ",%'";
  2227. $data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
  2228. }
  2229. }
  2230. if ($districtLv == 2) {
  2231. $a = "";
  2232. if (! empty ( $lv2 ))
  2233. $condition .= " and district like '" . $lv1 . "," . $lv2 . ",%'";
  2234. else
  2235. $condition .= " and district like '" . $lv1 . ",%'";
  2236. $data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
  2237. $data ['htmllv3'] = $district->get_lvByid ( 2, $lv2 );
  2238. }
  2239. if ($districtLv == 3) {
  2240. $a = "";
  2241. if (! empty ( $lv3 ))
  2242. $condition .= " and district like '" . $lv1 . "," . $lv2 . "," . $lv3 . "'";
  2243. else
  2244. $condition .= " and district like '" . $lv1 . "," . $lv2 . ",%'";
  2245. $data ['htmllv2'] = $district->get_lvByid ( 2, $lv1 );
  2246. $data ['htmllv3'] = $district->get_lvByid ( 2, $lv2 );
  2247. }
  2248. $condition .= $a;
  2249. $districtCount = $condition;
  2250. if (! empty ( $lv4 )) {
  2251. $condition .= " and nature like '%" . $lv4 . "%'";
  2252. }
  2253. $tagSQL = false;
  2254. if (! empty ( $tagList )) {
  2255. $tagSQL = true;
  2256. foreach ( $tagList as $value ) {
  2257. $condition .= " and c.tag like '%" . $value . "%' ";
  2258. }
  2259. $search = "";
  2260. }
  2261. if (! empty ( $search ))
  2262. $condition .= $sch;
  2263. // if(!empty($tooltip))
  2264. // $condition.=" and tooltip like '%".$tooltip."%'";
  2265. $pageinfo = array (
  2266. 'lower' => 0,
  2267. 'total_page' => 0,
  2268. 'total_data' => 0
  2269. );
  2270. if (! empty ( $didListContont ) || ! empty ( $search ))
  2271. $pageinfo = $this->get_page ( "CLD_client_staff", $condition, $page, $page_size, "", "", "", $staffid, $search, $tooltip, $this->staff [0] ['cid'], $tagSQL );
  2272. if ($sortV == "h") { // order by a.cid desc
  2273. $limit = " order by cid desc limit " . $pageinfo ['lower'] . " , " . $page_size . " ";
  2274. }
  2275. if ($sortV == "g") { // order by updatetime desc
  2276. $limit = " limit " . $pageinfo ['lower'] . " , " . $page_size . " ";
  2277. }
  2278. if ($sortV == "f") { // order by updatetime desc
  2279. $limit = " limit " . $pageinfo ['lower'] . " , " . $page_size . " ";
  2280. }
  2281. if ($sortV == "i") { // order by servicetime desc
  2282. $limit = " limit " . $pageinfo ['lower'] . " , " . $page_size . " ";
  2283. }
  2284. // 检索是全局
  2285. // echo $condition;
  2286. $data ['clientInfo'] = array ();
  2287. if (! empty ( $didListContont ) || ! empty ( $search ))
  2288. $data ['clientInfo'] = $client_staff->getClientByStaff ( $condition, $limit, $staffid, $this->staff [0] ['sid'], $search, $tooltip, $this->staff [0] ['cid'], $tagSQL );
  2289. // 获取其他办事处的客户
  2290. // if(!empty($districtstr)){
  2291. // $buclient=$client->getClientByDistrict($districtstr);
  2292. //
  2293. // foreach ($buclient as $key=>$vlaue){
  2294. //
  2295. // $falg=true;
  2296. //
  2297. // foreach ($data['clientInfo'] as $y=>$v){
  2298. // if($vlaue['clientname']==$v['clientname']&&$vlaue['companyname']==$v['companyname'])
  2299. // $falg=false;
  2300. // }
  2301. // if($falg)
  2302. // array_push($data['clientInfo'], $vlaue);
  2303. // }
  2304. //
  2305. // }
  2306. $k = "";
  2307. for($i = 1; $i <= $pageinfo ['total_page']; $i ++) {
  2308. if ($page == $i)
  2309. $k .= "<option value='" . $search . ":" . $i . ":" . $lv1 . ":" . $lv2 . ":" . $lv3 . "' selected>第" . $i . "页</option>";
  2310. else
  2311. $k .= "<option value='" . $search . ":" . $i . ":" . $lv1 . ":" . $lv2 . ":" . $lv3 . "'>第" . $i . "页</option>";
  2312. }
  2313. $data ['pageinfo'] = $k;
  2314. Doo::loadModel ( 'product' );
  2315. $product = new product ();
  2316. $data ['nature'] = $this->nature;
  2317. $data ['product'] = $product->getProudct ();
  2318. // 获得标签
  2319. $ClientTagList = $tagClient->getTagClientBySid ( $this->staff [0] ['sid'] );
  2320. $toollist = $c_tooltip->find ( array (
  2321. 'where' => 'cateid=' . $this->staff [0] ['cid'],
  2322. 'asArray' => true
  2323. ) );
  2324. // $ToolTipList=$
  2325. foreach ( $ClientTagList as $key => $value ) {
  2326. $ClientTagList [$key] ['taginfo'] = $tag->getTagByTidL ( $value ['tag'] );
  2327. }
  2328. foreach ( $data ['clientInfo'] as $key => $value ) {
  2329. if (! empty ( $value ['cid'] )) {
  2330. // $tinfo=$tagClient->getTagClientBySCid($value['cid'], $this->staff[0]['sid']);
  2331. $data ['clientInfo'] [$key] ['taginfo'] = array ();
  2332. $data ['clientInfo'] [$key] ['tag'] = "";
  2333. foreach ( $ClientTagList as $k => $v ) {
  2334. // $tag->getTagByTidL($value['tag']);$value['tag'];
  2335. if ($value ['cid'] == $v ['client']) {
  2336. $data ['clientInfo'] [$key] ['taginfo'] = $v ['taginfo'];
  2337. $data ['clientInfo'] [$key] ['tag'] = $v ['tag'];
  2338. }
  2339. }
  2340. // array_pop 可以优化数组
  2341. }
  2342. $data ['clientInfo'] [$key] ['tooltipList'] = array ();
  2343. foreach ( $toollist as $k => $v ) {
  2344. if ($v ['cid'] == $value ['cid']) {
  2345. $data ['clientInfo'] [$key] ['tooltipList'] = explode ( ",", $v ['name'] );
  2346. break;
  2347. } // array_pop 可以优化数组
  2348. }
  2349. // $tl=array();
  2350. // if(!empty($value['tooltip']))
  2351. // $tl=explode(',', $value['tooltip']);
  2352. // $data['clientInfo'][$key]['tooltipList']=$tl;
  2353. $data ['clientInfo'] [$key] ['locount'] = 0; // $longle->count(array('where'=>'clientid='.$value['cid']));
  2354. }
  2355. $CC1 = "";
  2356. $CC2 = "";
  2357. $CC3 = "";
  2358. if (! empty ( $districtCount )) {
  2359. $clientCount = $client->find ( array (
  2360. 'select' => 'district',
  2361. 'where' => "district like '" . $lv1 . ",%'",
  2362. 'asArray' => TRUE
  2363. ) );
  2364. $CC1 = count ( $clientCount );
  2365. if (! empty ( $clientCount ) && ! empty ( $lv2 )) {
  2366. $CC2 = 0;
  2367. foreach ( $clientCount as $key => $value ) {
  2368. if (strpos ( $value ['district'], ','.$lv2.',' )) {
  2369. //echo $value ['district'].'<br/>';
  2370. $CC2 ++;
  2371. }
  2372. }
  2373. }
  2374. if (! empty ( $clientCount ) && ! empty ( $lv3 )) {
  2375. $CC3 = 0;
  2376. foreach ( $clientCount as $key => $value ) {
  2377. if (strpos ( $value ['district'], ','.$lv3 )) {
  2378. $CC3 ++;
  2379. }
  2380. }
  2381. }
  2382. }
  2383. Doo::loadModel ( 'remind' );
  2384. $remind = new remind ();
  2385. // and date_add(time, INTERVAL day DAY) <= CURDATE()
  2386. $remindList = $remind->find ( array (
  2387. 'where' => "staffID = '" . $this->staff [0] ['sid'] . "' and status=0 ",
  2388. 'asc' => 'date_add(time, INTERVAL day DAY)',
  2389. 'asArray' => TRUE
  2390. ) );
  2391. $rc = 0;
  2392. foreach ( $remindList as $key => $value ) {
  2393. $a = strtotime ( $value ['time'] . " +" . $value ['day'] . " days" );
  2394. $b = strtotime ( date ( 'y-m-d' ) );
  2395. if ($a <= $b) {
  2396. $rc ++;
  2397. $remindList [$key] ['isRemind'] = 1;
  2398. } else
  2399. $remindList [$key] ['isRemind'] = 0;
  2400. $remindList [$key] ['Ctime'] = date ( 'm-d', strtotime ( $value ['time'] ) );
  2401. $remindList [$key] ['Etime'] = date ( 'm-d', strtotime ( $value ['time'] . " +" . $value ['day'] . " days" ) );
  2402. }
  2403. $token = $this->set_token ();
  2404. $tokenTime=time().rand(5, 15);
  2405. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  2406. $data['tokenTime']=$tokenTime;
  2407. $data ['token'] = $token;
  2408. $data ['remindCount'] = $rc;
  2409. $data ['remindList'] = $remindList;
  2410. $data ['CC1'] = $CC1;
  2411. $data ['CC2'] = $CC2;
  2412. $data ['CC3'] = $CC3;
  2413. $data ['lv1'] = $lv1;
  2414. $data ['lv2'] = $lv2;
  2415. $data ['lv3'] = $lv3;
  2416. $data ['lv4'] = $lv4;
  2417. $data ['districtLv'] = $districtLv;
  2418. $data ['tagList'] = $tagList;
  2419. $data ['tooltip'] = $this->tooltip;
  2420. $data ['ttip'] = $tooltip;
  2421. $data ['search'] = $search;
  2422. $data ['totalData'] = $pageinfo ['total_data'];
  2423. // $data['messagehtml']=$html;
  2424. $this->render ( "/contacts_client", $data );
  2425. }
  2426. function remindCL() {
  2427. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2428. Doo::loadModel ( 'remind' );
  2429. $remind = new remind ();
  2430. $remind->status = 1;
  2431. $remind->update ( array (
  2432. 'where' => "staffID = '" . $this->staff [0] ['sid'] . "' and rid=" . $rid,
  2433. 'asArray' => TRUE
  2434. ) );
  2435. return "/contacts";
  2436. }
  2437. function communication() {
  2438. $data ['memu'] = "contacts";
  2439. $data ['staff'] = $this->staff;
  2440. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2441. Doo::loadModel ( 'L_category' );
  2442. $L_category = new L_category ();
  2443. Doo::loadModel ( 'staff' );
  2444. $staff = new staff ();
  2445. Doo::loadModel ( 'staffDynamic' );
  2446. $staffDynamic = new staffDynamic ();
  2447. if (! empty ( $cid ))
  2448. $data ['staffList'] = $staff->getStaffByCid ( $cid );
  2449. else
  2450. $data ['staffList'] = $staff->getStaff ( true );
  2451. foreach ( $data ['staffList'] as $key => $value ) {
  2452. if (! empty ( $value ['birthday'] )) {
  2453. $dataD = date ( "d", strtotime ( $value ['birthday'] ) );
  2454. if (date ( 'm' ) == date ( "m", strtotime ( $value ['birthday'] ) )) {
  2455. $now = date ( 'd' );
  2456. $post = $dataD - 7; // date("d",mktime(0,0,0,date("m"),date("d")+7,date("Y")));
  2457. if ($now >= $post && $now <= $dataD) {
  2458. $data ['staffList'] [$key] ['birthday'] = "birthday";
  2459. $data ['staffList'] [$key] ['birthDAY'] = date ( "m-d", strtotime ( $value ['birthday'] ) );
  2460. }
  2461. }
  2462. }
  2463. $happy = date ( "m-d", strtotime ( $value ['birthday'] ) );
  2464. if ($happy == date ( 'm-d' )) {
  2465. $SBL = $staffDynamic->getStaffBirthday ( $happy, $value ['sid'] );
  2466. if (empty ( $SBL )) {
  2467. $staffDynamic->content = '<img src="/global/img/cake.gif"><span class="colOrange">今天过生日!</span>';
  2468. $staffDynamic->cid = $value ['cid'];
  2469. $staffDynamic->category = $value ['category'];
  2470. $staffDynamic->time = time ();
  2471. $staffDynamic->sid = $value ['sid'];
  2472. $staffDynamic->staff = $value ['username'];
  2473. $staffDynamic->insert ();
  2474. }
  2475. }
  2476. }
  2477. $sDynaimic = $staffDynamic->getStaffDynamic ();
  2478. foreach ( $sDynaimic as $key => $value ) {
  2479. $time = date ( "Y-m-d", $value ['time'] );
  2480. $timeArray = explode ( '-', $time );
  2481. $sDynaimic [$key] ['year'] = $timeArray [0];
  2482. $sDynaimic [$key] ['month'] = $timeArray [1];
  2483. $sDynaimic [$key] ['day'] = $timeArray [2];
  2484. }
  2485. $data ['sDynaimic'] = $sDynaimic;
  2486. $data ['category'] = $L_category->getCategory ();
  2487. $data ['cid'] = $cid;
  2488. $this->render ( "/staff_contacts", $data );
  2489. }
  2490. function app() {
  2491. $data ['memu'] = "app";
  2492. $data ['staff'] = $this->staff;
  2493. $this->render ( "/app", $data );
  2494. }
  2495. function synClient() {
  2496. if ($this->staff [0] ['isadmin'] != 1) {
  2497. Doo::loadModel ( 'L_category' );
  2498. Doo::loadModel ( 'client_staff' );
  2499. $client_staff = new client_staff ();
  2500. $cate = new L_category ();
  2501. $district = $cate->getOne ( array (
  2502. 'where' => 'cid=' . $this->staff [0] ['cid'],
  2503. 'asArray' => true
  2504. ) );
  2505. $syn = $client_staff->synClient ( $this->staff [0] ['sid'], $district ['districtid'] );
  2506. $bei = $client_staff->find ( array (
  2507. 'where' => "sid = " . $this->staff [0] ['sid'],
  2508. 'asArray' => true
  2509. ) );
  2510. foreach ( $syn as $value ) {
  2511. $falg = true;
  2512. foreach ( $bei as $v ) {
  2513. if (($v ['cid'] == $value ['cid']) && ($v ['sid'] == $this->staff [0] ['sid'])) {
  2514. $falg = false;
  2515. break;
  2516. }
  2517. }
  2518. if ($falg) {
  2519. $client_staff = new client_staff ();
  2520. $client_staff->sid = $this->staff [0] ['sid'];
  2521. $client_staff->cid = $value ['cid'];
  2522. $client_staff->insert ();
  2523. }
  2524. }
  2525. }
  2526. return "/contacts";
  2527. }
  2528. function DoAddTagCompany() {
  2529. $cid = $this->get_args ( 'id' );
  2530. $tid = $this->get_args ( 'tagALD' );
  2531. Doo::loadModel ( 'tagCompanyNexus' );
  2532. $strtid = implode ( ",", $tid );
  2533. foreach ( $cid as $key => $value ) {
  2534. $tagClient = new tagCompanyNexus ();
  2535. $tagClientInfo = $tagClient->getTagClientBySCid ( $value, $this->staff [0] ['sid'] );
  2536. $ar = explode ( ",", $strtid . ',' . $tagClientInfo ['tag'] );
  2537. $re = array_filter ( array_unique ( $ar ) );
  2538. $tagClient->tag = implode ( ",", $re );
  2539. if (! empty ( $tagClientInfo )) {
  2540. $tagClient->tcid = $tagClientInfo ['tcid'];
  2541. $tagClient->update ();
  2542. } else {
  2543. $tagClient->sid = $this->staff [0] ['sid'];
  2544. $tagClient->company = $value;
  2545. $tagClient->insert ();
  2546. }
  2547. }
  2548. header ( "Location: /mycompany" );
  2549. }
  2550. function DoAddTag() {
  2551. $cid = $this->get_args ( 'id' );
  2552. $tooltipAct = $this->get_args ( 'tooltipAct' ) ? $this->get_args ( 'tooltipAct' ) : "";
  2553. Doo::loadModel ( 'client' );
  2554. if (! empty ( $tooltipAct )) {
  2555. $tid = $this->get_args ( 'tooltiplist' );
  2556. $k = implode ( ",", $tid );
  2557. Doo::loadModel ( 'C_tooltip' );
  2558. $s = " and cateid=" . $this->staff [0] ['cid'];
  2559. if (! empty ( $this->staff [0] ['othercid'] )) {
  2560. $othercid = explode ( ",", $this->staff [0] ['othercid'] );
  2561. foreach ( $othercid as $value ) {
  2562. $s .= " or cateid=" . $value;
  2563. }
  2564. }
  2565. foreach ( $cid as $key => $value ) {
  2566. $C_tooltip = new C_tooltip ();
  2567. $tooltip = $C_tooltip->getOne ( array (
  2568. 'where' => 'cid=' . $value . " " . $s,
  2569. 'asArray' => true
  2570. ) );
  2571. if (empty ( $tooltip )) {
  2572. $C_tooltip->cid = $value;
  2573. $C_tooltip->name = $k;
  2574. $C_tooltip->cateid = $this->staff [0] ['cid'];
  2575. $C_tooltip->insert ();
  2576. } else {
  2577. $C_tooltip->tip = $tooltip ['tip'];
  2578. $C_tooltip->name = $k;
  2579. $C_tooltip->update ();
  2580. }
  2581. }
  2582. } else {
  2583. $tid = $this->get_args ( 'tagALD' );
  2584. Doo::loadModel ( 'tag_client' );
  2585. $strtid = implode ( ",", $tid );
  2586. foreach ( $cid as $key => $value ) {
  2587. $tagClient = new tag_client ();
  2588. $tagClientInfo = $tagClient->getTagClientBySCid ( $value, $this->staff [0] ['sid'] );
  2589. $ar = explode ( ",", $strtid . ',' . $tagClientInfo ['tag'] );
  2590. $re = array_filter ( array_unique ( $ar ) );
  2591. $tagClient->tag = implode ( ",", $re );
  2592. if (! empty ( $tagClientInfo )) {
  2593. $tagClient->tcid = $tagClientInfo ['tcid'];
  2594. $tagClient->update ();
  2595. } else {
  2596. $tagClient->sid = $this->staff [0] ['sid'];
  2597. $tagClient->client = $value;
  2598. $tagClient->insert ();
  2599. }
  2600. }
  2601. }
  2602. header ( "Location: /contacts" );
  2603. }
  2604. function ajaxDeleteTag() {
  2605. $cid = $this->get_args ( 'cid' );
  2606. $tid = $this->get_args ( 'tid' );
  2607. Doo::loadModel ( 'tag_client' );
  2608. $tagClient = new tag_client ();
  2609. $tagInfo = $tagClient->getTagClientBySCid ( $cid, $this->staff [0] ['sid'] );
  2610. $tag = str_replace ( $tid, "", $tagInfo ['tag'] );
  2611. $ar = explode ( ',', $tag );
  2612. $tag = implode ( ',', array_filter ( $ar ) );
  2613. $tagClient->tcid = $tagInfo ['tcid'];
  2614. $tagClient->tag = $tag;
  2615. $tagClient->update ();
  2616. }
  2617. function ajaxDeleteTagCompany() {
  2618. $cid = $this->get_args ( 'cid' );
  2619. $tid = $this->get_args ( 'tid' );
  2620. Doo::loadModel ( 'tagCompanyNexus' );
  2621. $tagClient = new tagCompanyNexus ();
  2622. $tagInfo = $tagClient->getTagClientBySCid ( $cid, $this->staff [0] ['sid'] );
  2623. $tag = str_replace ( $tid, "", $tagInfo ['tag'] );
  2624. $ar = explode ( ',', $tag );
  2625. $tag = implode ( ',', array_filter ( $ar ) );
  2626. $tagClient->tcid = $tagInfo ['tcid'];
  2627. $tagClient->tag = $tag;
  2628. $tagClient->update ();
  2629. }
  2630. function deleteToolTip() {
  2631. $cid = $this->get_args ( 'cid' );
  2632. $cateid = $this->get_args ( 'cateid' );
  2633. $name = $this->get_args ( 'name' );
  2634. Doo::loadModel ( "C_tooltip" );
  2635. $tooltip = new C_tooltip ();
  2636. if (! empty ( $cid ) && ! empty ( $cateid ) && ! empty ( $name )) {
  2637. $tool = $tooltip->getOne ( array (
  2638. 'where' => 'cid=' . $cid . ' and cateid=' . $cateid,
  2639. 'asArray' => true
  2640. ) );
  2641. if (! empty ( $tool )) {
  2642. $name = str_replace ( $name, "", $tool ['name'] );
  2643. $name = explode ( ',', $name );
  2644. $name = implode ( ',', array_filter ( $name ) );
  2645. $tooltip->name = $name;
  2646. $tooltip->tip = $tool ['tip'];
  2647. $tooltip->update ();
  2648. }
  2649. }
  2650. }
  2651. function DoEdiTagCompany() {
  2652. $tag_1 = $this->get_args ( 'tag_1' ) ? $this->get_args ( 'tag_1' ) : "";
  2653. $tag_2 = $this->get_args ( 'tag_2' ) ? $this->get_args ( 'tag_2' ) : "";
  2654. $tag_3 = $this->get_args ( 'tag_3' ) ? $this->get_args ( 'tag_3' ) : "";
  2655. $tag_4 = $this->get_args ( 'tag_4' ) ? $this->get_args ( 'tag_4' ) : "";
  2656. $tag_5 = $this->get_args ( 'tag_5' ) ? $this->get_args ( 'tag_5' ) : "";
  2657. $tag_6 = $this->get_args ( 'tag_6' ) ? $this->get_args ( 'tag_6' ) : "";
  2658. $tag_7 = $this->get_args ( 'tag_7' ) ? $this->get_args ( 'tag_7' ) : "";
  2659. $tid_1 = $this->get_args ( 'tid_1' ) ? $this->get_args ( 'tid_1' ) : 0;
  2660. $tid_2 = $this->get_args ( 'tid_2' ) ? $this->get_args ( 'tid_2' ) : 0;
  2661. $tid_3 = $this->get_args ( 'tid_3' ) ? $this->get_args ( 'tid_3' ) : 0;
  2662. $tid_4 = $this->get_args ( 'tid_4' ) ? $this->get_args ( 'tid_4' ) : 0;
  2663. $tid_5 = $this->get_args ( 'tid_5' ) ? $this->get_args ( 'tid_5' ) : 0;
  2664. $tid_6 = $this->get_args ( 'tid_6' ) ? $this->get_args ( 'tid_6' ) : 0;
  2665. $tid_7 = $this->get_args ( 'tid_7' ) ? $this->get_args ( 'tid_7' ) : 0;
  2666. Doo::loadModel ( 'tagCompany' );
  2667. if (! empty ( $tag_1 ) && ! empty ( $tid_1 )) {
  2668. $tag = new tagCompany ();
  2669. $tag->tid = $tid_1;
  2670. $tag->name = $tag_1;
  2671. $tag->update ();
  2672. }
  2673. if (! empty ( $tag_2 ) && ! empty ( $tid_2 )) {
  2674. $tag = new tagCompany ();
  2675. $tag->tid = $tid_2;
  2676. $tag->name = $tag_2;
  2677. $tag->update ();
  2678. }
  2679. if (! empty ( $tag_3 ) && ! empty ( $tid_3 )) {
  2680. $tag = new tagCompany ();
  2681. $tag->tid = $tid_3;
  2682. $tag->name = $tag_3;
  2683. $tag->update ();
  2684. }
  2685. if (! empty ( $tag_4 ) && ! empty ( $tid_4 )) {
  2686. $tag = new tagCompany ();
  2687. $tag->tid = $tid_4;
  2688. $tag->name = $tag_4;
  2689. $tag->update ();
  2690. }
  2691. if (! empty ( $tag_5 ) && ! empty ( $tid_5 )) {
  2692. $tag = new tagCompany ();
  2693. $tag->tid = $tid_5;
  2694. $tag->name = $tag_5;
  2695. $tag->update ();
  2696. }
  2697. if (! empty ( $tag_6 ) && ! empty ( $tid_6 )) {
  2698. $tag = new tagCompany ();
  2699. $tag->tid = $tid_6;
  2700. $tag->name = $tag_6;
  2701. $tag->update ();
  2702. }
  2703. if (! empty ( $tag_7 ) && ! empty ( $tid_7 )) {
  2704. $tag = new tagCompany ();
  2705. $tag->tid = $tid_7;
  2706. $tag->name = $tag_7;
  2707. $tag->update ();
  2708. }
  2709. return "/mycompany";
  2710. }
  2711. function DoEdiTag() {
  2712. $tag_1 = $this->get_args ( 'tag_1' ) ? $this->get_args ( 'tag_1' ) : "";
  2713. $tag_2 = $this->get_args ( 'tag_2' ) ? $this->get_args ( 'tag_2' ) : "";
  2714. $tag_3 = $this->get_args ( 'tag_3' ) ? $this->get_args ( 'tag_3' ) : "";
  2715. $tag_4 = $this->get_args ( 'tag_4' ) ? $this->get_args ( 'tag_4' ) : "";
  2716. $tag_5 = $this->get_args ( 'tag_5' ) ? $this->get_args ( 'tag_5' ) : "";
  2717. $tag_6 = $this->get_args ( 'tag_6' ) ? $this->get_args ( 'tag_6' ) : "";
  2718. $tag_7 = $this->get_args ( 'tag_7' ) ? $this->get_args ( 'tag_7' ) : "";
  2719. $tid_1 = $this->get_args ( 'tid_1' ) ? $this->get_args ( 'tid_1' ) : 0;
  2720. $tid_2 = $this->get_args ( 'tid_2' ) ? $this->get_args ( 'tid_2' ) : 0;
  2721. $tid_3 = $this->get_args ( 'tid_3' ) ? $this->get_args ( 'tid_3' ) : 0;
  2722. $tid_4 = $this->get_args ( 'tid_4' ) ? $this->get_args ( 'tid_4' ) : 0;
  2723. $tid_5 = $this->get_args ( 'tid_5' ) ? $this->get_args ( 'tid_5' ) : 0;
  2724. $tid_6 = $this->get_args ( 'tid_6' ) ? $this->get_args ( 'tid_6' ) : 0;
  2725. $tid_7 = $this->get_args ( 'tid_7' ) ? $this->get_args ( 'tid_7' ) : 0;
  2726. Doo::loadModel ( 'tag' );
  2727. if (! empty ( $tag_1 ) && ! empty ( $tid_1 )) {
  2728. $tag = new tag ();
  2729. $tag->tid = $tid_1;
  2730. $tag->name = $tag_1;
  2731. $tag->update ();
  2732. }
  2733. if (! empty ( $tag_2 ) && ! empty ( $tid_2 )) {
  2734. $tag = new tag ();
  2735. $tag->tid = $tid_2;
  2736. $tag->name = $tag_2;
  2737. $tag->update ();
  2738. }
  2739. if (! empty ( $tag_3 ) && ! empty ( $tid_3 )) {
  2740. $tag = new tag ();
  2741. $tag->tid = $tid_3;
  2742. $tag->name = $tag_3;
  2743. $tag->update ();
  2744. }
  2745. if (! empty ( $tag_4 ) && ! empty ( $tid_4 )) {
  2746. $tag = new tag ();
  2747. $tag->tid = $tid_4;
  2748. $tag->name = $tag_4;
  2749. $tag->update ();
  2750. }
  2751. if (! empty ( $tag_5 ) && ! empty ( $tid_5 )) {
  2752. $tag = new tag ();
  2753. $tag->tid = $tid_5;
  2754. $tag->name = $tag_5;
  2755. $tag->update ();
  2756. }
  2757. if (! empty ( $tag_6 ) && ! empty ( $tid_6 )) {
  2758. $tag = new tag ();
  2759. $tag->tid = $tid_6;
  2760. $tag->name = $tag_6;
  2761. $tag->update ();
  2762. }
  2763. if (! empty ( $tag_7 ) && ! empty ( $tid_7 )) {
  2764. $tag = new tag ();
  2765. $tag->tid = $tid_7;
  2766. $tag->name = $tag_7;
  2767. $tag->update ();
  2768. }
  2769. return "/contacts";
  2770. }
  2771. function ajaxGetLv2() {
  2772. $lv1 = $this->get_args ( 'lv1' ) ? $this->get_args ( 'lv1' ) : 0;
  2773. $s = $this->get_args ( 's' ) ? $this->get_args ( 's' ) : 0;
  2774. if ($lv1 == 0) {
  2775. echo json_encode ( array (
  2776. "success" => false,
  2777. "info" => ""
  2778. ) );
  2779. die ();
  2780. }
  2781. if (! empty ( $lv1 )) {
  2782. Doo::loadModel ( 'district' );
  2783. $district = new district ();
  2784. $district = $district->get_lvByid ( $s, $lv1 );
  2785. echo json_encode ( array (
  2786. "success" => true,
  2787. "info" => $district
  2788. ) );
  2789. }
  2790. }
  2791. function keyonline() {
  2792. $data ['memu'] = "keyonline";
  2793. $data ['staff'] = $this->staff;
  2794. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  2795. if (empty ( $year ))
  2796. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( 'Y' );
  2797. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  2798. if (empty ( $cid ))
  2799. $cid = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : $this->staff [0] ['cid'];
  2800. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  2801. if (empty ( $staff ))
  2802. $staff = isset ( $this->params ['staff'] ) ? $this->params ['staff'] : "";
  2803. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "";
  2804. if (empty ( $status ))
  2805. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  2806. $search = $this->get_args ( 'search' ) ? $this->get_args ( 'search' ) : "";
  2807. $productW = $this->get_args ( 'product' ) ? $this->get_args ( 'product' ) : "";
  2808. $lidKey = $this->get_args ( 'lid' ) ? $this->get_args ( 'lid' ) : "";
  2809. Doo::loadModel ( 'longle' );
  2810. $longle = new longle ();
  2811. Doo::loadClass ( 'XDeode' );
  2812. $XDeode = new XDeode ( 5 );
  2813. Doo::loadModel ( 'longle_log' );
  2814. $longle_log = new longle_log ();
  2815. $lid =0;
  2816. if(!empty($lidKey)){
  2817. $lid = $XDeode->decode ( $lidKey );
  2818. }
  2819. $data ['longleArray'] = $longle->getLongleByStatus ( $year, $cid, $staff, $status, $search, $productW );
  2820. $longleDetail=$longle->getLongleByLid($lid);
  2821. $longleLogDetail=$longle_log->getLongleByLid ( $lid );
  2822. // 获取接收锁信息
  2823. // $longle->getLongleByRe($this->staff[0]['cid'],1);
  2824. $othstr = "";
  2825. if (! empty ( $this->staff [0] ['othercid'] ))
  2826. $othstr = " cid in (" . $this->staff [0] ['cid'] . "," . $this->staff [0] ['othercid'] . ")";
  2827. else
  2828. $othstr = " cid in (" . $this->staff [0] ['cid'] . ")";
  2829. $data ['reLongle'] = $longle->count ( array (
  2830. 'where' => $othstr . ' and (status=1 or responsible="") and make_day>="2019-01-01"'
  2831. ) );
  2832. $data['lidKey']=$lidKey;
  2833. if (isset($longleDetail[0])){
  2834. $data['longleDetail']=$longleDetail[0];
  2835. }else{
  2836. $data['longleDetail']=array();
  2837. }
  2838. $data ['longleLogHtml'] = $this->_getLongleLogHtml ( $longleLogDetail );
  2839. $data ['cid'] = $cid;
  2840. $data ['year'] = $year;
  2841. $data ['staff'] = $staff;
  2842. $data ['status'] = $status;
  2843. $data ['productName'] = $productW;
  2844. $data ['search'] =$search;
  2845. Doo::loadModel ( 'L_category' );
  2846. Doo::loadModel ( 'staff' );
  2847. Doo::loadModel ( 'product' );
  2848. $product = new product ();
  2849. $staff = new staff ();
  2850. $L_category = new L_category ();
  2851. $data ['product'] = $product->getProudct ();
  2852. $data ['staffu'] = $staff->getUserById ( $this->staff [0] ['sid'] );
  2853. $data ['category'] = $L_category->getCategory ();
  2854. $data ['staffList'] = $staff->getStaffByCid ( $cid );
  2855. if ($cid == 1)
  2856. $data ['cid'] = $data ['category'] [0] ['cid'];
  2857. $dateHtml = "";
  2858. $now = date ( "Y" );
  2859. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  2860. if ($YEARD <= $now) {
  2861. $dateHtml .= '<option ';
  2862. if ($data ['year'] == $YEARD) {
  2863. $dateHtml .= 'selected ';
  2864. }
  2865. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  2866. }
  2867. }
  2868. $data ['dateHtml'] = $dateHtml;
  2869. $this->render ( "/lock_look", $data );
  2870. }
  2871. function keyStatistics() {
  2872. Doo::loadModel ( 'staff' );
  2873. $staff = new staff ();
  2874. Doo::loadModel ( 'longle' );
  2875. $longle = new longle ();
  2876. Doo::loadModel ( 'L_category' );
  2877. $L_category = new L_category ();
  2878. Doo::loadClass ( 'XDeode' );
  2879. $XDeode = new XDeode ( 5 );
  2880. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  2881. $staffCondition = "";
  2882. if ($this->staff [0] ['cid'] != 12){
  2883. $staffCondition = " and cid=" . $this->staff [0] ['cid'];
  2884. $cid=$this->staff [0] ['cid'];
  2885. }else{
  2886. $cid=$this->staff [0] ['cid'];
  2887. if (!empty($cidKey)){
  2888. $cid = $XDeode->decode ( $cidKey );
  2889. if (! is_numeric ( $cid )){
  2890. $cid=$this->staff [0] ['cid'];
  2891. }
  2892. }
  2893. $staffCondition = " and cid=" . $cid;
  2894. }
  2895. $staffList = $staff->find ( array (
  2896. 'where' => "isadmin= 0 and nature !=4 " . $staffCondition,
  2897. 'asArray' => TRUE
  2898. ) );
  2899. //
  2900. $sql = "select COUNT(*) as count,responsible
  2901. from CLD_longle
  2902. where status!= 1 and make_day >='2019-12-01'
  2903. GROUP BY responsible";
  2904. $query = Doo::db ()->query ( $sql );
  2905. $resultSum = $query->fetchAll ();
  2906. $sql = "select COUNT(*) as count,responsible
  2907. from CLD_longle
  2908. where status!= 2 and status!= 1 and make_day >='2019-12-01'
  2909. GROUP BY responsible";
  2910. $query = Doo::db ()->query ( $sql );
  2911. $resultA = $query->fetchAll ();
  2912. foreach ( $staffList as $key => $value ) {
  2913. $sum=$a=0;
  2914. foreach ($resultSum as $k=>$v){
  2915. if($value ['username']==$v['responsible']){
  2916. $sum=$v['count'];
  2917. break;
  2918. }
  2919. }
  2920. foreach ($resultA as $k=>$v){
  2921. if($value ['username']==$v['responsible']){
  2922. $a=$v['count'];
  2923. break;
  2924. }
  2925. }
  2926. $b = $sum - $a;
  2927. $staffList [$key] ['sum'] = $sum;
  2928. $staffList [$key] ['a'] = $a;
  2929. $staffList [$key] ['b'] = $b;
  2930. }
  2931. /* Doo::db ()->beginTransaction ();
  2932. foreach ( $staffList as $key => $value ) { // not in(1,2)
  2933. $sum = $longle->count ( array (
  2934. 'where' => "status!= 1 and responsible ='" . $value ['username'] . "' and make_day >='2019-12-01'",
  2935. 'asArray' => TRUE
  2936. ) );
  2937. $a = $longle->count ( array (
  2938. 'where' => "status!= 2 and status!= 1 and responsible ='" . $value ['username'] . "' and make_day >='2019-12-01'",
  2939. 'asArray' => TRUE
  2940. ) );
  2941. $b = $sum - $a;
  2942. $staffList [$key] ['sum'] = $sum;
  2943. $staffList [$key] ['a'] = $a;
  2944. $staffList [$key] ['b'] = $b;
  2945. }
  2946. Doo::db ()->commit (); */
  2947. $data ['cid'] = $cid;
  2948. $data ['category'] = $L_category->getCategory ();
  2949. $data ['staff'] = $this->staff;
  2950. $data ['staffList'] = $staffList;
  2951. $data ['memu'] = "keyStatistics";
  2952. $this->render ( "lock_count", $data );
  2953. }
  2954. function addDoLockLog() {
  2955. Doo::loadModel ( 'longle_log' );
  2956. Doo::loadModel ( 'longle' );
  2957. Doo::loadModel ( "action_log" );
  2958. Doo::loadModel ( 'client' );
  2959. $clientobj = new client ();
  2960. $longle = new longle ();
  2961. $longle_log = new longle_log ();
  2962. Doo::loadModel ( 'district' );
  2963. $district = new district ();
  2964. $status = $this->get_args ( 'longleStatus' ) ? $this->get_args ( 'longleStatus' ) : 0;
  2965. $lidKey = $this->get_args ( 'klid' ) ? $this->get_args ( 'klid' ) : 0;
  2966. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
  2967. $company = $this->get_args ( 'company' ) ? $this->get_args ( 'company' ) : '';
  2968. $alloted_time = $this->get_args ( 'alloted_time' ) ? $this->get_args ( 'alloted_time' ) : '';
  2969. if (empty ( $lidKey ))
  2970. return "/keyonline/";
  2971. Doo::loadClass ( 'XDeode' );
  2972. $XDeode = new XDeode ( 5 );
  2973. $lid = $XDeode->decode ( $lidKey );
  2974. $linfo = $longle->getLongleByLid ( $lid );
  2975. if ($status == 0)
  2976. return "/keyonline/" . $lid;
  2977. elseif ($status == 3) {
  2978. $clientname = $clientobj->getClientByName2 ( $name, $company );
  2979. if (empty ( $clientname ))
  2980. return "/keyonline/" . $lid;
  2981. if ($name != "") {
  2982. $longle->client = $name;
  2983. $longle->clientid = $clientname [0] ['cid'];
  2984. }
  2985. // if($product!="")
  2986. // $longle->product=$product;
  2987. $longle->statusT = "借出";
  2988. $longle_log->client = $name;
  2989. $longle_log->clientid = $clientname [0] ['cid'];
  2990. $longle_log->product = $linfo [0] ['product'];
  2991. $longle_log->statusT = "借出";
  2992. // 日常行为
  2993. $action_log = new action_log ();
  2994. $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'] . ')';
  2995. $action_log->sid = $this->staff [0] ['sid'];
  2996. $action_log->cid = $this->staff [0] ['cid'];
  2997. $action_log->updatetime = date ( "Y-m-d" );
  2998. $action_log->time = date ( "H:i" );
  2999. $action_log->status = 4;
  3000. $action_log->districtid = $clientname [0] ['district'];
  3001. $local = $district->getbyidlist ( $clientname [0] ['district'] );
  3002. $action_log->city = $local [0] ['name'];
  3003. $action_log->province = $local [1] ['name'];
  3004. $action_log->company = $clientname [0] ['companyname'];
  3005. Doo::loadModel ( 'company' );
  3006. $company = new company ();
  3007. $companyInfo = $company->getOne ( array (
  3008. 'where' => ' companyname="' . $clientname [0] ['companyname'] . '"',
  3009. 'asArray' => true
  3010. ) );
  3011. $nature = explode ( ',', $companyInfo ['nature'] );
  3012. $action_log->nature = $nature [0];
  3013. $action_log->class = $action_log->iconBorrow;
  3014. $action_log->insert ();
  3015. } elseif ($status == 4) {
  3016. $clientname = $clientobj->getClientByName2 ( $name, $company );
  3017. if (empty ( $clientname ))
  3018. return "/keyonline/" . $lid;
  3019. if ($name != "") {
  3020. $longle->client = $name;
  3021. $longle->clientid = $clientname [0] ['cid'];
  3022. }
  3023. $longle->statusT = "销售";
  3024. $longle_log->client = $name;
  3025. $longle_log->clientid = $clientname [0] ['cid'];
  3026. $longle_log->product = $linfo [0] ['product'];
  3027. $longle_log->statusT = "销售";
  3028. // 日常行为
  3029. $action_log = new action_log ();
  3030. $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'] . ')';
  3031. $action_log->sid = $this->staff [0] ['sid'];
  3032. $action_log->cid = $this->staff [0] ['cid'];
  3033. $action_log->updatetime = date ( "Y-m-d" );
  3034. $action_log->time = date ( "H:i" );
  3035. $action_log->status = 5;
  3036. $action_log->districtid = $clientname [0] ['district'];
  3037. $local = $district->getbyidlist ( $clientname [0] ['district'] );
  3038. $action_log->city = $local [0] ['name'];
  3039. $action_log->province = $local [1] ['name'];
  3040. $action_log->company = $clientname [0] ['companyname'];
  3041. Doo::loadModel ( 'company' );
  3042. $company = new company ();
  3043. $companyInfo = $company->getOne ( array (
  3044. 'where' => ' companyname="' . $clientname [0] ['companyname'] . '"',
  3045. 'asArray' => true
  3046. ) );
  3047. $nature = explode ( ',', $companyInfo ['nature'] );
  3048. $action_log->nature = $nature [0];
  3049. $action_log->class = $action_log->iconSell;
  3050. $action_log->insert ();
  3051. } elseif ($status == 5) {
  3052. $product = $this->get_args ( 'newProduct' ) ? $this->get_args ( 'newProduct' ) : "";
  3053. if ($product != "")
  3054. $longle->product = $linfo [0] ['product'] . "+" . $product;
  3055. $longle->statusT = "升级";
  3056. $longle_log->product = $linfo [0] ['product'] . "+" . $product;
  3057. $longle_log->statusT = "升级";
  3058. $longle_log->client = $linfo [0] ['client'];
  3059. $longle_log->clientid = $linfo [0] ['clientid'];
  3060. $clientname = $clientobj->getOne ( array (
  3061. 'where' => "cid= '" . $linfo [0] ['clientid'] . "'",
  3062. 'asArray' => TRUE
  3063. ) );
  3064. // 日常行为
  3065. $action_log = new action_log ();
  3066. $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>';
  3067. $action_log->sid = $this->staff [0] ['sid'];
  3068. $action_log->cid = $this->staff [0] ['cid'];
  3069. $action_log->updatetime = date ( "Y-m-d" );
  3070. $action_log->time = date ( "H:i" );
  3071. $action_log->class = $action_log->iconUpdate;
  3072. $action_log->sid = $this->staff [0] ['sid'];
  3073. $action_log->cid = $this->staff [0] ['cid'];
  3074. $action_log->status = 7;
  3075. $action_log->insert ();
  3076. } elseif ($status == 6) {
  3077. $key_num = $this->get_args ( 'key_num' ) ? $this->get_args ( 'key_num' ) : "";
  3078. $key_num2 = explode ( "-", $key_num );
  3079. $key_num = $key_num2 [0] . "-" . $key_num2 [1];
  3080. // if($key_num!="")
  3081. // $longle->key_num=$key_num;
  3082. // 新锁拷贝记录
  3083. $newLongle = new longle ();
  3084. // $newLongle->product=$linfo[0]['product'];
  3085. $newLongle->statusT = "更换";
  3086. $newLongle->status = 6;
  3087. $newLongle->client = $linfo [0] ['client'];
  3088. $newLongle->clientid = $linfo [0] ['clientid'];
  3089. $newlid = $newLongle->update ( array (
  3090. 'where' => ' key_num= \'' . $key_num . "'"
  3091. ) );
  3092. $longleinfo = $longle->getOne ( array (
  3093. 'where' => ' key_num =\'' . $key_num . "'",
  3094. 'asArray' => true
  3095. ) );
  3096. $longleLog = $longle_log->getOne ( array (
  3097. 'where' => ' lid =' . $linfo [0] ['lid'],
  3098. 'desc' => 'logid',
  3099. 'asArray' => true
  3100. ) );
  3101. // 新记录日志
  3102. $newlongle_log = new longle_log ();
  3103. $newlongle_log->statusT = "更换";
  3104. $newlongle_log->status = 6;
  3105. $newlongle_log->client = $linfo [0] ['client'];
  3106. $newlongle_log->new_key_num = $linfo [0] ['key_num'];
  3107. $newlongle_log->product = $linfo [0] ['product'];
  3108. $newlongle_log->category = $this->staff [0] ['category'];
  3109. $newlongle_log->dateline = date ( "Y-m-d" );
  3110. $newlongle_log->operator = $this->staff [0] ['username'];
  3111. $newlongle_log->lid = $longleinfo ['lid'];
  3112. $newlongle_log->insert ();
  3113. $newlongle_log = new longle_log ();
  3114. $newlongle_log->statusT = $longleLog ['statusT'];
  3115. $newlongle_log->status = $longleLog ['status'];
  3116. $newlongle_log->client = $longleLog ['client'];
  3117. $newlongle_log->new_key_num = $longleLog ['new_key_num'];
  3118. $newlongle_log->product = $longleLog ['product'];
  3119. $newlongle_log->category = $longleLog ['category'];
  3120. $newlongle_log->dateline = $longleLog ['dateline'];
  3121. $newlongle_log->operator = $longleLog ['operator'];
  3122. $newlongle_log->lid = $longleinfo ['lid'];
  3123. $newlongle_log->insert ();
  3124. $newLongle = new longle ();
  3125. $newLongle->statusT = $longleLog ['statusT'];
  3126. $newLongle->status = $longleLog ['status'];
  3127. $newlid = $newLongle->update ( array (
  3128. 'where' => ' key_num= \'' . $key_num . "'"
  3129. ) );
  3130. // 新锁状态拷贝
  3131. $longle->statusT = "更换";
  3132. $longle_log->new_key_num = $key_num;
  3133. $longle_log->statusT = "更换";
  3134. $longle_log->client = $linfo [0] ['client'];
  3135. $clientname = $clientobj->getOne ( array (
  3136. 'where' => "cid= '" . $linfo [0] ['clientid'] . "'",
  3137. 'asArray' => TRUE
  3138. ) );
  3139. // 日常行为
  3140. $action_log = new action_log ();
  3141. $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'] . ')';
  3142. $action_log->sid = $this->staff [0] ['sid'];
  3143. $action_log->cid = $this->staff [0] ['cid'];
  3144. $action_log->updatetime = date ( "Y-m-d" );
  3145. $action_log->time = date ( "H:i" );
  3146. $action_log->class = $action_log->iconReplace;
  3147. $action_log->sid = $this->staff [0] ['sid'];
  3148. $action_log->cid = $this->staff [0] ['cid'];
  3149. $action_log->status = 8;
  3150. $action_log->insert ();
  3151. } elseif ($status == 7) {
  3152. $longle->statusT = "收回";
  3153. $longle_log->statusT = "收回";
  3154. $longle_log->responsible = $linfo [0] ['responsible'];
  3155. // 日常行为
  3156. $action_log = new action_log ();
  3157. $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>';
  3158. $action_log->sid = $this->staff [0] ['sid'];
  3159. $action_log->cid = $this->staff [0] ['cid'];
  3160. $action_log->updatetime = date ( "Y-m-d" );
  3161. $action_log->time = date ( "H:i" );
  3162. $action_log->class = $action_log->iconRecycle;
  3163. $action_log->sid = $this->staff [0] ['sid'];
  3164. $action_log->cid = $this->staff [0] ['cid'];
  3165. $action_log->status = 9;
  3166. $action_log->insert ();
  3167. } elseif ($status == 8) {
  3168. $mark = $this->get_args ( 'mark' ) ? $this->get_args ( 'mark' ) : "";
  3169. if (empty ( $mark )) {
  3170. echo json_encode ( array (
  3171. 'msg' => 2
  3172. ) );
  3173. die ();
  3174. }
  3175. $longle_log->mark = $mark;
  3176. // 日常行为
  3177. $action_log = new action_log ();
  3178. $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>添加新备注。';
  3179. $action_log->sid = $this->staff [0] ['sid'];
  3180. $action_log->cid = $this->staff [0] ['cid'];
  3181. $action_log->updatetime = date ( "Y-m-d" );
  3182. $action_log->time = date ( "H:i" );
  3183. $action_log->sid = $this->staff [0] ['sid'];
  3184. $action_log->cid = $this->staff [0] ['cid'];
  3185. $action_log->status = 10;
  3186. $action_log->class = $action_log->iconLock;
  3187. $action_log->insert ();
  3188. } elseif ($status == 9) {
  3189. $longle->statusT = "赠送";
  3190. $longle_log->statusT = "赠送";
  3191. $clientname = $clientobj->getClientByName2 ($name, $company );
  3192. if (empty ( $clientname ))
  3193. return "/keyonline/" . $lid;
  3194. if ($name != "") {
  3195. $longle->client = $name;
  3196. $longle->clientid = $clientname [0] ['cid'];
  3197. }
  3198. $longle_log->client = $name;
  3199. $longle_log->clientid = $clientname [0] ['cid'];
  3200. // 日常行为
  3201. $action_log = new action_log ();
  3202. $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'] . ')';
  3203. $action_log->updatetime = date ( "Y-m-d" );
  3204. $action_log->time = date ( "H:i" );
  3205. $action_log->class = $action_log->iconRecycle;
  3206. $action_log->sid = $this->staff [0] ['sid'];
  3207. $action_log->cid = $this->staff [0] ['cid'];
  3208. $action_log->status = 6;
  3209. $action_log->districtid = $clientname [0] ['district'];
  3210. $local = $district->getbyidlist ( $clientname [0] ['district'] );
  3211. $action_log->city = $local [0] ['name'];
  3212. $action_log->province = $local [1] ['name'];
  3213. $action_log->company = $clientname [0] ['companyname'];
  3214. Doo::loadModel ( 'company' );
  3215. $company = new company ();
  3216. $companyInfo = $company->getOne ( array (
  3217. 'where' => ' companyname="' . $clientname [0] ['companyname'] . '"',
  3218. 'asArray' => true
  3219. ) );
  3220. $nature = explode ( ',', $companyInfo ['nature'] );
  3221. $action_log->nature = $nature [0];
  3222. $action_log->insert ();
  3223. }elseif($status == 10){
  3224. $longle->alloted_time = $alloted_time;
  3225. $longle_log->mark ='由'.$linfo[0]['alloted_time'].'延期至'.$alloted_time;
  3226. // 日常行为
  3227. $action_log = new action_log ();
  3228. $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;
  3229. $action_log->sid = $this->staff [0] ['sid'];
  3230. $action_log->cid = $this->staff [0] ['cid'];
  3231. $action_log->updatetime = date ( "Y-m-d" );
  3232. $action_log->time = date ( "H:i" );
  3233. $action_log->sid = $this->staff [0] ['sid'];
  3234. $action_log->cid = $this->staff [0] ['cid'];
  3235. $action_log->status = 12;
  3236. $action_log->class = $action_log->iconLock;
  3237. $action_log->insert ();
  3238. }
  3239. // 记录使用过的状态
  3240. $statuslog = $status . "," . $linfo [0] ['statuslog'];
  3241. $ar = explode ( ',', $statuslog );
  3242. $statuslog = implode ( ',', array_unique ( array_filter ( $ar ) ) );
  3243. $longle->statuslog = $statuslog;
  3244. if ($linfo [0] ['status'] <= 2) {
  3245. if ($status >= 4 && $status <= 2) {
  3246. return "/keyonline/" . $lid;
  3247. }
  3248. }
  3249. if ($lid != 0) {
  3250. $longle->lid = $lid;
  3251. if (!($status == 8||$status == 10))
  3252. $longle->status = $status;
  3253. // if($status!=8)
  3254. $longle->responsible = $this->staff [0] ['username'];
  3255. $longle->update ();
  3256. }
  3257. $longle_log->lid = $lid;
  3258. $longle_log->status = $status;
  3259. $longle_log->operator = $this->staff [0] ['username'];
  3260. // 责任人
  3261. $longle_log->category = $this->staff [0] ['category'];
  3262. $longle_log->dateline = date ( "Y-m-d" );
  3263. $longle_log->insert ();
  3264. echo json_encode ( array (
  3265. 'msg' => 1
  3266. ) );
  3267. die ();
  3268. // return "/keyonline/".$lid;
  3269. }
  3270. function ajaxGetLongleByName() {
  3271. Doo::loadModel ( 'longle_log' );
  3272. Doo::loadModel ( 'longle' );
  3273. $longle = new longle ();
  3274. $longle_log = new longle_log ();
  3275. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
  3276. if (empty ( $name )) {
  3277. echo json_encode ( array (
  3278. "success" => false
  3279. ) );
  3280. die ();
  3281. }
  3282. $ky = $longle->getLongleBykeynum ( $name );
  3283. $t = $longle_log->getLongleByLid ( $ky [0] ['lid'] );
  3284. if (isset ( $t [0] ))
  3285. $tk = $t [0];
  3286. else
  3287. $tk = array ();
  3288. $longleLog = $tk;
  3289. $longleLog ['klid'] = $t [0] ['lid'];
  3290. $longleLog ['longle'] = $ky [0];
  3291. $longleLog ['longleLogHtml'] = $this->_getLongleLogHtml ( $t );
  3292. echo json_encode ( $longleLog );
  3293. }
  3294. function ajaxGetLongleN() {
  3295. Doo::loadModel ( 'longle_log' );
  3296. Doo::loadModel ( 'longle' );
  3297. $longle = new longle ();
  3298. $longle_log = new longle_log ();
  3299. $keynum = $this->get_args ( 'keynum' ) ? $this->get_args ( 'keynum' ) : "";
  3300. if (empty ( $keynum )) {
  3301. echo json_encode ( array (
  3302. "success" => false
  3303. ) );
  3304. die ();
  3305. }
  3306. $ky = $longle->getLongleBykeynum ( $keynum );
  3307. if (! empty ( $ky )) {
  3308. $t = $longle_log->getLongleByLid ( $ky [0] ['lid'] );
  3309. if (isset ( $t [0] ))
  3310. $tk = $t [0];
  3311. else
  3312. $tk = array ();
  3313. $longleLog = $tk;
  3314. $longleLog ['klid'] = $ky [0] ['lid'];
  3315. $longleLog ['longle'] = $ky [0];
  3316. $longleLog ['longleLogHtml'] = $this->_getLongleLogHtml ( $t );
  3317. echo json_encode ( $longleLog );
  3318. }
  3319. }
  3320. function ajaxGetLongle() {
  3321. Doo::loadModel ( 'longle_log' );
  3322. Doo::loadModel ( 'longle' );
  3323. $longle = new longle ();
  3324. $longle_log = new longle_log ();
  3325. Doo::loadClass ( 'XDeode' );
  3326. $XDeode = new XDeode ( 5 );
  3327. $lid = $this->get_args ( 'lid' ) ? $this->get_args ( 'lid' ) : 0;
  3328. if ($lid == 0) {
  3329. echo json_encode ( array (
  3330. "success" => false
  3331. ) );
  3332. die ();
  3333. }
  3334. $t = $longle_log->getLongleByLid ( $lid );
  3335. if (isset ( $t [0] ))
  3336. $tk = $t [0];
  3337. else
  3338. $tk = array ();
  3339. $longleLog = $tk;
  3340. $longleLog ['klid'] = $lid;
  3341. $longleLog ['lidKey'] =$XDeode->encode ( $lid );
  3342. $ky = $longle->getLongleByLid ( $lid );
  3343. $longleLog ['longle'] = $ky [0];
  3344. $longleLog ['longleLogHtml'] = $this->_getLongleLogHtml ( $t );
  3345. echo json_encode ( $longleLog );
  3346. }
  3347. function ajaxGetStaffInfo() {
  3348. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  3349. if ($username == "") {
  3350. echo json_encode ( array (
  3351. "success" => false
  3352. ) );
  3353. die ();
  3354. }
  3355. Doo::loadModel ( 'staff' );
  3356. $staff = new staff ();
  3357. $staffInfo = $staff->getOne ( array (
  3358. 'where' => ' username like "' . $username . '"',
  3359. 'asArray' => TRUE
  3360. ) );
  3361. if (empty ( $staffInfo )) {
  3362. echo json_encode ( array (
  3363. "success" => false,
  3364. 'html' => ''
  3365. ) );
  3366. die ();
  3367. }
  3368. $staffHtml = array (
  3369. 'html' => '<div class="contactPanel"><h1>' . $staffInfo ['username'] . '</h1>
  3370. <table><tbody><tr><th>性别</th><td>' . $staffInfo ['gender'] . '</td><th>办事处</th><td>' . $staffInfo ['category'] . '</td></tr>
  3371. <tr><th>手机</th><td>' . $staffInfo ['telephone'] . '</td><th>电话</th><td>' . $staffInfo ['phone'] . '</td></tr>
  3372. <tr><th>QQ</th><td>' . $staffInfo ['qq'] . '</td><th>邮箱</th><td>' . $staffInfo ['email'] . '</td></tr>
  3373. </tbody></table>
  3374. </div>'
  3375. );
  3376. echo json_encode ( $staffHtml );
  3377. }
  3378. function ajaxGetCompanyByAdd() {
  3379. session_start ();
  3380. $cidKey = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  3381. if (empty($cidKey)){
  3382. echo json_encode ( array (
  3383. "success" => false,
  3384. 'data' => ''
  3385. ) );
  3386. }
  3387. Doo::loadClass ( 'XDeode' );
  3388. $XDeode = new XDeode ( 5 );
  3389. $cid = $XDeode->decode ( $cidKey );
  3390. if (! empty ( $cid )) {
  3391. Doo::loadModel ( 'company' );
  3392. $company = new company ();
  3393. Doo::loadModel ( 'client' );
  3394. Doo::loadModel ( 'district' );
  3395. $district = new district ();
  3396. $client = new client ();
  3397. $districtInfo = $district->get_lv ( 1 );
  3398. // $companyInfo = $client->getClientByCompanyId ( $cid );
  3399. // $companyInfo = $companyInfo [0];
  3400. $companyInfo = $company->getOne ( array (
  3401. 'where' => "cid = " . $cid,
  3402. 'asArray' => TRUE
  3403. ) );
  3404. $companyInfo ['companyKey'] = $XDeode->encode ( $companyInfo ['cid'] );
  3405. // $companyInfo ['companyname'] = $cInfo ['companyname'];
  3406. // $companyInfo ['address'] = $cInfo ['address'];
  3407. // $companyInfo ['ride'] = $cInfo ['ride'];
  3408. // $companyInfo ['landmarks'] = $cInfo ['landmarks'];
  3409. // $companyInfo ['stay'] = $cInfo ['stay'];
  3410. $artld = explode ( ',', $companyInfo ['local'] );
  3411. $districtid = explode ( ',', $companyInfo ['district'] );
  3412. $html = "";
  3413. $html .= '<select name="lv21" id="lv31" onchange="dislv(\'lv31\',\'32\');"><option value="' . $districtid [0] . '">' . $artld [0] . '</option>';
  3414. // foreach ($districtInfo as $key=>$value){
  3415. //
  3416. // $html.='<option selected value="'.$value['id'].'">'.$value['name'].'</option>';
  3417. // }
  3418. $html .= '</select>&nbsp;';
  3419. $html .= '<span id="mlv32">
  3420. <select id="lv32" name="lv22">
  3421. <option selected value="' . $districtid [1] . '" >' . $artld [1] . '</option>
  3422. </select>
  3423. </span>';
  3424. $html .= '<span id="mlv33">
  3425. <select id="lv33" name="lv23">
  3426. <option selected value="' . $districtid [2] . '" >' . $artld [2] . '</option>
  3427. </select>&nbsp;
  3428. </span>';
  3429. $companyInfo ['dishtml'] = $html;
  3430. $companyInfo ['natureAr'] = $this->nature;
  3431. $companyInfo ['natureArlenght'] = 12;
  3432. $token = $this->set_token ();
  3433. $_SESSION ['token_' . $this->staff [0] ['sidKey']] = $token;
  3434. $companyInfo ['token'] = $token;
  3435. echo json_encode ( array (
  3436. "success" => true,
  3437. 'data' => $companyInfo
  3438. ) );
  3439. die ();
  3440. } else
  3441. echo json_encode ( array (
  3442. "success" => false,
  3443. 'data' => ''
  3444. ) );
  3445. die ();
  3446. }
  3447. function doEditCompanyD() {
  3448. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  3449. $companyname = $this->get_args ( 'companyname' ) ? $this->get_args ( 'companyname' ) : "";
  3450. $lv21 = $this->get_args ( 'lv21' ) ? $this->get_args ( 'lv21' ) : 0;
  3451. $lv22 = $this->get_args ( 'lv22' ) ? $this->get_args ( 'lv22' ) : 0;
  3452. $lv23 = $this->get_args ( 'lv23' ) ? $this->get_args ( 'lv23' ) : 0;
  3453. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  3454. $fax = $this->get_args ( 'fax' ) ? $this->get_args ( 'fax' ) : "";
  3455. $webservice = $this->get_args ( 'webservice' ) ? $this->get_args ( 'webservice' ) : "";
  3456. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  3457. $ride = $this->get_args ( 'ride' ) ? $this->get_args ( 'ride' ) : "";
  3458. $stay = $this->get_args ( 'stay' ) ? $this->get_args ( 'stay' ) : "";
  3459. $landmarks = $this->get_args ( 'landmarks' ) ? $this->get_args ( 'landmarks' ) : "";
  3460. if (empty ( $cid ) || empty ( $companyname )) {
  3461. echo json_encode ( array (
  3462. "success" => false
  3463. ) );
  3464. die ();
  3465. }
  3466. Doo::loadModel ( "company" );
  3467. Doo::loadModel ( "client" );
  3468. $client = new client ();
  3469. $company = new company ();
  3470. $company->cid = $cid;
  3471. if (! empty ( $lv21 ) && ! empty ( $lv22 ) && ! empty ( $lv23 )) {
  3472. Doo::loadModel ( 'district' );
  3473. $district = new district ();
  3474. // 更新公司信息
  3475. $lv1 = $district->getbyid ( $lv21 );
  3476. $lv2 = $district->getbyid ( $lv22 );
  3477. $lv3 = $district->getbyid ( $lv23 );
  3478. $company->district = $lv21 . "," . $lv22 . "," . $lv23;
  3479. $company->local = $lv1 [0] ['name'] . "," . $lv2 [0] ['name'] . "," . $lv3 [0] ['name'];
  3480. }
  3481. if (! empty ( $nature )) {
  3482. $nature = implode ( ",", $nature );
  3483. $company->nature = $nature;
  3484. }
  3485. if (! empty ( $companyname )) {
  3486. $company->companyname = $companyname;
  3487. $client->companyname = $companyname;
  3488. }
  3489. if (! empty ( $fax ))
  3490. $company->fax = $fax;
  3491. if (! empty ( $webservice ))
  3492. $company->webservice = $webservice;
  3493. $company->address = $address;
  3494. $company->ride = $ride;
  3495. $company->stay = $stay;
  3496. $company->landmarks = $landmarks;
  3497. $company->update ();
  3498. $client->update ( array (
  3499. 'where' => ' companyid =' . $cid
  3500. ) );
  3501. echo json_encode ( array (
  3502. "success" => true
  3503. ) );
  3504. die ();
  3505. }
  3506. function ajaxEditCompany() {
  3507. $companyname = $this->get_args ( 'companyId' ) ? $this->get_args ( 'companyId' ) : 0;
  3508. if (! empty ( $companyname )) {
  3509. Doo::loadModel ( 'company' );
  3510. $company = new company ();
  3511. $companyInfo = $company->getOne ( array (
  3512. 'where' => "cid = '" . $companyname . "'",
  3513. 'asArray' => TRUE
  3514. ) );
  3515. if (! empty ( $companyInfo )) {
  3516. Doo::loadModel ( 'district' );
  3517. $district = new district ();
  3518. $districtinfo = $district->get_lv ( 1 );
  3519. $dinfo = $district->getbyidlist ( $companyInfo ['district'] );
  3520. $html = '
  3521. <div class="contactInfo clearfix">
  3522. <div class="header">
  3523. <h1 class="companyName">' . $companyInfo ['companyname'] . '</h1>
  3524. </div>
  3525. </div>
  3526. <div class="lockRecord">
  3527. <div class="contactPanel">
  3528. <table>
  3529. <tbody><tr><th>单位全称</th><td colspan="3"><input type="text" name="companyname" id="companyname" value="' . $companyInfo ['companyname'] . '"></td></tr>
  3530. <tr><th>地区</th><td colspan="3">
  3531. <select name="lv21" id="lv21" onchange="dislv(\'lv21\',22);">
  3532. <option value="0">请选择</option>';
  3533. foreach ( $districtinfo as $key => $value ) {
  3534. if ($value ['id'] == $dinfo [0] ['id'])
  3535. $html .= '<option selected value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  3536. else
  3537. $html .= '<option value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  3538. }
  3539. $html .= '</select>
  3540. <span id="mlv22">
  3541. <select id="lv22">
  3542. <option value="' . $dinfo [1] ['id'] . '">' . $dinfo [1] ['name'] . '</option>
  3543. </select>
  3544. </span>
  3545. <span id="mlv23">
  3546. <select id="lv23">
  3547. <option value="' . $dinfo [2] ['id'] . '">' . $dinfo [2] ['name'] . '</option>
  3548. </select>&nbsp;
  3549. </span>
  3550. </td></tr>
  3551. ';
  3552. $html .= '<tr><th>性质</th><td colspan="3">';
  3553. $ntre = explode ( ",", $companyInfo ['nature'] );
  3554. foreach ( $this->nature as $key => $value ) {
  3555. $falg = true;
  3556. foreach ( $ntre as $k => $v ) {
  3557. if ($value == $v) {
  3558. $falg = false;
  3559. $html .= '<label><input type="checkbox" checked name="nature[]" value="' . $value . '">' . $value . '</label>&nbsp;';
  3560. }
  3561. }
  3562. if ($falg)
  3563. $html .= '<label><input type="checkbox" name="nature[]" value="' . $value . '">' . $value . '</label>&nbsp;';
  3564. }
  3565. $html .= ' </td></tr>
  3566. <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>
  3567. <tr><th>单位地址</th><td colspan="3"><input type="text" name="address" id="address" value="' . $companyInfo ['address'] . '"> </td></tr>
  3568. <tr><th>乘车路线</th><td colspan="3"><input type="text" name="ride" id="ride" value="' . $companyInfo ['ride'] . '"> </td></tr>
  3569. <tr><th>地标建筑</th><td colspan="3"><input type="text" name="landmarks" id="landmarks" value="' . $companyInfo ['landmarks'] . '"> </td></tr>
  3570. <tr><th>住宿参考</th><td colspan="3"><input type="text" name="stay" id="stay" value="' . $companyInfo ['stay'] . '"> </td></tr>
  3571. <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>
  3572. </tbody></table>
  3573. <div class="bsAlert bsInfo">单位全称将与该单位已存在的客户进行同步;其他单位信息不会进行同步;<br>单位信息随该单位第一位客户录入,并作为“在这添加客户”的基础数据</div>
  3574. </div>
  3575. </div>
  3576. ';
  3577. echo json_encode ( array (
  3578. "success" => true,
  3579. 'html' => $html
  3580. ) );
  3581. die ();
  3582. }
  3583. } else
  3584. echo json_encode ( array (
  3585. "success" => false,
  3586. 'html' => ''
  3587. ) );
  3588. die ();
  3589. }
  3590. function ajaxGetCompany() {
  3591. $companyIdKey = $this->get_args ( 'companyId' ) ? $this->get_args ( 'companyId' ) : 0;
  3592. if (empty($companyIdKey)){
  3593. echo json_encode ( array (
  3594. "success" => false,
  3595. 'html' => ''
  3596. ) );
  3597. }
  3598. Doo::loadClass ( 'XDeode' );
  3599. $XDeode = new XDeode ( 5 );
  3600. $companyname = $XDeode->decode ( $companyIdKey );
  3601. if (! empty ( $companyname )) {
  3602. Doo::loadModel ( 'company' );
  3603. $company = new company ();
  3604. $companyInfo = $company->getOne ( array (
  3605. 'where' => "cid = '" . $companyname . "'",
  3606. 'asArray' => TRUE
  3607. ) );
  3608. if (! empty ( $companyInfo )) {
  3609. Doo::loadModel ( 'client' );
  3610. Doo::loadModel ( 'staff' );
  3611. Doo::loadModel ( 'client_staff' );
  3612. Doo::loadModel ( 'longle' );
  3613. $longle = new longle ();
  3614. $client_staff = new client_staff ();
  3615. $staff = new staff ();
  3616. $client = new client ();
  3617. Doo::loadModel ( 'district' );
  3618. $district = new district ();
  3619. $clientlist = $client->getClientByCompanyId ( $companyInfo ['cid'] );
  3620. $department = $client->getDepartment ( $companyInfo ['cid'] );
  3621. Doo::loadModel ( "tagCompanyNexus" );
  3622. Doo::loadModel ( "tagCompany" );
  3623. $tag = new tagCompany ();
  3624. $tag_client = new tagCompanyNexus ();
  3625. $tagId = $tag_client->getTagClientBySCid ( $companyInfo ['cid'], $this->staff [0] ['sid'] );
  3626. $taginfo = $tag->getTagByTidL ( $tagId ['tag'] );
  3627. $taghtml = "";
  3628. foreach ( $taginfo as $key => $value ) {
  3629. $taghtml .= '<span class="contactsTag tagCol-0' . $value ['colorid'] . '">' . $value ['name'] . '</span>';
  3630. }
  3631. $html = '<div class="header">
  3632. <h1 class="companyName"><div class="fR">
  3633. <a class="icon- add" node-syn="show" href="javascript:void(0)" title="同步地址信息">S</a>
  3634. <a href="javascript:void(0)" title="编辑单位" class="icon- edit" onclick="editByCompany(' . $companyInfo ['cid'] . ')" >I</a> |
  3635. <a title="在这个单位下添加客户" href="javascript:void(0)" class="icon- add" onclick="addClientByCompany(\'' . $companyIdKey . '\')" >H</a></div>' . $companyInfo ['companyname'] . '</h1>
  3636. <div class="contactPanel">
  3637. <table>
  3638. <tbody>
  3639. <tr><th>单位地区</th><td><span>' . $companyInfo ['local'] . '</span></td><th>单位性质</th><td>' . $companyInfo ['nature'] . '</td></tr>
  3640. <tr><th>单位地址</th><td colspan="3">' . $companyInfo ['address'] . '</td></tr>
  3641. <tr><th>单位乘车</th><td colspan="3">' . $companyInfo ['ride'] . '</td></tr>
  3642. <tr><th>单位地标</th><td colspan="3">' . $companyInfo ['landmarks'] . '</td></tr>
  3643. <tr><th>单位住宿</th><td colspan="3">' . $companyInfo ['stay'] . '</td></tr>
  3644. <tr><td colspan="4">
  3645. ' . $taghtml . '
  3646. </td></tr>
  3647. <tr><td colspan="4" >
  3648. <a class="button" style="display:none" node-synadd="true" href="javascript:void(0)">确定同步</a>
  3649. <span node-synAdd="msg" class="bsAlert bsSuccess fL hide"></span>
  3650. <span class="hide" id="skop">已选择 <span id="tl">0</span>/<span id="bl">' . sizeof ( $clientlist ) . '</span>
  3651. <input type="checkbox" name="CASYN[]" cas-all="TR" class="hide" value="19595" style="display: inline-block;">全选客户
  3652. </td>
  3653. </tr>
  3654. </tbody></table></div>
  3655. <h2 class="cate">';
  3656. $html .= '<a href="javascript:void(0)" onclick="departmentC()" class="now">不限</a>';
  3657. foreach ( $department as $key => $value ) {
  3658. if ($value != "")
  3659. $html .= '<a href="javascript:void(0)" onclick="departmentC(\'' . $value ['department'] . '\')">' . $value ['department'] . '</a>';
  3660. }
  3661. $html .= '</h2></div><script>$(".header .cate a").click(function(){
  3662. $(this).addClass("now").siblings("a").removeClass("now");
  3663. });
  3664. </script>';
  3665. $html .= '<div class="lockRecord autoHeightR2" >';
  3666. foreach ( $clientlist as $key => $value ) {
  3667. $scinfo = $client_staff->getClientByCid ( $value ['cid'] );
  3668. $staffinfo = $staff->getUserById ( $scinfo ['sid'] );
  3669. // 客户信息
  3670. $html .= '<div class="contactPanel" id="PART_' . $value ['department'] . '">
  3671. <h1><p class="fR">' . $staffinfo [0] ['category'] . '-<a href="javascript:void(0)" onclick="getStaffInfo(\'' . $staffinfo [0] ['username'] . '\')" >
  3672. ' . $staffinfo [0] ['username'] . '</a></p>
  3673. <input type="checkbox" name="CASYN[]" CAS-NUM="TR" class="hide" value="' . $value ['cid'] . '">
  3674. <a href="javascript:void(0)" onclick="getClientInfo(\'' . $value ['cid'] . '\')" class="clientName">' . $value ['clientname'] . ' </a>
  3675. <i class="icon- sport">' . $value ['priority'] . '</i><a class="icon- edit" title="编辑客户" href="javascript:clientEdit(' . $value ['cid'] . ')">I</a></h1><table>
  3676. <tbody><tr><th>性别</th><td>' . $value ['gender'] . '</td><th>昵称</th><td>' . $value ['nicename'] . '</td></tr>
  3677. <tr><th>部门</th><td>' . $value ['department'] . '</td><th>办公室</th><td>' . $value ['office'] . '</td></tr>
  3678. <tr><th>手机</th><td>' . $value ['telephone'] . '</td><th>电话</th><td>' . $value ['phone'] . '</td></tr>
  3679. <tr><th>QQ</th><td>' . $value ['qq'] . '</td><th>邮箱</th><td>' . $value ['email'] . '</td></tr>
  3680. <tr node-ck=fz ><th>备注</th><td >' . $value ['mark'] . '</td>
  3681. </tr>';
  3682. $longleinfo = $longle->getLongleByClientid ( $value ['cid'] );
  3683. if (empty ( $longleinfo )) {
  3684. $longleinfo = array (
  3685. 0 => array (
  3686. 'lid' => '',
  3687. 'key_num' => '',
  3688. 'product' => '',
  3689. 'statusT' => ''
  3690. )
  3691. );
  3692. }
  3693. $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>';
  3694. $districtList = $district->getbyidlist ( $value ['district'] );
  3695. $localdis = '';
  3696. foreach ( $districtList as $lov ) {
  3697. $localdis .= ' ' . $lov ['name'];
  3698. }
  3699. $html .= '
  3700. <tr node-synCom=pany style="display:none" ><th>客户地区</th><td colspan="4">' . $localdis . '</td></tr>
  3701. <tr node-synCom=pany style="display:none" ><th>客户地址</th><td colspan="4">' . $value ['address'] . '</td></tr>
  3702. <tr node-synCom=pany style="display:none" ><th>客户乘车</th><td colspan="4">' . $value ['ride'] . '</td></tr>
  3703. <tr node-synCom=pany style="display:none" ><th>客户地标</th><td colspan="4">' . $value ['landmarks'] . '</td></tr>
  3704. <tr node-synCom=pany style="display:none" ><th>客户住宿</th><td colspan="4">' . $value ['stay'] . '</td></tr>';
  3705. $html .= '</tbody></table></div>';
  3706. }
  3707. $html .= "</div><script type='text/javascript'>
  3708. $(\"a[node-syn=show]\").click(function() {
  3709. $(\"a[node-synadd='true']\").show();
  3710. $('input[CAS-NUM=TR]').show();
  3711. $('#skop').show();
  3712. $('tr[node-ck=fz]').hide();
  3713. $('tr[node-synCom=pany]').show();
  3714. });
  3715. $(\"input[cas-all='TR']\").click(function() {
  3716. if (this.checked) {
  3717. $(\"input[CAS-NUM=TR]:checkbox\").each(function() {
  3718. $(this).attr(\"checked\", true);
  3719. })
  3720. }else{
  3721. $(\"input[CAS-NUM=TR]:checkbox\").each(function() {
  3722. $(this).attr(\"checked\", false);
  3723. })
  3724. }
  3725. $('#tl').html($('input[CAS-NUM=TR]:checked').length);
  3726. });
  3727. $(\"input[CAS-NUM='TR']\").click(function() {
  3728. $('#tl').html($('input[CAS-NUM=TR]:checked').length);
  3729. });
  3730. $(\"a[node-synadd='true']\").click(function() {
  3731. var id_array=new Array();
  3732. $('input[CAS-NUM=TR]:checked').each(function(){
  3733. id_array.push($(this).val());
  3734. });
  3735. if(id_array.length==0){
  3736. alert('未选中客户');
  3737. }else{
  3738. var idstr=id_array.join(',');
  3739. var url='/ajaxSetCompanyAddress';
  3740. $.ajax({
  3741. url:url,
  3742. type: 'post',
  3743. cache: false,
  3744. dataType: 'json',
  3745. data: {
  3746. cidString:idstr,
  3747. company:" . $companyInfo ['cid'] . "
  3748. },
  3749. global: true,
  3750. success: function(data){
  3751. if(data.status>0){
  3752. $(\"span[node-synAdd=msg]\").html('同步成功');
  3753. for(var i=0;i<id_array.length;i++){
  3754. $(\"td[node-address=company_\"+id_array[i]+\"]\").html('" . $companyInfo ['address'] . "');
  3755. }
  3756. $(\"a[node-synadd='true']\").hide();
  3757. $('input[CAS-NUM=TR]').hide();
  3758. $('#skop').hide();
  3759. $(\"span[node-synAdd=msg]\").show().delay(2000).fadeOut();
  3760. }else if(data.status==-1){
  3761. $(\"span[node-synAdd=msg]\").html('操作不成功');
  3762. $(\"span[node-synAdd=msg]\").show().delay(2000).fadeOut();
  3763. }else if(data.status==0){
  3764. $(\"span[node-synAdd=msg]\").html('地址已同步过');
  3765. $(\"span[node-synAdd=msg]\").show().delay(2000).fadeOut();
  3766. }
  3767. },
  3768. error:function(err){
  3769. }
  3770. });
  3771. }
  3772. });
  3773. autoFlashHeight();
  3774. </script>";
  3775. echo json_encode ( array (
  3776. "success" => true,
  3777. 'html' => $html
  3778. ) );
  3779. die ();
  3780. }
  3781. }
  3782. die ();
  3783. }
  3784. function ajaxSetCompanyAddress() {
  3785. $cidString = $this->get_args ( 'cidString' ) ? $this->get_args ( 'cidString' ) : "";
  3786. $companyId = $this->get_args ( 'company' ) && is_numeric ( $this->get_args ( 'company' ) ) ? $this->get_args ( 'company' ) : 0;
  3787. if (! empty ( $cidString ) && ! empty ( $companyId )) {
  3788. Doo::loadModel ( 'client' );
  3789. $client = new client ();
  3790. Doo::loadModel ( 'company' );
  3791. $company = new company ();
  3792. $cidList = explode ( ',', $cidString );
  3793. foreach ( $cidList as $value ) {
  3794. if (! is_numeric ( $value ))
  3795. die ( 'illegal request3' );
  3796. }
  3797. $companyInfo = $company->getOne ( array (
  3798. 'where' => "cid = '" . $companyId . "'",
  3799. 'asArray' => TRUE
  3800. ) );
  3801. $client->address = $companyInfo ['address'];
  3802. $client->ride = $companyInfo ['ride'];
  3803. $client->landmarks = $companyInfo ['landmarks'];
  3804. $client->stay = $companyInfo ['stay'];
  3805. $client->local = $companyInfo ['local'];
  3806. $client->district = $companyInfo ['district'];
  3807. $falg = $client->update ( array (
  3808. 'where' => 'companyid =' . $companyInfo ['cid'] . ' and cid in (' . $cidString . ')'
  3809. ) );
  3810. echo json_encode ( array (
  3811. 'status' => $falg,
  3812. 'msg' => 'illegal request2'
  3813. ) );
  3814. die ();
  3815. }
  3816. echo json_encode ( array (
  3817. 'status' => - 1,
  3818. 'msg' => 'illegal request'
  3819. ) );
  3820. die ();
  3821. }
  3822. function checkclicomname() { // 地区区分
  3823. $companyname = $this->get_args ( 'companyname' ) ? $this->get_args ( 'companyname' ) : "";
  3824. $clientname = $this->get_args ( 'clientname' ) ? $this->get_args ( 'clientname' ) : "";
  3825. $district1 = $this->get_args ( 'district1' ) ? $this->get_args ( 'district1' ) : 0;
  3826. $district2 = $this->get_args ( 'district2' ) ? $this->get_args ( 'district2' ) : 0;
  3827. $district3 = $this->get_args ( 'district3' ) ? $this->get_args ( 'district3' ) : 0;
  3828. Doo::loadModel ( 'client' );
  3829. $client = new client ();
  3830. $local = $district1 . "," . $district2 . "," . $district3;
  3831. $companyname = trim ( $companyname );
  3832. $clientname = trim ( $clientname );
  3833. $clientinfo = $client->getClientToName ( $clientname, $companyname, $local );
  3834. if (! empty ( $clientinfo )) {
  3835. echo json_encode ( array (
  3836. 'success' => false
  3837. ) );
  3838. } else {
  3839. echo json_encode ( array (
  3840. 'success' => true
  3841. ) );
  3842. }
  3843. }
  3844. function ajaxGetClientInfoN() {
  3845. $clientname = $this->get_args ( 'client' ) ? $this->get_args ( 'client' ) : "";
  3846. if ($clientname == "") {
  3847. echo json_encode ( array (
  3848. "success" => false
  3849. ) );
  3850. die ();
  3851. }
  3852. Doo::loadModel ( 'client' );
  3853. Doo::loadModel ( 'client_staff' );
  3854. Doo::loadModel ( 'longle' );
  3855. Doo::loadModel ( 'company' );
  3856. Doo::loadModel ( 'service_log' );
  3857. $service_log = new service_log ();
  3858. $company = new company ();
  3859. $longle = new longle ();
  3860. $client = new client ();
  3861. $client_staff = new client_staff ();
  3862. $clientInfo = $client->getOne ( array (
  3863. "where" => ' cid like "' . $clientname . '"',
  3864. 'asArray' => TRUE
  3865. ) );
  3866. if (empty ( $clientInfo )) {
  3867. echo json_encode ( array (
  3868. "success" => false,
  3869. 'html' => ''
  3870. ) );
  3871. die ();
  3872. }
  3873. // 获取锁
  3874. $longleInfo = $longle->getLongleByClientid ( $clientname );
  3875. $k = "";
  3876. foreach ( $longleInfo as $key => $value ) {
  3877. if ($value ['status'] == 6 || $value ['status'] == 7)
  3878. $k .= '<a href="javascript:void(0)" class="disenable" onclick="getLock(' . $value ['lid'] . ')" >' . $value ['key_num'] . '/' . $value ['product'] . '/' . $value ['statusT'] . '</a>&nbsp; ';
  3879. else
  3880. $k .= '<a href="javascript:void(0)" onclick="getLock(' . $value ['lid'] . ')" >' . $value ['key_num'] . '/' . $value ['product'] . '/' . $value ['statusT'] . '</a>&nbsp; ';
  3881. }
  3882. // 获取办事人
  3883. $staffInfo = $client_staff->getClientByCid ( $clientInfo ['cid'] );
  3884. // 获取公司信息
  3885. $companyInfo = $company->getCompanyByCid ( $clientInfo ['companyid'] );
  3886. $serviceLog = $service_log->getServiceByClientid ( $clientInfo ['cid'] );
  3887. $u = "";
  3888. $order = array (
  3889. "\r\n",
  3890. "\n",
  3891. "\r"
  3892. );
  3893. $replace = '</br>';
  3894. foreach ( $serviceLog as $key => $value ) {
  3895. $datetime = explode ( "-", $value ['date'] );
  3896. $u .= '<div class="infoFlowList">
  3897. <div class="dateTitle">
  3898. <em class="month"><span class="num">' . $datetime ['1'] . '</span><span class="text">-' . $datetime ['2'] . '</span></em>
  3899. <span class="year">' . $datetime ['0'] . '</span>
  3900. </div>
  3901. <ul class="flowList">';
  3902. if ($value ['status'] == 1)
  3903. $u .= '<li class="item iconService">上门服务</li>';
  3904. elseif ($value ['status'] == 2)
  3905. $u .= '<li class="item iconPhone">电话拜访</li>';
  3906. elseif ($value ['status'] == 3)
  3907. $u .= '<li class="item iconOther">其他</li>';
  3908. $u .= '
  3909. <li class="item">' . $value ['category'] . '<a href="javascript:void(0)" onclick="getStaffInfo(\'' . $value ['staffname'] . '\')" >' . $value ['staffname'] . '</a></li>
  3910. <li class="item">
  3911. ' . str_replace ( $order, $replace, $value ['mark'] ) . '
  3912. </li>
  3913. </ul>
  3914. </div>';
  3915. }
  3916. Doo::loadModel ( "tag_client" );
  3917. Doo::loadModel ( "tag" );
  3918. $tag = new tag ();
  3919. $tag_client = new tag_client ();
  3920. $tagId = $tag_client->getTagClientBySCid ( $clientInfo ['cid'], $this->staff [0] ['sid'] );
  3921. $taginfo = $tag->getTagByTidL ( $tagId ['tag'] );
  3922. // $taghtml="";
  3923. //
  3924. // foreach ($taginfo as $key=>$value){
  3925. // $taghtml.='<span class="contactsTag tagCol-0'.$value['colorid'].'">'.$value['name'].'</span>';
  3926. // }
  3927. $mhtml = "";
  3928. $dhtml = "";
  3929. for($month = 1; $month <= 12; $month ++) {
  3930. if (date ( "m" ) == $month)
  3931. $mhtml .= '<option selected value="' . $month . '">' . $month . '月</option>';
  3932. else
  3933. $mhtml .= '<option value="' . $month . '">' . $month . '月</option>';
  3934. }
  3935. for($day = 1; $day <= 31; $day ++) {
  3936. if (date ( "d" ) == $day)
  3937. $dhtml .= '<option selected value="' . $day . '">' . $day . '日</option>';
  3938. else
  3939. $dhtml .= '<option value="' . $day . '">' . $day . '日</option>';
  3940. }
  3941. // $b="";
  3942. // if(!empty($staffInfo))
  3943. // $b='<p class="fR">'.$staffInfo['category'].'-<a href="javascript:void(0)" onclick="getStaffInfo(\''.$staffInfo['username'].'\')" >'.$staffInfo['username'].'</a></p>'.$clientInfo['clientname'].' ';
  3944. //
  3945. $m = "";
  3946. if (! empty ( $companyInfo )) {
  3947. $m = '
  3948. <table width="100%">
  3949. <tbody>
  3950. <tr><th>单位全称</th><td colspan="3"><a href="javascript:void(0)" >' . $companyInfo [0] ['companyname'] . '</a></td></tr>
  3951. <tr><th>地区</th><td>' . $companyInfo [0] ['local'] . '</td><th>部门/职位</th><td>' . $clientInfo ['department'] . '/' . $clientInfo ['position'] . '</td></tr>
  3952. <tr><th>传真</th><td>' . $companyInfo [0] ['fax'] . '</td><th>办公室</th><td>' . $clientInfo ['office'] . '</td></tr>
  3953. <tr><th>单位地址</th><td colspan="3">' . $companyInfo [0] ['address'] . '</td></tr>
  3954. <tr><th>乘车路线</th><td colspan="3">' . $companyInfo [0] ['ride'] . '</td></tr>
  3955. <tr><th>地标建筑</th><td colspan="3">' . $companyInfo [0] ['landmarks'] . '</td></tr>
  3956. <tr><th>参考住宿</th><td colspan="3">' . $clientInfo ['stay'] . '</td></tr>
  3957. <tr><th>单位主页</th><td colspan="3">' . $clientInfo ['webservice'] . '</td></tr>
  3958. </tbody></table>
  3959. ';
  3960. }
  3961. $clientHtml = array (
  3962. 'html' => '
  3963. <div class="modal-dialog ">
  3964. <div class="modal-content">
  3965. <div class="modal-header">
  3966. <h3><span class="fR"><a>' . $staffInfo ['category'] . ' ' . $staffInfo ['username'] . '</a></span>' . $clientInfo ['clientname'] . '</h3>
  3967. </div>
  3968. <div class="modal-body">
  3969. <div class="modalClientTable">
  3970. <table width="100%">
  3971. <tbody><tr><th>性别</th><td>' . $clientInfo ['gender'] . '</td><th>昵称</th><td>' . $clientInfo ['nicename'] . '</td></tr>
  3972. <tr><th>手机</th><td>' . $clientInfo ['telephone'] . '</td><th>QQ</th><td>' . $clientInfo ['qq'] . '</td></tr>
  3973. <tr><th>电话</th><td>' . $clientInfo ['phone'] . '</td><th>邮箱</th><td>' . $clientInfo ['email'] . '</td></tr>
  3974. <tr><th>软件锁</th><td colspan="3"> <div class="lockContent">' . $k . '</div></td></tr>
  3975. <tr><td colspan="4">
  3976. </td></tr>
  3977. </tbody>
  3978. </table>
  3979. ' . $m . '
  3980. <div class="clearfix">
  3981. ' . $u . '
  3982. </div>
  3983. </div>
  3984. </div>
  3985. <div class="modal-footer">
  3986. <a href="javascript:void(0)" onclick="closeClick()" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a>
  3987. </div>
  3988. </div></div>'
  3989. );
  3990. echo json_encode ( $clientHtml );
  3991. }
  3992. function ajaxGetClientInfo() {
  3993. $clientname = $this->get_args ( 'client' )&&is_numeric($this->get_args ( 'client' )) ? $this->get_args ( 'client' ) : "";
  3994. if ($clientname == "") {
  3995. echo json_encode ( array (
  3996. "success" => false
  3997. ) );
  3998. die ();
  3999. }
  4000. Doo::loadModel ( 'client' );
  4001. Doo::loadModel ( 'client_staff' );
  4002. Doo::loadModel ( 'longle' );
  4003. Doo::loadModel ( 'company' );
  4004. Doo::loadModel ( 'service_log' );
  4005. Doo::loadModel ( "district" );
  4006. $district = new district ();
  4007. $service_log = new service_log ();
  4008. $company = new company ();
  4009. $longle = new longle ();
  4010. $client = new client ();
  4011. $client_staff = new client_staff ();
  4012. $clientInfo = $client->getOne ( array (
  4013. "where" => ' cid = "' . $clientname . '"',
  4014. 'asArray' => TRUE
  4015. ) );
  4016. if (empty ( $clientInfo )) {
  4017. echo json_encode ( array (
  4018. "success" => false,
  4019. 'html' => ''
  4020. ) );
  4021. die ();
  4022. }
  4023. // 获取锁
  4024. $longleInfo = $longle->getLongleByClientid ( $clientInfo ['cid'] );
  4025. $k = "";
  4026. foreach ( $longleInfo as $key => $value ) {
  4027. if ($value ['status'] == 6 || $value ['status'] == 7)
  4028. $k .= '<a href="javascript:void(0)" class="disenable" onclick="getLock(' . $value ['lid'] . ')" >' . $value ['key_num'] . '/' . $value ['product'] . '/' . $value ['statusT'] . '</a>&nbsp; ';
  4029. else
  4030. $k .= '<a href="javascript:void(0)" onclick="getLock(' . $value ['lid'] . ')" >' . $value ['key_num'] . '/' . $value ['product'] . '/' . $value ['statusT'] . '</a>&nbsp; ';
  4031. }
  4032. // 获取办事人
  4033. $staffInfo = $client_staff->getClientByCid ( $clientInfo ['cid'] );
  4034. $b = "";
  4035. if (! empty ( $staffInfo ))
  4036. $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>';
  4037. // 获取公司信息
  4038. $companyInfo = $company->getCompanyByCid ( $clientInfo ['companyid'] );
  4039. $serviceLog = $service_log->getServiceByClientid ( $clientInfo ['cid'] );
  4040. $local = $district->getbyidlist ( $clientInfo ['district'] );
  4041. if (! isset ( $local [1] ))
  4042. $local [1] ['name'] = "";
  4043. if (! isset ( $local [2] ))
  4044. $local [2] ['name'] = "";
  4045. $m = "";
  4046. if (! empty ( $companyInfo )) {
  4047. $m = '<div class="contactPanel">
  4048. <table>
  4049. <tbody>
  4050. <tr><th>单位全称</th><td colspan="3"><a href="javascript:void(0)" onclick="getCompany(\'' . $companyInfo [0] ['cidKey'] . '\')">' . $companyInfo [0] ['companyname'] . '</a></td></tr>
  4051. <tr><th>单位主页</th><td colspan="3">' . $clientInfo ['webservice'] . '</td></tr>
  4052. <tr><th>客户地区</th><td>' . $local [0] ['name'] . ',' . $local [1] ['name'] . ',' . $local [2] ['name'] . '</td><th>部门/职位</th><td>' . $clientInfo ['department'] . '/' . $clientInfo ['position'] . '</td></tr>
  4053. <tr><th>客户传真</th><td>' . $clientInfo ['fax'] . '</td><th>办公室</th><td>' . $clientInfo ['office'] . '</td></tr>
  4054. <tr><th>客户地址</th><td colspan="3">' . $clientInfo ['address'] . '</td></tr>
  4055. <tr><th>客户乘车</th><td colspan="3">' . $clientInfo ['ride'] . '</td></tr>
  4056. <tr><th>客户地标</th><td colspan="3">' . $clientInfo ['landmarks'] . '</td></tr>
  4057. <tr><th>客户住宿</th><td colspan="3">' . $clientInfo ['stay'] . '</td></tr>
  4058. </tbody></table>
  4059. </div>';
  4060. }
  4061. $u = "";
  4062. $order = array (
  4063. "\r\n",
  4064. "\n",
  4065. "\r"
  4066. );
  4067. $replace = '</br>';
  4068. foreach ( $serviceLog as $key => $value ) {
  4069. $datetime = explode ( "-", $value ['date'] );
  4070. $u .= '<div class="infoFlowList">
  4071. <div class="dateTitle">
  4072. <em class="month"><span class="num">' . $datetime ['1'] . '</span><span class="text">-' . $datetime ['2'] . '</span></em>
  4073. <span class="year">' . $datetime ['0'] . '</span>
  4074. </div>
  4075. <ul class="flowList">';
  4076. if ($value ['status'] == 1)
  4077. $u .= '<li class="item iconService">上门服务<';
  4078. elseif ($value ['status'] == 2)
  4079. $u .= '<li class="item iconPhone">电话拜访<';
  4080. elseif ($value ['status'] == 3)
  4081. $u .= '<li class="item iconOther">其他<';
  4082. $u .= $value ['category'] . '<a href="javascript:void(0)" onclick="getStaffInfo(\'' . $value ['staffname'] . '\')" >' . $value ['staffname'] . '</a></li>
  4083. <li class="item">
  4084. ' . str_replace ( $order, $replace, $value ['mark'] ) . '
  4085. </li>
  4086. </ul>
  4087. </div>';
  4088. }
  4089. Doo::loadModel ( "tag_client" );
  4090. Doo::loadModel ( "tag" );
  4091. $tag = new tag ();
  4092. $tag_client = new tag_client ();
  4093. $tagId = $tag_client->getTagClientBySCid ( $clientInfo ['cid'], $this->staff [0] ['sid'] );
  4094. $taginfo = $tag->getTagByTidL ( $tagId ['tag'] );
  4095. $taghtml = "";
  4096. foreach ( $taginfo as $key => $value ) {
  4097. $taghtml .= '<span class="contactsTag tagCol-0' . $value ['colorid'] . '">' . $value ['name'] . '</span>';
  4098. }
  4099. $mhtml = "";
  4100. $dhtml = "";
  4101. $yhtml = "";
  4102. for($year = 2020; $year >= 2004; $year --) {
  4103. if (date ( "Y" ) == $year)
  4104. $yhtml .= '<option selected value="' . $year . '">' . $year . '年</option>';
  4105. else
  4106. $yhtml .= '<option value="' . $year . '">' . $year . '年</option>';
  4107. }
  4108. for($month = 1; $month <= 12; $month ++) {
  4109. if (date ( "m" ) == $month)
  4110. $mhtml .= '<option selected value="' . $month . '">' . $month . '月</option>';
  4111. else
  4112. $mhtml .= '<option value="' . $month . '">' . $month . '月</option>';
  4113. }
  4114. for($day = 1; $day <= 31; $day ++) {
  4115. if (date ( "d" ) == $day)
  4116. $dhtml .= '<option selected value="' . $day . '">' . $day . '日</option>';
  4117. else
  4118. $dhtml .= '<option value="' . $day . '">' . $day . '日</option>';
  4119. }
  4120. $clientHtml = array (
  4121. 'html' => '<div class="contactInfo clearfix">
  4122. <div class="contactPanel">
  4123. <h1>' . $b . '<a data-original-title="编辑客户" data-toggle="ctooltip" data-placement="right" href="javascript:clientEdit(' . $clientInfo ['cid'] . ')" class="icon- edit">I</a></h1>
  4124. <table>
  4125. <tbody><tr><th>性别</th><td>' . $clientInfo ['gender'] . '</td><th>昵称</th><td>' . $clientInfo ['nicename'] . '</td></tr>
  4126. <tr><th>手机</th><td>' . $clientInfo ['telephone'] . '</td><th>QQ</th><td>' . $clientInfo ['qq'] . '</td></tr>
  4127. <tr><th>电话</th><td>' . $clientInfo ['phone'] . '</td><th>邮箱</th><td>' . $clientInfo ['email'] . '</td></tr>
  4128. <tr><th>软件锁</th><td colspan="3"><div class="lockContent">' . $k . '</div></td></tr>
  4129. <tr><th>备注</th><td colspan="3">' . $clientInfo ['mark'] . '</td></tr>
  4130. <tr><td colspan="4">
  4131. ' . $taghtml . '
  4132. </td></tr>
  4133. </tbody></table>
  4134. </div>
  4135. ' . $m . '
  4136. </div>
  4137. <div class="lockRecord autoHeightR1" >
  4138. <!--添加记录按钮-->
  4139. <div class="addRecord addRecordButton clearfix" >
  4140. <a href="#" onclick="slideupInfo(this)">+ 打开添加服务记录</a>
  4141. </div>
  4142. <!--添加记录-->
  4143. <div class="addRecord addRecordForm clearfix hide">
  4144. <a onclick="slidedownInfo(this)" class="fR slidedownInfo">- 关闭添加记录</a>
  4145. <form name="lk" action="/addServiceLog" method="post" >
  4146. <div class="control-group">
  4147. <div class="controls">
  4148. <label class="radio inline">
  4149. <input type="radio" name="logstatus" id="status" checked value="2">电话拜访
  4150. </label>
  4151. <label class="radio inline">
  4152. <input type="radio" name="logstatus" id="status" value="1" >上门服务
  4153. </label>
  4154. <label class="radio inline">
  4155. <input type="radio" name="logstatus" id="status" value="3">其他
  4156. </label>
  4157. </div>
  4158. </div>
  4159. <div class="control-group">
  4160. <div class="controls">时间:
  4161. <select name="y" id="y">
  4162. ' . $yhtml . '
  4163. </select>
  4164. <select name="m" id="m">
  4165. ' . $mhtml . '
  4166. </select>
  4167. <select name="d" id="d">
  4168. ' . $dhtml . '
  4169. </select>
  4170. </div>
  4171. </div>
  4172. <link href="' . WEB_SITE_GLOBAL . 'css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
  4173. <!--添加记录-备注-->
  4174. <!--<div class="control-group">
  4175. <div class="controls">
  4176. <select name="date" id="date">
  4177. <option value="2013">2013</option>
  4178. </select>
  4179. </div>
  4180. </div>-->
  4181. <div class="control-group">
  4182. <div class="controls" onclick="slideupInfo()">
  4183. <textarea name="mark" id="mark" style="width:95%" rows="5"></textarea>
  4184. <div class="bsAlert bsWarning"><b>含泪告知:</b>客户记录暂时无法修改!删除!,添加时请谨慎。点击确定添加成功后,信息会立即出现在下方!注意咯,别猛戳‘确定添加’导致重复添加了哦~</div>
  4185. </div>
  4186. </div>
  4187. <div class="control-group">
  4188. <div class="controls">
  4189. <div style="display:inline-block;margin-right:10px"><label><input name="Remind" onclick="reFK()" type="checkbox" value="1"> 添加提醒</label></div>
  4190. <span id="reHL" class="hide">
  4191. <div>
  4192. 限期:
  4193. <input type="date" name="time" id="dtp_input2" value="" class="hide"/>
  4194. </div>
  4195. <div>
  4196. 备注:<input id="remark" name="remark" type="text"></span>
  4197. </div>
  4198. </div>
  4199. <div class="control-group">
  4200. <div class="controls clearfix">
  4201. <input type="button" value="确定添加" id="conSer" onclick="aServiceLog(\'' . $this->staff [0] ['category'] . '\',\'' . $this->staff [0] ['username'] . '\',' . $clientInfo ['cid'] . ')" class="button"></input>
  4202. <div id="load"></div>
  4203. </div>
  4204. </div>
  4205. </div>
  4206. </form>
  4207. </div>
  4208. <!--添加记录按钮-->
  4209. <!--记录列表-->
  4210. <div id="kl"></div>
  4211. ' . $u . '
  4212. <script type="text/javascript">autoFlashHeight();</script> </div>'
  4213. );
  4214. echo json_encode ( $clientHtml );
  4215. }
  4216. function ajaxGetCompanyInfo() {
  4217. }
  4218. function checkClient() {
  4219. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
  4220. $company = $this->get_args ( 'company' ) ? $this->get_args ( 'company' ) : "";
  4221. if (! empty ( $name )&&! empty ( $company )) {
  4222. Doo::loadModel ( 'client' );
  4223. $client = new client ();
  4224. $clientInfo = $client->getClientByName2 ( $name, $company );
  4225. if (! empty ( $clientInfo ))
  4226. echo json_encode ( array (
  4227. "success" => true
  4228. ) );
  4229. else
  4230. echo json_encode ( array (
  4231. "success" => false
  4232. ) );
  4233. } else {
  4234. echo json_encode ( array (
  4235. "success" => false
  4236. ) );
  4237. }
  4238. }
  4239. function searchClient() {
  4240. $searchDbInforItem = $this->get_args ( 'searchDbInforItem' ) ? $this->get_args ( 'searchDbInforItem' ) : "";
  4241. if (! empty ( $searchDbInforItem )) {
  4242. Doo::loadModel ( 'client' );
  4243. $client = new client ();
  4244. $clientInfo = $client->getClientByName ( $searchDbInforItem );
  4245. echo json_encode ( $clientInfo );
  4246. } else {
  4247. echo json_encode ( array (
  4248. 0 => array (
  4249. 'clientname' => ''
  4250. )
  4251. ) );
  4252. }
  4253. }
  4254. function searchCompany() {
  4255. $searchDbInforItem = $this->get_args ( 'searchDbInforItem' ) ? $this->get_args ( 'searchDbInforItem' ) : "";
  4256. if (! empty ( $searchDbInforItem )) {
  4257. Doo::loadModel ( 'company' );
  4258. $company = new company ();
  4259. $clientInfo = $company->searchCompany ( $searchDbInforItem );
  4260. echo json_encode ( $clientInfo );
  4261. } else {
  4262. echo json_encode ( array (
  4263. 0 => array (
  4264. 'companyname' => '',
  4265. 'local' => ''
  4266. )
  4267. ) );
  4268. }
  4269. }
  4270. function checkCompany() {
  4271. $searchDbInforItem = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
  4272. $searchDbInforItem = explode ( '-', $searchDbInforItem );
  4273. $this->nature ['naturelenght'] = 15;
  4274. Doo::loadModel ( 'district' );
  4275. $district = new district ();
  4276. $d = $district->get_lv ( 1 );
  4277. $html = '<option vlaue="0">请选择</option>';
  4278. foreach ( $d as $key => $value ) {
  4279. $html .= '<option value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  4280. }
  4281. $this->nature ['district'] = $html;
  4282. if (! empty ( $searchDbInforItem )) {
  4283. Doo::loadModel ( 'company' );
  4284. $company = new company ();
  4285. if (! isset ( $searchDbInforItem [1] )) {
  4286. echo json_encode ( array (
  4287. "success" => false,
  4288. 'nature' => $this->nature
  4289. ) );
  4290. die ();
  4291. }
  4292. $clientInfo = $company->getCompanyByName ( $searchDbInforItem [0], $searchDbInforItem [1] );
  4293. if (! empty ( $clientInfo ))
  4294. echo json_encode ( array (
  4295. "success" => true,
  4296. 'data' => $clientInfo
  4297. ) );
  4298. else
  4299. echo json_encode ( array (
  4300. "success" => false,
  4301. 'nature' => $this->nature
  4302. ) );
  4303. } else {
  4304. echo json_encode ( array (
  4305. "success" => false,
  4306. 'nature' => $this->nature
  4307. ) );
  4308. }
  4309. }
  4310. function checkLongle() {
  4311. $searchDbInforItem = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
  4312. $searchDbInforItem = explode ( ' ', $searchDbInforItem );
  4313. if (! empty ( $searchDbInforItem )) {
  4314. Doo::loadModel ( 'longle' );
  4315. $longle = new longle ();
  4316. $clientInfo = $longle->getLongleBykeynum ( $searchDbInforItem [0] );
  4317. if (! empty ( $clientInfo ))
  4318. echo json_encode ( array (
  4319. "success" => true
  4320. ) );
  4321. else
  4322. echo json_encode ( array (
  4323. "success" => false
  4324. ) );
  4325. } else {
  4326. echo json_encode ( array (
  4327. "success" => false
  4328. ) );
  4329. }
  4330. }
  4331. function searchLongle() {
  4332. $searchDbInforItem = $this->get_args ( 'searchDbInforItem' ) ? $this->get_args ( 'searchDbInforItem' ) : "";
  4333. if (! empty ( $searchDbInforItem )) {
  4334. Doo::loadModel ( 'longle' );
  4335. $longle = new longle ();
  4336. $longleInfo = $longle->getLongleBykeynum2 ( $searchDbInforItem );
  4337. echo json_encode ( $longleInfo );
  4338. } else {
  4339. echo json_encode ( array (
  4340. 0 => array (
  4341. 'clientname' => ''
  4342. )
  4343. ) );
  4344. }
  4345. }
  4346. function updateChangeCompany() {
  4347. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4348. $clientID = $this->get_args ( 'clientID' ) ? $this->get_args ( 'clientID' ) : 0;
  4349. $companyname = $this->get_args ( 'companyname' ) ? $this->get_args ( 'companyname' ) : "";
  4350. Doo::loadModel ( 'company' );
  4351. Doo::loadModel ( 'client' );
  4352. $client = new client ();
  4353. $company = new company ();
  4354. $companyname = explode ( "-", $companyname );
  4355. if (isset ( $companyname [1] ))
  4356. $k = $company->getCompanyByName ( $companyname [0], $companyname [1] );
  4357. else
  4358. $k = array ();
  4359. if (! empty ( $cid ) && ! empty ( $k ) && ! empty ( $clientID )) {
  4360. $client->cid = $clientID;
  4361. $client->companyid = $cid;
  4362. $client->companyname = $companyname [0];
  4363. $client->update ();
  4364. } else {
  4365. $local1 = $this->get_args ( 'lv21' ) ? $this->get_args ( 'lv21' ) : 0;
  4366. $local2 = $this->get_args ( 'lv22' ) ? $this->get_args ( 'lv22' ) : 0;
  4367. $local3 = $this->get_args ( 'lv23' ) ? $this->get_args ( 'lv23' ) : 0;
  4368. Doo::loadModel ( 'district' );
  4369. $district = new district ();
  4370. // 更新公司信息
  4371. $lv1 = $district->getbyid ( $local1 );
  4372. $lv2 = $district->getbyid ( $local2 );
  4373. $lv3 = $district->getbyid ( $local3 );
  4374. if (empty ( $local1 ) || empty ( $local2 ))
  4375. return "/";
  4376. if (! empty ( $local1 ) && ! empty ( $local2 ))
  4377. $company->local = $lv1 [0] ['name'] . "," . $lv2 [0] ['name'] . "," . $lv3 [0] ['name'];
  4378. if (! empty ( $local1 ) && ! empty ( $local2 ))
  4379. $company->district = $local1 . "," . $local2 . "," . $local3;
  4380. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  4381. $fax = $this->get_args ( 'fax' ) ? $this->get_args ( 'fax' ) : "";
  4382. $webservice = $this->get_args ( 'webservice' ) ? $this->get_args ( 'webservice' ) : "";
  4383. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  4384. $landmarks = $this->get_args ( 'landmarks' ) ? $this->get_args ( 'landmarks' ) : "";
  4385. $stay = $this->get_args ( 'stay' ) ? $this->get_args ( 'stay' ) : "";
  4386. $ride = $this->get_args ( 'ride' ) ? $this->get_args ( 'ride' ) : "";
  4387. $nature = implode ( ",", $nature );
  4388. $company->companyname = $companyname [0];
  4389. $company->ride = $ride;
  4390. $company->fax = $fax;
  4391. $company->webservice = $webservice;
  4392. $company->address = $address;
  4393. $company->landmarks = $landmarks;
  4394. $company->stay = $stay;
  4395. $company->nature = $nature;
  4396. $cid = $company->insert ();
  4397. $client->cid = $clientID;
  4398. $client->companyid = $cid;
  4399. $client->companyname = $companyname [0];
  4400. $client->update ();
  4401. }
  4402. return "/contacts";
  4403. }
  4404. function AddClientInfo() { // 不编辑公司
  4405. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4406. $clientname = $this->get_args ( 'clientname' ) ? $this->get_args ( 'clientname' ) : "";
  4407. $gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : "";
  4408. $nicename = $this->get_args ( 'nicename' ) ? $this->get_args ( 'nicename' ) : "";
  4409. $telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : "";
  4410. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  4411. $email = $this->get_args ( 'email' ) ? $this->get_args ( 'email' ) : "";
  4412. $unit = $this->get_args ( 'unit' ) ? $this->get_args ( 'unit' ) : "";
  4413. $fax = $this->get_args ( 'fax' ) ? $this->get_args ( 'fax' ) : "";
  4414. $webservice = $this->get_args ( 'webservice' ) ? $this->get_args ( 'webservice' ) : "";
  4415. $department = $this->get_args ( 'department' ) ? $this->get_args ( 'department' ) : "";
  4416. $position = $this->get_args ( 'position' ) ? $this->get_args ( 'position' ) : "";
  4417. $office = $this->get_args ( 'office' ) ? $this->get_args ( 'office' ) : "";
  4418. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  4419. $ride = $this->get_args ( 'ride' ) ? $this->get_args ( 'ride' ) : "";
  4420. $landmarks = $this->get_args ( 'landmarks' ) ? $this->get_args ( 'landmarks' ) : "";
  4421. $qq = $this->get_args ( 'qq' ) ? $this->get_args ( 'qq' ) : "";
  4422. $priority = $this->get_args ( 'priority' ) ? $this->get_args ( 'priority' ) : 5;
  4423. $stay = $this->get_args ( 'stay' ) ? $this->get_args ( 'stay' ) : "";
  4424. $mark = $this->get_args ( 'mark' ) ? $this->get_args ( 'mark' ) : "";
  4425. $lv21 = $this->get_args ( 'lv21' ) ? $this->get_args ( 'lv21' ) : "";
  4426. $lv22 = $this->get_args ( 'lv22' ) ? $this->get_args ( 'lv22' ) : "";
  4427. $lv23 = $this->get_args ( 'lv23' ) ? $this->get_args ( 'lv23' ) : "";
  4428. if (! empty ( $cid ) && ! empty ( $clientname )) {
  4429. Doo::loadModel ( 'client' );
  4430. Doo::loadModel ( 'district' );
  4431. $district = new district ();
  4432. $client = new client ();
  4433. $client->cid = $cid;
  4434. $client->clientname = $clientname;
  4435. $client->gender = $gender;
  4436. $client->nicename = $nicename;
  4437. $client->telephone = $telephone;
  4438. $client->phone = $phone;
  4439. $client->email = $email;
  4440. // if(!empty($unit)){
  4441. // $client->unit=$unit;
  4442. // $client->companyname=$unit;
  4443. // }
  4444. if (! empty ( $lv21 ) && ! empty ( $lv22 ) && ! empty ( $lv23 )) {
  4445. $client->district = $lv21 . "," . $lv22 . "," . $lv23;
  4446. }
  4447. if (! empty ( $client->district )) {
  4448. $districtList = $district->find ( array (
  4449. 'where' => 'id in(' . $client->district . ')',
  4450. 'asArray' => true
  4451. ) );
  4452. $jsonString = array ();
  4453. foreach ( $districtList as $value ) {
  4454. array_push ( $jsonString, $value ['name'] );
  4455. }
  4456. $jsonString = implode ( ",", $jsonString );
  4457. if (! empty ( $jsonString ))
  4458. $client->local = $jsonString;
  4459. }
  4460. $client->fax = $fax;
  4461. $client->webservice = $webservice;
  4462. $client->department = $department;
  4463. $client->position = $position;
  4464. $client->office = $office;
  4465. $client->address = $address;
  4466. $client->ride = $ride;
  4467. $client->landmarks = $landmarks;
  4468. $client->qq = $qq;
  4469. $client->stay = $stay;
  4470. $client->priority = $priority;
  4471. $client->mark = $mark;
  4472. $client->updatetime = time ();
  4473. $client->update ();
  4474. // Doo::loadModel ( 'company' );
  4475. // $company = new company();
  4476. // $companyid=$client->getOne(array('where'=>' cid='.$cid,'asArray'=>true));
  4477. // $company->office=$office;
  4478. // $company->fax=$fax;
  4479. // $company->address=$address;
  4480. // $company->ride=$ride;
  4481. // $company->landmarks=$landmarks;
  4482. // $company->cid=$companyid['companyid'];
  4483. // if(!empty($unit)){
  4484. // $company->companyname=$unit;
  4485. // }
  4486. // $company->update();
  4487. $clientInfo = $client->getOne ( array (
  4488. 'where' => ' cid=' . $cid,
  4489. 'asArray' => true
  4490. ) );
  4491. // 日常行为
  4492. Doo::loadModel ( "action_log" );
  4493. $action_log = new action_log ();
  4494. $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'] . ')';
  4495. $action_log->sid = $this->staff [0] ['sid'];
  4496. $action_log->cid = $this->staff [0] ['cid'];
  4497. $action_log->updatetime = date ( "Y-m-d" );
  4498. $action_log->time = date ( "H:i" );
  4499. $action_log->class = $action_log->iconContacts;
  4500. $action_log->status = 2;
  4501. $action_log->districtid = $clientInfo ['district'];
  4502. $local = $district->getbyidlist ( $clientInfo ['district'] );
  4503. $action_log->city = $local [0] ['name'];
  4504. $action_log->province = $local [1] ['name'];
  4505. $action_log->company = $clientInfo ['companyname'];
  4506. Doo::loadModel ( 'company' );
  4507. $company = new company ();
  4508. $companyInfo = $company->getOne ( array (
  4509. 'where' => ' companyname="' . $clientInfo ['companyname'] . '"',
  4510. 'asArray' => true
  4511. ) );
  4512. $nature = explode ( ',', $companyInfo ['nature'] );
  4513. $action_log->nature = $nature [0];
  4514. $action_log->insert ();
  4515. echo json_encode ( array (
  4516. "success" => true
  4517. ) );
  4518. die ();
  4519. } else
  4520. echo json_encode ( array (
  4521. "success" => false
  4522. ) );
  4523. die ();
  4524. }
  4525. function ajaxClientInfo() {
  4526. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4527. if (! empty ( $cid )) {
  4528. Doo::loadModel ( 'client' );
  4529. Doo::loadModel ( 'company' );
  4530. $company = new company ();
  4531. $client = new client ();
  4532. $info = $client->getOne ( array (
  4533. 'where' => ' cid=' . $cid,
  4534. 'asArray' => true
  4535. ) );
  4536. $cinfo = $company->getOne ( array (
  4537. 'where' => ' cid=' . $info ['companyid'],
  4538. 'asArray' => true
  4539. ) );
  4540. Doo::loadClass ( 'XDeode' );
  4541. $XDeode = new XDeode ( 5 );
  4542. $cinfo['cidKey']=$XDeode->encode ( $cinfo['cid'] );
  4543. Doo::loadModel ( 'district' );
  4544. $district = new district ();
  4545. $districtLv1 = $district->get_lv ( 1 );
  4546. $info ['districtList'] = $district->getbyidlist ( $info ['district'] );
  4547. $optionHtml = '<option vlaue="0">请选择</option>';
  4548. foreach ( $districtLv1 as $key => $value ) {
  4549. if ($value ['name'] == $info ['districtList'] [0] ['name']) {
  4550. $optionHtml .= '<option selected value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  4551. } else
  4552. $optionHtml .= '<option value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  4553. }
  4554. $districtLv2 = $district->get_lvByid ( 2, $info ['districtList'] [0] ['id'] );
  4555. $optionHtml2 = '';
  4556. foreach ( $districtLv2 as $key => $value ) {
  4557. if ($value ['name'] == $info ['districtList'] [1] ['name'])
  4558. $optionHtml2 .= '<option selected value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  4559. else
  4560. $optionHtml2 .= '<option value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  4561. }
  4562. $districtLv3 = $district->get_lvByid ( 2, $info ['districtList'] [1] ['id'] );
  4563. $optionHtml3 = '';
  4564. foreach ( $districtLv3 as $key => $value ) {
  4565. if ($value ['name'] == $info ['districtList'] [2] ['name'])
  4566. $optionHtml3 .= '<option selected value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  4567. else
  4568. $optionHtml3 .= '<option value="' . $value ['id'] . '">' . $value ['name'] . '</option>';
  4569. }
  4570. $info ['districtLv1'] = $optionHtml;
  4571. $info ['districtLv2'] = $optionHtml2;
  4572. $info ['districtLv3'] = $optionHtml3;
  4573. $info ['companyInfo'] = $cinfo;
  4574. echo json_encode ( array (
  4575. "success" => true,
  4576. 'html' => $info
  4577. ) );
  4578. die ();
  4579. } else
  4580. echo json_encode ( array (
  4581. "success" => false,
  4582. 'html' => ''
  4583. ) );
  4584. die ();
  4585. }
  4586. /**
  4587. * 为客户添加服务日志
  4588. */
  4589. function ajaxAddServiceLog() {
  4590. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "";
  4591. $clientid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  4592. $mark = $this->get_args ( 'mark' ) ? $this->get_args ( 'mark' ) : "";
  4593. $m = $this->get_args ( 'm' ) ? $this->get_args ( 'm' ) : "";
  4594. $d = $this->get_args ( 'd' ) ? $this->get_args ( 'd' ) : "";
  4595. $y = $this->get_args ( 'y' ) ? $this->get_args ( 'y' ) : date ( "Y" );
  4596. $Remind = $this->get_args ( 'Remind' ) ? $this->get_args ( 'Remind' ) : 0;
  4597. $time = $this->get_args ( 'time' ) ? $this->get_args ( 'time' ) : 0;
  4598. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  4599. if (! empty ( $status ) && ! empty ( $clientid )) {
  4600. Doo::loadModel ( 'service_log' );
  4601. Doo::loadModel ( 'client_staff' );
  4602. Doo::loadModel ( 'client' );
  4603. Doo::loadModel ( 'district' );
  4604. $district = new district ();
  4605. $client = new client ();
  4606. $clientStaff = new client_staff ();
  4607. $service_log = new service_log ();
  4608. $service_log->status = $status;
  4609. $service_log->clientid = $clientid;
  4610. $service_log->mark = htmlspecialchars ( $mark );
  4611. $service_log->date = $y . "-" . $m . "-" . $d;
  4612. $service_log->category = $this->staff [0] ['category'];
  4613. $service_log->staffname = $this->staff [0] ['username'];
  4614. $service_log->staffid = $this->staff [0] ['sid'];
  4615. $service_log->insert ();
  4616. // 日常行为
  4617. Doo::loadModel ( "action_log" );
  4618. Doo::loadModel ( "client" );
  4619. $client = new client ();
  4620. // 记录服务时间
  4621. $client->cid = $clientid;
  4622. $client->servicetime = time ();
  4623. $client->update ();
  4624. $action_log = new action_log ();
  4625. $clientInfo = $client->getOne ( array (
  4626. 'where' => ' cid=' . $clientid,
  4627. 'asArray' => TRUE
  4628. ) );
  4629. $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'] . ')添加新客户记录。';
  4630. $action_log->sid = $this->staff [0] ['sid'];
  4631. $action_log->cid = $this->staff [0] ['cid'];
  4632. $action_log->updatetime = date ( "Y-m-d" );
  4633. $action_log->time = date ( "H:i" );
  4634. $action_log->status = 3;
  4635. $action_log->districtid = $clientInfo ['district'];
  4636. $local = $district->getbyidlist ( $clientInfo ['district'] );
  4637. $action_log->city = $local [0] ['name'];
  4638. $action_log->province = $local [1] ['name'];
  4639. $action_log->company = $clientInfo ['companyname'];
  4640. Doo::loadModel ( 'company' );
  4641. $company = new company ();
  4642. $companyInfo = $company->getOne ( array (
  4643. 'where' => ' companyname="' . $clientInfo ['companyname'] . '"',
  4644. 'asArray' => true
  4645. ) );
  4646. $nature = explode ( ',', $companyInfo ['nature'] );
  4647. $action_log->nature = $nature [0];
  4648. $action_log->class = $action_log->iconContacts;
  4649. $action_log->insert ();
  4650. // 更新信息中心服务日志统计数量
  4651. $redis = new Redis ();
  4652. $redis->connect ( '127.0.0.1', '6379' );
  4653. $categoryCondition = " and cid=" . $this->staff [0] ['cid'];
  4654. $sidCondition = " and sid=" . $this->staff [0] ['sid'];
  4655. // actionlog免查询值 $alCondition='';
  4656. $alCondition = ' aid>' . REMIT . ' and ';
  4657. // 个人服务日志数量redis值
  4658. $redisKeyCS = date ( 'Y-m-d' ) . 'SL_' . $this->staff [0] ['cid'] . '_' . $this->staff [0] ['sid'];
  4659. $action_log = new action_log ();
  4660. $actionLogLongle = $action_log->find ( array (
  4661. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  4662. 'where' => $alCondition . " status=3 " . $categoryCondition . $sidCondition . " and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) ",
  4663. 'groupby' => 'date_format(updatetime,"%m-%d")',
  4664. 'asArray' => true
  4665. ) );
  4666. $statisticsLongle = array ();
  4667. for($d = 0; $d <= 29; $d ++) {
  4668. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  4669. $falgLongle = true;
  4670. foreach ( $actionLogLongle as $value ) {
  4671. if ($value ['updatetime'] == $MD) {
  4672. array_push ( $statisticsLongle, $value ['count'] );
  4673. $falgLongle = false;
  4674. break;
  4675. }
  4676. }
  4677. if ($falgLongle)
  4678. array_push ( $statisticsLongle, 0 );
  4679. }
  4680. $statisticsLongle = array_reverse ( $statisticsLongle );
  4681. $jsl = json_encode ( $statisticsLongle );
  4682. $redis->set ( $redisKeyCS, $jsl );
  4683. // 办事处服务日志数量reids值
  4684. $redisKeyC = date ( 'Y-m-d' ) . 'SL_' . $this->staff [0] ['cid'] . '_';
  4685. $action_log = new action_log ();
  4686. $actionLogLongle = $action_log->find ( array (
  4687. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  4688. 'where' => $alCondition . " status=3 " . $categoryCondition . " and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) ",
  4689. 'groupby' => 'date_format(updatetime,"%m-%d")',
  4690. 'asArray' => true
  4691. ) );
  4692. $statisticsLongle = array ();
  4693. for($d = 0; $d <= 29; $d ++) {
  4694. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  4695. $falgLongle = true;
  4696. foreach ( $actionLogLongle as $value ) {
  4697. if ($value ['updatetime'] == $MD) {
  4698. array_push ( $statisticsLongle, $value ['count'] );
  4699. $falgLongle = false;
  4700. break;
  4701. }
  4702. }
  4703. if ($falgLongle)
  4704. array_push ( $statisticsLongle, 0 );
  4705. }
  4706. $statisticsLongle = array_reverse ( $statisticsLongle );
  4707. $jsl = json_encode ( $statisticsLongle );
  4708. $redis->set ( $redisKeyC, $jsl );
  4709. // 全员处服务日志数量的redis值
  4710. $redisKey = date ( 'Y-m-d' ) . 'SL__';
  4711. $action_log = new action_log ();
  4712. $actionLogLongle = $action_log->find ( array (
  4713. 'select' => 'date_format(updatetime,"%m-%d") as updatetime,COUNT(*) as count',
  4714. 'where' => $alCondition . " status=3 and date_sub(curdate(), INTERVAL 30 DAY) <= date(updatetime) ",
  4715. 'groupby' => 'date_format(updatetime,"%m-%d")',
  4716. 'asArray' => true
  4717. ) );
  4718. $statisticsLongle = array ();
  4719. for($d = 0; $d <= 29; $d ++) {
  4720. $MD = date ( "m-d", strtotime ( "-" . $d . " day" ) );
  4721. $falgLongle = true;
  4722. foreach ( $actionLogLongle as $value ) {
  4723. if ($value ['updatetime'] == $MD) {
  4724. array_push ( $statisticsLongle, $value ['count'] );
  4725. $falgLongle = false;
  4726. break;
  4727. }
  4728. }
  4729. if ($falgLongle)
  4730. array_push ( $statisticsLongle, 0 );
  4731. }
  4732. $statisticsLongle = array_reverse ( $statisticsLongle );
  4733. $jsl = json_encode ( $statisticsLongle );
  4734. $redis->set ( $redisKey, $jsl );
  4735. if (! empty ( $Remind )) {
  4736. Doo::loadModel ( 'remind' );
  4737. $remindObj = new remind ();
  4738. $datetime1 = new DateTime ( date ( 'Y-m-d' ) );
  4739. $datetime2 = new DateTime ( $time );
  4740. $interval = $datetime1->diff ( $datetime2 );
  4741. $remindObj->day = $interval->format ( '%a' );
  4742. $remindObj->remark = $remark;
  4743. $remindObj->time = date ( "Y-m-d" );
  4744. $remindObj->clientName = $clientInfo ['clientname'];
  4745. $remindObj->clientID = $clientid;
  4746. $remindObj->companyName = $clientInfo ['companyname'];
  4747. $remindObj->companyID = $companyInfo ['cid'];
  4748. $remindObj->staffID = $this->staff [0] ['sid'];
  4749. if ($status == 1)
  4750. $remindObj->class = "iconService";
  4751. if ($status == 2)
  4752. $remindObj->class = "iconPhone";
  4753. if ($status == 3)
  4754. $remindObj->class = "iconOther";
  4755. $remindObj->insert ();
  4756. }
  4757. echo json_encode ( array (
  4758. "success" => true,
  4759. 'html' => ''
  4760. ) );
  4761. die ();
  4762. } else
  4763. echo json_encode ( array (
  4764. "success" => false,
  4765. 'html' => ''
  4766. ) );
  4767. die ();
  4768. }
  4769. function _getLongleLogHtml($longleLog = array()) {
  4770. $html = "";
  4771. foreach ( $longleLog as $key => $value ) {
  4772. $dateline = explode ( "-", $value ['dateline'] );
  4773. $html .= '<div class="infoFlowList">
  4774. <div class="dateTitle">
  4775. <em class="month"><span class="num">' . $dateline [1] . '</span><span class="text">-' . $dateline [2] . '</span></em>
  4776. <span class="year">' . $dateline [0] . '</span>
  4777. </div>
  4778. ';
  4779. // 备注
  4780. if ($value ['status'] == 8) {
  4781. $html .= '
  4782. <ul class="flowList">
  4783. <li class="item iconLock">备注<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
  4784. <li class="item">' . $value ['mark'] . '</li>
  4785. </ul>';
  4786. } elseif ($value ['status'] == 10) {
  4787. $html .= '
  4788. <ul class="flowList">
  4789. <li class="item iconLock">延期<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
  4790. <li class="item">' . $value ['mark'] . '</li>
  4791. </ul>';
  4792. // 生成
  4793. }elseif ($value ['status'] == 1) {
  4794. $html .= '<ul class="flowList">
  4795. <li class="item iconGenerate">生成<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
  4796. </ul>';
  4797. // 接收
  4798. } elseif ($value ['status'] == 2) {
  4799. $html .= '<ul class="flowList">
  4800. <li class="item iconReceive">接收<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
  4801. </ul>';
  4802. // 借出
  4803. } elseif ($value ['status'] == 3) {
  4804. $html .= '<ul class="flowList">
  4805. <li class="item iconBorrow">借出<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
  4806. <li class="item">' . $value ['product'] . '</li>
  4807. <li class="item"><a href="javascript:void(0);" onclick="getClientInfo(\'' . $value ['clientid'] .'\')" >' . $value ['client'] . '</a></li>
  4808. </ul>';
  4809. // 销售
  4810. } elseif ($value ['status'] == 4) {
  4811. $html .= '<ul class="flowList">
  4812. <li class="item iconSell">销售<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
  4813. <li class="item">' . $value ['product'] . '</li>
  4814. <li class="item"><a href="javascript:void(0);" onclick="getClientInfo(\'' . $value ['clientid'] . '\')" >' . $value ['client'] . '</a></li>
  4815. </ul>';
  4816. // 升级
  4817. } elseif ($value ['status'] == 5) {
  4818. $html .= '<ul class="flowList">
  4819. <li class="item iconUpdate">升级<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')" >' . $value ['operator'] . '</a></li>
  4820. <li class="item">' . $value ['product'] . '</li>
  4821. <li class="item"><a href="javascript:void(0);" onclick="getClientInfo(\'' . $value ['clientid'] . '\')" >' . $value ['client'] . '</a></li>
  4822. </ul>';
  4823. // 更换
  4824. } elseif ($value ['status'] == 6) {
  4825. $html .= '<ul class="flowList">
  4826. <li class="item iconReplace">更换<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')">' . $value ['operator'] . '</a></li>
  4827. <li class="item"><a href="javascript:void(0);" onclick="getLockByName(\'' . $value ['new_key_num'] . '\')">' . $value ['new_key_num'] . '</a>
  4828. <li class="item"><a href="javascript:void(0);" onclick="getClientInfo(\'' . $value ['clientid'] . '\')" >' . $value ['client'] . '</a></li>
  4829. </ul>';
  4830. // 回收
  4831. } elseif ($value ['status'] == 7) {
  4832. Doo::loadModel ( 'staff' );
  4833. $staff = new staff ();
  4834. $staffinfo = $staff->getOne ( array (
  4835. 'where' => ' username like "' . $value ['responsible'] . '"',
  4836. 'asArray' => true
  4837. ) );
  4838. if (empty ( $staffinfo ))
  4839. $staffinfo ['category'] = "";
  4840. $html .= '<ul class="flowList">
  4841. <li class="item iconRecycle">收回<' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')">' . $value ['operator'] . '</a></li>
  4842. <li class="item">' . $staffinfo ['category'] . '<a href="javascript:void(0);" id="ajaxStaff" data="' . $value ['responsible'] . '">' . $value ['responsible'] . '</a></li>
  4843. </ul>';
  4844. } elseif ($value ['status'] == 9) {
  4845. $html .= '<ul class="flowList">
  4846. <li class="item iconGif">赠送 &lt; ' . $value ['category'] . '<a href="javascript:void(0);" onclick="getStaffInfo(\'' . $value ['operator'] . '\')">' . $value ['operator'] . '</a></li>
  4847. <li class="item"><a href="javascript:void(0);" onclick="getClientInfo(\'' . $value ['clientid'] . '\')" >' . $value ['client'] . '</a></li>
  4848. </ul>';
  4849. }
  4850. $html .= '</div>';
  4851. }
  4852. return $html;
  4853. }
  4854. function adminLock() {
  4855. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  4856. $data ['emsg'] = "";
  4857. if ($emsg != "")
  4858. $data ['emsg'] = "请填写完整的数据";
  4859. $data ['memu'] = "keyonline";
  4860. $data ['staff'] = $this->staff;
  4861. if ($this->staff [0] ['isadmin'] != 1)
  4862. return "/adminmyinfo";
  4863. Doo::loadModel ( 'L_category' );
  4864. $L_category = new L_category ();
  4865. $data ['category'] = $L_category->getCategory ();
  4866. $data ['time'] = time ();
  4867. $this->render ( "/admin/admin_addlock", $data );
  4868. }
  4869. function adminAddLock() {
  4870. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4871. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  4872. if ($cid != 0 && $path != "") {
  4873. Doo::loadModel ( 'longle' );
  4874. Doo::loadModel ( 'L_category' );
  4875. $L_category = new L_category ();
  4876. Doo::loadModel ( 'longle_log' );
  4877. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/" . iconv ( "UTF-8", "GB2312", $path ) );
  4878. // print_r($exlArray);die;
  4879. // echo json_encode($exlArray);die;
  4880. $category = $L_category->getCategoryById ( $cid );
  4881. foreach ( $exlArray as $key => $value ) {
  4882. // 锁记录
  4883. $longle = new longle ();
  4884. $longle->key_num = str_replace ( "'", "", $value ['key_num'] );
  4885. $longle->product = str_replace ( "'", "", $value ['product'] );
  4886. $longle->make_day = $value ['make_day'];
  4887. $longle->alloted_time = $value ['alloted_time'];
  4888. $longle->status = 1;
  4889. $longle->statusT = "生成";
  4890. $longle->cid = $cid;
  4891. $longle->category = $category [0] ['title'];
  4892. $longle->SerialNumber = $value ['SerialNumber'];
  4893. $longle->version = $value ['version'];
  4894. $lid = $longle->insert ();
  4895. // 锁日志记录
  4896. $longle_log = new longle_log ();
  4897. $longle_log->lid = $lid;
  4898. $longle_log->status = 1;
  4899. $longle_log->statusT = "生成";
  4900. $longle_log->operator = $this->staff [0] ['username'];
  4901. $longle_log->product = $longle->product;
  4902. $longle_log->category = $this->staff [0] ['category'];
  4903. $longle_log->dateline = date ( "Y-m-d" );
  4904. $id = $longle_log->insert ();
  4905. }
  4906. // 记录日常行为
  4907. Doo::loadModel ( "action_log" );
  4908. $action_log = new action_log ();
  4909. $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>个锁';
  4910. $action_log->sid = $this->staff [0] ['sid'];
  4911. $action_log->cid = $this->staff [0] ['cid'];
  4912. $action_log->class = $action_log->iconGenerate;
  4913. $action_log->updatetime = date ( "Y-m-d" );
  4914. $action_log->time = date ( "H:i" );
  4915. $action_log->status = 11;
  4916. $action_log->insert ();
  4917. return "/keyonline";
  4918. } else
  4919. return "/adminlock/error";
  4920. }
  4921. function avatarCM() {
  4922. $vid = isset ( $this->params ['vid'] ) ? $this->params ['vid'] : 0;
  4923. if (! empty ( $vid )) {
  4924. Doo::loadModel ( "verify" );
  4925. $verify = new verify ();
  4926. Doo::loadModel ( 'staff' );
  4927. $staff = new staff ();
  4928. $list = $verify->getOne ( array (
  4929. 'where' => 'vid=' . $vid,
  4930. 'asArray' => true
  4931. ) );
  4932. if (empty ( $list ))
  4933. return "/adminverify";
  4934. $avatar = json_decode ( $list ['staff'] );
  4935. foreach ( $avatar as $key => $value ) {
  4936. $uinfo = $staff->getOne ( array (
  4937. 'where' => 'sid=' . $value [0],
  4938. 'asArray' => true
  4939. ) );
  4940. $avatar [$key] ['2'] = $uinfo ['avatar'];
  4941. }
  4942. $verify->staff = json_encode ( $avatar );
  4943. $verify->update ( array (
  4944. 'where' => 'vid=' . $vid
  4945. ) );
  4946. }
  4947. return "/adminverify";
  4948. }
  4949. function adminmyinfo() {
  4950. $data ['memu'] = "adminmyinfo";
  4951. $data ['staff'] = $this->staff;
  4952. $birArray = explode ( '-', $this->staff [0] ['birthday'] );
  4953. $data ['year'] = $birArray [0];
  4954. $year = date ( 'Y' );
  4955. $yearHtml = "";
  4956. for(; $year >= 1900; $year --) {
  4957. $yearHtml .= '<option ';
  4958. if ($data ['year'] == $year)
  4959. $yearHtml .= 'selected';
  4960. $yearHtml .= ' value="' . $year . '">' . $year . '</option>';
  4961. }
  4962. $data ['yearHtml'] = $yearHtml;
  4963. $data ['month'] = 01;
  4964. $data ['day'] = 01;
  4965. if (isset ( $birArray [1] )) {
  4966. $data ['month'] = $birArray [1];
  4967. $data ['day'] = $birArray [2];
  4968. }
  4969. $data ['msg'] = urldecode ( $this->params ['msg'] );
  4970. $this->render ( "/admin/admin_myinfo", $data );
  4971. }
  4972. function updateMyinfo() {
  4973. $telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : 0;
  4974. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : 0;
  4975. $email = $this->get_args ( 'email' ) ? $this->get_args ( 'email' ) : "";
  4976. $qq = is_numeric ( $this->get_args ( 'qq' ) ) ? $_POST ['qq'] : 0;
  4977. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4978. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  4979. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : "";
  4980. $position = $this->get_args ( 'position' ) ? $this->get_args ( 'position' ) : "";
  4981. $gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : "男";
  4982. $oldpassword = $this->get_args ( 'oldpassword' ) ? $this->get_args ( 'oldpassword' ) : "";
  4983. $newpassword = $this->get_args ( 'newpassword' ) ? $this->get_args ( 'newpassword' ) : "";
  4984. $rnewpassword = $this->get_args ( 'rnewpassword' ) ? $this->get_args ( 'rnewpassword' ) : "";
  4985. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  4986. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  4987. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  4988. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  4989. Doo::loadModel ( 'staff' );
  4990. $staff = new staff ();
  4991. Doo::loadModel ( 'staffDynamic' );
  4992. $staffDynamic = new staffDynamic ();
  4993. $staff->sid = $this->staff [0] ['sid'];
  4994. if (! empty ( $remittanceName ))
  4995. $staff->remittanceName = $remittanceName;
  4996. if (! empty ( $bankName ))
  4997. $staff->bankName = $bankName;
  4998. if (! empty ( $bankNumber ))
  4999. $staff->bankNumber = $bankNumber;
  5000. if (! empty ( $coupletNumber ))
  5001. $staff->coupletNumber = $coupletNumber;
  5002. $content = "";
  5003. $ext = "更新了他的";
  5004. if ($telephone != 0 && $this->staff [0] ['telephone'] != $telephone) {
  5005. $staff->telephone = $telephone;
  5006. $content .= "<b>手机</b>&nbsp;";
  5007. }
  5008. if ($phone != 0 && $this->staff [0] ['phone'] != $phone) {
  5009. $staff->phone = $phone;
  5010. $content .= "<b>电话</b>&nbsp;";
  5011. }
  5012. if ($qq != 0 && $this->staff [0] ['qq'] != $qq) {
  5013. $staff->qq = $qq;
  5014. $content .= "<b>QQ</b>&nbsp;";
  5015. }
  5016. if ($year != 2014) {
  5017. $staff->birthday = $year . "-" . $month . "-" . $day;
  5018. $content .= "<b>生日</b>&nbsp;";
  5019. }
  5020. if ($email != "" && filter_var ( $email, FILTER_VALIDATE_EMAIL ) && $this->staff [0] ['email'] != $email) {
  5021. $staff->email = $email;
  5022. $content .= "<b>邮箱</b>&nbsp;";
  5023. }
  5024. if (! empty ( $position )) {
  5025. $staff->position = $position;
  5026. $content .= "<b>职位</b>&nbsp;";
  5027. }
  5028. $staff->gender = $gender;
  5029. $msg = "更新成功";
  5030. if ($this->staff [0] ['passwork'] == md5 ( $oldpassword )) {
  5031. if ($newpassword == $rnewpassword && (! empty ( $newpassword )))
  5032. $staff->passwork = md5 ( $newpassword );
  5033. else
  5034. $msg = "密码不一致";
  5035. } else {
  5036. if ($oldpassword != "")
  5037. $msg = "密码错误";
  5038. }
  5039. if (! empty ( $content )) {
  5040. $staffDynamic->content = $ext . $content;
  5041. $staffDynamic->cid = $this->staff [0] ['cid'];
  5042. $staffDynamic->category = $this->staff [0] ['category'];
  5043. $staffDynamic->time = time ();
  5044. $staffDynamic->sid = $this->staff [0] ['sid'];
  5045. $staffDynamic->staff = $this->staff [0] ['username'];
  5046. $staffDynamic->insert ();
  5047. }
  5048. $staff->update ( array (
  5049. 'where' => ' sid=' . $this->staff [0] ['sid']
  5050. ) );
  5051. return "/adminmyinfo/" . $msg;
  5052. }
  5053. function admincontacts() {
  5054. $data ['memu'] = "admincontacts";
  5055. $data ['staff'] = $this->staff;
  5056. Doo::loadModel ( 'L_category' );
  5057. Doo::loadModel ( 'staff' );
  5058. $staff = new staff ();
  5059. $L_category = new L_category ();
  5060. $this->render ( "/admin/admin_addContacts", $data );
  5061. }
  5062. /**
  5063. * 微信通知设置
  5064. */
  5065. // function notificationConf() {
  5066. // Doo::loadModel ( "notificationConf" );
  5067. // $notificationConf = new notificationConf ();
  5068. // $detail = $notificationConf->getNotificationConfBySid ( $this->staff [0] ['sid'] );
  5069. // $rule = json_decode ( $detail ['conf'], true );
  5070. // $data ['rule'] = $rule;
  5071. // $data ['memu'] = "notificationConf";
  5072. // $data ['staff'] = $this->staff;
  5073. // $this->render ( "/admin/invoiceNotificationConf", $data );
  5074. // }
  5075. // function ajaxSetNotificationConf() {
  5076. // $notificationType = $this->get_args ( 'notificationType' ) ? $this->get_args ( 'notificationType' ) : "";
  5077. // $notificationValue = $this->get_args ( 'notificationValue' ) ? $this->get_args ( 'notificationValue' ) : '';
  5078. // if (! empty ( $notificationType ) && ! empty ( $notificationValue ) && ! empty ( $this->staff [0] ['sid'] )) {
  5079. // Doo::loadModel ( "notificationConf" );
  5080. // $notificationConf = new notificationConf ();
  5081. // $detail = $notificationConf->getNotificationConfBySid ( $this->staff [0] ['sid'] );
  5082. // if (empty ( $detail )) {
  5083. // $rule = array (
  5084. // $notificationType => $notificationValue
  5085. // );
  5086. // $rule = json_encode ( $rule );
  5087. // $item = array (
  5088. // 'sid' => $this->staff [0] ['sid'],
  5089. // 'conf' => $rule
  5090. // );
  5091. // $notificationConf->addNotification ( $item );
  5092. // } else {
  5093. // $rule = json_decode ( $detail ['conf'], true );
  5094. // $rule [$notificationType] = $notificationValue;
  5095. // $rule = json_encode ( $rule );
  5096. // $item = array (
  5097. // 'nid' => $detail ['nid'],
  5098. // 'conf' => $rule
  5099. // );
  5100. // $notificationConf->setNotificationByCondition ( $item );
  5101. // }
  5102. // echo json_encode ( array (
  5103. // 'status' => 1,
  5104. // 'msgType' => $notificationType,
  5105. // 'msg' => ''
  5106. // ) );
  5107. // die ();
  5108. // }
  5109. // echo json_encode ( array (
  5110. // 'status' => 2,
  5111. // 'msgType' => $notificationType,
  5112. // 'msg' => 'illegal request'
  5113. // ) );
  5114. // die ();
  5115. // }
  5116. function eMailTask() {
  5117. Doo::loadModel ( 'tag' );
  5118. $tag = new tag ();
  5119. Doo::loadModel ( 'district' );
  5120. $district = new district ();
  5121. $tagList = $tag->getAllBySid ( $this->staff [0] ['sid'] );
  5122. $districtList = $district->get_lv ( 1 );
  5123. $districtlv2List=$district->get_lvByid(2,$districtList[0]['id']);
  5124. $data ['tagList'] = $tagList;
  5125. $data ['districtList'] = $districtList;
  5126. $data ['districtlv2List'] = $districtlv2List;
  5127. $data ['memu'] = "eMailTask";
  5128. $data ['staff'] = $this->staff;
  5129. $data ['mailMemu'] = 'eMailTask';
  5130. $data ['nature'] = $this->nature;
  5131. $this->render ( "/mail_create", $data );
  5132. }
  5133. function eMialCenter() {
  5134. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  5135. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : 0;
  5136. Doo::loadModel ( 'eMailList' );
  5137. $eMailList = new eMailList ();
  5138. Doo::loadModel ( 'tag' );
  5139. $tag = new tag ();
  5140. Doo::loadModel ( 'staff' );
  5141. $staff = new staff ();
  5142. $dateCondition = "status!=2 and Year(date) =" . $year;
  5143. if (! empty ( $month ))
  5144. $dateCondition = "Year(date) =" . $year . " and Month(date) = " . $month;
  5145. $mailList = $eMailList->find ( array (
  5146. 'where' => $dateCondition,
  5147. 'asc' => 'status',
  5148. 'desc' => 'elid',
  5149. 'asArray' => true
  5150. ) );
  5151. foreach ( $mailList as $key => $value ) {
  5152. $mailList [$key] ['clientName2'] = $mailList [$key] ['clientName3'] = array ();
  5153. $mailList [$key] ['clientName'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName'] ) ), true );
  5154. if (! empty ( $value ['clientName2'] ))
  5155. $mailList [$key] ['clientName2'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName2'] ) ), true );
  5156. if (! empty ( $value ['clientName3'] ))
  5157. $mailList [$key] ['clientName3'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName3'] ) ), true );
  5158. $mailList [$key] ['illegalEmail'] = json_decode ( $value ['illegalEmail'], true );
  5159. $mailList [$key] ['sendEmail'] = json_decode ( $value ['sendEmail'], true );
  5160. $mailList [$key] ['clientCount'] = count ( $mailList [$key] ['clientName'] ) + count ( $mailList [$key] ['clientName2'] ) + count ( $mailList [$key] ['clientName3'] );
  5161. $mailList [$key] ['tag'] = array ();
  5162. $kks = $staff->getOne ( array (
  5163. 'where' => 'username like "' . $value ['staffName'] . '"',
  5164. 'asArray' => true
  5165. ) );
  5166. $mailList [$key] ['category'] = $kks ['category'];
  5167. if (! empty ( $value ['tag'] ))
  5168. $mailList [$key] ['tag'] = $tag->find ( array (
  5169. 'where' => 'tid in ( ' . $value ['tag'] . ') ',
  5170. 'asArray' => true
  5171. ) );
  5172. }
  5173. $dateHtml = "";
  5174. $now = date ( "Y" );
  5175. for($YEARD = 2014; $YEARD <= 2050; $YEARD ++) {
  5176. if ($YEARD <= $now) {
  5177. $dateHtml .= '<option ';
  5178. if ($year == $YEARD)
  5179. $dateHtml .= ' selected ';
  5180. $dateHtml .= ' value="' . $YEARD . '">' . $YEARD . '</option>';
  5181. }
  5182. }
  5183. $monthHtml = '<option value="0">所有月份</option>';
  5184. for($i = 1; $i <= 12; $i ++) {
  5185. $monthHtml .= '<option ';
  5186. if ($i == $month)
  5187. $monthHtml .= ' selected ';
  5188. $monthHtml .= ' value="' . $i . '">' . $i . '</option>';
  5189. }
  5190. $data ['monthHtml'] = $monthHtml;
  5191. $data ['dateHtml'] = $dateHtml;
  5192. $data ['mailList'] = $mailList;
  5193. $data ['memu'] = "eMailTask";
  5194. $data ['staff'] = $this->staff;
  5195. $data ['mailMemu'] = 'eMialCenter';
  5196. $data ['nature'] = $this->nature;
  5197. $this->render ( "/mailCenter", $data );
  5198. }
  5199. function authMail() {
  5200. $elid = isset ( $this->params ['elid'] ) ? $this->params ['elid'] : 0;
  5201. if (! empty ( $elid )) {
  5202. Doo::loadModel ( 'eMailList' );
  5203. $eMailList = new eMailList ();
  5204. $eMailList->examine = 2;
  5205. $eMailList->mark = $this->staff [0] ['username'] . "已同意";
  5206. $eMailList->update ( array (
  5207. 'where' => 'elid=' . $elid,
  5208. 'asArray' => true
  5209. ) );
  5210. }
  5211. return '/eMialCenter';
  5212. }
  5213. function editMailView() {
  5214. $elid = isset ( $this->params ['elid'] ) ? $this->params ['elid'] : 0;
  5215. Doo::loadModel ( 'tag' );
  5216. $tag = new tag ();
  5217. Doo::loadModel ( 'district' );
  5218. $district = new district ();
  5219. Doo::loadModel ( 'eMailList' );
  5220. $eMList = new eMailList ();
  5221. $mail = $eMList->getOne ( array (
  5222. 'where' => 'elid =' . $elid . '',
  5223. 'asArray' => true
  5224. ) );
  5225. if (empty ( $mail ))
  5226. return "/eMailList";
  5227. $mail ['tagList'] = explode ( ",", $mail ['tag'] );
  5228. $tagList = $tag->getAllBySid ( $this->staff [0] ['sid'] );
  5229. $districtList = $district->get_lv ( 1 );
  5230. $tagHtml = '';
  5231. foreach ( $tagList as $key => $value ) {
  5232. $tagHtml .= '<label><span data-original-title="' . $value ['name'] . '" data-toggle="ctooltip" data-placement="right" class="contactsTag tagCol-0' . $value ['colorid'] . '">
  5233. <input type="checkbox" name="tagId[]"';
  5234. foreach ( $mail ['tagList'] as $k => $v ) {
  5235. if ($value ['tid'] == $v) {
  5236. $tagHtml .= ' checked ';
  5237. break;
  5238. }
  5239. }
  5240. $tagHtml .= ' value="' . $value ['tid'] . '"></span></label>';
  5241. }
  5242. $districtHtml = '';
  5243. foreach ( $districtList as $key => $value ) {
  5244. $districtHtml .= '<option value="' . $value ['id'] . '"';
  5245. if ($value ['id'] == $mail ['districtId'])
  5246. $districtHtml .= 'selected';
  5247. $districtHtml .= '>' . $value ['name'] . '</option>';
  5248. }
  5249. $natureHtml = '';
  5250. $natList = explode ( ",", $mail ['nature'] );
  5251. foreach ( $this->nature as $key => $value ) {
  5252. $natureHtml .= '<label><input type="checkbox" name="nature[]" ';
  5253. foreach ( $natList as $k => $v ) {
  5254. if ($value == $v) {
  5255. $natureHtml .= ' checked ';
  5256. break;
  5257. }
  5258. }
  5259. $natureHtml .= 'value="' . $value . '">' . $value . '</label>';
  5260. }
  5261. $data ['natureHtml'] = $natureHtml;
  5262. $data ['districtHtml'] = $districtHtml;
  5263. $data ['tagHtml'] = $tagHtml;
  5264. $data ['mail'] = $mail;
  5265. $data ['tagList'] = $tagList;
  5266. $data ['districtList'] = $districtList;
  5267. $data ['memu'] = "eMailTask";
  5268. $data ['staff'] = $this->staff;
  5269. $data ['mailMemu'] = 'eMailList';
  5270. $data ['nature'] = $this->nature;
  5271. $this->render ( "/mailEdit", $data );
  5272. }
  5273. function editEmail() {
  5274. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  5275. $skin = $this->get_args ( 'skin' ) ? $this->get_args ( 'skin' ) : "";
  5276. $content = isset ( $_POST ['content'] ) ? $_POST ['content'] : "";
  5277. $tagId = $this->get_args ( 'tagId' ) ? $this->get_args ( 'tagId' ) : array ();
  5278. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : array ();
  5279. $natureNULL = $this->get_args ( 'natureNULL' ) ? $this->get_args ( 'natureNULL' ) : "";
  5280. $did = $this->get_args ( 'did' ) ? $this->get_args ( 'did' ) : "";
  5281. $stype = $this->get_args ( 'stype' ) ? $this->get_args ( 'stype' ) : "";
  5282. $elid = $this->get_args ( 'elid' ) ? $this->get_args ( 'elid' ) : "";
  5283. if (! empty ( $title ) && ! empty ( $elid ) && (! empty ( $tagId ) || ! empty ( $did ))) {
  5284. Doo::loadModel ( 'eMailList' );
  5285. $eMailList = new eMailList ();
  5286. $etid = $eMailList->getOne ( array (
  5287. 'select' => 'etid,annexName,annex',
  5288. 'where' => 'elid=' . $elid,
  5289. 'asArray' => true
  5290. ) );
  5291. Doo::loadModel ( 'eMailTemplate' );
  5292. $eMailTemplate = new eMailTemplate ();
  5293. Doo::loadModel ( 'eMailJournal' );
  5294. $eMailJournal = new eMailJournal ();
  5295. if ($natureNULL != 'NULL') {
  5296. if (empty ( $tagId ) && ! empty ( $did ) && empty ( $nature ))
  5297. die ( '请选择性质' );
  5298. }
  5299. // annex
  5300. $annexPath = "";
  5301. $annexEXT = $this->_GetFileEXT ( $_FILES ["annex"] ["name"] );
  5302. $annexName = "";
  5303. if (isset ( $_FILES ['annex'] ['name'] )) {
  5304. 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)) {
  5305. $path = DOO::conf ()->SITE_PATH . "upload/emailAnnex/";
  5306. if (! file_exists ( $path . $_FILES ["annex"] ["name"] )) {
  5307. $fileName = time () . "." . $annexEXT;
  5308. $annexName = $_FILES ['annex'] ['name'];
  5309. $annexPath = $path . $fileName;
  5310. move_uploaded_file ( $_FILES ["annex"] ["tmp_name"], $annexPath );
  5311. $annexPath = $this->webPath . $fileName;
  5312. }
  5313. }
  5314. }
  5315. if (! empty ( $annexPath )) {
  5316. $annexHtml = '<table style="width:100%;margin:10px 0">
  5317. <thead>
  5318. <tr>
  5319. <th align="left" colspan="2" style="background-color:ff6501;color:#fff;font-size:16px;padding:5px">下载附件:</th>
  5320. </tr>
  5321. </thead>
  5322. <tbody>
  5323. <tr>
  5324. <td style="padding:5px"><a href="' . $annexPath . '" target="_blank" style="font-size:16px">' . $annexName . '</a></td>
  5325. <td>&nbsp;</td>
  5326. </tr>
  5327. </tbody>
  5328. </table>';
  5329. } elseif (! empty ( $etid ['annexName'] ) && empty ( $annexPath ))
  5330. $annexHtml = $etid ['annex'];
  5331. $smartcostMail = 'smartcost_mail_1';
  5332. $info = "";
  5333. // html template
  5334. if ($skin == 1) {
  5335. $html = '<div><table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  5336. <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">
  5337. <tbody><tr>
  5338. <td style="background-color:#ff6501;padding:20px 0 25px;" align="center">
  5339. <span style="vertical-align:bottom;font-size:20px;color:#fff;">' . $title . '</span>
  5340. </td></tr><tr><td>
  5341. <table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;border-top:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  5342. <tbody><tr><td style="padding: 0 40px;" align="left">
  5343. <p style="margin-top:40px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;"><b>CLIENTNAME</b>,您好</p>
  5344. </td></tr><tr><td style="padding: 0 40px;" align="left">
  5345. <p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;">我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
  5346. <p style="margin-top:0px;margin-bottom:20px;color:#383838;font-size:16px;line-height:32px;">
  5347. ' . $content . '</p>
  5348. </td></tr>
  5349. <tr><td align="left" style="padding: 0 40px;background:#fff">
  5350. ' . $annexHtml . '
  5351. </td></tr>
  5352. <tr> <td style="padding: 20px 40px;border-top:1px dashed #ddd" align="left">
  5353. <p style="margin-bottom:10px;color:#383838;font-size:16px;line-height:22px;border-left:2px solid #FF6501;padding-left:5px">
  5354. 纵横公路造价软件' . $this->staff [0] ['category'] . '办事处</p>
  5355. <table>
  5356. <tr><th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td></tr>
  5357. <tr><th align="right">联系人:</th><td>' . $this->staff [0] ['username'] . '</td></tr>
  5358. <tr><th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr>
  5359. <tr><th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td></tr>
  5360. <tr><th align="right">邮箱:</th><td>' . $this->staff [0] ['email'] . '</td></tr>
  5361. </table></td></tr></tbody></table></td></tr><tr>
  5362. <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>
  5363. </tr></tbody></table></td></tr></tbody></table></div>';
  5364. $info = '<table><tr><th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td></tr>
  5365. <tr><th align="right">联系人:</th><td>' . $this->staff [0] ['username'] . '</td></tr>
  5366. <tr><th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr>
  5367. <tr><th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td></tr>
  5368. <tr><th align="right">邮箱:</th><td>' . $this->staff [0] ['email'] . '</td></tr></table>';
  5369. } elseif ($skin == 2) {
  5370. $smartcostMail = 'smartcost_mail_2';
  5371. $html = '<table cellspacing="0" cellpadding="0" style="background-color:#e4e4e4; width:100%;"><tbody><tr><td>
  5372. <table align="center" cellspacing="0" cellpadding="0" style="background-color:#f8f8f8; width:640px;margin-bottom:20px">
  5373. <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;">
  5374. <b><span name="titleHtml">' . $title . '</span></b></p></td>
  5375. </tr><tr><td><table align="center" cellspacing="0" cellpadding="0" style="border:1px solid #ddd;"><tbody><tr>
  5376. <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>
  5377. </tr><tr><td align="center" style="background-color:#fff;"><img width="640" height="191" src="http://zonghengvideo.qiniudn.com/hero.jpg"></td>
  5378. </tr><tr><td align="left" style="background-color:#fff;padding:40px;border-bottom:1px solid #ddd;">
  5379. <p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;"><b>CLIENTNAME</b>,您好</p>
  5380. <p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;">我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
  5381. <p name="contentHtml" style="margin-top:0px;margin-bottom:15px;color:#383838;font-size:16px;line-height:32px;">' . $content . '</p></td>
  5382. </tr>
  5383. <tr><td align="left" style="padding: 0 40px;background:#fff">
  5384. ' . $annexHtml . '
  5385. </td></tr>
  5386. <tr><td style="padding: 10px 0;background:#EEF2F5"><table><tbody><tr>
  5387. <td style="font-size:14pxl;color:#333;padding:0 20px"><b>纵横公路造价软件' . $this->staff [0] ['category'] . '办事处</b><br>' . $this->staff [0] ['username'] . '</td>
  5388. <td><table><tbody><tr style="font-size:12px;color:#666">
  5389. <th align="right">电话:</th><td style="padding:0 20px 0 0">' . $this->staff [0] ['phone'] . '</td>
  5390. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#666">
  5391. <th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5392. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td>
  5393. </tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr>
  5394. <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>
  5395. </tr></tbody></table></td></tr></tbody> </table>';
  5396. $info = '<table><tbody><tr style="font-size:12px;color:#666">
  5397. <th align="right">电话:</th><td style="padding:0 20px 0 0">' . $this->staff [0] ['phone'] . '</td>
  5398. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#666">
  5399. <th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5400. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td>
  5401. </tr></tbody></table>';
  5402. } else {
  5403. $smartcostMail = 'smartcost_mail_3';
  5404. $html = '<table cellspacing="0" cellpadding="0" style="background-color:#ECF0E1; width:100%">
  5405. <tbody>
  5406. <tr>
  5407. <td>
  5408. <table align="center" cellspacing="0" cellpadding="0" style="width:698px;margin-bottom:30px;margin-top:30px;">
  5409. <tbody>
  5410. <tr>
  5411. <td>
  5412. <table align="center" cellspacing="0" cellpadding="0" style="border:1px solid #ccc;width:100%;border-top:none">
  5413. <tbody>
  5414. <tr>
  5415. <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;">
  5416. <div style="position:relative;text-align:right">
  5417. <b style="font-size:24px;color:#8A9F98;z-index:999"><span name="titleHtml">' . $title . '</span></b>
  5418. <div style="width:80px;height:80px;position:absolute;top:0;left:0"><img src="http://zonghengvideo.qiniudn.com/zonghenglogo.png"></div>
  5419. </div>
  5420. </td>
  5421. </tr>
  5422. <tr>
  5423. <td align="left" style="background-color:#fff;padding:40px;border-bottom:1px solid #ddd;">
  5424. <p style="margin-top:0px;margin-bottom:10px;color:#666;font-size:16px;line-height:32px;"><b>CLIENTNAME</b>,您好</p>
  5425. <p style="margin-top:0px;margin-bottom:10px;color:#666;font-size:16px;line-height:32px;">我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
  5426. <p name="contentHtml" style="margin-top:0px;margin-bottom:15px;color:#666;font-size:16px;line-height:32px;">' . $content . '</p></td>
  5427. </tr>
  5428. <tr><td align="left" style="padding: 0 40px;background:#fff">
  5429. ' . $annexHtml . '
  5430. </td></tr>
  5431. <tr>
  5432. <td style="padding: 10px 0 0;background:#F6F6F6;">
  5433. <table>
  5434. <tbody><tr>
  5435. <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>
  5436. <td>
  5437. <table style="width:100%">
  5438. <tbody><tr style="font-size:12px;color:#496781">
  5439. <th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td>
  5440. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td>
  5441. </tr>
  5442. <tr style="font-size:12px;color:#496781">
  5443. <th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5444. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td>
  5445. </tr>
  5446. </tbody></table>
  5447. </td>
  5448. </tr>
  5449. </tbody></table>
  5450. </td>
  5451. </tr>
  5452. <tr>
  5453. <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>
  5454. </tr>
  5455. </tbody>
  5456. </table></td>
  5457. </tr>
  5458. </tbody>
  5459. </table></td>
  5460. </tr>
  5461. </tbody>
  5462. </table>';
  5463. $info = '<table><tr style="font-size:12px;color:#496781"><th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td>
  5464. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#496781">
  5465. <th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5466. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td></tr></table>
  5467. ';
  5468. }
  5469. Doo::loadModel ( 'tag_client' );
  5470. $tagClient = new tag_client ();
  5471. Doo::loadModel ( 'client' );
  5472. $client = new client ();
  5473. Doo::loadModel ( 'company' );
  5474. $company = new company ();
  5475. $eMailTemplate->title = $title;
  5476. $eMailTemplate->skin = $skin;
  5477. $eMailTemplate->content = $content;
  5478. if (! empty ( $tagId ))
  5479. $eMailTemplate->tag = implode ( ",", $tagId );
  5480. $eMailTemplate->staffId = $this->staff [0] ['sid'];
  5481. $eMailTemplate->staffName = $this->staff [0] ['username'];
  5482. $eMailTemplate->status = 0;
  5483. $eMailTemplate->html = $html;
  5484. if (! empty ( $annexPath )) {
  5485. $eMailTemplate->annex = $annexPath;
  5486. $eMailTemplate->annexName = $annexName;
  5487. }
  5488. $etid = $eMailTemplate->update ( array (
  5489. 'where' => 'etid=' . $etid ['etid']
  5490. ) );
  5491. // create email list
  5492. $tagCondition = "";
  5493. $tagArray = array ();
  5494. foreach ( $tagId as $value ) {
  5495. array_push ( $tagArray, " tag like '%" . $value . "%' " );
  5496. }
  5497. if (! empty ( $tagArray ))
  5498. $tagCondition = ' and (' . implode ( " or ", $tagArray ) . ')';
  5499. $clientList = $tagClient->find ( array (
  5500. 'select' => 'client',
  5501. 'where' => 'sid=' . $this->staff [0] ['sid'] . $tagCondition,
  5502. 'asArray' => true
  5503. ) );
  5504. $clientArray = array ();
  5505. foreach ( $clientList as $value ) {
  5506. array_push ( $clientArray, $value ['client'] );
  5507. }
  5508. $clientEmailList = array ();
  5509. if (! empty ( $clientArray ))
  5510. $clientEmailList = $client->find ( array (
  5511. 'select' => 'email,cid,nicename as clientname,companyname',
  5512. 'where' => 'cid in (' . implode ( ",", $clientArray ) . ')',
  5513. 'asArray' => true
  5514. ) );
  5515. //
  5516. if ($stype == 2) {
  5517. // 获取性质相关数据
  5518. $cidList = '';
  5519. if ($natureNULL == '') {
  5520. $nD = array ();
  5521. foreach ( $nature as $key => $value ) {
  5522. array_push ( $nD, ' nature like "' . $value . '"' );
  5523. // $nD=' nature like "'.$value.'"';
  5524. }
  5525. $nD = implode ( ' or ', $nD );
  5526. $companycid = $company->find ( array (
  5527. 'select' => 'cid',
  5528. 'where' => $nD,
  5529. 'asArray' => true
  5530. ) );
  5531. $cidList = array ();
  5532. foreach ( $companycid as $key => $value ) {
  5533. array_push ( $cidList, $value ['cid'] );
  5534. }
  5535. $cidList = implode ( ',', $cidList );
  5536. if (! empty ( $cidList ))
  5537. $cidList = ' and companyid in (' . $cidList . ')';
  5538. else
  5539. $cidList = '';
  5540. }
  5541. // 'select'=>'email,cid,nicename as clientname,companyname,district'
  5542. $clientEmailList = $client->find ( array (
  5543. 'select' => 'email,cid,nicename as clientname,companyname,district',
  5544. 'where' => 'district like "' . $did . ',%" ' . $cidList,
  5545. 'asArray' => true
  5546. ) );
  5547. }
  5548. // ;datediff(curdate(), 'date')>=10
  5549. $eMailJournal->delete ( array (
  5550. 'where' => "datediff(curdate(), date)>=7"
  5551. ) );
  5552. $eMailJournal->delete ( array (
  5553. 'where' => 'DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(date)'
  5554. ) );
  5555. $checkMail = $eMailJournal->find ( array (
  5556. 'where' => 'DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(date)',
  5557. ' groupby' => 'email',
  5558. 'asArray' => true
  5559. ) );
  5560. $emailNameList = $emailArray = $illegalEmail = $sendEmail = array ();
  5561. Doo::db ()->beginTransaction ();
  5562. foreach ( $clientEmailList as $value ) {
  5563. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  5564. if (! empty ( $checkMail )) {
  5565. $falg = true;
  5566. foreach ( $checkMail as $v ) {
  5567. if ($v ['email'] == $value ['email']) {
  5568. $Bdate = strtotime ( $v ['date'] ) + 7 * 24 * 3600;
  5569. if ($Bdate <= time ()) {
  5570. array_push ( $emailArray, $value ['email'] );
  5571. array_push ( $emailNameList, $value );
  5572. $eMailJournal->date = date ( "Y-m-d" );
  5573. $eMailJournal->update ( array (
  5574. 'where' => 'ejid=' . $v ['ejid']
  5575. ) );
  5576. } else {
  5577. array_push ( $sendEmail, $value );
  5578. }
  5579. $falg = false;
  5580. break;
  5581. }
  5582. }
  5583. if ($falg) {
  5584. array_push ( $emailArray, $value ['email'] );
  5585. array_push ( $emailNameList, $value );
  5586. $eMailJournal->clientId = $value ['cid'];
  5587. $eMailJournal->status = 1;
  5588. $eMailJournal->email = $value ['email'];
  5589. $eMailJournal->date = date ( "Y-m-d" );
  5590. $eMailJournal->insert ();
  5591. }
  5592. } else {
  5593. array_push ( $emailArray, $value ['email'] );
  5594. array_push ( $emailNameList, $value );
  5595. $eMailJournal->clientId = $value ['cid'];
  5596. $eMailJournal->status = 1;
  5597. $eMailJournal->email = $value ['email'];
  5598. $eMailJournal->date = date ( "Y-m-d" );
  5599. $eMailJournal->insert ();
  5600. }
  5601. } else {
  5602. array_push ( $illegalEmail, $value );
  5603. }
  5604. }
  5605. Doo::db ()->commit ();
  5606. // echo json_encode($illegalEmail);
  5607. // json_encode(array_slice($illegalEmail,0,100))
  5608. // $kk=gzcompress();
  5609. // $ll=gzuncompress($kk);
  5610. // ."</br>".strlen($kk)."</br>".strlen($ll);die;
  5611. $size = floor ( count ( $emailArray ) / 3 );
  5612. if (! empty ( $emailArray )) {
  5613. if (count ( $emailArray ) < 3) {
  5614. $list = array (
  5615. 0 => $emailArray,
  5616. 1 => array (),
  5617. 2 => array ()
  5618. );
  5619. } else
  5620. $list = array_chunk ( $emailArray, $size );
  5621. } else
  5622. $list = array (
  5623. 0 => array (),
  5624. 1 => array (),
  5625. 2 => array ()
  5626. );
  5627. $emailJson = array ();
  5628. foreach ( $list as $value ) {
  5629. $em = array ();
  5630. foreach ( $value as $v ) {
  5631. array_push ( $em, $v );
  5632. }
  5633. array_push ( $emailJson, $em );
  5634. }
  5635. $size = floor ( count ( $emailNameList ) / 3 );
  5636. if (! empty ( $emailNameList )) {
  5637. if (count ( $emailNameList ) < 3) {
  5638. $list = array (
  5639. 0 => $emailNameList,
  5640. 1 => array (),
  5641. 2 => array ()
  5642. );
  5643. } else
  5644. $list = array_chunk ( $emailNameList, $size );
  5645. } else
  5646. $list = array (
  5647. 0 => array (),
  5648. 1 => array (),
  5649. 2 => array ()
  5650. );
  5651. $emailNameJson = array ();
  5652. foreach ( $list as $value ) {
  5653. $em = array ();
  5654. foreach ( $value as $v ) {
  5655. array_push ( $em, $v );
  5656. }
  5657. array_push ( $emailNameJson, $em );
  5658. }
  5659. //
  5660. $eMailList->date = date ( "Y-m-d" );
  5661. $eMailList->clientEmail = base64_encode ( gzcompress ( json_encode ( $emailJson [0] ) ) );
  5662. $eMailList->clientEmail2 = base64_encode ( gzcompress ( json_encode ( $emailJson [1] ) ) );
  5663. $eMailList->clientEmail3 = base64_encode ( gzcompress ( json_encode ( $emailJson [2] ) ) );
  5664. $eMailList->clientName = base64_encode ( gzcompress ( json_encode ( $emailNameJson [0] ) ) );
  5665. $eMailList->clientName2 = base64_encode ( gzcompress ( json_encode ( $emailNameJson [1] ) ) );
  5666. $eMailList->clientName3 = base64_encode ( gzcompress ( json_encode ( $emailNameJson [2] ) ) );
  5667. $eMailList->illegalEmail = json_encode ( array_slice ( $illegalEmail, 0, 100 ) ); // json_encode($illegalEmail);
  5668. $eMailList->sendEmail = json_encode ( $sendEmail );
  5669. $eMailList->templateName = $smartcostMail;
  5670. $eMailList->eTitle = $title;
  5671. $eMailList->html = $html;
  5672. $eMailList->content = $content;
  5673. $eMailList->info = $info;
  5674. if (! empty ( $annexName )) {
  5675. $eMailList->annex = $annexHtml;
  5676. $eMailList->annexName = $annexName;
  5677. }
  5678. if ($stype == 1) {
  5679. $eMailList->tag = implode ( ",", $tagId );
  5680. $eMailList->districtId = "";
  5681. $eMailList->nature = "";
  5682. }
  5683. if ($stype == 2) {
  5684. $eMailList->districtId = $did;
  5685. $eMailList->nature = implode ( ",", $nature );
  5686. $eMailList->tag = "";
  5687. }
  5688. $eMailList->update ( array (
  5689. 'where' => 'elid=' . $elid
  5690. ) );
  5691. return "/eMailList";
  5692. }
  5693. return "/eMailTask";
  5694. }
  5695. function createEmail() {
  5696. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  5697. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  5698. $skin = $this->get_args ( 'skin' ) ? $this->get_args ( 'skin' ) : "";
  5699. $content = isset ( $_POST ['content'] ) ? $_POST ['content'] : "";
  5700. $tagId = $this->get_args ( 'tagId' ) ? $this->get_args ( 'tagId' ) : array ();
  5701. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : array ();
  5702. $natureNULL = $this->get_args ( 'natureNULL' ) ? $this->get_args ( 'natureNULL' ) : "";
  5703. $did = $this->get_args ( 'did' ) ? $this->get_args ( 'did' ) : "";
  5704. $didCity = $this->get_args ( 'didCity' ) ? $this->get_args ( 'didCity' ) : "";
  5705. $stype = $this->get_args ( 'stype' ) ? $this->get_args ( 'stype' ) : "";
  5706. if (! empty ( $title ) && (! empty ( $tagId ) || ! empty ( $did ))) {
  5707. Doo::loadModel ( 'eMailTemplate' );
  5708. $eMailTemplate = new eMailTemplate ();
  5709. Doo::loadModel ( 'eMailJournal' );
  5710. $eMailJournal = new eMailJournal ();
  5711. if ($natureNULL != 'NULL') {
  5712. if (empty ( $tagId ) && ! empty ( $did ) && empty ( $nature )) {
  5713. header ( 'Content-Type:text/html;charset=utf-8' );
  5714. die ( '请选择性质' );
  5715. }
  5716. }
  5717. // annex
  5718. $annexPath = "";
  5719. $annexEXT = $this->_GetFileEXT ( $_FILES ["annex"] ["name"] );
  5720. $annexName = "";
  5721. if (isset ( $_FILES ['annex'] ['name'] )) {
  5722. 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)) {
  5723. $path = DOO::conf ()->SITE_PATH . "upload/emailAnnex/";
  5724. if (! file_exists ( $path . $_FILES ["annex"] ["name"] )) {
  5725. $fileName = time () . "." . $annexEXT;
  5726. $annexName = $_FILES ['annex'] ['name'];
  5727. $annexPath = $path . $fileName;
  5728. move_uploaded_file ( $_FILES ["annex"] ["tmp_name"], $annexPath );
  5729. $annexPath = $this->webPath . $fileName;
  5730. }
  5731. }
  5732. }
  5733. $annexHtml = '<table style="width:100%;margin:10px 0">
  5734. <thead>
  5735. <tr>
  5736. <th align="left" colspan="2">下载附件:</th>
  5737. </tr>
  5738. </thead>
  5739. <tbody>
  5740. <tr>
  5741. <td><a href="' . $annexPath . '" target="_blank">' . $annexName . '</a></td>
  5742. <td>&nbsp;</td>
  5743. </tr>
  5744. </tbody>
  5745. </table>';
  5746. $smartcostMail = 'smartcost_mail_1';
  5747. $info = "";
  5748. // html template
  5749. if ($skin == 1) {
  5750. $html = '<div><table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  5751. <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">
  5752. <tbody><tr>
  5753. <td style="background-color:#ff6501;padding:20px 0 25px;" align="center">
  5754. <span style="vertical-align:bottom;font-size:20px;color:#fff;">' . $title . '</span>
  5755. </td></tr><tr><td>
  5756. <table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;border-top:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  5757. <tbody><tr><td style="padding: 0 40px;" align="left">
  5758. <p style="margin-top:40px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;"><b>CLIENTNAME</b></p>
  5759. </td></tr><tr><td style="padding: 0 40px;" align="left">
  5760. <p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;">您好,我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
  5761. <p style="margin-top:0px;margin-bottom:20px;color:#383838;font-size:16px;line-height:32px;">
  5762. ' . $content . '</p>
  5763. </td></tr>
  5764. <tr><td align="left" style="padding: 0 40px;background:#fff">
  5765. ' . $annexHtml . '
  5766. </td></tr>
  5767. <tr>
  5768. <td style="padding: 10px 0 0;background:#F6F6F6;">
  5769. <table>
  5770. <tr>
  5771. <td style="font-size:14pxl;color:#666;padding:0 20px"><b>纵横软件公司' . $this->staff [0] ['category'] . '服务中心</b><br>' . $this->staff [0] ['username'] . '<br>
  5772. <a href="[图片]http://www.smartcost.com.cn" style="color:#666;font-size:12px;text-decoration:underline;">[图片]smartcost.com.cn</a></td>
  5773. <td>
  5774. <table>
  5775. <tr style="font-size:12px;color:#666">
  5776. <th align="right">电话:</th><td style="padding:0 20px 0 0">' . $this->staff [0] ['phone'] . '</td>
  5777. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td>
  5778. </tr>
  5779. <tr style="font-size:12px;color:#666">
  5780. <th align="right">Q Q:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5781. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td>
  5782. </tr>
  5783. </table>
  5784. </td>
  5785. </tr>
  5786. </table>
  5787. </td></tr></tbody></table></td></tr><tr>
  5788. <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>
  5789. </tr></tbody></table></td></tr></tbody></table></div>';
  5790. $info = '<table><tr><th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td></tr>
  5791. <tr><th align="right">联系人:</th><td>' . $this->staff [0] ['username'] . '</td></tr>
  5792. <tr><th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr>
  5793. <tr><th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td></tr>
  5794. <tr><th align="right">邮箱:</th><td>' . $this->staff [0] ['email'] . '</td></tr></table>';
  5795. } elseif ($skin == 2) {
  5796. $smartcostMail = 'smartcost_mail_2';
  5797. $html = '<table cellspacing="0" cellpadding="0" style="background-color:#e4e4e4; width:100%;"><tbody><tr><td>
  5798. <table align="center" cellspacing="0" cellpadding="0" style="background-color:#f8f8f8; width:640px;margin-bottom:20px">
  5799. <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;">
  5800. <b><span name="titleHtml">' . $title . '</span></b></p></td>
  5801. </tr><tr><td><table align="center" cellspacing="0" cellpadding="0" style="border:1px solid #ddd;"><tbody><tr>
  5802. <td align="center" style="background-color:#EEF2F5;padding:20px 0 "><a style="text-decoration:none;" href="https://smartcost.com.cn" target="_blank"><img src="http://d4.smartcost.com.cn/zonghenglogo.png"></a></td>
  5803. </tr><tr><td align="center" style="background-color:#fff;"></td>
  5804. </tr><tr><td align="left" style="background-color:#fff;padding:40px;border-bottom:1px solid #ddd;">
  5805. <p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;"><b>CLIENTNAME</b></p>
  5806. <p style="margin-top:0px;margin-bottom:10px;color:#383838;font-size:16px;line-height:32px;">您好,我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
  5807. <p name="contentHtml" style="margin-top:0px;margin-bottom:15px;color:#383838;font-size:16px;line-height:32px;">' . $content . '</p></td>
  5808. </tr>
  5809. <tr><td align="left" style="padding: 0 40px;background:#fff">
  5810. ' . $annexHtml . '
  5811. </td></tr>
  5812. <tr>
  5813. <td style="padding: 10px 0;background:#F6F6F6">
  5814. <table>
  5815. <tbody>
  5816. <tr>
  5817. <td style="font-size:14pxl;color:#333;padding:0 20px">
  5818. <b>纵横公路造价软件' . $this->staff [0] ['category'] . '服务中心</b><br>' . $this->staff [0] ['username'] . '</td>
  5819. <td>
  5820. <table>
  5821. <tbody>
  5822. <tr style="font-size:12px;color:#666">
  5823. <th align="right">电话:</th><td style="padding:0 20px 0 0">' . $this->staff [0] ['phone'] . '</td>
  5824. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#666">
  5825. <th align="right">Q Q:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5826. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td>
  5827. </tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr>
  5828. <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>
  5829. </tr></tbody></table></td></tr></tbody> </table>';
  5830. $info = '<table><tbody><tr style="font-size:12px;color:#666">
  5831. <th align="right">电话:</th><td style="padding:0 20px 0 0">' . $this->staff [0] ['phone'] . '</td>
  5832. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#666">
  5833. <th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5834. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td>
  5835. </tr></tbody></table>';
  5836. } else {
  5837. $smartcostMail = 'smartcost_mail_3';
  5838. $html = '<table cellspacing="0" cellpadding="0" style="background-color:#ECF0E1; width:100%">
  5839. <tbody>
  5840. <tr>
  5841. <td>
  5842. <table align="center" cellspacing="0" cellpadding="0" style="width:698px;margin-bottom:30px;margin-top:30px;">
  5843. <tbody>
  5844. <tr>
  5845. <td>
  5846. <table align="center" cellspacing="0" cellpadding="0" style="border:1px solid #ccc;width:100%;border-top:none">
  5847. <tbody>
  5848. <tr>
  5849. <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;">
  5850. <div style="position:relative;text-align:right">
  5851. <b style="font-size:24px;color:#8A9F98;z-index:999"><span name="titleHtml">' . $title . '</span></b>
  5852. <div style="width:80px;height:80px;position:absolute;top:0;left:0"><img src="http://d4.smartcost.com.cn/zonghenglogo.png"></div>
  5853. </div>
  5854. </td>
  5855. </tr>
  5856. <tr>
  5857. <td align="left" style="background-color:#fff;padding:40px;border-bottom:1px solid #ddd;">
  5858. <p style="margin-top:0px;margin-bottom:10px;color:#666;font-size:16px;line-height:32px;"><b>CLIENTNAME</b></p>
  5859. <p style="margin-top:0px;margin-bottom:10px;color:#666;font-size:16px;line-height:32px;">您好,我是纵横公路造价软件 <b>' . $this->staff [0] ['username'] . '</b>:</p>
  5860. <p name="contentHtml" style="margin-top:0px;margin-bottom:15px;color:#666;font-size:16px;line-height:32px;">' . $content . '</p></td>
  5861. </tr>
  5862. <tr><td align="left" style="padding: 0 40px;background:#fff">
  5863. ' . $annexHtml . '
  5864. </td></tr>
  5865. <tr>
  5866. <td style="padding: 10px 0 0;background:#F6F6F6;">
  5867. <table>
  5868. <tbody><tr>
  5869. <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>
  5870. <td>
  5871. <table style="width:100%">
  5872. <tbody><tr style="font-size:12px;color:#496781">
  5873. <th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td>
  5874. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td>
  5875. </tr>
  5876. <tr style="font-size:12px;color:#496781">
  5877. <th align="right">Q Q:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5878. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td>
  5879. </tr>
  5880. </tbody></table>
  5881. </td>
  5882. </tr>
  5883. </tbody></table>
  5884. </td>
  5885. </tr>
  5886. <tr>
  5887. <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>
  5888. </tr>
  5889. </tbody>
  5890. </table></td>
  5891. </tr>
  5892. </tbody>
  5893. </table></td>
  5894. </tr>
  5895. </tbody>
  5896. </table>';
  5897. $info = '<table><tr style="font-size:12px;color:#496781"><th align="right">电话:</th><td>' . $this->staff [0] ['phone'] . '</td>
  5898. <th align="right">手机:</th><td>' . $this->staff [0] ['telephone'] . '</td></tr><tr style="font-size:12px;color:#496781">
  5899. <th align="right">QQ:</th><td>' . $this->staff [0] ['qq'] . '</td>
  5900. <th align="right">邮箱: </th><td>' . $this->staff [0] ['email'] . '</td></tr></table>
  5901. ';
  5902. }
  5903. $eMailTemplate->title = $title;
  5904. $eMailTemplate->skin = $skin;
  5905. $eMailTemplate->content = $content;
  5906. if (! empty ( $tagId ))
  5907. $eMailTemplate->tag = implode ( ",", $tagId );
  5908. $eMailTemplate->staffId = $this->staff [0] ['sid'];
  5909. $eMailTemplate->staffName = $this->staff [0] ['username'];
  5910. $eMailTemplate->status = 0;
  5911. $eMailTemplate->html = $html;
  5912. $eMailTemplate->annex = $annexPath;
  5913. $eMailTemplate->annexName = $annexName;
  5914. $etid = $eMailTemplate->insert ();
  5915. // create email list
  5916. Doo::loadModel ( 'tag_client' );
  5917. $tagClient = new tag_client ();
  5918. Doo::loadModel ( 'client' );
  5919. $client = new client ();
  5920. Doo::loadModel ( 'eMailList' );
  5921. $eMailList = new eMailList ();
  5922. Doo::loadModel ( 'company' );
  5923. $company = new company ();
  5924. $tagCondition = "";
  5925. $tagArray = array ();
  5926. foreach ( $tagId as $value ) {
  5927. array_push ( $tagArray, " tag like '%" . $value . "%' " );
  5928. }
  5929. if (! empty ( $tagArray ))
  5930. $tagCondition = ' and (' . implode ( " or ", $tagArray ) . ')';
  5931. $clientList = $tagClient->find ( array (
  5932. 'select' => 'client',
  5933. 'where' => 'sid=' . $this->staff [0] ['sid'] . $tagCondition,
  5934. 'asArray' => true
  5935. ) );
  5936. $clientArray = array ();
  5937. foreach ( $clientList as $value ) {
  5938. array_push ( $clientArray, $value ['client'] );
  5939. }
  5940. $clientEmailList = array ();
  5941. if (! empty ( $clientArray ))
  5942. $clientEmailList = $client->find ( array (
  5943. 'select' => 'email,cid,nicename as clientname,companyname',
  5944. 'where' => 'cid in (' . implode ( ",", $clientArray ) . ')',
  5945. 'asArray' => true
  5946. ) );
  5947. //
  5948. if ($stype == 2) {
  5949. // 获取性质相关数据
  5950. $cidList = '';
  5951. if ($natureNULL == '') {
  5952. $nD = array ();
  5953. foreach ( $nature as $key => $value ) {
  5954. array_push ( $nD, ' nature like "' . $value . '"' );
  5955. // $nD=' nature like "'.$value.'"';
  5956. }
  5957. $nD = implode ( ' or ', $nD );
  5958. $companycid = $company->find ( array (
  5959. 'select' => 'cid',
  5960. 'where' => $nD,
  5961. 'asArray' => true
  5962. ) );
  5963. $cidList = array ();
  5964. foreach ( $companycid as $key => $value ) {
  5965. array_push ( $cidList, $value ['cid'] );
  5966. }
  5967. $cidList = implode ( ',', $cidList );
  5968. if (! empty ( $cidList ))
  5969. $cidList = ' and companyid in (' . $cidList . ')';
  5970. else
  5971. $cidList = '';
  5972. }
  5973. // 'select'=>'email,cid,nicename as clientname,companyname,district'
  5974. $where='district like "' . $did . ',%" ' . $cidList;
  5975. if ($didCity!="ALL"){
  5976. Doo::loadClass ( 'XDeode' );
  5977. $XDeode = new XDeode ( 5 );
  5978. $didCity = $XDeode->decode ( $didCity );
  5979. $where='district like "' . $did . ','.$didCity.',%" ' . $cidList;
  5980. }
  5981. $clientEmailList = $client->find ( array (
  5982. 'select' => 'email,cid,nicename as clientname,companyname,district',
  5983. 'where' => $where,
  5984. 'asArray' => true
  5985. ) );
  5986. }
  5987. // ;datediff(curdate(), 'date')>=10
  5988. $eMailJournal->delete ( array (
  5989. 'where' => "datediff(curdate(), date)>=7"
  5990. ) );
  5991. $checkMail = $eMailJournal->find ( array (
  5992. 'where' => 'DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(date)',
  5993. ' groupby' => 'email',
  5994. 'asArray' => true
  5995. ) );
  5996. $emailNameList = $emailArray = $illegalEmail = $sendEmail = array ();
  5997. Doo::db ()->beginTransaction ();
  5998. foreach ( $clientEmailList as $value ) {
  5999. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  6000. if (! empty ( $checkMail )) {
  6001. $falg = true;
  6002. foreach ( $checkMail as $v ) {
  6003. if ($v ['email'] == $value ['email']) {
  6004. $Bdate = strtotime ( $v ['date'] ) + 7 * 24 * 3600;
  6005. if ($Bdate <= time ()) {
  6006. array_push ( $emailArray, $value ['email'] );
  6007. array_push ( $emailNameList, $value );
  6008. $eMailJournal->date = date ( "Y-m-d" );
  6009. $eMailJournal->update ( array (
  6010. 'where' => 'ejid=' . $v ['ejid']
  6011. ) );
  6012. } else {
  6013. array_push ( $sendEmail, $value );
  6014. }
  6015. $falg = false;
  6016. break;
  6017. }
  6018. }
  6019. if ($falg) {
  6020. array_push ( $emailArray, $value ['email'] );
  6021. array_push ( $emailNameList, $value );
  6022. $eMailJournal->clientId = $value ['cid'];
  6023. $eMailJournal->status = 1;
  6024. $eMailJournal->email = $value ['email'];
  6025. $eMailJournal->date = date ( "Y-m-d" );
  6026. // $eMailJournal->insert();
  6027. }
  6028. } else {
  6029. array_push ( $emailArray, $value ['email'] );
  6030. array_push ( $emailNameList, $value );
  6031. $eMailJournal->clientId = $value ['cid'];
  6032. $eMailJournal->status = 1;
  6033. $eMailJournal->email = $value ['email'];
  6034. $eMailJournal->date = date ( "Y-m-d" );
  6035. // $eMailJournal->insert();
  6036. }
  6037. } else {
  6038. array_push ( $illegalEmail, $value );
  6039. }
  6040. }
  6041. Doo::db ()->commit ();
  6042. // echo json_encode($illegalEmail);
  6043. // json_encode(array_slice($illegalEmail,0,100))
  6044. // $kk=gzcompress();
  6045. // $ll=gzuncompress($kk);
  6046. // ."</br>".strlen($kk)."</br>".strlen($ll);die;
  6047. $size = floor ( count ( $emailArray ) / 3 );
  6048. if (! empty ( $emailArray )) {
  6049. if (count ( $emailArray ) < 3) {
  6050. $list = array (
  6051. 0 => $emailArray,
  6052. 1 => array (),
  6053. 2 => array ()
  6054. );
  6055. } else
  6056. $list = array_chunk ( $emailArray, $size );
  6057. } else
  6058. $list = array (
  6059. 0 => array (),
  6060. 1 => array (),
  6061. 2 => array ()
  6062. );
  6063. $emailJson = array ();
  6064. foreach ( $list as $value ) {
  6065. $em = array ();
  6066. foreach ( $value as $v ) {
  6067. array_push ( $em, $v );
  6068. }
  6069. array_push ( $emailJson, $em );
  6070. }
  6071. $size = floor ( count ( $emailNameList ) / 3 );
  6072. if (! empty ( $emailNameList )) {
  6073. if (count ( $emailNameList ) < 3) {
  6074. $list = array (
  6075. 0 => $emailNameList,
  6076. 1 => array (),
  6077. 2 => array ()
  6078. );
  6079. } else
  6080. $list = array_chunk ( $emailNameList, $size );
  6081. } else
  6082. $list = array (
  6083. 0 => array (),
  6084. 1 => array (),
  6085. 2 => array ()
  6086. );
  6087. $emailNameJson = array ();
  6088. foreach ( $list as $value ) {
  6089. $em = array ();
  6090. foreach ( $value as $v ) {
  6091. array_push ( $em, $v );
  6092. }
  6093. array_push ( $emailNameJson, $em );
  6094. }
  6095. //
  6096. $eMailList->date = date ( "Y-m-d" );
  6097. $eMailList->clientEmail = base64_encode ( gzcompress ( json_encode ( $emailJson [0] ) ) );
  6098. $eMailList->clientEmail2 = base64_encode ( gzcompress ( json_encode ( $emailJson [1] ) ) );
  6099. $eMailList->clientEmail3 = base64_encode ( gzcompress ( json_encode ( $emailJson [2] ) ) );
  6100. $eMailList->clientName = base64_encode ( gzcompress ( json_encode ( $emailNameJson [0] ) ) );
  6101. $eMailList->clientName2 = base64_encode ( gzcompress ( json_encode ( $emailNameJson [1] ) ) );
  6102. $eMailList->clientName3 = base64_encode ( gzcompress ( json_encode ( $emailNameJson [2] ) ) );
  6103. $eMailList->illegalEmail = json_encode ( array_slice ( $illegalEmail, 0, 100 ) ); // json_encode($illegalEmail);
  6104. $eMailList->sendEmail = json_encode ( $sendEmail );
  6105. $eMailList->etid = $etid;
  6106. $eMailList->templateName = $smartcostMail;
  6107. $eMailList->eTitle = $title;
  6108. $eMailList->html = $html;
  6109. $eMailList->content = $content;
  6110. $eMailList->info = $info;
  6111. if (! empty ( $annexName ))
  6112. $eMailList->annex = $annexHtml;
  6113. $eMailList->annexName = $annexName;
  6114. $eMailList->staffId = $this->staff [0] ['sid'];
  6115. $eMailList->staffName = $this->staff [0] ['username'];
  6116. if ($stype == 1)
  6117. $eMailList->tag = implode ( ",", $tagId );
  6118. if ($stype == 2) {
  6119. $eMailList->districtId = $did;
  6120. $eMailList->nature = implode ( ",", $nature );
  6121. }
  6122. $eMailList->insert ();
  6123. // 创建邮件地址
  6124. // 'http://sendcloud.sohu.com/webapi/list_member.add.json';
  6125. // print_r($emailJson);
  6126. // die;
  6127. return "/eMailList";
  6128. }
  6129. return "/eMailTask";
  6130. }
  6131. function eMailList() {
  6132. Doo::loadModel ( 'eMailList' );
  6133. $eMailList = new eMailList ();
  6134. Doo::loadModel ( 'tag' );
  6135. $tag = new tag ();
  6136. $mailList = $eMailList->find ( array (
  6137. 'where' => 'staffId=' . $this->staff [0] ['sid'],
  6138. 'desc' => 'elid',
  6139. 'asArray' => true
  6140. ) );
  6141. foreach ( $mailList as $key => $value ) {
  6142. $mailList [$key] ['clientName2'] = $mailList [$key] ['clientName3'] = array ();
  6143. $mailList [$key] ['clientName'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName'] ) ), true );
  6144. if (! empty ( $value ['clientName2'] ))
  6145. $mailList [$key] ['clientName2'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName2'] ) ), true );
  6146. if (! empty ( $value ['clientName3'] ))
  6147. $mailList [$key] ['clientName3'] = json_decode ( gzuncompress ( base64_decode ( $value ['clientName3'] ) ), true );
  6148. $mailList [$key] ['illegalEmail'] = json_decode ( $value ['illegalEmail'], true );
  6149. $mailList [$key] ['sendEmail'] = json_decode ( $value ['sendEmail'], true );
  6150. $mailList [$key] ['clientCount'] = count ( $mailList [$key] ['clientName'] ) + count ( $mailList [$key] ['clientName2'] ) + count ( $mailList [$key] ['clientName3'] );
  6151. $mailList [$key] ['tag'] = array ();
  6152. if (! empty ( $value ['tag'] ))
  6153. $mailList [$key] ['tag'] = $tag->find ( array (
  6154. 'where' => 'tid in ( ' . $value ['tag'] . ') ',
  6155. 'asArray' => true
  6156. ) );
  6157. }
  6158. $data ['mailList'] = $mailList;
  6159. $data ['memu'] = "eMailTask";
  6160. $data ['staff'] = $this->staff;
  6161. $data ['mailMemu'] = 'eMailList';
  6162. $this->render ( "/mail_list", $data );
  6163. }
  6164. function showEmailContent() {
  6165. $elid = isset ( $this->params ['elid'] ) ? $this->params ['elid'] : 0;
  6166. Doo::loadModel ( 'eMailList' );
  6167. $eMList = new eMailList ();
  6168. $isSend = $eMList->getOne ( array (
  6169. 'where' => 'elid =' . $elid . '',
  6170. 'asArray' => true
  6171. ) );
  6172. echo htmlspecialchars ( $isSend ['content'] );
  6173. }
  6174. function postEmail() {
  6175. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  6176. $elid = isset ( $this->params ['elid'] ) ? $this->params ['elid'] : 0;
  6177. $send = isset ( $this->params ['send'] ) ? $this->params ['send'] : 0;
  6178. Doo::loadModel ( 'eMailList' );
  6179. $eMList = new eMailList ();
  6180. if (! empty ( $elid )) {
  6181. $isSend = $eMList->getOne ( array (
  6182. 'select' => 'send' . $send,
  6183. 'where' => 'elid =' . $elid . ' and status=0 and send' . $send . '=1',
  6184. 'asArray' => true
  6185. ) );
  6186. if (! empty ( $isSend ))
  6187. die ( '这批邮件已经发送' );
  6188. if ($send == 1)
  6189. $send = '';
  6190. $eMailList = $eMList->getOne ( array (
  6191. 'select' => 'eTitle,staffName,clientName' . $send . ' as clientName,clientEmail' . $send . ' as clientEmail,annex,info,content,templateName',
  6192. 'where' => 'elid =' . $elid . ' and status=0',
  6193. 'asArray' => true
  6194. ) );
  6195. if ($send == "")
  6196. $send = 1;
  6197. $sql = "update `CLD_eMailList` set send" . $send . "='1' where elid = '" . $elid . "'";
  6198. Doo::db ()->query ( $sql );
  6199. $isSend = $eMList->getOne ( array (
  6200. 'where' => 'elid =' . $elid . ' and status=0 and send1=1 and send2=1 and send3=1',
  6201. 'asArray' => true
  6202. ) );
  6203. if (! empty ( $isSend )) {
  6204. $sql = "update `CLD_eMailList` set status='2' where elid = '" . $elid . "'";
  6205. Doo::db ()->query ( $sql );
  6206. }
  6207. $toFormatMail = array ();
  6208. $sub = array ();
  6209. // file_put_contents("test.txt", "This is another something.<br/>", FILE_APPEND);
  6210. // sleep(4);
  6211. // die;
  6212. $toMail = json_decode ( gzuncompress ( base64_decode ( $eMailList ['clientEmail'] ) ), true );
  6213. // $toMailCount=count($toMail);
  6214. $subMail = json_decode ( gzuncompress ( base64_decode ( $eMailList ['clientName'] ) ), true );
  6215. $chunkMail = array_chunk ( $toMail, 80 );
  6216. $chunkSubMail = array_chunk ( $subMail, 80 );
  6217. $vii = 0;
  6218. foreach ( $chunkMail as $key => $value ) {
  6219. $l = $s = $c = $i = $cate = $con = $annex = array ();
  6220. $toFormatMail ['to'] = $value;
  6221. $cn = $chunkSubMail [$key];
  6222. foreach ( $cn as $v ) {
  6223. array_push ( $l, $eMailList ['eTitle'] );
  6224. array_push ( $s, $eMailList ['staffName'] );
  6225. array_push ( $c, $v ['clientname'] );
  6226. array_push ( $annex, $eMailList ['annex'] );
  6227. array_push ( $i, $eMailList ['info'] );
  6228. // array_push($con, $eMailList['content']);
  6229. array_push ( $cate, $this->staff [0] ['category'] );
  6230. }
  6231. $sub ['%eTitle%'] = $l;
  6232. $sub ['%staffName%'] = $s;
  6233. $sub ['%clientName%'] = $c;
  6234. $sub ['%category%'] = $cate;
  6235. $sub ['%info%'] = $i;
  6236. // $sub['%content%']=$con;
  6237. $sub ['%annex%'] = $annex;
  6238. $toFormatMail ['sub'] = $sub;
  6239. $url = 'http://sendcloud.sohu.com/webapi/mail.send_template.xml';
  6240. $param = array (
  6241. 'api_user' => 'cldmail',
  6242. 'api_key' => 'cDO1GjtY1seH',
  6243. 'template_invoke_name' => $eMailList ['templateName'],
  6244. 'from' => $this->staff [0] ['email'],
  6245. 'fromname' => '纵横' . $eMailList ['staffName'],
  6246. 'subject' => $eMailList ['eTitle'],
  6247. 'substitution_vars' => json_encode ( $toFormatMail )
  6248. );
  6249. $post_data = http_build_query ( $param );
  6250. $ch = curl_init ();
  6251. curl_setopt ( $ch, CURLOPT_POST, 1 );
  6252. curl_setopt ( $ch, CURLOPT_URL, $url );
  6253. curl_setopt ( $ch, CURLOPT_HEADER, false ); // 设定是否输出页面内容
  6254. curl_setopt ( $ch, CURLOPT_NOBODY, false );
  6255. curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_data );
  6256. $result = curl_exec ( $ch );
  6257. curl_close ( $ch );
  6258. /*
  6259. * if($result=='success'){ $eM=new eMailList(); $eM->status='2'; $eM->update(array('where'=>'elid=?','param'=>array($elid))); }
  6260. */
  6261. }
  6262. // die;
  6263. return '/eMailList';
  6264. }
  6265. }
  6266. function a() {
  6267. $substitution_vars = $this->get_args ( 'substitution_vars' );
  6268. file_put_contents ( DOO::conf ()->SITE_PATH . 'upload/' . "_" . time () . "_" . rand ( 100, 999 ) . ".log", $substitution_vars );
  6269. }
  6270. function deleteEmail() {
  6271. $elid = isset ( $this->params ['elid'] ) ? $this->params ['elid'] : 0;
  6272. if (! empty ( $elid )) {
  6273. $sql = "DELETE FROM `CLD_eMailList` where elid = '" . $elid . "'";
  6274. Doo::db ()->query ( $sql );
  6275. return '/eMailList';
  6276. }
  6277. }
  6278. /**
  6279. * 发送post请求
  6280. * @param string $url 请求地址
  6281. * @param array $post_data post键值对数据
  6282. * @return string
  6283. */
  6284. function sendPost($url, $post_data) {
  6285. $postdata = http_build_query ( $post_data );
  6286. // X-Amzn-Authorization: AWS3 AWSAccessKeyId=AKIAIDSE5VYNX5ERJHXQ,Signature=lBP67vCvGlDMBQ=dofZxg8E8SUEXAMPLE,Algorithm=HmacSHA256,SignedHeaders=qG1BdSh9QyYPlWLnjqvjDXjyPdFjl7fUSkfs0Hk2
  6287. $options = array (
  6288. 'http' => array (
  6289. 'method' => 'POST',
  6290. 'header' => '
  6291. Content-Type: application/x-www-form-urlencoded
  6292. ',
  6293. 'content' => $postdata,
  6294. 'timeout' => 15 * 60
  6295. )
  6296. ); // 超时时间(单位:s)
  6297. $context = stream_context_create ( $options );
  6298. $result = file_get_contents ( $url, false, $context );
  6299. return $result;
  6300. }
  6301. function avatar() {
  6302. $result = array ();
  6303. $result ['success'] = false;
  6304. $successNum = 0;
  6305. // 定义一个变量用以储存当前头像的序号
  6306. $avatarNumber = 1;
  6307. $i = 0;
  6308. $msg = '';
  6309. // 上传目录
  6310. $dir = DOO::conf ()->SITE_PATH . "global/avatar";
  6311. // 遍历所有文件域
  6312. while ( list ( $key, $val ) = each ( $_FILES ) ) {
  6313. if ($_FILES [$key] ['error'] > 0)
  6314. $msg .= $_FILES [$key] ['error'];
  6315. else {
  6316. $fileName = 'avatar_' . $this->staff [0] ['sid'];
  6317. // 原始图片(file 域的名称:__source,如果客户端定义可以上传的话,可在此处理)。
  6318. if ($key == '__source') { // 当前头像基于原图的初始化参数,用于修改头像时保证界面的视图跟保存头像时一致。帮助提升用户体验度。修改头像时设置默认加载的原图的url为此图片的url+该参数即可。
  6319. $initParams = $_POST ["__initParams"];
  6320. $virtualPath = $dir . "/" . $fileName . "_" . $avatarNumber . ".jpg";
  6321. $result ['sourceUrl'] = '/' . $virtualPath . $initParams;
  6322. move_uploaded_file ( $_FILES [$key] ["tmp_name"], $virtualPath );
  6323. $successNum ++;
  6324. } else if (strpos ( $key, '__avatar' ) === 0) { // 头像图片(file 域的名称:__avatar1,2,3...)。
  6325. $virtualPath = $dir . "/" . $fileName . "_" . $avatarNumber . ".jpg";
  6326. $result ['avatarUrls'] [$i] = '/' . $virtualPath;
  6327. move_uploaded_file ( $_FILES [$key] ["tmp_name"], $virtualPath );
  6328. $avatarNumber ++;
  6329. $successNum ++;
  6330. $i ++;
  6331. }
  6332. }
  6333. }
  6334. $result ['msg'] = $msg;
  6335. if ($successNum > 0)
  6336. $result ['success'] = true;
  6337. // 返回图片的保存结果(返回内容为json字符串)
  6338. Doo::loadModel ( 'staff' );
  6339. $staff = new staff ();
  6340. $staff->sid = $this->staff [0] ['sid'];
  6341. $staff->avatar = "/global/avatar/" . $fileName;
  6342. $staff->update ();
  6343. echo json_encode ( $result );
  6344. }
  6345. function lockUpload() {
  6346. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6347. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6348. $file = $_FILES ['Filedata'] ['tmp_name'];
  6349. $error = false;
  6350. if (! is_uploaded_file ( $file )) {
  6351. $error = '400 Bad Request';
  6352. }
  6353. if ($error) {
  6354. header ( 'HTTP/1.0 ' . $error );
  6355. die ( 'Error ' . $error );
  6356. } else {
  6357. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6358. $this->IoHandler = new IoHandler ();
  6359. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6360. // $filedir=$_POST['time'];
  6361. // 调用定义物理路径
  6362. $t = DOO::conf ()->SITE_PATH . "upload/";
  6363. $this->IoHandler->MakeDir ( $t );
  6364. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6365. if ($filename != 'xlsx')
  6366. return "";
  6367. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6368. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6369. $upload_dir = $t . "/" . $upload_file;
  6370. $k = move_uploaded_file ( $file, $upload_dir );
  6371. if ($k) {
  6372. // "series/".$filedir."/".
  6373. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6374. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6375. }
  6376. }
  6377. }
  6378. }
  6379. function getAuthentication() {
  6380. }
  6381. function loadCVS() {
  6382. Doo::loadModel ( 'longle' );
  6383. $longle = new longle ();
  6384. $list = $longle->find ( array (
  6385. 'select' => 'key_num',
  6386. 'asArray' => TRUE
  6387. ) );
  6388. $file = fopen ( DOO::conf ()->SITE_PATH . "upload/key2.csv", 'r' );
  6389. while ( $data = fgetcsv ( $file ) ) {
  6390. $goods_list [$data [0]] = $data [1];
  6391. }
  6392. fclose ( $file );
  6393. $sqlArray = array ();
  6394. $sql = 'UPDATE CLD_longle SET SerialNumber = CASE key_num ';
  6395. foreach ( $list as $key => $value ) {
  6396. if (array_key_exists ( $value ['key_num'], $goods_list )) {
  6397. // echo $value['key_num'].'-'.$goods_list[$value['key_num']].'<br/>';
  6398. // $longle->SerialNumber=$goods_list[$value['key_num']];
  6399. // $longle->update(array('where'=>'key_num="'.$value['key_num'].'"'));
  6400. $sql .= ' WHEN "' . $value ['key_num'] . '" THEN "' . $goods_list [$value ['key_num']] . '" ';
  6401. array_push ( $sqlArray, '"' . $value ['key_num'] . '"' );
  6402. unset ( $goods_list [$value ['key_num']] );
  6403. }
  6404. }
  6405. $sql .= 'END WHERE key_num IN (' . implode ( ',', $sqlArray ) . ')';
  6406. echo $sql . '<br/>--------------------------------<br/>';
  6407. foreach ( $goods_list as $key => $value ) {
  6408. echo $key . ',' . $value . '<br/>';
  6409. }
  6410. }
  6411. private function getRandChar($length) {
  6412. $str = null;
  6413. $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
  6414. $max = strlen ( $strPol ) - 1;
  6415. for($i = 0; $i < $length; $i ++) {
  6416. $str .= $strPol [rand ( 0, $max )]; // rand($min,$max)生成介于min和max两个数之间的一个随机整数
  6417. }
  6418. return $str;
  6419. }
  6420. // private function getReceiptCount(){
  6421. // $status=2;
  6422. // $year=date('Y');
  6423. // Doo::loadModel('receipt');
  6424. // $receipt=new receipt();
  6425. // $dateCondition=" and Year(date) =".$year;
  6426. // $approvalCondition=' and nowStaff like "%'.$this->staff[0]['sid'].'%" ';
  6427. // $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  6428. // return count($receiptList);
  6429. // }
  6430. // private function getExeCount(){
  6431. // Doo::loadModel('receipt');
  6432. // $receipt=new receipt();
  6433. // $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));
  6434. // return count($receiptList);
  6435. // }
  6436. /**
  6437. * 格式化excel文件为数组
  6438. * @param unknown_type $file_url
  6439. * @param unknown_type $mcid
  6440. */
  6441. function _format_excel_to_array($file_url = "") {
  6442. if (! file_exists ( $file_url ))
  6443. return array ();
  6444. Doo::loadClass ( 'PHPExcel' );
  6445. $PHPExcel = new PHPExcel ();
  6446. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6447. if (! $PHPReader->canRead ( $file_url )) {
  6448. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6449. if (! $PHPReader->canRead ( $file_url )) {
  6450. echo 'no Excel';
  6451. return;
  6452. }
  6453. }
  6454. $PHPExcel = $PHPReader->load ( $file_url );
  6455. /**
  6456. * 读取excel文件中的第一个工作表
  6457. */
  6458. $currentSheet = $PHPExcel->getSheet ( 0 );
  6459. /**
  6460. * 取得最大的列号
  6461. */
  6462. $allColumn = $currentSheet->getHighestColumn ();
  6463. /**
  6464. * 取得一共有多少行
  6465. */
  6466. $allRow = $currentSheet->getHighestRow ();
  6467. $excel_array = array ();
  6468. for($currentRow = 2; $currentRow <= $allRow; $currentRow ++) {
  6469. $excel_column = array ();
  6470. // 后期改进
  6471. if ($allColumn == 'AM')
  6472. $allColumn = 'Z';
  6473. /**
  6474. * 从第A列开始输出
  6475. */
  6476. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6477. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6478. /**
  6479. * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312',
  6480. */
  6481. $val = "'" . addslashes ( $val ) . "'";
  6482. if ($currentColumn == 'A')
  6483. $excel_column ['key_num'] = $val;
  6484. elseif ($currentColumn == 'C')
  6485. $excel_column ['product'] = $val;
  6486. elseif ($currentColumn == 'D') {
  6487. $val = str_replace ( "'", "", $val );
  6488. $excel_column ['make_day'] = $this->excelTime ( $val );
  6489. } elseif ($currentColumn == 'E') {
  6490. $val = str_replace ( "'", "", $val );
  6491. $excel_column ['alloted_time'] = $this->excelTime ( $val );
  6492. } elseif ($currentColumn == 'F') {
  6493. $val = str_replace ( "'", "", $val );
  6494. $excel_column ['version'] = $val;
  6495. } elseif ($currentColumn == 'B') {
  6496. $val = str_replace ( "'", "", $val );
  6497. $excel_column ['SerialNumber'] = $val;
  6498. }
  6499. }
  6500. array_push ( $excel_array, $excel_column );
  6501. }
  6502. return $excel_array;
  6503. }
  6504. function excelTime($date, $time = false) {
  6505. if (function_exists ( 'GregorianToJD' )) {
  6506. if (is_numeric ( $date )) {
  6507. $jd = GregorianToJD ( 1, 1, 1970 );
  6508. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6509. $date = explode ( '/', $gregorian );
  6510. $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" : '');
  6511. return $date_str;
  6512. }
  6513. } else {
  6514. $date = $date > 25568 ? $date + 1 : 25569;
  6515. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6516. $ofs = (70 * 365 + 17 + 2) * 86400;
  6517. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6518. }
  6519. return $date;
  6520. }
  6521. function _GetFileEXT($filename) {
  6522. $pics = explode ( '.', $filename );
  6523. $num = count ( $pics );
  6524. return $pics [$num - 1];
  6525. }
  6526. /**
  6527. * 获取get或者POST值
  6528. * @param string $name 属性名称
  6529. * @return fixed 值
  6530. */
  6531. function get_args($name) {
  6532. if (isset ( $_GET [$name] )) {
  6533. if (is_array ( $_GET [$name] ))
  6534. return $_GET [$name];
  6535. else {
  6536. return addslashes ( $_GET [$name] );
  6537. }
  6538. } elseif (isset ( $_POST [$name] )) {
  6539. if (is_array ( $_POST [$name] ))
  6540. return $_POST [$name];
  6541. else {
  6542. return addslashes ( $_POST [$name] );
  6543. }
  6544. } else {
  6545. return false;
  6546. }
  6547. }
  6548. function get_previous($on_page = 1) {
  6549. return $on_page != 0 ? $on_page - 1 : $on_page;
  6550. }
  6551. /**
  6552. * 获得分页数据
  6553. * @param unknown_type $table
  6554. * @param unknown_type $condition
  6555. * @param unknown_type $on_page
  6556. * @param unknown_type $page_size
  6557. */
  6558. function get_Tpage($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $tagSQL) {
  6559. $page_c = "";
  6560. $page ['previous'] = $this->get_previous ( $on_page );
  6561. $page ['on_page'] = $on_page;
  6562. $total_count = $this->get_table_Tcount ( $table, $condition, $tagSQL );
  6563. $total = intval ( $total_count / $page_size );
  6564. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6565. $page ['total_data'] = $total_count;
  6566. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6567. $i = 1;
  6568. $page_max = 1;
  6569. if ($on_page > 10) {
  6570. $page_max = intval ( $on_page / 10 ) + 1;
  6571. $i = intval ( $on_page / 10 ) * 10 - 1;
  6572. }
  6573. $page ['page'] = $page_c;
  6574. $page ['lower'] = (-- $on_page) * $page_size;
  6575. return $page;
  6576. }
  6577. /**
  6578. * 获得分页数据
  6579. * @param unknown_type $table
  6580. * @param unknown_type $condition
  6581. * @param unknown_type $on_page
  6582. * @param unknown_type $page_size
  6583. */
  6584. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page", $staffid = "", $search, $tooltip, $cateid, $tagSQL) {
  6585. $page_c = "";
  6586. $page ['previous'] = $this->get_previous ( $on_page );
  6587. $page ['on_page'] = $on_page;
  6588. $total_count = $this->get_table_count ( $table, $condition, $staffid, $search, $tooltip, $cateid, $tagSQL );
  6589. $total = intval ( $total_count / $page_size );
  6590. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6591. $page ['total_data'] = $total_count;
  6592. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6593. $i = 1;
  6594. $page_max = 1;
  6595. if ($on_page > 10) {
  6596. $page_max = intval ( $on_page / 10 ) + 1;
  6597. $i = intval ( $on_page / 10 ) * 10 - 1;
  6598. }
  6599. for(; $i <= $page ['total_page']; $i ++) {
  6600. if ($i == $on_page) {
  6601. if ($other == "page")
  6602. $page_c .= '<a href="javascript:void(0);" class="current">' . $i . '</a>';
  6603. else
  6604. $page_c .= '&nbsp;<span class="current">' . $i . '</span>&nbsp;';
  6605. } else if ($other == "page")
  6606. $page_c .= '<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>';
  6607. else
  6608. $page_c .= '&nbsp;<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>&nbsp;';
  6609. if ($i == (10 * $page_max))
  6610. break;
  6611. }
  6612. $page ['page'] = $page_c;
  6613. $page ['lower'] = (-- $on_page) * $page_size;
  6614. return $page;
  6615. }
  6616. /**
  6617. * 获取总页数
  6618. * @param unknown_type $table
  6619. * @param unknown_type $condition
  6620. */
  6621. public function get_table_Tcount($table = "", $condition = "", $tagSQL) {
  6622. if ($tagSQL)
  6623. $sql = "select count(*) as count from CLD_tagCompanyNexus as a left join CLD_company as b on (a.company=b.cid ) where " . $condition;
  6624. else
  6625. $sql = "select count(*) as count from CLD_company where " . $condition;
  6626. $query = Doo::db ()->query ( $sql );
  6627. $result = $query->fetch ();
  6628. return $result ['count'];
  6629. }
  6630. /**
  6631. * 获取总页数
  6632. * @param unknown_type $table
  6633. * @param unknown_type $condition
  6634. */
  6635. public function get_table_count($table = "", $condition = "", $staffid = "", $search, $tooltip, $cateid, $tagSQL) {
  6636. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  6637. // echo $staffid;die;
  6638. //
  6639. if (! empty ( $staffid )) {
  6640. // $staffid="and a.sid= '".$staffid."'"; " . $table . " as a left join on (a.cid=b.cid ".$staffid.")
  6641. $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;
  6642. } else {
  6643. if (strlen ( $condition ) == 1 || empty ( $condition ))
  6644. $sql = "select count(*) as count from CLD_client as a " . $condition;
  6645. else
  6646. $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;
  6647. }
  6648. if (! empty ( $search ))
  6649. $sql = "select count(*) as count from CLD_client as a where 1 " . $condition;
  6650. if (! empty ( $tooltip )) {
  6651. $condition = str_replace ( "a.", "c.", $condition );
  6652. if ($tagSQL)
  6653. $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;
  6654. else
  6655. $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;
  6656. }
  6657. // echo $sql;
  6658. $query = Doo::db ()->query ( $sql );
  6659. $result = $query->fetch ();
  6660. return $result ['count'];
  6661. }
  6662. /**
  6663. * 生成token
  6664. * @return string
  6665. */
  6666. function set_token() {
  6667. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  6668. $str = sha1 ( $str ); // 加密
  6669. return $str;
  6670. }
  6671. }
  6672. ?>