MainController.php 264 KB

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