NewsService.php 279 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  65. class NewsService implements NewsServiceInterface
  66. {
  67. #[Inject]
  68. protected Redis $redis;
  69. /**
  70. * 获取导航池列表
  71. * @param array $data
  72. * @return array
  73. */
  74. public function getCategoryList(array $data): array
  75. {
  76. $search = $data['name'] ?? '';
  77. $page = (int)($data['page'] ?? 1);
  78. $perPage = (int)($data['pageSize'] ?? 10);
  79. // 1. 查出所有匹配的分类id
  80. if ($search) {
  81. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  82. if (empty($matchedIds)) {
  83. return Result::success(['rows' => [], 'total' => 0]);
  84. }
  85. // 2. 递归查所有父级,直到一级分类
  86. $idsStr = implode(',', $matchedIds);
  87. $sql = "
  88. WITH RECURSIVE parents AS (
  89. SELECT * FROM category WHERE id IN ($idsStr)
  90. UNION ALL
  91. SELECT c.* FROM category c
  92. INNER JOIN parents p ON c.id = p.pid
  93. )
  94. SELECT * FROM parents
  95. ";
  96. $parents = Db::select($sql);
  97. $parentIds = [];
  98. foreach ($parents as $row) {
  99. if ($row->pid == 0) {
  100. $parentIds[] = $row->id;
  101. }
  102. }
  103. $parentIds = array_unique($parentIds);
  104. } else {
  105. // 没有搜索,一级分类就是根
  106. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  107. }
  108. // 3. 一级分类分页
  109. $total = count($parentIds);
  110. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  111. if (empty($parentIds)) {
  112. return Result::success(['rows' => [], 'total' => $total]);
  113. }
  114. // 4. 递归查所有子孙
  115. $idsStr = implode(',', $parentIds);
  116. $sql = "
  117. WITH RECURSIVE subcategories AS (
  118. SELECT * FROM category WHERE id IN ($idsStr)
  119. UNION ALL
  120. SELECT c.* FROM category c
  121. INNER JOIN subcategories s ON c.pid = s.id
  122. )
  123. SELECT * FROM subcategories ORDER BY updated_at DESC
  124. ";
  125. $allCategories = Db::select($sql);
  126. // 5. 组装树结构
  127. $categoryMap = [];
  128. foreach ($allCategories as $cat) {
  129. $cat = (array)$cat;
  130. $cat['children'] = [];
  131. $categoryMap[$cat['id']] = $cat;
  132. }
  133. foreach ($categoryMap as $id => &$cat) {
  134. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  135. $categoryMap[$cat['pid']]['children'][] = &$cat;
  136. }
  137. }
  138. unset($cat);
  139. $categoryTree = [];
  140. foreach ($parentIds as $id) {
  141. if (isset($categoryMap[$id])) {
  142. $categoryTree[] = $categoryMap[$id];
  143. }
  144. }
  145. return Result::success([
  146. 'rows' => $categoryTree,
  147. 'total' => $total,
  148. ]);
  149. }
  150. private function findMatchedCategories($search)
  151. {
  152. if ($search) {
  153. return Category::where('name', 'like', "%{$search}%")
  154. ->orderBy('updated_at', 'desc')
  155. ->get();
  156. }
  157. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  158. ->get();
  159. }
  160. private function findAllParents($categories)
  161. {
  162. $allCategories = [];
  163. foreach ($categories as $category) {
  164. $parentId = $category->pid;
  165. while ($parentId > 0) {
  166. $parent = Category::find($parentId);
  167. if ($parent) {
  168. $allCategories[$parent->id] = $parent;
  169. $parentId = $parent->pid;
  170. } else {
  171. break;
  172. }
  173. }
  174. $allCategories[$category->id] = $category;
  175. }
  176. return array_values($allCategories);
  177. }
  178. private function buildCategoryTree($category, $allRequiredCategories)
  179. {
  180. $categoryData = $category->toArray();
  181. $children = [];
  182. foreach ($allRequiredCategories as $c) {
  183. if ($c->pid === $category->id) {
  184. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  185. }
  186. }
  187. if (!empty($children)) {
  188. $categoryData['children'] = $children;
  189. }
  190. return $categoryData;
  191. }
  192. public function myCategoryList(array $data): array
  193. {
  194. $sszq = $data['sszq'] ?? '';
  195. unset($data['sszq']);
  196. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  197. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  198. $where[] = [
  199. 'pid',
  200. '=',
  201. $data['pid'],
  202. ];
  203. if (isset($data['name'])) {
  204. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  205. }
  206. var_dump($where);
  207. //根据分类id,从category表中取出分类信息
  208. $result = Category::where($where)
  209. ->whereIn('category.id', $catorytids)
  210. ->select('category.*', 'category.id as category_id')->get();
  211. if (empty($result)) {
  212. return Result::error("没有栏目数据");
  213. }
  214. return Result::success($result);
  215. }
  216. /**
  217. * @param array $data
  218. * @return array
  219. */
  220. public function categoryList(array $data): array
  221. {
  222. $where[] = [
  223. 'pid',
  224. '=',
  225. $data['pid']
  226. ];
  227. if (isset($data['name'])) {
  228. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  229. }
  230. var_dump($where);
  231. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  232. if (empty($result)) {
  233. return Result::error("没有栏目数据");
  234. }
  235. return Result::success($result);
  236. }
  237. /**
  238. * @param array $data
  239. * @return array
  240. */
  241. public function addCategory(array $data): array
  242. {
  243. if (isset($data['id'])) {
  244. unset($data['id']);
  245. }
  246. $id = Category::insertGetId($data);
  247. if (empty($id)) {
  248. return Result::error("添加失败");
  249. }
  250. return Result::success(['id' => $id]);
  251. }
  252. /**
  253. * @param array $data
  254. * @return array
  255. */
  256. public function delCategory(array $data): array
  257. {
  258. Db::beginTransaction();
  259. try {
  260. $categoryList = Category::where(['pid' => $data['id']])->get();
  261. if ($categoryList->toArray()) {
  262. Db::rollBack();
  263. return Result::error("分类下面有子分类不能删除");
  264. }
  265. $articleList = Article::where(['catid' => $data['id']])->get();
  266. if ($articleList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有资讯不能删除");
  269. }
  270. $result = Category::where($data)->delete();
  271. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  272. if (!$result) {
  273. Db::rollBack();
  274. return Result::error("删除失败");
  275. }
  276. Db::commit();
  277. return Result::success($result);
  278. } catch (\Exception $e) {
  279. Db::rollBack();
  280. return Result::error("删除失败" . $e->getMessage());
  281. }
  282. }
  283. /**
  284. * @param array $data
  285. * @return array
  286. */
  287. public function updateCategory(array $data): array
  288. {
  289. $where = [
  290. 'id' => $data['id'],
  291. ];
  292. $result = Category::where($where)->update($data);
  293. if ($result) {
  294. return Result::success($result);
  295. } else {
  296. return Result::error("更新失败");
  297. }
  298. }
  299. /**
  300. * 获取导航池信息
  301. * @param array $data
  302. * @return array
  303. */
  304. public function getCategoryInfo(array $data): array
  305. {
  306. $where = [
  307. 'id' => $data['id'],
  308. ];
  309. $result = Category::where($where)->first();
  310. if ($result) {
  311. return Result::success($result);
  312. } else {
  313. return Result::error("更新失败");
  314. }
  315. }
  316. public function getArticleCommend(array $data): array
  317. {
  318. $where = [
  319. 'website_id' => $data['website_id'],
  320. ];
  321. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  322. var_dump($ids);
  323. if (empty($ids)) {
  324. return Result::error("没有推荐数据");
  325. }
  326. //id
  327. $whereArticle = [];
  328. if (isset($data['id'])) {
  329. $whereArticle['id'] = $data['id'];
  330. }
  331. //title like
  332. if (isset($data['title'])) {
  333. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  334. }
  335. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  336. ->where($whereArticle)
  337. ->orderBy('id', 'desc')
  338. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  339. if ($article) {
  340. $data = [
  341. 'rows' => $article->items(),
  342. 'count' => $article->total(),
  343. ];
  344. return Result::success($data);
  345. } else {
  346. return Result::error("获取失败失败");
  347. }
  348. }
  349. /**
  350. * @param array $data
  351. * @return array
  352. */
  353. public function getArticleList(array $data): array
  354. {
  355. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  356. $type_id = $data['type_id'];
  357. unset($data['type_id']);
  358. $user_id = $data['user_id'];
  359. unset($data['user_id']);
  360. $where = [];
  361. $status1 = [];
  362. if (isset($data['id']) && $data['id']) {
  363. array_push($where, ['article.id', '=', $data['id']]);
  364. }
  365. if (isset($data['title']) && $data['title']) {
  366. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  367. }
  368. if (isset($data['category_name']) && $data['category_name']) {
  369. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  370. }
  371. if (isset($data['catid']) && $data['catid']) {
  372. array_push($where, ['article.catid', '=', $data['catid']]);
  373. }
  374. if (isset($data['author']) && $data['author']) {
  375. array_push($where, ['article.author', '=', $data['author']]);
  376. }
  377. if (isset($data['islink']) && $data['islink'] !== "") {
  378. array_push($where, ['article.islink', '=', $data['islink']]);
  379. }
  380. if (isset($data['status']) && $data['status'] !== "") {
  381. array_push($where, ['article.status', '=', $data['status']]);
  382. }
  383. if (isset($data['status1'])) {
  384. $status1 = json_decode(($data['status1']));
  385. }
  386. //不是管理员展示个人数据;
  387. if ($type_id != 10000) {
  388. $where[] = ['article.admin_user_id', '=', $user_id];
  389. }
  390. $rep = Article::where($where)
  391. ->whereNotIn('article.status', [404])
  392. ->when($status1, function ($query) use ($status1) {
  393. if (isset($status1) && $status1) {
  394. $query->whereIn('article.status', $status1);
  395. }
  396. })
  397. ->leftJoin('category', 'article.catid', 'category.id')
  398. ->leftJoin('website_category', function ($join) {
  399. $join->on('article.web_site_id', '=', 'website_category.website_id')
  400. ->on('article.catid', '=', 'website_category.category_id');
  401. })
  402. ->select("article.*", "category.name as category_name", "website_category.alias")
  403. ->orderBy("article.updated_at", "desc")
  404. ->limit($data['pageSize'])
  405. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  406. $count = Article::where($where)->whereNotIn('article.status', [404])
  407. ->when($status1, function ($query) use ($status1) {
  408. if (isset($status1) && $status1) {
  409. $query->whereIn('article.status', $status1);
  410. }
  411. })
  412. ->leftJoin('category', 'article.catid', 'category.id')->count();
  413. $data = [
  414. 'rows' => $rep->toArray(),
  415. 'count' => $count,
  416. ];
  417. if (empty($rep)) {
  418. return Result::error("没有信息数据");
  419. }
  420. return Result::success($data);
  421. }
  422. /**
  423. * @param array $data
  424. * @return array
  425. */
  426. public function addArticle(array $data): array
  427. {
  428. var_dump($data, '----------12-----------1');
  429. unset($data['user_type']);
  430. unset($data['nav_add_pool_id']);
  431. // unset($data['commend_id']);
  432. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  433. Db::beginTransaction();
  434. try {
  435. //处理投票
  436. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  437. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  438. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  439. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  440. unset($data['is_survey']);
  441. unset($data['survey_name']);
  442. unset($data['suvey_array']);
  443. // unset($data['website_id']);
  444. // unset($data['web_site_id']);
  445. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  446. if ($data['hits'] == '') {
  447. $data['hits'] = 0;
  448. }
  449. if ($data['is_original'] == '') {
  450. $data['is_original'] = 0;
  451. }
  452. if ($data['status'] == '') {
  453. $data['status'] = 0;
  454. }
  455. $articleData = $data;
  456. unset($articleData['content']);
  457. //自动处理缩略图、关键字、描述
  458. if ($articleData['imgurl'] == '') {
  459. //如果没有图,设置level=0
  460. $levelArr = json_decode($articleData['level'], true);
  461. var_dump($levelArr, '----------levelArr-----------1');
  462. //content中提取图片第一个图,正则提取
  463. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  464. preg_match_all($reg, $data['content'], $matches);
  465. if (isset($matches[1][0])) {
  466. //截取varchar240
  467. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  468. //如果有图,设置level=3
  469. if (!in_array(3, $levelArr)) {
  470. $levelArr[] = 3;
  471. }
  472. $articleData['level'] = json_encode($levelArr);
  473. } else {
  474. if (!in_array(0, $levelArr)) {
  475. $levelArr[] = 0;
  476. }
  477. $articleData['level'] = json_encode($levelArr);
  478. }
  479. }
  480. var_dump($articleData['level'], '----------$articleData[level]----------1');
  481. if ($articleData['keyword'] == '') {
  482. //提取标题+内容中的关键词
  483. $articleData['keyword'] = $data['title'];
  484. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  485. Jieba::init(); // 初始化 jieba-php
  486. Finalseg::init();
  487. $segList = Jieba::cut($articleData['keyword']);
  488. $segList1 = array_slice($segList, 0, 8);
  489. $articleData['keyword'] = implode(',', $segList1);
  490. }
  491. if ($articleData['introduce'] == '') {
  492. //提取内容中的描述
  493. $content = $data['content'];
  494. // 去除 <style> 和 <script> 标签及其内容
  495. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  496. // 去除所有 HTML 标签
  497. $content = strip_tags($content);
  498. // 去除 HTML 实体
  499. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  500. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  501. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  502. // 去除多余空白
  503. $content = preg_replace('/\s+/u', '', $content);
  504. // 截取 100 个字符
  505. $articleData['introduce'] = mb_substr($content, 0, 100);
  506. }
  507. if ($articleData['status'] == 0) {
  508. $this->sendMessage([
  509. 'talk_type' => 100,
  510. 'title' => $articleData['title'],
  511. 'content' => '提交了审核',
  512. 'messageType' => 2,
  513. ]);
  514. }
  515. $id = Article::insertGetId($articleData);
  516. $articleDataContent = [
  517. 'article_id' => $id,
  518. 'content' => $data['content'],
  519. ];
  520. ArticleData::insertGetId($articleDataContent);
  521. //处理投票
  522. if ($is_survey == 1) {
  523. //生成年月日时分秒+8位随机数
  524. $uuid = date('YmdHis') . rand(10000000, 99999999);
  525. var_dump($suvey_array, 'suvey_array________');
  526. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  527. var_dump($suveys_array, '---------------------1');
  528. var_dump($suvey_array, '---------------------2');
  529. $suvey_data = [];
  530. foreach ($suveys_array as $key => $value) {
  531. if ($value == '') {
  532. continue;
  533. }
  534. if (is_array($value)) {
  535. $suvey_data[] = [
  536. 'sur_id' => $uuid,
  537. 'art_id' => $id,
  538. 'website_id' => $website_id ?? 2,
  539. 'survey_name' => $survey_name,
  540. 'choice_name' => $value[1],
  541. 'is_other' => 1,
  542. 'other_id' => 0,
  543. 'results' => 0,
  544. ];
  545. } else {
  546. $suvey_data[] = [
  547. 'sur_id' => $uuid,
  548. 'art_id' => $id,
  549. 'website_id' => $website_id ?? 2,
  550. 'survey_name' => $survey_name,
  551. 'choice_name' => $value,
  552. 'is_other' => 0,
  553. 'other_id' => 0,
  554. 'results' => 0,
  555. ];
  556. }
  557. if (empty($suvey_data)) {
  558. throw new \Exception("投票数据为空");
  559. }
  560. }
  561. $result = ArticleSurvey::insert($suvey_data);
  562. if (!$result) {
  563. throw new \Exception("投票失败,ArticleSurvey插入失败");
  564. }
  565. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  566. if (!$result) {
  567. throw new \Exception("投票失败,更新主表失败");
  568. }
  569. }
  570. Db::commit();
  571. return Result::success(['id' => $id]);
  572. } catch (\Throwable $ex) {
  573. Db::rollBack();
  574. var_dump($ex->getMessage());
  575. return Result::error("创建失败", 0);
  576. }
  577. }
  578. /**
  579. * @param array $data
  580. * @return array
  581. */
  582. public function delArticle(array $data): array
  583. {
  584. $result = Article::where($data)->delete();
  585. //survey投票删除
  586. articleSurvey::where(['art_id' => $data['id']])->delete();
  587. if (!$result) {
  588. return Result::error("删除失败");
  589. }
  590. return Result::success($result);
  591. }
  592. /**
  593. * @param array $data
  594. * @return array
  595. */
  596. public function updateArticle(array $data): array
  597. {
  598. var_dump($data, '----------12-----------1');
  599. Db::beginTransaction();
  600. unset($data['user_type']);
  601. // unset($data['web_site_id']);
  602. unset($data['nav_add_pool_id']);
  603. try {
  604. //处理投票
  605. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  606. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  607. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  608. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  609. unset($data['is_survey']);
  610. unset($data['survey_name']);
  611. unset($data['suvey_array']);
  612. unset($data['website_id']);
  613. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  614. if ($data['hits'] == '') {
  615. $data['hits'] = 0;
  616. }
  617. if ($data['is_original'] == '') {
  618. $data['is_original'] = 0;
  619. }
  620. if ($data['status'] == '') {
  621. $data['status'] = 0;
  622. }
  623. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  624. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  625. $articleData = $data;
  626. unset($articleData['content']);
  627. unset($articleData['status_name']);
  628. unset($articleData['name']);
  629. unset($articleData['content']);
  630. unset($articleData['pid_arr']);
  631. unset($articleData['pid']);
  632. //自动处理缩略图、关键字、描述
  633. if ($articleData['imgurl'] == '') {
  634. //如果没有图,设置level=0
  635. $levelArr = json_decode($articleData['level'], true);
  636. var_dump($levelArr, '----------levelArr-----------1');
  637. //content中提取图片第一个图,正则提取
  638. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  639. preg_match_all($reg, $data['content'], $matches);
  640. if (isset($matches[1][0])) {
  641. //截取varchar240
  642. // 截取到第一个<
  643. $articleData['imgurl'] = $matches[1][0];
  644. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  645. $pos = strpos($articleData['imgurl'], '"');
  646. if ($pos !== false) {
  647. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  648. }
  649. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  650. //如果有图,设置level=3
  651. if (!in_array(3, $levelArr)) {
  652. $levelArr[] = 3;
  653. }
  654. $articleData['level'] = json_encode($levelArr);
  655. } else {
  656. if (!in_array(0, $levelArr)) {
  657. $levelArr[] = 0;
  658. }
  659. $articleData['level'] = json_encode($levelArr);
  660. }
  661. }
  662. var_dump($articleData['level'], '----------$articleData[level]----------1');
  663. if ($articleData['keyword'] == '') {
  664. //提取标题+内容中的关键词
  665. $articleData['keyword'] = $data['title'];
  666. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  667. Jieba::init(); // 初始化 jieba-php
  668. Finalseg::init();
  669. $segList = Jieba::cut($articleData['keyword']);
  670. $segList1 = array_slice($segList, 0, 8);
  671. $articleData['keyword'] = implode(',', $segList1);
  672. }
  673. if ($articleData['introduce'] == '') {
  674. //提取内容中的描述
  675. $content = $data['content'];
  676. // 去除 <style> 和 <script> 标签及其内容
  677. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  678. // 去除所有 HTML 标签
  679. $content = strip_tags($content);
  680. // 去除 HTML 实体
  681. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  682. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  683. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  684. // 去除多余空白
  685. $content = preg_replace('/\s+/u', '', $content);
  686. // 截取 100 个字符
  687. $articleData['introduce'] = mb_substr($content, 0, 100);
  688. }
  689. if ($articleData['status'] == 0) {
  690. $this->sendMessage([
  691. 'talk_type' => 100,
  692. 'title' => $articleData['title'],
  693. 'content' => '提交了审核',
  694. 'messageType' => 2,
  695. ]);
  696. }
  697. $id = Article::where(['id' => $data['id']])->update($articleData);
  698. $articleDataContent = [
  699. 'content' => $data['content'],
  700. ];
  701. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  702. //处理投票
  703. $id = $data['id'];
  704. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  705. var_dump($suvey_array, 'suvey_array________delete');
  706. //处理投票
  707. if ($is_survey == 1) {
  708. //生成年月日时分秒+8位随机数
  709. $uuid = date('YmdHis') . rand(10000000, 99999999);
  710. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  711. var_dump($suveys_array, '---------------------1');
  712. $suvey_data = [];
  713. if (is_array($suveys_array)) {
  714. foreach ($suveys_array as $key => $value) {
  715. if ($value == '') {
  716. continue;
  717. }
  718. if (is_array($value)) {
  719. $suvey_data[] = [
  720. 'sur_id' => $uuid,
  721. 'art_id' => $id,
  722. 'website_id' => $website_id ?? 2,
  723. 'survey_name' => $survey_name,
  724. 'choice_name' => $value[1],
  725. 'is_other' => 1,
  726. 'other_id' => 0,
  727. 'results' => 0,
  728. ];
  729. } else {
  730. $suvey_data[] = [
  731. 'sur_id' => $uuid,
  732. 'art_id' => $id,
  733. 'website_id' => $website_id ?? 2,
  734. 'survey_name' => $survey_name,
  735. 'choice_name' => $value,
  736. 'is_other' => 0,
  737. 'other_id' => 0,
  738. 'results' => 0,
  739. ];
  740. }
  741. if (empty($suvey_data)) {
  742. throw new \Exception("投票数据为空");
  743. }
  744. }
  745. }
  746. $result = ArticleSurvey::insert($suvey_data);
  747. if (!$result) {
  748. throw new \Exception("投票失败");
  749. }
  750. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  751. if (!$result) {
  752. throw new \Exception("投票失败");
  753. }
  754. } else {
  755. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  756. }
  757. Db::commit();
  758. return Result::success([]);
  759. } catch (\Throwable $ex) {
  760. Db::rollBack();
  761. var_dump($ex->getMessage());
  762. return Result::error("更新失败" . $ex->getMessage(), 0);
  763. }
  764. }
  765. /**
  766. * 更新资讯状态
  767. * @param array $data
  768. * @return array
  769. */
  770. public function upArticleStatus(array $data): array
  771. {
  772. $articleData = Article::where(['id' => $data['id']])->first();
  773. if ($data['status'] == 1) {
  774. $this->sendMessage([
  775. 'talk_type' => 101,
  776. 'title' => $articleData['title'],
  777. 'content' => '审核通过',
  778. 'messageType' => 2,
  779. 'user_id' => $articleData['admin_user_id'],
  780. ]);
  781. }
  782. if ($data['status'] == 2) {
  783. $this->sendMessage([
  784. 'talk_type' => 101,
  785. 'title' => $articleData['title'],
  786. 'content' => '审核拒绝',
  787. 'messageType' => 2,
  788. 'user_id' => $articleData['admin_user_id'],
  789. ]);
  790. }
  791. if ($data['status'] == 0) {
  792. $this->sendMessage([
  793. 'talk_type' => 100,
  794. 'title' => $articleData['title'],
  795. 'content' => '提交了审核',
  796. 'messageType' => 2,
  797. ]);
  798. }
  799. $result = Article::where(['id' => $data['id']])->update($data);
  800. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  801. //article_ignore 表插入数据 db操作
  802. //转成数组
  803. //删掉数据重新写入
  804. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  805. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  806. $insert_data = [];
  807. foreach ($website_ids as $key => $value) {
  808. $insert_data[] = [
  809. 'article_id' => $data['id'],
  810. 'website_id' => $value,
  811. ];
  812. }
  813. DB::table('article_ignore')->insert($insert_data);
  814. }
  815. if ($result) {
  816. return Result::success();
  817. } else {
  818. return Result::error("更新状态失败", 0);
  819. }
  820. }
  821. /**
  822. * 获取新闻详情
  823. * @param array $data
  824. * @return array
  825. */
  826. public function getArticleInfo(array $data): array
  827. {
  828. $where = [
  829. 'article.id' => $data['id'],
  830. // 'article.status' => 1,
  831. ];
  832. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  833. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  834. $info = $result;
  835. // var_dump($info, 'info');
  836. $info['survey_array'] = $articleSurvey;
  837. if ($result) {
  838. return Result::success($info);
  839. } else {
  840. return Result::error("查询失败", 0);
  841. }
  842. }
  843. /**
  844. * 获取头条新闻
  845. * @param array $data
  846. * @return array
  847. */
  848. public function getWebsiteArticlett(array $data): array
  849. {
  850. $website_id = $data['website_id'];
  851. $categorys = $this->processArticlePro($website_id);
  852. $catiall = $categorys['catiall'];
  853. $categoryIds = $categorys['categoryIds'];
  854. $where = [
  855. 'status' => 1
  856. ];
  857. $website_id = $data['website_id'];
  858. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  859. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  860. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  861. switch ($data['level']) {
  862. case 1:
  863. case 2:
  864. case 3:
  865. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  866. $query = Article::where($where)
  867. ->where('level', 'like', '%' . $data['level'] . '%')
  868. ->orderBy('updated_at', 'desc');
  869. break;
  870. case 4: //最新资讯
  871. $query = Article::where($where)->orderBy('updated_at', 'desc');
  872. break;
  873. case 5: //资讯推荐
  874. $query = Article::where($where)
  875. ->where('updated_at', '>', $month);
  876. break;
  877. case 7: //资讯分类
  878. if (isset($data['id']) && !empty($data['id'])) {
  879. $keyword = Article::where('id', $data['id'])->value('keyword');
  880. $keywordArray = explode(',', $keyword);
  881. $whereL7 = [];
  882. foreach ($keywordArray as $k => $v) {
  883. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  884. }
  885. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  886. break;
  887. } else {
  888. return Result::error("请输入资讯ID", 0);
  889. break;
  890. }
  891. default:
  892. break;
  893. }
  894. // $whereL7 = [];
  895. // if(isset($data['id']) && !empty($data['id'])){
  896. // $keyword = Article::where('id', $data['id'])->value('keyword');
  897. // $keywordArray = explode(',', $keyword);
  898. // foreach ($keywordArray as $k => $v) {
  899. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  900. // }
  901. // }
  902. // $query = Article::where($where)
  903. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  904. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  905. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  906. // }
  907. // if($data['level'] == 7){
  908. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  909. // }
  910. // if($data['level'] == 4){
  911. // $query = $query->inRandomOrder()
  912. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  913. // }
  914. // if($data['level'] == 5){
  915. // $query = $query->orderBy('updated_at','desc');
  916. // }
  917. // });
  918. if ($data['textnum'] > 0) {
  919. $query = clone $query;
  920. $result['text'] = $query
  921. ->whereIn('catid', $categoryIds)
  922. ->leftJoinSub(function ($query) use ($website_id) {
  923. $query->from('article_ignore')
  924. ->where('website_id', $website_id);
  925. }, 'article_ignore', function ($join) {
  926. $join->on('article_ignore.article_id', '=', 'article.id');
  927. })
  928. ->where(function ($query) use ($website_id) {
  929. $query->whereNull('article_ignore.article_id')
  930. ->orWhere('article_ignore.website_id', '!=', $website_id);
  931. })
  932. ->select(
  933. 'article.id',
  934. 'article.title',
  935. 'article.author',
  936. 'article.updated_at',
  937. 'article.introduce',
  938. 'article.islink',
  939. 'article.linkurl',
  940. 'article.copyfrom',
  941. 'article.cat_arr_id',
  942. 'article.catid',
  943. 'article.level'
  944. )
  945. ->offset($data['placeid'])
  946. ->limit($data['textnum'])
  947. ->get()->all();
  948. foreach ($result['text'] as $k => $v) {
  949. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  950. }
  951. }
  952. if ($data['imgnum'] > 0) {
  953. $query = clone $query;
  954. $result['img'] = $query
  955. ->whereIn('catid', $categoryIds)
  956. ->where('article.imgurl', '!=', '')
  957. ->select(
  958. 'article.id',
  959. 'article.title',
  960. 'article.imgurl',
  961. 'article.author',
  962. 'article.updated_at',
  963. 'article.introduce',
  964. 'article.islink',
  965. 'article.linkurl',
  966. 'article.copyfrom',
  967. 'article.cat_arr_id',
  968. 'article.catid',
  969. 'article.level'
  970. )
  971. ->offset($data['placeid'])
  972. ->limit($data['imgnum'])
  973. ->get()->all();
  974. foreach ($result['img'] as $k => $v) {
  975. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  976. }
  977. }
  978. if (empty($result)) {
  979. return Result::error("暂无相关资讯", 0);
  980. }
  981. return Result::success($result);
  982. }
  983. /**
  984. * 获取模块新闻
  985. * @param array $data
  986. * @return array
  987. */
  988. public function getWebsiteModelArticles(array $data): array
  989. {
  990. $catid = $data['catid'];
  991. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  992. $category = $category->toArray();
  993. if (!empty($category)) {
  994. $where = [
  995. 'status' => 1,
  996. 'catid' => $catid,
  997. ];
  998. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  999. // 1:文字新闻;2:轮播图;3:图文;
  1000. // 级别:0:未分类
  1001. // 3:推荐图片
  1002. if ($data['level'] == 1) {
  1003. $data['level'] = 0;
  1004. }
  1005. $result = Article::where($where)
  1006. ->where(function ($query) use ($data) {
  1007. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1008. ->orWhereNull("level")
  1009. ->orWhereRaw("level = '[]'");
  1010. })
  1011. ->where(function ($query) use ($data) {
  1012. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1013. ->orWhereNull("ignore_ids");
  1014. })
  1015. ->orderBy("updated_at", "desc")
  1016. ->offset($placeid)
  1017. ->limit($data['pagesize'])
  1018. ->get();
  1019. if (empty($result)) {
  1020. return Result::error("此栏目暂无相关新闻", 0);
  1021. }
  1022. } else {
  1023. return Result::error("此网站暂无此栏目", 0);
  1024. }
  1025. return Result::success($result);
  1026. }
  1027. /**
  1028. *获取新闻列表
  1029. * @param array $data
  1030. * @return array
  1031. */
  1032. public function getWebsiteArticleList(array $data): array
  1033. {
  1034. // return Result::success($data);
  1035. $where[] = ['status', '=', 1];
  1036. $website_id = $data['website_id'];
  1037. if (isset($data['catid']) && !empty($data['catid'])) {
  1038. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1039. if (empty($category)) {
  1040. return Result::error("此网站暂无此栏目", 0);
  1041. }
  1042. array_push($where, ['catid', '=', $data['catid']]);
  1043. }
  1044. // return Result::success($where);
  1045. $query = Article::where($where)
  1046. ->leftJoinSub(function ($query) use ($website_id) {
  1047. $query->from('article_ignore')
  1048. ->where('website_id', $website_id);
  1049. }, 'article_ignore', function ($join) {
  1050. $join->on('article_ignore.article_id', '=', 'article.id');
  1051. })
  1052. ->where(function ($query) use ($website_id) {
  1053. $query->whereNull('article_ignore.article_id')
  1054. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1055. })
  1056. ->select(
  1057. 'article.id',
  1058. 'article.title',
  1059. 'article.imgurl',
  1060. 'article.author',
  1061. 'article.updated_at',
  1062. 'article.introduce',
  1063. 'article.islink',
  1064. 'article.linkurl',
  1065. 'article.copyfrom',
  1066. 'article.cat_arr_id',
  1067. 'article.catid'
  1068. );
  1069. $count = $query->count();
  1070. $rep = $query->orderBy("updated_at", "desc")
  1071. ->offset(($data['page'] - 1) * $data['pageSize'])
  1072. ->limit($data['pageSize'])
  1073. ->get()->all();
  1074. $categorys = $this->processArticlePro($website_id);
  1075. $cat_1st_arr = $categorys['cat_1st_arr'];
  1076. $catiall = $categorys['catiall'];
  1077. // $web['website_id'] = $data['website_id'];
  1078. foreach ($rep as $k => $v) {
  1079. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1080. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1081. }
  1082. // $rep = $this->processArticles($rep,$web);
  1083. $data = [
  1084. 'rows' => $rep,
  1085. 'count' => $count,
  1086. ];
  1087. if (empty($rep)) {
  1088. return Result::error("没有信息数据");
  1089. }
  1090. return Result::success($data);
  1091. }
  1092. /**
  1093. * 前端-获取新闻详情
  1094. * @param array $data
  1095. * @return array
  1096. */
  1097. public function selectWebsiteArticleInfo(array $data): array
  1098. {
  1099. $where = [
  1100. 'article.id' => $data['id'],
  1101. 'article.status' => 1,
  1102. ];
  1103. $result = Article::where($where)
  1104. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1105. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1106. ->where(function ($query) use ($data) {
  1107. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1108. ->orWhereNull("ignore_ids");
  1109. })
  1110. ->select(
  1111. 'article.*',
  1112. 'article_data.content',
  1113. 'article_data.article_id',
  1114. 'article_extend.website_url',
  1115. 'article_extend.email',
  1116. 'article_extend.contacts',
  1117. 'article_extend.contacts_mobile',
  1118. 'article_extend.contacts_address',
  1119. 'article_extend.zip_code',
  1120. 'article_extend.enterprise_name'
  1121. )
  1122. ->first();
  1123. if (empty($result)) {
  1124. return Result::error("暂无此新闻!", 0);
  1125. }
  1126. if (!empty($result['publiced_at'])) {
  1127. $result['updated_at'] = $result['publiced_at'];
  1128. }
  1129. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1130. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1131. ->where('website_category.website_id', $data['website_id'])
  1132. ->where(['website_category.category_id' => $result['catid']])
  1133. ->first();
  1134. if (empty($category)) {
  1135. return Result::error("查询失败", 0);
  1136. }
  1137. //手动推荐文章
  1138. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1139. if (empty($commend_ids)) {
  1140. $commendArticle = [];
  1141. } else {
  1142. //去除不存在的文章ID
  1143. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1144. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1145. ->where('article.status', 1)
  1146. ->where('website_category.website_id', $data['website_id'])
  1147. ->select('article.id', 'article.cat_arr_id', 'article.title', 'article.catid', 'article.imgurl', 'article.hits', 'article.created_at', 'website_category.alias', 'website_category.alias_pinyin', 'website_category.website_id')
  1148. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1149. // ->orderBy('article.updated_at', 'desc')
  1150. ->limit(5)
  1151. ->get();
  1152. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1153. foreach ($commendArticle as $k => $v) {
  1154. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1155. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1156. $cat_arr_id = array_unique($cat_arr_id);
  1157. // 从website_category取出alias_pinyin
  1158. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1159. ->whereIn('category_id', $cat_arr_id)
  1160. ->pluck('alias_pinyin', 'category_id')
  1161. ->toArray();
  1162. // 将cat_arr_id的json转成路径/隔开
  1163. $path_parts = [];
  1164. foreach ($cat_arr_id as $cat_id) {
  1165. if (isset($cat_arr[$cat_id])) {
  1166. $path_parts[] = $cat_arr[$cat_id];
  1167. }
  1168. }
  1169. $v->alias_pinyin = implode('/', $path_parts);
  1170. } else {
  1171. $v->alias_pinyin = '';
  1172. }
  1173. }
  1174. }
  1175. $result['category_id'] = $category['category_id'];
  1176. $result['cat_name'] = $category['alias'];
  1177. $result['website_name'] = $category['website_name'] ?? "";
  1178. $result['suffix'] = $category['suffix'] ?? "";
  1179. $result['commendArticle'] = $commendArticle;
  1180. $result['commend_ids'] = $commend_ids;
  1181. return Result::success($result);
  1182. }
  1183. /**
  1184. * 前端-获取网站调查问卷
  1185. * @param array $data
  1186. * @return array
  1187. */
  1188. public function getWebsiteSurvey(array $data): array
  1189. {
  1190. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1191. $website = Website::where('id', $data['website_id'])->first();
  1192. if (empty($website)) {
  1193. return Result::error("暂无此网站", 0);
  1194. }
  1195. }
  1196. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1197. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1198. if (empty($article)) {
  1199. return Result::error("暂无此文章", 0);
  1200. }
  1201. // return Result::error($data,0);
  1202. $where['art_id'] = $data['art_id'];
  1203. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1204. } else {
  1205. $survey = Article::where(function ($query) {
  1206. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1207. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1208. })
  1209. ->where('status', 1)
  1210. ->where('is_survey', 1)
  1211. ->select('survey_id')
  1212. ->orderBy('updated_at', 'desc')
  1213. ->first();
  1214. if (empty($survey)) {
  1215. return Result::error("暂无调查问卷", 0);
  1216. }
  1217. $where['sur_id'] = $survey['survey_id'];
  1218. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1219. }
  1220. // return Result::success($where);
  1221. $result = ArticleSurvey::where($where)
  1222. ->where(function ($query) {
  1223. $query->where('is_other', 0)
  1224. ->orWhere(function ($subQuery) {
  1225. $subQuery->where('is_other', 1)
  1226. ->where('other_id', 0);
  1227. });
  1228. })
  1229. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1230. ->select('article_survey.*', 'article.survey_type')
  1231. ->get()->all();
  1232. if (empty($result)) {
  1233. return Result::error("此文章暂无调查问卷", 0);
  1234. }
  1235. return Result::success($result);
  1236. }
  1237. /**
  1238. * 前端-添加网站调查问卷选项
  1239. * @param array $data
  1240. * @return array
  1241. */
  1242. public function addWebsiteSurveyOption(array $data): array
  1243. {
  1244. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1245. $website = Website::where('id', $data['website_id'])->first();
  1246. if (empty($website)) {
  1247. return Result::error("暂无此网站", 0);
  1248. }
  1249. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1250. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1251. if (empty($survey)) {
  1252. return Result::error("此调查问卷不可添加选项", 0);
  1253. }
  1254. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1255. $choice = [
  1256. 'art_id' => $survey['art_id'],
  1257. 'website_id' => $data['website_id'],
  1258. 'survey_name' => $survey['survey_name'],
  1259. 'choice_name' => $data['choice_name'],
  1260. 'sur_id' => $survey['sur_id'],
  1261. 'is_other' => 1,
  1262. 'other_id' => $survey['id'],
  1263. ];
  1264. $result = ArticleSurvey::insertGetId($choice);
  1265. if (empty($result)) {
  1266. return Result::error("添加失败", 0);
  1267. }
  1268. return Result::success($result);
  1269. }
  1270. }
  1271. return Result::error("添加失败", 0);
  1272. }
  1273. return Result::error("添加失败", 0);
  1274. }
  1275. /**
  1276. * 前端-调查问卷投票
  1277. * @param array $data
  1278. * @return array
  1279. */
  1280. public function addWebsiteSurveyVote(array $data): array
  1281. {
  1282. // return Result::success($data);
  1283. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1284. $website = Website::where('id', $data['website_id'])->first();
  1285. if (empty($website)) {
  1286. return Result::error("暂无此网站", 0);
  1287. }
  1288. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1289. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1290. // return Result::success($survey);
  1291. if (empty($is_survey)) {
  1292. return Result::error("此调查问卷不存在", 0);
  1293. }
  1294. // return Result::success($survey);
  1295. // 调查问卷类型
  1296. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1297. //多选 若是json型则转化成数组类型
  1298. if (strpos($data['choice_id'], '[') === 0) {
  1299. $data['choice_id'] = json_decode($data['choice_id'], true);
  1300. } else {
  1301. // 单选 也转换成数组
  1302. $data['choice_id'] = [$data['choice_id']];
  1303. }
  1304. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1305. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1306. // ->where('website_id',$data['website_id'])
  1307. ->where('is_other', 1)
  1308. ->where('other_id', 0)
  1309. ->first();
  1310. if (!empty($other)) {
  1311. return Result::error("请选择已有的选项!", 0);
  1312. }
  1313. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1314. // ->where('website_id',$data['website_id'])
  1315. ->where('is_other', 1)
  1316. ->where('other_id', '!=', 0)
  1317. ->first();
  1318. // return Result::success($choice['other']);
  1319. $choice_id = $data['choice_id'];
  1320. if (!empty($choice['other'])) {
  1321. // array_push($data['choice_id'],$choice['other']['other_id']);
  1322. if (!empty($choice_id)) {
  1323. $key = array_search($choice['other']['id'], $choice_id);
  1324. if ($key !== false) {
  1325. unset($choice_id[$key]);
  1326. $choice_id = array_values($choice_id);
  1327. }
  1328. array_push($choice_id, $choice['other']['other_id']);
  1329. } else {
  1330. $choice_id[0] = $choice['other']['other_id'];
  1331. }
  1332. array_push($data['choice_id'], $choice['other']['other_id']);
  1333. }
  1334. // return Result::success($data);
  1335. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1336. // ->where('website_id',$data['website_id'])
  1337. ->increment('results', 1);
  1338. if (empty($choice)) {
  1339. return Result::error("请选择已有的选项!", 0);
  1340. }
  1341. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1342. // ->where('website_id',$data['website_id'])
  1343. ->where('other_id', 0)
  1344. ->get();
  1345. $survey['choice'] = $choice_id;
  1346. return Result::success($survey);
  1347. }
  1348. return Result::error("参数必填!");
  1349. }
  1350. return Result::error("此调查问卷不存在", 0);
  1351. }
  1352. return Result::error("参数必填!");
  1353. }
  1354. /**
  1355. * 后端-获取网站调查问卷列表
  1356. * @param array $data
  1357. * @return array
  1358. */
  1359. public function getSurveyList(array $data): array
  1360. {
  1361. $where = [];
  1362. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1363. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1364. }
  1365. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1366. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1367. }
  1368. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1369. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1370. }
  1371. // return Result::success($where);
  1372. if (!empty($where)) {
  1373. $query = Article::where($where)->where(function ($q) {
  1374. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1375. });
  1376. } else {
  1377. $query = Article::where(function ($q) {
  1378. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1379. });
  1380. }
  1381. $count = $query->count();
  1382. $survey = $query->orderByDesc('id')
  1383. ->limit($data['pageSize'])
  1384. ->offset(($data['page'] - 1) * $data['pageSize'])
  1385. ->get();
  1386. if (empty($survey->toArray())) {
  1387. return Result::error("暂无调查问卷!", 0);
  1388. }
  1389. $result = [
  1390. 'rows' => $survey,
  1391. 'count' => $count,
  1392. ];
  1393. return Result::success($result);
  1394. }
  1395. /**
  1396. * 后端-获取网站调查问卷详情
  1397. * @param array $data
  1398. * @return array
  1399. */
  1400. public function getSurveyInfo(array $data): array
  1401. {
  1402. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1403. $where = ['sur_id' => $data['sur_id']];
  1404. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1405. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1406. ->select('article_survey.*', 'article.survey_type')
  1407. ->get()->all();
  1408. if (empty($choose)) {
  1409. return Result::error("此调查问卷不存在", 0);
  1410. }
  1411. $resultsArray = array_column($choose, 'results');
  1412. $total = array_sum($resultsArray);
  1413. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1414. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1415. // $total = 0;
  1416. if (!empty($other)) {
  1417. $total = $total + $other['results'];
  1418. $other['choice_name'] = '(其他)';
  1419. if (!empty($others)) {
  1420. $other['hasChildren'] = true;
  1421. // array_push($other,['hasChildren','=',true]);
  1422. $other['children'] = $others;
  1423. $other_choices = [$other->toArray()];
  1424. $mer_choice = array_merge($choose, $other_choices);
  1425. $value_choice = array_values($mer_choice);
  1426. } else {
  1427. // return Result::error('1111');
  1428. $other_choices = [$other->toArray()];
  1429. $other_choices = array_merge($choose, $other_choices);
  1430. $value_choice = array_values($other_choices);
  1431. // return Result::success($result);
  1432. }
  1433. } else {
  1434. $value_choice = $choose;
  1435. }
  1436. $result = [
  1437. 'choose' => $value_choice,
  1438. 'total' => $total,
  1439. ];
  1440. }
  1441. return Result::success($result);
  1442. }
  1443. /**
  1444. * 前端-搜索新闻列表
  1445. * @param array $data
  1446. * @return array
  1447. */
  1448. public function selectWebsiteArticle(array $data): array
  1449. {
  1450. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1451. $website_id = $data['website_id'];
  1452. $categorys = $this->processArticlePro($website_id);
  1453. $catiall = $categorys['catiall'];
  1454. $query = Article::where('status', 1)
  1455. ->whereIn('catid', $category)
  1456. ->leftJoinSub(function ($query) use ($website_id) {
  1457. $query->from('article_ignore')
  1458. ->where('website_id', $website_id);
  1459. }, 'article_ignore', function ($join) {
  1460. $join->on('article_ignore.article_id', '=', 'article.id');
  1461. })
  1462. ->where(function ($query) use ($website_id) {
  1463. $query->whereNull('article_ignore.article_id')
  1464. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1465. });
  1466. // return Result::success($all_articles);
  1467. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1468. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1469. }
  1470. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1471. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1472. }
  1473. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1474. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1475. }
  1476. // 计算总数
  1477. $count = $query->count();
  1478. // 分页查询
  1479. $articles = $query
  1480. ->select(
  1481. 'article.id',
  1482. 'article.title',
  1483. 'article.imgurl',
  1484. 'article.author',
  1485. 'article.updated_at',
  1486. 'article.introduce',
  1487. 'article.islink',
  1488. 'article.linkurl',
  1489. 'article.copyfrom',
  1490. 'article.cat_arr_id',
  1491. 'article.catid',
  1492. 'article.department_arr_id',
  1493. 'article.city_arr_id',
  1494. )
  1495. ->orderBy("updated_at", "desc")
  1496. ->offset(($data['page'] - 1) * $data['pageSize'])
  1497. ->limit($data['pageSize'])
  1498. ->get();
  1499. foreach ($articles as $k => $v) {
  1500. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1501. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1502. }
  1503. if (empty($articles)) {
  1504. return Result::error("没有符合条件的资讯数据");
  1505. }
  1506. $result = [
  1507. 'rows' => $articles,
  1508. 'count' => $count,
  1509. ];
  1510. return Result::success($result);
  1511. }
  1512. /**
  1513. * 模块新闻加强版
  1514. * @param array $data
  1515. * @return array
  1516. */
  1517. public function getWebsiteCatidArticle(array $data): array
  1518. {
  1519. $where = [
  1520. 'website_category.category_id' => $data['catid'],
  1521. 'website_category.website_id' => $data['website_id'],
  1522. ];
  1523. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1524. $child_catnum = $data['child_catnum'] ?? 1;
  1525. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1526. $childCategoryIds = array_column($category['child'], 'category_id');
  1527. if (empty($childCategoryIds)) {
  1528. return Result::error("暂无子栏目", 0);
  1529. }
  1530. $imgArticles = [];
  1531. $textArticles = [];
  1532. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1533. // 初始化子分类图片新闻和文字新闻数组
  1534. // 查询所有子级栏目的图文新闻
  1535. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1536. ->where(function ($query) use ($data) {
  1537. $query->where(function ($subQuery) use ($data) {
  1538. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1539. })->orWhereNull("ignore_ids");
  1540. })
  1541. ->where('status', 1)
  1542. ->where('imgurl', '!=', '')
  1543. ->select('*')
  1544. ->orderBy('updated_at', 'desc')
  1545. ->limit($data['child_imgnum'])
  1546. ->get();
  1547. }
  1548. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1549. // 查询所有子级栏目的文字新闻
  1550. $textArticles = Article::where('catid', $childCategoryIds[0])
  1551. ->where('status', 1)
  1552. ->where(function ($query) use ($data) {
  1553. $query->where(function ($subQuery) use ($data) {
  1554. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1555. })->orWhereNull("ignore_ids");
  1556. })
  1557. ->select('*')
  1558. ->orderBy('updated_at', 'desc')
  1559. ->limit($data['child_textnum'])
  1560. ->get();
  1561. }
  1562. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1563. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1564. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1565. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1566. return $child;
  1567. }, $category['child']);
  1568. }
  1569. // }
  1570. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1571. $category['img'] = WebsiteCategory::where($where)
  1572. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1573. ->where('article.status', 1)
  1574. ->where('article.imgurl', '!=', '')
  1575. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1576. ->orderBy('article.updated_at', 'desc')
  1577. ->limit($data['img_num'])
  1578. ->get();
  1579. }
  1580. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1581. $category['text'] = WebsiteCategory::where($where)
  1582. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1583. ->where('article.status', 1)
  1584. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1585. ->orderBy('article.updated_at', 'desc')
  1586. ->limit($data['text_num'])
  1587. ->get();
  1588. }
  1589. // $category = $category->get();
  1590. if (empty($category)) {
  1591. return Result::error("查询失败", 0);
  1592. }
  1593. return Result::success($category);
  1594. }
  1595. /**
  1596. * 模块新闻加强plus版
  1597. * @param array $data
  1598. * @return array
  1599. */
  1600. public function getWebsiteAllArticle(array $data): array
  1601. {
  1602. $time1 = microtime(true);
  1603. $wetbsite_id = $data['website_id'] ?? 2;
  1604. $data = json_decode($data['id'], true);
  1605. $categorys = $this->processArticlePro($wetbsite_id);
  1606. $cat_1st_arr = $categorys['cat_1st_arr'];
  1607. $catiall = $categorys['catiall'];
  1608. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1609. $parent_category = array_column($data, 'parent');
  1610. $parent_cat = [];
  1611. $child_category = array_column($data, 'child');
  1612. if (!empty($parent_category)) {
  1613. foreach ($parent_category as $key => $value) {
  1614. $arr = array_map('intval', explode(',', $value));
  1615. $parent_cat[$key] = $arr[0] ?? 0;
  1616. $parent_category = $arr[0] ?? 0;
  1617. $article_imgnum = $arr[1] ?? 0;
  1618. $article_textnum = $arr[2] ?? 0;
  1619. if ($parent_category != 0) {
  1620. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1621. // return Result::success($category_arr);
  1622. if ($article_imgnum != 0) {
  1623. $img_article = Article::whereIn('catid', $category_arr)
  1624. ->where('status', 1)
  1625. ->where('imgurl', '!=', '')
  1626. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1627. $query->from('article_ignore')
  1628. ->where('website_id', $wetbsite_id);
  1629. }, 'article_ignore', function ($join) {
  1630. $join->on('article_ignore.article_id', '=', 'article.id');
  1631. })
  1632. ->where(function ($query) use ($wetbsite_id) {
  1633. $query->whereNull('article_ignore.article_id')
  1634. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1635. })
  1636. ->select('article.id', 'article.title', 'article.imgurl', 'article.author', 'article.updated_at', 'article.introduce', 'article.islink', 'article.linkurl', 'article.copyfrom', 'article.cat_arr_id', 'article.catid')
  1637. ->orderBy('updated_at', 'desc')
  1638. ->limit($article_imgnum)
  1639. ->get()->all();
  1640. foreach ($img_article as $k => $v) {
  1641. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1642. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1643. }
  1644. } else {
  1645. $img_article = [];
  1646. }
  1647. if ($article_textnum != 0) {
  1648. $text_article = Article::whereIn('catid', $category_arr)
  1649. ->where('status', 1)
  1650. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1651. $query->from('article_ignore')
  1652. ->where('website_id', $wetbsite_id);
  1653. }, 'article_ignore', function ($join) {
  1654. $join->on('article_ignore.article_id', '=', 'article.id');
  1655. })
  1656. ->where(function ($query) use ($wetbsite_id) {
  1657. $query->whereNull('article_ignore.article_id')
  1658. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1659. })
  1660. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1661. ->orderBy('updated_at', 'desc')
  1662. ->limit($article_textnum)
  1663. ->get()->all();
  1664. foreach ($text_article as $k => $v) {
  1665. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1666. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1667. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1668. }
  1669. } else {
  1670. $text_article = [];
  1671. }
  1672. $catiall[$parent_category]['imgnum'] = $img_article;
  1673. $catiall[$parent_category]['textnum'] = $text_article;
  1674. $parent[$key] = $catiall[$parent_category];
  1675. } else {
  1676. $parent[$key] = '';
  1677. }
  1678. }
  1679. }
  1680. if (!empty($child_category)) {
  1681. foreach ($child_category as $key => $value) {
  1682. $arr = array_map('intval', explode(',', $value));
  1683. $parent_category = $parent_cat[$key];
  1684. $child_category = $arr[0] ?? 0;
  1685. $article_imgnum = $arr[1] ?? 0;
  1686. $article_textnum = $arr[2] ?? 0;
  1687. if ($child_category != 0) {
  1688. $all_childcat = $cat_1st_arr[$parent_category];
  1689. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1690. // 从 $websiteInfoIndexed 中获取对应的数据
  1691. $info = $websiteInfoIndexed[$v];
  1692. // 返回一个包含所需信息的数组
  1693. return [
  1694. 'alias' => $info->alias,
  1695. 'category_id' => $info->category_id,
  1696. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1697. 'pid' => $info->pid,
  1698. 'type' => $info->type,
  1699. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1700. 'pinyin' => $info->pinyin,
  1701. ];
  1702. }, $all_childcat);
  1703. if ($article_imgnum != 0) {
  1704. $img_article = Article::where('catid', $child_category)
  1705. ->where('status', 1)
  1706. ->where('imgurl', '!=', '')
  1707. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1708. $query->from('article_ignore')
  1709. ->where('website_id', $wetbsite_id);
  1710. }, 'article_ignore', function ($join) {
  1711. $join->on('article_ignore.article_id', '=', 'article.id');
  1712. })
  1713. ->where(function ($query) use ($wetbsite_id) {
  1714. $query->whereNull('article_ignore.article_id')
  1715. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1716. })
  1717. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1718. ->orderBy('updated_at', 'desc')
  1719. ->limit($article_imgnum)
  1720. ->get()->all();
  1721. foreach ($img_article as $k => $v) {
  1722. // var_dump($v);
  1723. // var_dump($k);
  1724. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1725. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1726. }
  1727. } else {
  1728. $img_article = [];
  1729. }
  1730. if ($article_textnum != 0) {
  1731. $text_article = Article::where('catid', $child_category)
  1732. ->where('status', 1)
  1733. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1734. $query->from('article_ignore')
  1735. ->where('website_id', $wetbsite_id);
  1736. }, 'article_ignore', function ($join) {
  1737. $join->on('article_ignore.article_id', '=', 'article.id');
  1738. })
  1739. ->where(function ($query) use ($wetbsite_id) {
  1740. $query->whereNull('article_ignore.article_id')
  1741. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1742. })
  1743. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1744. ->orderBy('updated_at', 'desc')
  1745. ->limit($article_textnum)
  1746. ->get()->all();
  1747. foreach ($text_article as $k => $v) {
  1748. // var_dump($v);
  1749. // var_dump($k);
  1750. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1751. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1752. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1753. }
  1754. } else {
  1755. $text_article = [];
  1756. }
  1757. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1758. $catiall[$child_category]['imgnum'] = $img_article;
  1759. $catiall[$child_category]['textnum'] = $text_article;
  1760. $child[$key] = $catiall[$child_category];
  1761. // var_dump($pids);
  1762. } else {
  1763. $child[$key] = '';
  1764. }
  1765. }
  1766. }
  1767. foreach ($parent as $key => $value) {
  1768. $result[$key] = $value;
  1769. if (!empty($child[$key])) {
  1770. // var_dump($child[$key]);
  1771. $result[$key]['child'] = $child[$key];
  1772. // $value[$key]['child'] = $child[$key];
  1773. } else {
  1774. $result[$key]['child'] = [
  1775. "alias" => null,
  1776. "category_id" => null,
  1777. "type" => null,
  1778. "pinyin" => null,
  1779. "all_childcat" => [],
  1780. "imgnum" => [],
  1781. "textnum" => []
  1782. ];
  1783. }
  1784. }
  1785. return Result::success($result);
  1786. }
  1787. /**
  1788. * 辅助方法:获取文章列表
  1789. */
  1790. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1791. {
  1792. sleep(1);
  1793. $query = Article::where('article.status', 1)
  1794. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1795. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1796. ->where(function ($query) use ($website) {
  1797. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1798. })
  1799. ->leftJoin('website_category', function ($join) use ($website) {
  1800. $join->on('article.catid', '=', 'website_category.category_id')
  1801. ->where('website_category.website_id', '=', $website['website_id']);
  1802. })
  1803. ->select(
  1804. 'article.id',
  1805. 'article.title',
  1806. 'article.imgurl',
  1807. 'article.author',
  1808. 'article.updated_at',
  1809. 'article.introduce',
  1810. 'article.islink',
  1811. 'article.linkurl',
  1812. 'article.copyfrom',
  1813. 'article.cat_arr_id',
  1814. 'article.catid',
  1815. 'website_category.alias as category_name'
  1816. )
  1817. ->orderBy('updated_at', 'desc')
  1818. ->limit($limit);
  1819. // 如果是图片文章,添加图片URL条件
  1820. if ($isImageArticle) {
  1821. $query->where('imgurl', '!=', '');
  1822. } else {
  1823. // 文字文章不需要imgurl字段
  1824. $query->addSelect('article.introduce');
  1825. }
  1826. $articles = $query->get();
  1827. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1828. }
  1829. /**
  1830. * 乡村网-获取特殊新闻模块
  1831. * @param array $data
  1832. * @return array
  1833. */
  1834. public function getWebsiteArticles(array $data): array
  1835. {
  1836. $website_id = $data['website_id'];
  1837. $catids = json_decode($data['id'], true);
  1838. $parent_category = array_column($catids, 'parent');
  1839. if (!empty($parent_category) && is_array($parent_category)) {
  1840. $categorys = $this->processArticlePro($website_id);
  1841. $catiall = $categorys['catiall'];
  1842. $cat_1st_arr = $categorys['cat_1st_arr'];
  1843. // return Result::success($categorys);
  1844. foreach ($parent_category as $key => $value) {
  1845. $arr = array_map('intval', explode(',', $value));
  1846. $parent_category = $arr[0] ?? 0;
  1847. $article_imgnum = $arr[1] ?? 0;
  1848. $article_textnum = $arr[2] ?? 0;
  1849. if ($parent_category != 0) {
  1850. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1851. // return Result::success($category_arr);
  1852. if ($article_imgnum != 0) {
  1853. $img_article = Article::whereIn('catid', $category_arr)
  1854. ->where('status', 1)
  1855. ->where('imgurl', '!=', '')
  1856. ->leftJoinSub(function ($query) use ($website_id) {
  1857. $query->from('article_ignore')
  1858. ->where('website_id', $website_id);
  1859. }, 'article_ignore', function ($join) {
  1860. $join->on('article_ignore.article_id', '=', 'article.id');
  1861. })
  1862. ->where(function ($query) use ($website_id) {
  1863. $query->whereNull('article_ignore.article_id')
  1864. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1865. })
  1866. ->select(
  1867. 'id',
  1868. 'title',
  1869. 'imgurl',
  1870. 'author',
  1871. 'updated_at',
  1872. 'introduce',
  1873. 'islink',
  1874. 'linkurl',
  1875. 'copyfrom',
  1876. 'cat_arr_id',
  1877. 'catid as category_id'
  1878. )
  1879. ->orderBy('updated_at', 'desc')
  1880. ->limit($article_imgnum)
  1881. ->get()->all();
  1882. foreach ($img_article as $k => $v) {
  1883. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1884. // return Result::success($v);
  1885. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1886. }
  1887. } else {
  1888. $img_article = [];
  1889. }
  1890. if ($article_textnum != 0) {
  1891. $text_article = Article::whereIn('catid', $category_arr)
  1892. ->where('status', 1)
  1893. ->leftJoinSub(function ($query) use ($website_id) {
  1894. $query->from('article_ignore')
  1895. ->where('website_id', $website_id);
  1896. }, 'article_ignore', function ($join) {
  1897. $join->on('article_ignore.article_id', '=', 'article.id');
  1898. })
  1899. ->where(function ($query) use ($website_id) {
  1900. $query->whereNull('article_ignore.article_id')
  1901. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1902. })
  1903. ->select(
  1904. 'id',
  1905. 'title',
  1906. 'author',
  1907. 'updated_at',
  1908. 'introduce',
  1909. 'islink',
  1910. 'linkurl',
  1911. 'copyfrom',
  1912. 'cat_arr_id',
  1913. 'catid as category_id'
  1914. )
  1915. ->orderBy('updated_at', 'desc')
  1916. ->limit($article_textnum)
  1917. ->get()->all();
  1918. foreach ($text_article as $k => $v) {
  1919. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1920. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1921. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1922. }
  1923. } else {
  1924. $text_article = [];
  1925. }
  1926. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  1927. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  1928. $parent[$key] = $catiall[$parent_category];
  1929. } else {
  1930. $parent[$key] = [];
  1931. }
  1932. }
  1933. }
  1934. return Result::success($parent);
  1935. }
  1936. // 封装处理商品的路由问题
  1937. function processGoods($goods, $data)
  1938. {
  1939. return $goods->map(function ($good) use ($data) {
  1940. $catid = $good->catid ?? 0;
  1941. // $pinyin = '';
  1942. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1943. if (!empty($category->pid) && $category->pid != 0) {
  1944. $level = json_decode($category->category_arr_id, true);
  1945. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1946. ->whereIn('category_id', $level)
  1947. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1948. ->get(['aLIas_pinyin'])
  1949. ->pluck('aLIas_pinyin')
  1950. ->implode('/');
  1951. } else {
  1952. $pinyin = $category->aLIas_pinyin ?? '';
  1953. }
  1954. if (isset($good->city_id) && !empty($good->city_id)) {
  1955. $city = District::where('id', $good->city_id)->first(['name']);
  1956. $good->city_name = $city->name ?? '';
  1957. }
  1958. // 解析imgurl JSON并取第一条数据
  1959. $imgUrls = json_decode($good->imgurl, true);
  1960. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1961. $good->pinyin = $pinyin;
  1962. return $good;
  1963. });
  1964. }
  1965. /**
  1966. * 获取商城首页-根据栏目id
  1967. * @param array $data
  1968. * @return array
  1969. * */
  1970. function getWebsiteCatidshop(array $data): array
  1971. {
  1972. $input['catid'] = $data['catid'];
  1973. $input['website_id'] = $data['website_id'];
  1974. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1975. $result = array_map(function ($item) use ($input) {
  1976. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1977. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1978. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1979. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1980. if (empty($category) || $category->type != 2) {
  1981. return Result::error("暂无此栏目", 0);
  1982. } else {
  1983. $website['website_id'] = $input['website_id'];
  1984. $goods = Good::where('good.status', 2)
  1985. ->where('good.website_id', $website['website_id'])
  1986. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1987. ->select(
  1988. 'good.id',
  1989. 'good.name',
  1990. 'good.imgurl',
  1991. 'good.description',
  1992. 'good.updated_at',
  1993. 'good.catid',
  1994. 'good.type_id',
  1995. 'good.price',
  1996. 'good.com',
  1997. 'good.level',
  1998. 'good.unit'
  1999. )
  2000. ->orderBy('updated_at', 'desc')
  2001. ->offset($goodStart)
  2002. ->limit($goodNum);
  2003. $all_goods = $goods->get();
  2004. $all_goods = $this->processGoods($all_goods, $website);
  2005. }
  2006. return $all_goods ?? [];
  2007. }
  2008. }, $data);
  2009. return Result::success($result);
  2010. }
  2011. /**
  2012. * 获取商品模块
  2013. * @param array $data
  2014. * @return array
  2015. * */
  2016. public function getWebsiteshop(array $data): array
  2017. {
  2018. $input['id'] = $data['id'];
  2019. $input['website_id'] = $data['website_id'];
  2020. $catid = $data['catid'];
  2021. $data = json_decode($input['id'] ?? '', true) ?? [];
  2022. $result['goods'] = array_map(function ($item) use ($input) {
  2023. // 检查parent元素是否存在且不是undefined
  2024. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2025. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2026. $website = $input['website_id'];
  2027. $query = Good::where('good.status', 2)
  2028. ->where('good.website_id', $website);
  2029. switch ($Levelid) {
  2030. case 1:
  2031. case 2:
  2032. case 3:
  2033. $goods = $query->where(function ($q) use ($Levelid) {
  2034. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2035. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2036. });
  2037. break;
  2038. case 4:
  2039. $goods = $query;
  2040. break;
  2041. case 5:
  2042. $goods = $query->where('type_id', 1);
  2043. break;
  2044. case 6:
  2045. $goods = $query->where('type_id', 2);
  2046. break;
  2047. default:
  2048. return [];
  2049. }
  2050. $all_goods = $goods
  2051. ->select(
  2052. 'good.id',
  2053. 'good.name',
  2054. 'good.imgurl',
  2055. 'good.description',
  2056. 'good.updated_at',
  2057. 'good.catid',
  2058. 'good.type_id',
  2059. 'good.price',
  2060. 'good.level',
  2061. 'good.website_id'
  2062. )
  2063. ->orderBy('updated_at', 'desc')
  2064. ->offset($goodStart)
  2065. ->limit($goodNum)
  2066. ->get();
  2067. $web['website_id'] = $website;
  2068. $all_goods = $this->processGoods($all_goods, $web);
  2069. }
  2070. return $all_goods;
  2071. }, $data);
  2072. $website = $input['website_id'];
  2073. $result['article'] = Article::where(function ($query) use ($website) {
  2074. $query->where(function ($subQuery) use ($website) {
  2075. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2076. })->orWhereNull("ignore_ids");
  2077. })
  2078. ->where('catid', $catid)
  2079. ->where('article.status', 1)
  2080. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2081. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2082. ->orderBy('article.updated_at', 'desc')
  2083. ->first();
  2084. return Result::success($result);
  2085. }
  2086. /**
  2087. * 获取商品分类
  2088. * @param array $data
  2089. * @return array
  2090. * */
  2091. public function getWebsiteshopCat(array $data): array
  2092. {
  2093. $website = $data['website_id'];
  2094. $category = WebsiteCategory::where('website_id', $website)
  2095. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2096. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2097. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2098. ->orderBy('sort')
  2099. ->get();
  2100. $cat = $category->map(function ($item) use ($website) {
  2101. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2102. $pid = $item->pid ?? 0;
  2103. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2104. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2105. ->where('website_id', $website)
  2106. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2107. ->get(['aLIas_pinyin'])
  2108. ->pluck('aLIas_pinyin')
  2109. ->implode('/');
  2110. } else {
  2111. $pinyin = $item->aLIas_pinyin ?? '';
  2112. }
  2113. $item->pinyin = $pinyin;
  2114. });
  2115. if (empty($category)) {
  2116. return Result::error("栏目查询失败", 0);
  2117. }
  2118. $cat_tree = Result::buildMenuTree($category);
  2119. $web['website_id'] = $website;
  2120. $goods = Good::where('website_id', $website)
  2121. ->where('status', 2)
  2122. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2123. ->latest('updated_at')
  2124. ->offset(($data['page'] - 1) * $data['pageSize'])
  2125. ->limit($data['pageSize'])
  2126. ->get();
  2127. if (!empty($goods)) {
  2128. if ($goods->count() > 1 && !empty($goods)) {
  2129. $goods = $this->processGoods($goods, $web);
  2130. }
  2131. } else {
  2132. $goods = [];
  2133. }
  2134. $result = [
  2135. 'category' => $cat_tree,
  2136. 'goods' => $goods,
  2137. ];
  2138. // $resul['goods'] = $goods;
  2139. if (empty($result)) {
  2140. return Result::error("查询失败", 0);
  2141. }
  2142. return Result::success($result);
  2143. }
  2144. /*
  2145. * 获取商品列表
  2146. * @param array $data
  2147. * @return array
  2148. * */
  2149. public function getWebsiteshopList(array $data): array
  2150. {
  2151. // return Result::success($data);
  2152. $where = [
  2153. 'status' => 2,
  2154. 'website_id' => $data['website_id'],
  2155. ];
  2156. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2157. // return Result::error("查询失败", 0);
  2158. // }
  2159. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2160. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2161. $data['catid'] = $category->category_id ?? 0;
  2162. }
  2163. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2164. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2165. }
  2166. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2167. array_push($where, ['type_id', $data['type_id']]);
  2168. }
  2169. $query = Good::where($where)
  2170. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2171. $query->where(function ($q) use ($data) {
  2172. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2173. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2174. });
  2175. })
  2176. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2177. $query->where(function ($q) use ($data) {
  2178. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2179. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2180. });
  2181. })
  2182. ->select(
  2183. 'good.id',
  2184. 'good.name',
  2185. 'good.imgurl',
  2186. 'good.description',
  2187. 'good.updated_at',
  2188. 'good.com',
  2189. 'good.catid',
  2190. 'good.type_id',
  2191. 'good.website_id',
  2192. 'good.cat_arr_id',
  2193. 'good.created_at',
  2194. 'good.city_id'
  2195. )
  2196. ->latest('updated_at');
  2197. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2198. $result['count'] = $query->clone()->count();
  2199. $result['goods'] = $this->processGoods(
  2200. $query->clone()
  2201. ->offset(($data['page'] - 1) * $data['pageSize'])
  2202. ->limit($data['pageSize'])
  2203. ->get(),
  2204. $data
  2205. );
  2206. } else {
  2207. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2208. // 获取 type_id 为 1 的数据
  2209. $result['type1'] = $this->processGoods(
  2210. $query->clone()
  2211. ->where('type_id', 1)
  2212. ->offset(($data['page'] - 1) * $data['pageSize'])
  2213. ->limit($data['pageSize'])
  2214. ->get(),
  2215. $data
  2216. );
  2217. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2218. // 获取 type_id 为 2 的数据
  2219. $result['type2'] = $this->processGoods(
  2220. $query->clone()
  2221. ->where('type_id', 2)
  2222. ->offset(($data['page'] - 1) * $data['pageSize'])
  2223. ->limit($data['pageSize'])
  2224. ->get(),
  2225. $data
  2226. );
  2227. }
  2228. if (empty($result)) {
  2229. return Result::error("查询失败", 0);
  2230. }
  2231. return Result::success($result);
  2232. }
  2233. /**
  2234. * 获取商品详情
  2235. * @param array $data
  2236. * @return array
  2237. * */
  2238. public function getWebsiteshopInfo(array $data): array
  2239. {
  2240. $where = [
  2241. 'good.status' => 2,
  2242. 'good.website_id' => $data['website_id'],
  2243. 'good.id' => $data['id'],
  2244. ];
  2245. $goods = Good::where($where)
  2246. ->where('good.id', $data['id'])
  2247. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2248. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2249. ->first();
  2250. if (empty($goods)) {
  2251. return Result::error("查询失败", 0);
  2252. }
  2253. $goods->imgurl = json_decode($goods->imgurl, true);
  2254. return Result::success($goods);
  2255. }
  2256. /**
  2257. * plus pro 处理文章路由问题
  2258. */
  2259. function processArticlePro($website_id)
  2260. {
  2261. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2262. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2263. // 取出category_id 对应的aLIas_pinyin
  2264. $categoryIds = array_column($categorys, 'category_id');
  2265. $categoryPIds = array_column($categorys, 'pid');
  2266. $aliasPinyins = array_column($categorys, 'aLIas_pinyin');
  2267. $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2268. // return Result::success($categorys);
  2269. $catiall = [];
  2270. //一级所有子级的记录
  2271. $cat_1st_arr = [];
  2272. foreach ($categorys as $key => $value) {
  2273. $category_arr_id = json_decode($value->category_arr_id);
  2274. $pinyin_str = '';
  2275. // 算出一级 并且算出子级
  2276. if ($value->pid != 0) {
  2277. $cat_1st_arr[$value->pid][] = $value->category_id;
  2278. }
  2279. foreach ($category_arr_id as $k => $v) {
  2280. $pinyin_str .= $cat_arr[$v] . '/';
  2281. }
  2282. $pinyin_str = rtrim($pinyin_str, '/');
  2283. $catiall[$value->category_id]['alias'] = $value->alias;
  2284. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2285. $catiall[$value->category_id]['type'] = $value->type;
  2286. $catiall[$value->category_id]['pinyin'] = $pinyin_str;
  2287. $websiteInfoIndexed[$value->category_id]->pinyin = $pinyin_str;
  2288. }
  2289. return [
  2290. 'cat_1st_arr' => $cat_1st_arr,
  2291. 'catiall' => $catiall,
  2292. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2293. 'categoryIds' => $categoryIds,
  2294. ];
  2295. }
  2296. /**
  2297. * 封装处理文章的路由问题
  2298. * */
  2299. function processArticles($articles, $data)
  2300. {
  2301. // 检查 $articles 是否为数组或可迭代对象
  2302. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2303. return $articles->map(function ($article) use ($data) {
  2304. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2305. $catid = $article->cat_arr_id ?? '';
  2306. }
  2307. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2308. $catid = $article->category_arr_id ?? '';
  2309. }
  2310. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2311. $level = json_decode($catid, true);
  2312. if (!is_array($level)) {
  2313. return $article;
  2314. } else {
  2315. $level = array_map('intval', $level);
  2316. }
  2317. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2318. ->where($data)
  2319. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2320. ->pluck('aLIas_pinyin')
  2321. ->implode('/');
  2322. $article->pinyin = $pinyin ?? '';
  2323. return $article;
  2324. });
  2325. } else {
  2326. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2327. $catid = $articles->cat_arr_id ?? '';
  2328. $level = json_decode($catid, true);
  2329. if (!is_array($level)) {
  2330. return $articles;
  2331. } else {
  2332. $level = array_map('intval', $level);
  2333. }
  2334. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2335. ->where($data)
  2336. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2337. ->pluck('aLIas_pinyin')
  2338. ->implode('/');
  2339. $articles->pinyin = $pinyin ?? '';
  2340. return $articles;
  2341. }
  2342. }
  2343. // 封装处理由问题
  2344. function processJob($job, $data)
  2345. {
  2346. return $job->map(function ($job) use ($data) {
  2347. $category = $job->cat_arr_id ?? '';
  2348. $cityid = $job->city_arr_id ?? '';
  2349. $city = json_decode($cityid, true);
  2350. $pinyin = '';
  2351. $level = json_decode($category, true);
  2352. // 路由
  2353. if (!empty($level) && is_array($level)) {
  2354. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2355. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2356. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2357. ->get(['aLIas_pinyin'])
  2358. ->pluck('aLIas_pinyin')
  2359. ->implode('/');
  2360. if (empty($pinyin)) {
  2361. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2362. }
  2363. $job->pinyin = $pinyin;
  2364. }
  2365. // 取职位-城市 市??省
  2366. if (!empty($city) && is_array($city)) {
  2367. if (isset($city[1]) && !empty($city[1])) {
  2368. $city = District::where('id', $city[1])->first(['name']);
  2369. $job->city_name = $city->name ?? '';
  2370. } else if (isset($city[0]) && !empty($city[0])) {
  2371. $city = District::where('id', $city[0])->first(['name']);
  2372. $job->city_name = $city->name ?? '';
  2373. } else {
  2374. $job->city_name = '全国';
  2375. }
  2376. }
  2377. // 获取简历最后一级地区
  2378. if (isset($job->city_id) && !empty($job->city_id)) {
  2379. $city = District::where('id', $job->city_id)->first(['name']);
  2380. $job->hunt_cityname = $city->name ?? '';
  2381. }
  2382. // 组合详细地址
  2383. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2384. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2385. if (is_array($address_id) && !empty($address_id)) {
  2386. $address = District::whereIn('id', $address_id)
  2387. ->orderBy('level', 'asc')
  2388. ->get(['name'])
  2389. ->pluck('name')
  2390. ->implode('');
  2391. // $job->address_name = $address ?? '';
  2392. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2393. }
  2394. }
  2395. // 取行业
  2396. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2397. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2398. if (!empty($job->industry)) {
  2399. $query->where('hyid', $job->industry);
  2400. } else if (!empty($job->hy_id)) {
  2401. $query->where('hyid', $job->hy_id);
  2402. } else if (!empty($job->company_hy_id)) {
  2403. $query->where('hyid', $job->company_hy_id);
  2404. } else {
  2405. $query->where('hyid', $job->job_industry);
  2406. }
  2407. })->first(['hyname']);
  2408. $job->hy_name = $hy_name->hyname ?? '';
  2409. }
  2410. // 取职位类别
  2411. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2412. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2413. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2414. $job->zw_name = $zw_name->zwname ?? '';
  2415. }
  2416. // 取具体职位
  2417. if ((isset($job->jtzw_id) && !empty($job->jtzw_id)) || (isset($job->job_name_get) && !empty($job->job_name_get)) || (isset($job->job_name) && !empty($job->job_name))) {
  2418. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2419. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2420. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2421. }
  2422. // 取工作经验
  2423. if (isset($job->experience) && !empty($job->experience)) {
  2424. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2425. $job->experience_name = $experience->ename ?? '';
  2426. }
  2427. // 取学历
  2428. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2429. $education = $job->educational ?? $job->school_education;
  2430. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2431. $job->education_name = $education->ename ?? '';
  2432. }
  2433. // 语言
  2434. if (isset($job->language) && !empty($job->language)) {
  2435. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2436. $job->language_name = $language->ename ?? '';
  2437. }
  2438. // 薪资
  2439. if (isset($job->salary) && !empty($job->salary)) {
  2440. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2441. $job->salary_name = $salary->ename ?? '';
  2442. }
  2443. // 职位性质
  2444. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2445. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2446. $job->job_nature_name = $job_nature->ename ?? '';
  2447. }
  2448. // 公司规模
  2449. if (isset($job->company_size) && !empty($job->company_size)) {
  2450. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2451. $job->company_size_name = $company_size->ename ?? '';
  2452. }
  2453. // 公司性质
  2454. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2455. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2456. $job->company_nature_name = $company_nature->nature_name ?? '';
  2457. }
  2458. // $job->pinyin = $pinyin;
  2459. return $job;
  2460. });
  2461. }
  2462. /**
  2463. * 获取书籍模块
  2464. * @param array $data
  2465. * @return array
  2466. * */
  2467. public function getWebsiteBook(array $data): array
  2468. {
  2469. $input['id'] = $data['id'];
  2470. $input['website_id'] = $data['website_id'];
  2471. // 将 JSON 字符串转换为 PHP 数组
  2472. $data = json_decode($input['id'], true);
  2473. // 使用 array_map 处理每个元素
  2474. $result = array_map(function ($item) use ($input) {
  2475. // 检查parent元素是否存在且不是undefined
  2476. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2477. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2478. $website = [
  2479. 'website_id' => $input['website_id'],
  2480. ];
  2481. // 查询栏目名称
  2482. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2483. if (empty($category)) {
  2484. $parent_alias = '';
  2485. $parent_pinyin = null;
  2486. $imgBooks = [];
  2487. $textBooks = [];
  2488. } else {
  2489. $parent_alias = $category->alias ?? '';
  2490. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2491. // 查找子分类ID数组
  2492. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2493. array_push($childCategoryIds, $parentCatId);
  2494. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2495. if ($parentImgNum != 0) {
  2496. // 查询图片新闻
  2497. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2498. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2499. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2500. })
  2501. ->where('book.status', 2)
  2502. ->where('book.img_url', '!=', '')
  2503. ->leftJoin('website_category', function ($join) use ($website) {
  2504. $join->on('book.cat_id', '=', 'website_category.category_id')
  2505. ->where('website_category.website_id', '=', $website['website_id']);
  2506. })
  2507. ->select(
  2508. 'book.id',
  2509. 'book.title',
  2510. 'book.img_url',
  2511. 'book.price',
  2512. 'book.market_price',
  2513. 'book.description',
  2514. 'book.cat_id',
  2515. 'book.description',
  2516. 'book.updated_at',
  2517. 'website_category.alias as category_name',
  2518. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2519. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2520. )
  2521. ->orderBy('updated_at', 'desc')
  2522. ->limit($parentImgNum)
  2523. ->get()->all();
  2524. // 查询文字新闻
  2525. }
  2526. if ($parentTextNum != 0) {
  2527. $textBooks = [];
  2528. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2529. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2530. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2531. })
  2532. ->where('book.status', 2)
  2533. ->leftJoin('website_category', function ($join) use ($website) {
  2534. $join->on('book.cat_id', '=', 'website_category.category_id')
  2535. ->where('website_category.website_id', '=', $website['website_id']);
  2536. })
  2537. ->select(
  2538. 'book.id',
  2539. 'book.title',
  2540. 'book.img_url',
  2541. 'book.price',
  2542. 'book.market_price',
  2543. 'book.description',
  2544. 'book.cat_id',
  2545. 'book.description',
  2546. 'book.updated_at',
  2547. 'website_category.alias as category_name',
  2548. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2549. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2550. )
  2551. ->orderBy('updated_at', 'desc')
  2552. ->limit($parentTextNum)
  2553. ->get()->all();
  2554. }
  2555. }
  2556. }
  2557. $resultItem = [
  2558. 'alias' => $parent_alias ?? '',
  2559. 'category_id' => $parentCatId ?? 0,
  2560. 'pinyin' => $parent_pinyin ?? null,
  2561. 'imgnum' => $imgBooks ?? [],
  2562. 'textnum' => $textBooks ?? [],
  2563. ];
  2564. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2565. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2566. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2567. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2568. ->get()->all();
  2569. if (!empty($childCategory)) {
  2570. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2571. // 查询子栏目名称
  2572. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2573. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2574. ->first();
  2575. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2576. $childImgArticles = [];
  2577. $childTextArticles = [];
  2578. $resultItem['child'] = [];
  2579. } else {
  2580. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2581. // 查询子栏目图片新闻
  2582. $childImgArticles = Book::where('cat_id', $childCatId)
  2583. ->where('status', 2)
  2584. ->where('img_url', '!=', '')
  2585. ->leftJoin('website_category', function ($join) use ($website) {
  2586. $join->on('book.cat_id', '=', 'website_category.category_id')
  2587. ->where('website_category.website_id', '=', $website['website_id']);
  2588. })
  2589. ->select(
  2590. 'book.id',
  2591. 'book.title',
  2592. 'book.img_url',
  2593. 'book.price',
  2594. 'book.market_price',
  2595. 'book.description',
  2596. 'book.cat_id',
  2597. 'book.description',
  2598. 'book.updated_at',
  2599. DB::raw("'$child_pinyin' as pinyin")
  2600. )
  2601. ->orderBy('updated_at', 'desc')
  2602. ->limit($childImgNum)
  2603. ->get()->all();
  2604. // 查询子栏目文字新闻
  2605. $childTextArticles = Book::where('cat_id', $childCatId)
  2606. ->where('status', 2)
  2607. ->leftJoin('website_category', function ($join) use ($website) {
  2608. $join->on('book.cat_id', '=', 'website_category.category_id')
  2609. ->where('website_category.website_id', '=', $website['website_id']);
  2610. })
  2611. ->select(
  2612. 'book.id',
  2613. 'book.title',
  2614. 'book.img_url',
  2615. 'book.price',
  2616. 'book.market_price',
  2617. 'book.description',
  2618. 'book.cat_id',
  2619. 'book.description',
  2620. 'book.updated_at',
  2621. DB::raw("'$child_pinyin' as pinyin")
  2622. )
  2623. ->orderBy('updated_at', 'desc')
  2624. ->limit($childTextNum)
  2625. ->get()->all();
  2626. $resultItem['child'] = [
  2627. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2628. 'category_id' => $childCatId,
  2629. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2630. 'all_childcat' => $childCategory,
  2631. 'imgnum' => $childImgArticles,
  2632. 'textnum' => $childTextArticles,
  2633. ];
  2634. }
  2635. }
  2636. } else {
  2637. $resultItem['child'] = [];
  2638. }
  2639. return $resultItem;
  2640. }, $data);
  2641. return Result::success($result);
  2642. }
  2643. /**
  2644. * 获取书刊列表
  2645. * @param array $data
  2646. * @return array
  2647. * */
  2648. public function getWebsiteBookList(array $data): array
  2649. {
  2650. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2651. if (empty($web)) {
  2652. return Result::error("查询失败", 0);
  2653. }
  2654. $catid = $data['id'];
  2655. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2656. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2657. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2658. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2659. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2660. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2661. ->where('pid', $category['pid'])
  2662. ->select(
  2663. 'category_id',
  2664. 'alias',
  2665. 'aLIas_pinyin',
  2666. 'pid',
  2667. 'sort',
  2668. 'is_url',
  2669. 'web_url',
  2670. 'seo_title',
  2671. 'seo_keywords',
  2672. 'seo_description',
  2673. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2674. )
  2675. ->orderBy('sort')
  2676. ->get()->all();
  2677. if (empty($category)) {
  2678. return Result::error("查询失败", 0);
  2679. }
  2680. $query = Book::where('book.status', 2)
  2681. ->where('book.website_id', $data['website_id'])
  2682. ->where('book.cat_id', $catid)
  2683. ->select(
  2684. 'book.id',
  2685. 'book.title',
  2686. 'book.img_url',
  2687. 'book.description',
  2688. 'book.updated_at',
  2689. 'book.cat_id',
  2690. DB::raw("'$pinyin' as pinyin")
  2691. )
  2692. ->orderBy('book.updated_at', 'desc');
  2693. $count = $query->count();
  2694. $query = clone $query;
  2695. $Book = $query
  2696. ->limit($data['pageSize'])
  2697. ->offset(($data['page'] - 1) * $data['pageSize'])
  2698. ->get()->all();
  2699. $result = [
  2700. 'category' => $categorys,
  2701. 'books' => $Book,
  2702. 'count' => $count,
  2703. ];
  2704. // if(empty($result)){
  2705. // return Result::error("查询失败", 0);
  2706. // }
  2707. return Result::success($result);
  2708. }
  2709. /**
  2710. * 获取书刊详情
  2711. * @param array $data
  2712. * @return array
  2713. * */
  2714. public function getWebsiteBookInfo(array $data): array
  2715. {
  2716. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2717. if (empty($web)) {
  2718. return Result::error("查询失败", 0);
  2719. }
  2720. $book = Book::where('status', 2)
  2721. ->where('website_id', $data['website_id'])
  2722. ->where('id', $data['id'])
  2723. ->select(
  2724. 'book.*',
  2725. )
  2726. ->orderBy('updated_at', 'desc')
  2727. ->first();
  2728. if (empty($book)) {
  2729. return Result::error("查询失败", 0);
  2730. }
  2731. // 先查询当前分类的 pid
  2732. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2733. ->where('category_id', $book['cat_id'])
  2734. ->first(['pid', 'category_id']);
  2735. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2736. if (!empty($carpid)) {
  2737. if ($carpid->pid != 0) {
  2738. $pid = $carpid['pid'];
  2739. // $parent_pinyin = '';
  2740. } else {
  2741. $pid = $carpid['category_id'];
  2742. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2743. }
  2744. }
  2745. $categorys = $query->where('pid', $pid)
  2746. ->select(
  2747. 'category_id',
  2748. 'alias',
  2749. 'aLIas_pinyin',
  2750. 'pid',
  2751. 'sort',
  2752. 'is_url',
  2753. 'web_url',
  2754. 'category_arr_id as cat_arr_id',
  2755. )
  2756. ->orderBy('sort')
  2757. ->get();
  2758. $category = $this->processArticle($categorys, $data);
  2759. $result = [
  2760. 'category' => $category,
  2761. 'books' => $book,
  2762. ];
  2763. return Result::success($result);
  2764. }
  2765. /**
  2766. * 尝试
  2767. * @param array $data
  2768. * @return array
  2769. * */
  2770. public function test(array $data): array
  2771. {
  2772. $input['id'] = $data['id'];
  2773. $input['website_id'] = $data['website_id'];
  2774. // 将 JSON 字符串转换为 PHP 数组
  2775. $data = json_decode($input['id'], true);
  2776. $result = [];
  2777. $article = $data;
  2778. $result = array_map(function ($item) use ($input) {
  2779. $website = [
  2780. 'website_id' => $input['website_id'],
  2781. ];
  2782. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2783. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2784. $parent = [
  2785. 0 => $category['category_id'] ?? [],
  2786. 1 => $parentImgNum ?? [],
  2787. 2 => $parentTextNum ?? [],
  2788. ];
  2789. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2790. $child = [];
  2791. $resultItem = [
  2792. // 'alias' => $parent_alias ?? '',
  2793. 'category_id' => $parentCatId ?? 0,
  2794. 'pinyin' => $parentImgNum ?? null,
  2795. 'imgnum' => $parentTextNum ?? [],
  2796. // 'textnum' => $textArticles ?? [],
  2797. ];
  2798. return $parent;
  2799. }, $data);
  2800. return Result::success($result);
  2801. // });
  2802. }
  2803. /**
  2804. * 封装处理文章的路由问题
  2805. * */
  2806. function processArticle($article, $data)
  2807. {
  2808. return $article->map(function ($article) use ($data) {
  2809. $catid = $article->cat_arr_id ?? '';
  2810. $level = json_decode($catid, true);
  2811. $pinyin = '';
  2812. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2813. if (!empty($level) && is_array($level)) {
  2814. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2815. ->where('website_id', $data['website_id'])
  2816. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2817. ->get(['aLIas_pinyin'])
  2818. ->pluck('aLIas_pinyin')
  2819. ->implode('/');
  2820. } else {
  2821. $pinyin = '';
  2822. }
  2823. $article->pinyin = $pinyin;
  2824. return $article;
  2825. });
  2826. }
  2827. /**
  2828. * c端-获取招工招聘下拉选框
  2829. * @param array $data
  2830. * @return array
  2831. * */
  2832. public function getWebsiteJobSelect(array $data): array
  2833. {
  2834. $web = Website::where('id', $data['website_id'])->first();
  2835. if (empty($web)) {
  2836. return Result::error("该网站不存在", 0);
  2837. }
  2838. $hy = JobIndustry::get()->all();
  2839. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2840. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2841. $result = [
  2842. 'hy' => $hy,
  2843. 'zw' => $zw,
  2844. 'jtzw' => $jtzw,
  2845. ];
  2846. if (empty($result)) {
  2847. return Result::error("查询失败", 0);
  2848. }
  2849. return Result::success($result);
  2850. }
  2851. /**
  2852. * c端-获取招工招聘
  2853. * @param array $data
  2854. * @return array
  2855. * */
  2856. public function getWebsiteJob(array $data): array
  2857. {
  2858. $web = Website::where('id', $data['website_id'])->first();
  2859. if (empty($web)) {
  2860. return Result::error("该网站不存在", 0);
  2861. }
  2862. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2863. ->where('job_hunting.website_id', $data['website_id'])
  2864. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2865. $query->where(function ($q) use ($data) {
  2866. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2867. });
  2868. })
  2869. ->select(
  2870. 'job_hunting.id',
  2871. 'job_hunting.cat_arr_id',
  2872. 'job_hunting.job_name_get',
  2873. 'job_hunting.industry',
  2874. 'job_hunting.name',
  2875. 'job_hunting.sexy',
  2876. 'job_hunting.origin',
  2877. 'job_hunting.city_arr_id',
  2878. 'job_hunting.experience',
  2879. 'job_hunting.updated_at',
  2880. 'job_hunting.salary'
  2881. )
  2882. ->orderBy('updated_at', 'desc')
  2883. ->limit($data['job1_num'])
  2884. ->get();
  2885. $web['website_id'] = $data['website_id'];
  2886. if (empty($job_hunting)) {
  2887. $job_huntings = "未查询到相关简历信息";
  2888. } else {
  2889. $job_huntings = $this->processJob($job_hunting, $web);
  2890. }
  2891. // 0:待审核 1:已通过 2:已拒绝
  2892. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2893. ->where('job_recruiting.website_id', $data['website_id'])
  2894. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2895. $query->where(function ($q) use ($data) {
  2896. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2897. });
  2898. })
  2899. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2900. ->select(
  2901. 'job_recruiting.id',
  2902. 'job_recruiting.cat_arr_id',
  2903. 'job_recruiting.title',
  2904. 'job_recruiting.jtzw_id',
  2905. 'job_recruiting.hy_id',
  2906. 'job_recruiting.city_arr_id',
  2907. 'job_recruiting.due_data',
  2908. 'job_recruiting.updated_at',
  2909. 'job_recruiting.experience',
  2910. 'job_recruiting.educational',
  2911. 'job_recruiting.salary',
  2912. 'job_recruiting.zw_id',
  2913. 'job_company.business_name'
  2914. )
  2915. ->orderBy('updated_at', 'desc')
  2916. ->limit($data['job2_num'])
  2917. ->get();
  2918. if (empty($job_recruiting->toArray())) {
  2919. $job_recruitings = "未查询到相关职位信息";
  2920. } else {
  2921. $job_recruitings = $this->processJob($job_recruiting, $web);
  2922. }
  2923. $result = [
  2924. 'job_hunting' => $job_huntings,
  2925. 'job_recuiting' => $job_recruitings,
  2926. ];
  2927. return Result::success($result);
  2928. }
  2929. /**
  2930. * c端-获取招工招聘列表
  2931. * @param array $data
  2932. * @return array
  2933. * */
  2934. public function getWebsiteJobList(array $data): array
  2935. {
  2936. $recruit_where = [];
  2937. $hunt_where = [];
  2938. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2939. if (empty($web)) {
  2940. return Result::error("此网站不存在", 0);
  2941. }
  2942. $website_id['website_id'] = $data['website_id'];
  2943. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2944. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2945. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2946. }
  2947. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2948. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2949. }
  2950. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2951. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2952. }
  2953. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2954. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  2955. }
  2956. $query = JobRecruiting::where('job_recruiting.status', 1)
  2957. ->where('job_recruiting.website_id', $data['website_id'])
  2958. ->where($recruit_where)
  2959. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2960. $query->where(function ($q) use ($data) {
  2961. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2962. });
  2963. })
  2964. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2965. $query->where(function ($q) use ($data) {
  2966. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2967. });
  2968. })
  2969. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2970. ->select(
  2971. 'job_recruiting.id',
  2972. 'job_recruiting.hy_id',
  2973. 'job_recruiting.title',
  2974. 'job_recruiting.zw_id',
  2975. 'job_recruiting.educational',
  2976. 'job_recruiting.jtzw_id',
  2977. 'job_recruiting.city_arr_id',
  2978. 'job_recruiting.due_data',
  2979. 'job_recruiting.experience',
  2980. 'job_recruiting.cat_arr_id',
  2981. 'job_recruiting.updated_at',
  2982. 'job_company.business_name'
  2983. )
  2984. ->orderBy('job_recruiting.updated_at', 'desc');
  2985. $recruit_count = $query->count();
  2986. $query = clone $query;
  2987. $JobRecruiting = $query
  2988. ->offset(($data['page'] - 1) * $data['pageSize'])
  2989. ->limit($data['pageSize'])
  2990. ->get();
  2991. if (empty($JobRecruiting)) {
  2992. $JobRecruiting = "暂无相关职位信息";
  2993. } else {
  2994. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2995. }
  2996. }
  2997. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2998. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2999. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3000. }
  3001. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3002. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3003. }
  3004. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3005. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3006. }
  3007. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3008. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3009. }
  3010. $query = JobHunting::where('job_hunting.status', 2)
  3011. ->where('job_hunting.website_id', $data['website_id'])
  3012. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3013. ->where($hunt_where)
  3014. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3015. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3016. // })
  3017. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3018. $query->where(function ($q) use ($data) {
  3019. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3020. });
  3021. })
  3022. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3023. $query->where(function ($q) use ($data) {
  3024. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3025. });
  3026. })
  3027. ->select(
  3028. 'job_hunting.id',
  3029. 'job_hunting.sexy',
  3030. 'job_hunting.experience',
  3031. 'job_hunting.origin',
  3032. 'job_hunting.industry',
  3033. 'job_hunting.name',
  3034. 'job_hunting.job',
  3035. 'job_hunting.job_name_get',
  3036. 'job_hunting.city_arr_id',
  3037. 'job_hunting.cat_arr_id',
  3038. 'job_hunting.created_at',
  3039. 'job_hunting.updated_at',
  3040. 'job_position.zwname as job_name'
  3041. )
  3042. ->orderBy('job_hunting.updated_at', 'desc');
  3043. $hunt_count = $query->count();
  3044. $query = clone $query;
  3045. $JobHunting = $query
  3046. ->offset(($data['page'] - 1) * $data['pageSize'])
  3047. ->limit($data['pageSize'])
  3048. ->get();
  3049. if (empty($JobHunting)) {
  3050. $JobRecruiting = "暂无相关简历信息";
  3051. } else {
  3052. $JobHunting = $this->processJob($JobHunting, $website_id);
  3053. }
  3054. }
  3055. $result = [
  3056. 'JobRecruiting' => $JobRecruiting ?? [],
  3057. 'recruit_count' => $recruit_count ?? 0,
  3058. 'JobHunting' => $JobHunting ?? [],
  3059. 'hunt_count' => $hunt_count ?? 0,
  3060. ];
  3061. return Result::success($result);
  3062. }
  3063. /**
  3064. * c端-获取招工招聘详情
  3065. * @param array $data
  3066. * @return array
  3067. * */
  3068. public function getWebsiteJobInfo(array $data): array
  3069. {
  3070. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3071. if (empty($web)) {
  3072. return Result::error("该网站不存在", 0);
  3073. }
  3074. $webid = [
  3075. 'website_id' => $data['website_id'],
  3076. ];
  3077. // 职位相关信息
  3078. if ($data['type'] == 1) {
  3079. $query = JobRecruiting::where('status', 1)
  3080. ->where('website_id', $data['website_id'])
  3081. ->select('*');
  3082. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3083. $company = JobCompany::where('job_id', $data['id'])->select('id', 'business_name', 'company_hy_id', 'company_size', 'company_nature', 'address_arr_id', 'address', 'job_company.email')->get();
  3084. if (!empty($company)) {
  3085. $result['company'] = $this->processJob($company, $webid);
  3086. }
  3087. $other_job = JobRecruiting::where('status', 1)
  3088. ->where('website_id', $data['website_id'])
  3089. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3090. ->where('id', '!=', $data['id'])
  3091. ->where('user_id', '=', $job[0]['user_id'])
  3092. ->limit($data['pageSize'])
  3093. ->get();
  3094. if (!empty($other_job)) {
  3095. $result['other_job'] = $this->processJob($other_job, $webid);
  3096. }
  3097. } else {
  3098. // 简历相关信息
  3099. $job = JobHunting::where('job_hunting.status', 2)
  3100. ->where('job_hunting.website_id', $data['website_id'])
  3101. ->where('job_hunting.id', $data['id'])
  3102. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3103. ->select('job_hunting.*', 'user_name')
  3104. ->get();
  3105. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3106. if (!empty($resume->toArray())) {
  3107. $result['resume'] = 1;
  3108. } else {
  3109. $result['resume'] = 0;
  3110. }
  3111. }
  3112. if (empty($job->toArray())) {
  3113. return Result::error("id参数错误", 0);
  3114. }
  3115. if (!empty($job[0]['job_experience'])) {
  3116. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3117. if (!empty($job_experience)) {
  3118. // $hy = [];
  3119. foreach ($job_experience as $key => $value) {
  3120. // $id = $value['id'];
  3121. $hy[$key] = $value['job_industry'];
  3122. $zw_id[$key] = $value['job_typename'];
  3123. $jtzw_id[$key] = $value['job_name'];
  3124. }
  3125. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3126. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3127. // 先将关联表转换为索引数组,提高查找效率
  3128. $hyLookup = [];
  3129. foreach ($hy_table as $item) {
  3130. $hyLookup[$item['hyid']] = $item['hyname'];
  3131. }
  3132. $zwLookup = [];
  3133. foreach ($zw_table as $item) {
  3134. $zwLookup[$item['zwid']] = $item['zwname'];
  3135. }
  3136. foreach ($job_experience as $key => &$value) {
  3137. // 处理行业名称
  3138. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3139. $value['hy_name'] = $hyLookup[$hy[$key]];
  3140. }
  3141. // 处理职位名称
  3142. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3143. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3144. }
  3145. // 处理具体职位名称
  3146. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3147. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3148. }
  3149. }
  3150. // 释放引用,防止意外修改后续代码
  3151. unset($value);
  3152. }
  3153. $result['job_experience'] = $job_experience ?? [];
  3154. }
  3155. if (!empty($job[0]['education_experience'])) {
  3156. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3157. if (!empty($education_experience)) {
  3158. foreach ($education_experience as $key => $value) {
  3159. // $id = $value['id'];
  3160. $education[$key] = $value['school_education'];
  3161. }
  3162. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3163. // // 先将关联表转换为索引数组,提高查找效率
  3164. $educationLookup = [];
  3165. foreach ($education_table as $item) {
  3166. $educationLookup[$item['evalue']] = $item['ename'];
  3167. }
  3168. foreach ($education_experience as $key => &$value) {
  3169. // 处理学历名称
  3170. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3171. $value['education_name'] = $educationLookup[$education[$key]];
  3172. }
  3173. }
  3174. }
  3175. $result['education_experience'] = $job_experience ?? [];
  3176. }
  3177. $result['job'] = $this->processJob($job, $webid);
  3178. // // 返现对应的栏目
  3179. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3180. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3181. ->whereIn('category_id', $catid)
  3182. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3183. ->orderBy('pid')->get()->all();
  3184. if (!empty($category)) {
  3185. $result['category'] = $category;
  3186. }
  3187. $result['job'] = $job;
  3188. $result['job_experience'] = $job_experience ?? [];
  3189. $result['education_experience'] = $education_experience ?? [];
  3190. if (empty($result)) {
  3191. return Result::error("参数错误", 0);
  3192. }
  3193. return Result::success($result);
  3194. }
  3195. /**
  3196. * c端-申请职位
  3197. * @param array $data
  3198. * @return array
  3199. * */
  3200. public function getWebsiteJobApply(array $data): array
  3201. {
  3202. // 首先验证网站是否存在
  3203. // return Result::success($data);
  3204. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3205. if (empty($web)) {
  3206. return Result::error("该网站不存在", 0);
  3207. }
  3208. // 验证用户是否存在且为个人会员/管理员
  3209. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3210. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3211. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3212. return Result::error("用户不存在", 0);
  3213. }
  3214. // 去除重复元素和空元素,并保持原始顺序
  3215. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3216. return !empty($value);
  3217. }));
  3218. // 验证职位是否存在 1:审核通过
  3219. $recruiting = JobRecruiting::where('status', 1)
  3220. ->where('website_id', $data['website_id'])
  3221. ->whereIn('id', $data['recruit_id'])
  3222. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3223. if (empty($recruiting)) {
  3224. return Result::error("该职位不存在", 0);
  3225. }
  3226. // 简历是否存在
  3227. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3228. if (empty($hunt_id)) {
  3229. return Result::error("该简历不存在", 0);
  3230. }
  3231. $data['hunt_id'] = $hunt_id['hunt_id'];
  3232. // // 验证是否已投递过该职位
  3233. $apply = JobApply::where('user_id', $data['user_id'])
  3234. ->where('hunt_id', $data['hunt_id'])
  3235. ->where('website_id', $data['website_id'])
  3236. ->whereIn('recruit_id', $data['recruit_id'])
  3237. ->get(['recruit_id']);
  3238. if (!empty($apply->toArray())) {
  3239. return Result::error("您已投递过该职位!");
  3240. }
  3241. $insertData = array_map(function ($recruiting) use ($data) {
  3242. return [
  3243. 'user_id' => $data['user_id'],
  3244. 'hunt_id' => $data['hunt_id'],
  3245. 'website_id' => $data['website_id'],
  3246. 'recruit_id' => $recruiting['recruit_id'],
  3247. 'receiver_id' => $recruiting['receiver_id'],
  3248. 'status' => 1,
  3249. ];
  3250. }, $recruiting);
  3251. // 批量插入数据
  3252. $result = JobApply::insert($insertData);
  3253. if (empty($result)) {
  3254. return Result::error("投递失败", 0);
  3255. }
  3256. return Result::success($result);
  3257. }
  3258. /**
  3259. * 招工招聘-沟通简历
  3260. * @param array $data
  3261. * @return array
  3262. * */
  3263. public function getWebsiteJobResume(array $data): array
  3264. {
  3265. // 首先验证网站是否存在
  3266. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3267. if (empty($web)) {
  3268. return Result::error("该网站不存在", 0);
  3269. }
  3270. // return Result::success($data);
  3271. // 验证用户是否存在且为企业会员/管理员
  3272. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3273. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3274. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3275. return Result::error("用户不存在", 0);
  3276. }
  3277. // 去除重复元素和空元素,并保持原始顺序
  3278. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3279. return !empty($value);
  3280. }));
  3281. // 验证简历是否存在
  3282. $hunting = JobHunting::where('status', 2)
  3283. ->where('website_id', $data['website_id'])
  3284. ->whereIn('id', $data['hunt_id'])
  3285. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3286. if (empty($hunting)) {
  3287. return Result::error("该简历不存在", 0);
  3288. }
  3289. // 验证是否已沟通过该简历
  3290. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3291. ->where('recruit_id', $data['recruit_id'])
  3292. ->where('website_id', $data['website_id'])
  3293. ->whereIn('hunt_id', $data['hunt_id'])
  3294. ->get(['hunt_id']);
  3295. if (!empty($remuse->toArray())) {
  3296. return Result::error("您已沟通过该简历!");
  3297. }
  3298. // 准备要插入的数据数组
  3299. $insertData = array_map(function ($hunting) use ($data) {
  3300. return [
  3301. 'user_id' => $data['user_id'],
  3302. 'recruit_id' => $data['recruit_id'],
  3303. 'website_id' => $data['website_id'],
  3304. 'hunt_id' => $hunting['hunt_id'],
  3305. 'receiver_id' => $hunting['receiver_id'],
  3306. 'status' => 1,
  3307. ];
  3308. }, $hunting);
  3309. // 批量插入数据
  3310. $result = JobRemuse::insert($insertData);
  3311. if (empty($result)) {
  3312. return Result::error("沟通失败", 0);
  3313. }
  3314. return Result::success($result);
  3315. }
  3316. /**
  3317. * 招工招聘 -我的职位(企业会员)
  3318. * @param array $data
  3319. * @return array
  3320. */
  3321. public function getWebsiteJobRecruiting(array $data): array
  3322. {
  3323. $web = Website::where('id', $data['website_id'])->first('id');
  3324. if (empty($web)) {
  3325. return Result::error("该网站不存在", 0);
  3326. }
  3327. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3328. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3329. return Result::error("用户暂无权限!", 0);
  3330. }
  3331. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3332. $result = JobRecruiting::where('website_id', $data['website_id'])
  3333. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3334. $query->where('user_id', $user['id']);
  3335. })
  3336. ->where('status', 1)
  3337. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3338. ->orderBy('updated_at', 'desc')
  3339. ->limit($data['pageSize'])
  3340. ->get();
  3341. if (empty($result)) {
  3342. return Result::error("暂无相关职位信息", 0);
  3343. }
  3344. return Result::success($result);
  3345. }
  3346. /**
  3347. * c端 - 验证路由
  3348. * @param array $data
  3349. * @return array
  3350. */
  3351. /**
  3352. * c端 - 验证路由
  3353. * @param array $data
  3354. * @return array
  3355. */
  3356. public function checkWebsiteRoute(array $data): array
  3357. {
  3358. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3359. if (empty($web)) {
  3360. return Result::error("该网站不存在", 0);
  3361. } elseif ($web['status'] != 1) {
  3362. return Result::error("网站已经关闭", 0);
  3363. }
  3364. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3365. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3366. // 验证路由是否存在
  3367. if (empty($whiteRouterInfo)) {
  3368. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3369. }
  3370. if (!empty($whiteRouterInfo)) {
  3371. return Result::success($whiteRouterInfo->toArray());
  3372. }
  3373. }
  3374. // 验证栏目路由
  3375. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3376. ->where('aLIas_pinyin', $data['last_route'])
  3377. ->get()->all();
  3378. if (count($last_category) == 0) {
  3379. return Result::error("该栏目不存在", 0);
  3380. }
  3381. if (count($last_category) > 1) {
  3382. return Result::error("该子级栏目存在多个,路由验证失败!", 0);
  3383. }
  3384. if (count($last_category) == 1) {
  3385. $last_category = $last_category[0];
  3386. }
  3387. // return Result::success($last_category);
  3388. if (isset($data['id']) && !empty($data['id'])) {
  3389. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3390. switch ($last_category['type']) {
  3391. case 1:
  3392. // 文章
  3393. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3394. $article = Article::where('status', 1)
  3395. ->where('id', $data['id'])
  3396. ->where(function ($query) use ($data) {
  3397. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3398. ->orWhereNull("ignore_ids");
  3399. })
  3400. ->first(['cat_arr_id']);
  3401. if (empty($article)) {
  3402. return Result::error("该文章不存在", 0);
  3403. }
  3404. // return Result::success($article);
  3405. break;
  3406. case 2:
  3407. // 商品
  3408. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3409. $article = Good::where('website_id', $data['website_id'])
  3410. ->where('status', 2)
  3411. ->where('id', $data['id'])
  3412. ->first(['cat_arr_id']);
  3413. if (empty($article)) {
  3414. return Result::error("该商品不存在", 0);
  3415. }
  3416. break;
  3417. case 3:
  3418. // 书刊信息
  3419. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3420. $article = Book::where('website_id', $data['website_id'])
  3421. ->where('status', 2)
  3422. ->where('id', $data['id'])
  3423. ->first(['id', 'cat_arr_id']);
  3424. if (empty($article)) {
  3425. return Result::error("该书刊不存在", 0);
  3426. }
  3427. break;
  3428. case 4:
  3429. // 招聘
  3430. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3431. $article = JobRecruiting::where('website_id', $data['website_id'])
  3432. ->where('status', 1)
  3433. ->where('id', $data['id'])
  3434. ->first(['cat_arr_id']);
  3435. if (empty($article)) {
  3436. return Result::error("该招聘不存在", 0);
  3437. }
  3438. break;
  3439. case 5:
  3440. // 求职
  3441. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3442. $article = JobHunting::where('website_id', $data['website_id'])
  3443. ->where('status', 2)
  3444. ->where('id', $data['id'])
  3445. ->first(['cat_arr_id']);
  3446. if (empty($article)) {
  3447. return Result::error("该求职不存在", 0);
  3448. }
  3449. break;
  3450. case 6:
  3451. // 企业
  3452. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3453. $article = Company::
  3454. // where('website_id', $data['website_id'])
  3455. // ->
  3456. where('status', 1)
  3457. ->where('id', $data['id'])
  3458. ->first(['cat_arr_id']);
  3459. if (empty($article)) {
  3460. return Result::error("该企业不存在", 0);
  3461. }
  3462. break;
  3463. case 7:
  3464. // 项目
  3465. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3466. $article = Project::where('website_id', $data['website_id'])
  3467. ->where('status', 1)
  3468. ->where('id', $data['id'])
  3469. ->first(['cat_arr_id']);
  3470. if (empty($article)) {
  3471. return Result::error("该项目不存在", 0);
  3472. }
  3473. break;
  3474. default:
  3475. return Result::error("该数据不存在", 0);
  3476. break;
  3477. }
  3478. $catid = 0;
  3479. $catidArray = json_decode($article['cat_arr_id'], true);
  3480. $catid = !empty($catidArray) ? end($catidArray) : null;
  3481. // return Result::success($article['cat_arr_id']);
  3482. if (empty($catid)) {
  3483. return Result::error("该数据不存在", 0);
  3484. }
  3485. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3486. ->where('category_id', $catid)
  3487. ->select('path')
  3488. ->pluck('path');
  3489. } else {
  3490. if ($last_category['pid'] != 0) {
  3491. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3492. $catid = !empty($cat_arr) ? end($cat_arr) : null;
  3493. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3494. ->where('category_id', $catid)
  3495. ->where('path', $data['all_route'])
  3496. ->pluck('path');
  3497. } else {
  3498. $pinyin[0] = $last_category['aLIas_pinyin'];
  3499. }
  3500. }
  3501. // return Result::success($pinyin[0]);
  3502. if (empty($pinyin) || count($pinyin) > 1 || $pinyin[0] != $data['all_route']) {
  3503. return Result::error('非法路径!');
  3504. } else {
  3505. return Result::success($pinyin);
  3506. }
  3507. }
  3508. /**
  3509. * 招工招聘 - 获取推荐职位
  3510. * @param array $data
  3511. * @return array
  3512. */
  3513. public function getWebsiteLevelJob(array $data): array
  3514. {
  3515. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3516. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3517. ->where('job_recruiting.status', 1)
  3518. ->where('job_level', $data['job_level'])
  3519. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3520. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3521. ->orderBy('job_recruiting.updated_at', 'desc')
  3522. ->limit($data['pageSize'])
  3523. ->get();
  3524. $web = ['website_id' => $data['website_id']];
  3525. if (!empty($job)) {
  3526. $result = $this->processJob($job, $web);
  3527. }
  3528. if (empty($result)) {
  3529. return Result::error("暂无相关职位信息", 0);
  3530. }
  3531. return Result::success($result);
  3532. }
  3533. /**
  3534. * 验证导航名称是否重复
  3535. * @return void
  3536. */
  3537. //20250226 产品列表
  3538. public function getGoodList(array $data): array
  3539. {
  3540. var_dump($data, '---------1-2--');
  3541. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3542. unset($data['user_type_id']);
  3543. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3544. $where = [];
  3545. if ($type_id != '10000') {
  3546. $where = [
  3547. 'good.user_id' => $user_id,
  3548. ];
  3549. }
  3550. //类型
  3551. if (isset($data['type_id']) && $data['type_id']) {
  3552. $where['good.type_id'] = $data['type_id'];
  3553. }
  3554. //名称
  3555. if (isset($data['name']) && $data['name']) {
  3556. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3557. }
  3558. //status
  3559. if (isset($data['status']) && $data['status'] != '') {
  3560. $where['good.status'] = $data['status'];
  3561. }
  3562. //status1
  3563. // if (isset($data['status1']) && $data['status1'] == 1) {
  3564. // $status1 = 1;
  3565. // }
  3566. $where1 = [];
  3567. //website_id
  3568. // if (isset($data['website_id']) && $data['website_id']) {
  3569. // $where1 = [
  3570. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3571. // ];
  3572. // }
  3573. // website_name
  3574. if (isset($data['website_name']) && $data['website_name']) {
  3575. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3576. }
  3577. // catid
  3578. if (isset($data['category_name']) && $data['category_name']) {
  3579. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3580. }
  3581. // $result = Good::where($where)
  3582. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3583. var_dump($where, '---------1---');
  3584. $result = Good::where($where)
  3585. ->when(!empty($where1), function ($query) use ($where1) {
  3586. return $query->where($where1);
  3587. })
  3588. //status 1待审核2已审核3已拒绝
  3589. ->when(isset($data['status1']), function ($query) {
  3590. return $query->whereIn('good.status', [1, 3]);
  3591. })
  3592. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3593. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3594. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3595. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3596. ->orderBy("updated_at", "desc")
  3597. ->limit($data['page_size'])
  3598. ->offset(($data['page'] - 1) * $data['page_size'])
  3599. ->get();
  3600. $count = Good::where($where)
  3601. ->when(!empty($where1), function ($query) use ($where1) {
  3602. return $query->where($where1);
  3603. })
  3604. //status 1待审核2已审核3已拒绝
  3605. ->when(isset($data['status1']), function ($query) {
  3606. return $query->whereIn('good.status', [1, 3]);
  3607. })
  3608. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3609. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3610. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3611. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3612. ->orderBy("updated_at", "desc")->count();
  3613. $data = [
  3614. 'rows' => $result->toArray(),
  3615. 'count' => $count,
  3616. ];
  3617. if (empty($result)) {
  3618. return Result::error("此栏目暂无相关产品", 0);
  3619. }
  3620. return Result::success($data);
  3621. }
  3622. public function getGoodInfo(array $data): array
  3623. {
  3624. $result = Good::where('id', $data['id'])->first();
  3625. if (empty($result)) {
  3626. return Result::error("此产品不存在", 0);
  3627. }
  3628. return Result::success($result);
  3629. }
  3630. public function addGood(array $data): array
  3631. {
  3632. // unset($data['city_arr_id']);
  3633. // unset($data['cat_arr_id']);
  3634. $data['city_id'] = end($data['city_arr_id']);
  3635. $data['catid'] = end($data['cat_arr_id']);
  3636. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3637. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3638. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3639. unset($data['imgUrl']); //大小写
  3640. if (isset($data['price']) && $data['price'] == '') {
  3641. $data['price'] = 0;
  3642. }
  3643. if ($data['imgurl'] == '') {
  3644. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3645. preg_match_all($reg, $data['detail'], $matches);
  3646. if (isset($matches[1][0])) {
  3647. //截取varchar240
  3648. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3649. }
  3650. }
  3651. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3652. //提取标题+内容中的关键词
  3653. $data['keyword'] = $data['name'];
  3654. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3655. Jieba::init(); // 初始化 jieba-php
  3656. Finalseg::init();
  3657. $segList = Jieba::cut($data['keyword']);
  3658. $segList1 = array_slice($segList, 0, 8);
  3659. $data['keyword'] = implode(',', $segList1);
  3660. }
  3661. if ($data['description'] == '') {
  3662. //提取内容中的描述
  3663. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3664. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3665. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3666. }
  3667. if ($data['status'] == 1) {
  3668. $this->sendMessage([
  3669. 'talk_type' => 200,
  3670. 'title' => $data['name'],
  3671. 'content' => '提交了审核',
  3672. 'messageType' => 3,
  3673. ]);
  3674. }
  3675. $result = Good::insert($data);
  3676. if (empty($result)) {
  3677. return Result::error("添加失败", 0);
  3678. }
  3679. return Result::success($result);
  3680. }
  3681. public function updateGood(array $data): array
  3682. {
  3683. $data['city_id'] = end($data['city_arr_id']);
  3684. $data['catid'] = end($data['cat_arr_id']);
  3685. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3686. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3687. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3688. //设置东八区
  3689. date_default_timezone_set('Asia/Shanghai');
  3690. $data['updated_at'] = date('Y-m-d H:i:s');
  3691. if (isset($data['price']) && $data['price'] == '') {
  3692. $data['price'] = 0;
  3693. }
  3694. if ($data['imgurl'] == '') {
  3695. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3696. preg_match_all($reg, $data['detail'], $matches);
  3697. if (isset($matches[1][0])) {
  3698. //截取varchar240
  3699. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3700. }
  3701. }
  3702. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3703. //提取标题+内容中的关键词
  3704. $data['keyword'] = $data['name'];
  3705. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3706. Jieba::init(); // 初始化 jieba-php
  3707. Finalseg::init();
  3708. $segList = Jieba::cut($data['keyword']);
  3709. $segList1 = array_slice($segList, 0, 8);
  3710. $data['keyword'] = implode(',', $segList1);
  3711. }
  3712. if ($data['description'] == '') {
  3713. //提取内容中的描述
  3714. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3715. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3716. }
  3717. if ($data['status'] == 1) {
  3718. $this->sendMessage([
  3719. 'talk_type' => 200,
  3720. 'title' => $data['name'],
  3721. 'content' => '提交了审核',
  3722. 'messageType' => 3,
  3723. ]);
  3724. }
  3725. $result = Good::where('id', $data['id'])->update($data);
  3726. if (empty($result)) {
  3727. return Result::error("更新失败", 0);
  3728. }
  3729. return Result::success($result);
  3730. }
  3731. public function delGood(array $data): array
  3732. {
  3733. $result = Good::where('id', $data['id'])->delete();
  3734. if (empty($result)) {
  3735. return Result::error("删除失败", 0);
  3736. }
  3737. return Result::success($result);
  3738. }
  3739. //20250226 产品列表
  3740. //20250306 求职信息
  3741. public function getJobHuntingList(array $data): array
  3742. {
  3743. $where = [];
  3744. if (isset($data['username']) && !empty($data['username'])) {
  3745. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3746. }
  3747. //status 1待审核2已审核3已拒绝
  3748. if (isset($data['status']) && $data['status'] != '') {
  3749. $where = [
  3750. 'job_hunting.status' => $data['status'],
  3751. ];
  3752. }
  3753. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3754. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3755. unset($data['type_id']);
  3756. if ($type_id != '10000') {
  3757. $where[] = ['job_hunting.user_id', '=', $user_id];
  3758. }
  3759. $result = JobHunting::where($where)
  3760. ->when(!empty($data['status1']), function ($query) use ($data) {
  3761. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3762. })
  3763. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3764. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3765. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3766. ->orderBy("updated_at", "desc")
  3767. ->limit($data['page_size'])
  3768. ->offset(($data['page'] - 1) * $data['page_size'])
  3769. ->get();
  3770. if (empty($result)) {
  3771. return Result::error("查询失败", 0);
  3772. }
  3773. $count = JobHunting::where($where)
  3774. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3775. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3776. ->count();
  3777. $data = [
  3778. 'rows' => $result->toArray(),
  3779. 'count' => $count,
  3780. ];
  3781. return Result::success($data);
  3782. }
  3783. public function getJobHuntingApply(array $data): array
  3784. {
  3785. var_dump($data, '-----------------test--------1-');
  3786. $where = [];
  3787. if (isset($data['username']) && !empty($data['username'])) {
  3788. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3789. }
  3790. if (isset($data['salary']) && !empty($data['salary'])) {
  3791. $where[] = [
  3792. 'job_hunting.salary',
  3793. '=',
  3794. $data['salary'],
  3795. ];
  3796. }
  3797. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3798. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3799. unset($data['type_id']);
  3800. if ($type_id != '10000') {
  3801. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3802. }
  3803. var_dump($where, '-----------------test---------');
  3804. $result = jobApply::where($where)
  3805. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3806. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3807. // })
  3808. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3809. ->where('job_enum.egroup', '=', 'income')
  3810. ->where('job_hunting.status', 2) //已审核
  3811. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3812. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3813. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3814. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3815. //职位----是申请职位
  3816. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3817. ->select('job_apply.*', 'job_position.zwname as job_name', 'job_hunting.salary as salary', 'district.name as cityname', 'job_enum.ename as salary_name', 'user.nickname as nickname', 'user.user_name as username', 'job_hunting.updated_at as updated_at')
  3818. ->orderBy("job_hunting.updated_at", "desc")
  3819. ->limit($data['page_size'])
  3820. ->offset(($data['page'] - 1) * $data['page_size'])
  3821. ->get();
  3822. if (empty($result)) {
  3823. return Result::error("查询失败", 0);
  3824. }
  3825. $count = jobApply::where($where)
  3826. ->where('job_enum.egroup', '=', 'income')
  3827. ->where('job_hunting.status', 2) //已审核
  3828. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3829. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3830. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3831. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3832. //职位----是申请职位
  3833. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3834. ->select('job_apply.*', 'job_position.zwname as job_name', 'job_hunting.salary as salary', 'district.name as cityname', 'job_enum.ename as salary_name', 'user.nickname as nickname', 'user.user_name as username', 'job_hunting.updated_at as updated_at')
  3835. ->count();
  3836. $data = [
  3837. 'rows' => $result->toArray(),
  3838. 'count' => $count,
  3839. ];
  3840. return Result::success($data);
  3841. }
  3842. public function addJobHunting(array $data): array
  3843. {
  3844. date_default_timezone_set('Asia/Shanghai');
  3845. unset($data['company_name']);
  3846. unset($data['job_industry']);
  3847. unset($data['job_name']);
  3848. unset($data['department']);
  3849. unset($data['job_timeList']);
  3850. unset($data['job_content']);
  3851. unset($data['job_typename']); //不知道这是啥,
  3852. $data['created_at'] = date('Y-m-d H:i:s');
  3853. $data['updated_at'] = date('Y-m-d H:i:s');
  3854. //根据用户 user_id 只能添加一次
  3855. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3856. if (!empty($result)) {
  3857. return Result::error("您已添加过求职信息", 0);
  3858. }
  3859. var_dump($result, '-----------------test---------');
  3860. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3861. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3862. $cityArr = json_decode($data['city_arr_id'], true);
  3863. $data['city_id'] = end($cityArr);
  3864. } else {
  3865. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3866. $data['city_id'] = end($data['city_arr_id']);
  3867. }
  3868. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  3869. $this->sendMessage([
  3870. 'talk_type' => 600,
  3871. 'title' => $data['name'],
  3872. 'content' => '提交了审核',
  3873. 'messageType' => 11,
  3874. ]);
  3875. }
  3876. $result = JobHunting::create($data);
  3877. if (empty($result)) {
  3878. return Result::error("添加失败", 0);
  3879. }
  3880. return Result::success($result);
  3881. }
  3882. public function delJobHunting(array $data): array
  3883. {
  3884. $result = JobHunting::where('id', $data['id'])->delete();
  3885. if (empty($result)) {
  3886. return Result::error("删除失败", 0);
  3887. }
  3888. return Result::success($result);
  3889. }
  3890. public function updateJobHunting(array $data): array
  3891. {
  3892. //设置东八区
  3893. date_default_timezone_set('Asia/Shanghai');
  3894. unset($data['company_name']);
  3895. unset($data['job_industry']);
  3896. unset($data['job_name']);
  3897. unset($data['department']);
  3898. unset($data['job_timeList']);
  3899. unset($data['job_content']);
  3900. unset($data['job_typename']); //不知道这是啥,
  3901. $data['created_at'] = date('Y-m-d H:i:s');
  3902. $data['updated_at'] = date('Y-m-d H:i:s');
  3903. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3904. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3905. $cityArr = json_decode($data['city_arr_id'], true);
  3906. $data['city_id'] = end($cityArr);
  3907. } else {
  3908. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3909. $data['city_id'] = end($data['city_arr_id']);
  3910. }
  3911. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  3912. $this->sendMessage([
  3913. 'talk_type' => 600,
  3914. 'title' => $data['name'],
  3915. 'content' => '提交了审核',
  3916. 'messageType' => 11,
  3917. ]);
  3918. }
  3919. $result = JobHunting::where('id', $data['id'])->update($data);
  3920. if (empty($result)) {
  3921. return Result::error("更新失败", 0);
  3922. }
  3923. return Result::success($result);
  3924. }
  3925. public function getJobHuntingInfo(array $data): array
  3926. {
  3927. $result = JobHunting::where('id', $data['id'])->first();
  3928. if (empty($result)) {
  3929. return Result::error("查询失败", 0);
  3930. }
  3931. return Result::success($result);
  3932. }
  3933. public function getJobHuntingData(array $data): array
  3934. {
  3935. $jobEnum = JobEnum::get();
  3936. $jobIndustry = JobIndustry::get();
  3937. $jobNature = JobNature::get();
  3938. $jobPosition = JobPosition::get();
  3939. $data = [
  3940. 'jobEnum' => $jobEnum,
  3941. 'jobIndustry' => $jobIndustry,
  3942. 'jobNature' => $jobNature,
  3943. 'jobPosition' => $jobPosition,
  3944. ];
  3945. return Result::success($data);
  3946. }
  3947. public function delJobHuntingInfo(array $data): array
  3948. {
  3949. $result = JobHunting::where('id', $data['id'])->delete();
  3950. return Result::success();
  3951. }
  3952. //20250324 通知,公告,消息
  3953. public function delNotice(array $data): array
  3954. {
  3955. $result = Notice::where('id', $data['id'])->delete();
  3956. if ($result) {
  3957. return Result::success();
  3958. } else {
  3959. return Result::error("删除失败", 0);
  3960. }
  3961. }
  3962. public function getNoticeInfo(array $data): array
  3963. {
  3964. $result = Notice::where('id', $data['id'])->first();
  3965. // var_dump($result['re_user_ids'], '--------------------');
  3966. if (empty($result)) {
  3967. return Result::error("查询失败", 0);
  3968. }
  3969. return Result::success($result);
  3970. }
  3971. public function readNotice(array $data): array
  3972. {
  3973. $result = Notice::where('id', $data['id'])->first();
  3974. // var_dump($result['re_user_ids'], '--------------------');
  3975. if (empty($result)) {
  3976. return Result::error("查询失败", 0);
  3977. }
  3978. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  3979. $re_user_ids = json_decode($result['re_user_ids'], true);
  3980. var_dump($re_user_ids, '--------------1---test---------');
  3981. var_dump($data, '--------------1---test---------');
  3982. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  3983. //如果已经存在,就不再添加
  3984. if (isset($result['read_id']) && !empty($result['read_id'])) {
  3985. $read_id = json_decode($result['read_id'], true);
  3986. if (!is_array($read_id)) {
  3987. $read_id = [];
  3988. }
  3989. if (!in_array($data['user_id'], $read_id)) {
  3990. $read_id[] = $data['user_id'];
  3991. $result['read_id'] = json_encode($read_id);
  3992. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  3993. }
  3994. } else {
  3995. //如果不存在,就添加
  3996. $result['read_id'] = json_encode([$data['user_id']]);
  3997. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  3998. }
  3999. }
  4000. return Result::success($result);
  4001. }
  4002. public function addNotice(array $data): array
  4003. {
  4004. date_default_timezone_set('Asia/Shanghai');
  4005. $data['created_at'] = date('Y-m-d H:i:s');
  4006. $data['updated_at'] = date('Y-m-d H:i:s');
  4007. $user_id = UserInfo::
  4008. //city_id不是null
  4009. whereNotNull('city_id')
  4010. ->whereNotNull('department_id')
  4011. ->where(function ($query) use ($data) {
  4012. $query->where(function ($subQuery) use ($data) {
  4013. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4014. });
  4015. })
  4016. ->where(function ($query) use ($data) {
  4017. $query->where(function ($subQuery) use ($data) {
  4018. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4019. });
  4020. })
  4021. ->pluck('user_id')->toArray();
  4022. $user_id = array_unique($user_id);
  4023. $chat_ids = $user_id;
  4024. $user_id = json_encode($user_id);
  4025. $data['re_user_ids'] = $user_id;
  4026. $this->sendMessage([
  4027. 'talk_type' => 700,
  4028. 'title' => $data['title'],
  4029. 'content' => '提交了审核',
  4030. 'messageType' => 5,
  4031. ]);
  4032. $result = Notice::insertGetId($data);
  4033. if (empty($result)) {
  4034. return Result::error("添加失败", 0);
  4035. }
  4036. return Result::success($result);
  4037. }
  4038. public function updateNotice(array $data): array
  4039. {
  4040. date_default_timezone_set('Asia/Shanghai');
  4041. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4042. $user_id = UserInfo::
  4043. //city_id不是null
  4044. whereNotNull('city_id')
  4045. ->whereNotNull('department_id')
  4046. ->where(function ($query) use ($data) {
  4047. $query->where(function ($subQuery) use ($data) {
  4048. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4049. });
  4050. })
  4051. ->where(function ($query) use ($data) {
  4052. $query->where(function ($subQuery) use ($data) {
  4053. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4054. });
  4055. })
  4056. ->pluck('user_id')->toArray();
  4057. $user_id = array_unique($user_id);
  4058. $user_id = json_encode($user_id);
  4059. $data['re_user_ids'] = $user_id;
  4060. $data['updated_at'] = date('Y-m-d H:i:s');
  4061. $this->sendMessage([
  4062. 'talk_type' => 700,
  4063. 'title' => $data['title'],
  4064. 'content' => '提交了审核',
  4065. 'messageType' => 5,
  4066. ]);
  4067. $result = Notice::where('id', $data['id'])->update($data);
  4068. return Result::success($result);
  4069. }
  4070. public function getNoticeList(array $data): array
  4071. {
  4072. $where = [];
  4073. //title
  4074. if (isset($data['title']) && !empty($data['title'])) {
  4075. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4076. }
  4077. //level
  4078. if (isset($data['level']) && !empty($data['level'])) {
  4079. $where[] = ['notice.level', '=', $data['level']];
  4080. }
  4081. //status
  4082. if (isset($data['status']) && !empty($data['status'])) {
  4083. $where[] = ['notice.status', '=', $data['status']];
  4084. }
  4085. //type
  4086. if (isset($data['type']) && !empty($data['type'])) {
  4087. $where[] = ['notice.type', '=', $data['type']];
  4088. }
  4089. var_dump($data, '------------11111-2----test---------');
  4090. if ($data['type_id'] == 10000) {
  4091. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4092. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4093. })
  4094. ->where($where)
  4095. ->orderBy('updated_at', 'desc')
  4096. ->limit($data['page_size'])
  4097. ->offset(($data['page'] - 1) * $data['page_size'])
  4098. ->get();
  4099. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4100. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4101. })
  4102. ->where($where)
  4103. ->orderBy('updated_at', 'desc')
  4104. ->count();
  4105. } else {
  4106. $result = Notice::where($where)
  4107. // ->where('user_id', $data['user_id'])
  4108. ->Where(function ($query) use ($data) {
  4109. $query->Where(function ($q) use ($data) {
  4110. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4111. ->orWhere('notice.user_id', $data['user_id']);
  4112. });
  4113. })
  4114. ->when(!empty($data['status1']), function ($query) use ($data) {
  4115. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4116. })
  4117. ->orderBy('updated_at', 'desc')
  4118. ->limit($data['page_size'])
  4119. ->offset(($data['page'] - 1) * $data['page_size'])
  4120. ->get();
  4121. $total = Notice::where($where)
  4122. ->when(!empty($data['status1']), function ($query) use ($data) {
  4123. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4124. })
  4125. // ->where('user_id', $data['user_id'])
  4126. ->Where(function ($query) use ($data) {
  4127. $query->Where(function ($q) use ($data) {
  4128. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4129. ->orWhere('notice.user_id', $data['user_id']);
  4130. });
  4131. })
  4132. ->count();
  4133. }
  4134. if (empty($result)) {
  4135. return Result::error("查询失败", 0);
  4136. }
  4137. $data = [
  4138. 'rows' => $result,
  4139. 'count' => $total,
  4140. ];
  4141. return Result::success($data);
  4142. }
  4143. public function noticeList(array $data): array
  4144. {
  4145. $where = [];
  4146. //title
  4147. if (isset($data['title']) && !empty($data['title'])) {
  4148. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4149. }
  4150. //level
  4151. if (isset($data['level']) && !empty($data['level'])) {
  4152. $where[] = ['notice.level', '=', $data['level']];
  4153. }
  4154. //status
  4155. if (isset($data['status']) && !empty($data['status'])) {
  4156. $where[] = ['notice.status', '=', $data['status']];
  4157. }
  4158. //type
  4159. if (isset($data['type']) && !empty($data['type'])) {
  4160. $where[] = ['notice.type', '=', $data['type']];
  4161. }
  4162. var_dump($data, '------------11111-2----test---------');
  4163. if ($data['type_id'] == 10000) {
  4164. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4165. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4166. })
  4167. ->where($where)
  4168. ->orderBy('updated_at', 'desc')
  4169. ->limit($data['page_size'])
  4170. ->offset(($data['page'] - 1) * $data['page_size'])
  4171. ->get();
  4172. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4173. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4174. })
  4175. ->where($where)
  4176. ->orderBy('updated_at', 'desc')
  4177. ->count();
  4178. } else {
  4179. $result = Notice::where($where)
  4180. // ->where('user_id', $data['user_id'])
  4181. ->Where(function ($query) use ($data) {
  4182. $query->Where(function ($q) use ($data) {
  4183. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4184. ->orWhere('notice.user_id', $data['user_id']);
  4185. });
  4186. })
  4187. ->when(!empty($data['status1']), function ($query) use ($data) {
  4188. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4189. })
  4190. ->orderBy('updated_at', 'desc')
  4191. ->limit($data['page_size'])
  4192. ->offset(($data['page'] - 1) * $data['page_size'])
  4193. ->get();
  4194. $total = Notice::where($where)
  4195. ->when(!empty($data['status1']), function ($query) use ($data) {
  4196. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4197. })
  4198. // ->where('user_id', $data['user_id'])
  4199. ->Where(function ($query) use ($data) {
  4200. $query->Where(function ($q) use ($data) {
  4201. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4202. ->orWhere('notice.user_id', $data['user_id']);
  4203. });
  4204. })
  4205. ->count();
  4206. }
  4207. if (empty($result)) {
  4208. return Result::error("查询失败", 0);
  4209. }
  4210. $data = [
  4211. 'rows' => $result,
  4212. 'count' => $total,
  4213. ];
  4214. return Result::success($data);
  4215. }
  4216. public function getNoticeDetail(array $data): array
  4217. {
  4218. $result = Notice::where('id', $data['id'])->first();
  4219. if (empty($result)) {
  4220. return Result::error("查询失败", 0);
  4221. }
  4222. return Result::success($result);
  4223. }
  4224. public function deleteNotice(array $data): array
  4225. {
  4226. $notice = Notice::where('id', $data['id'])->first();
  4227. if (empty($notice)) {
  4228. return Result::error("删除失败", 0);
  4229. }
  4230. $chat_group_id = $notice->group_id;
  4231. if ($chat_group_id) {
  4232. //删除群聊
  4233. ChatGroups::where('id', $chat_group_id)->delete();
  4234. //删除群成员
  4235. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4236. //删除群聊记录
  4237. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4238. }
  4239. $result = Notice::where('id', $data['id'])->delete();
  4240. return Result::success($result);
  4241. }
  4242. public function complaintList(array $data): array
  4243. {
  4244. var_dump($data, '---------1---------');
  4245. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4246. unset($data['type_id']);
  4247. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4248. $where = [];
  4249. if ($type_id != 10000 && empty($data['deal_user'])) {
  4250. // $where['complaint.user_id'] = $user_id;
  4251. }
  4252. if (!empty($data['title'])) {
  4253. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4254. }
  4255. if (!empty($data['department_id'])) {
  4256. $where['complaint.department_id'] = $data['department_id'];
  4257. }
  4258. if (!empty($data['deal'])) {
  4259. $where['complaint.deal'] = $data['deal'];
  4260. }
  4261. if (!empty($data['status'])) {
  4262. $where['complaint.status'] = $data['status'];
  4263. }
  4264. var_dump(!empty($data['deal_user']), '----------1');
  4265. var_dump($where, '----------2');
  4266. $result = Complaint::where($where)
  4267. ->when(!empty($data['status1']), function ($query) use ($data) {
  4268. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4269. })
  4270. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4271. //json re_user_ids data[user_id]是不是在里面
  4272. $query->Where(function ($q) use ($data) {
  4273. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4274. ->where('complaint.status', 2);
  4275. });
  4276. })
  4277. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4278. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4279. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4280. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4281. ->orderBy('updated_at', 'desc')
  4282. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4283. //sql输出
  4284. if (empty($result)) {
  4285. return Result::error("暂无投诉信息", 0);
  4286. }
  4287. // 取出数据
  4288. $rows = $result->items();
  4289. $count = $result->total();
  4290. $responseData = [
  4291. 'rows' => $rows,
  4292. 'count' => $count,
  4293. ];
  4294. return Result::success($responseData);
  4295. }
  4296. public function getComplaintList(array $data): array
  4297. {
  4298. var_dump($data, '00000001000000000000');
  4299. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4300. unset($data['type_id']);
  4301. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4302. $where = [];
  4303. if ($type_id != 10000 && empty($data['deal_user'])) {
  4304. $where['complaint.user_id'] = $user_id;
  4305. }
  4306. if (!empty($data['title'])) {
  4307. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4308. }
  4309. if (!empty($data['department_id'])) {
  4310. $where['complaint.department_id'] = $data['department_id'];
  4311. }
  4312. if (!empty($data['deal'])) {
  4313. $where['complaint.deal'] = $data['deal'];
  4314. }
  4315. if (!empty($data['status'])) {
  4316. $where['complaint.status'] = $data['status'];
  4317. }
  4318. var_dump(!empty($data['deal_user']), '----------1');
  4319. var_dump($where, '----------2');
  4320. $result = Complaint::where($where)
  4321. ->when(!empty($data['status1']), function ($query) use ($data) {
  4322. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4323. })
  4324. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4325. // //json re_user_ids data[user_id]是不是在里面
  4326. // $query->Where(function ($q) use ($data) {
  4327. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4328. // ->where('complaint.status', 2);
  4329. // });
  4330. // })
  4331. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4332. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4333. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4334. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4335. ->orderBy('updated_at', 'desc')
  4336. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4337. //sql输出
  4338. if (empty($result)) {
  4339. return Result::error("暂无投诉信息", 0);
  4340. }
  4341. // 取出数据
  4342. $rows = $result->items();
  4343. $count = $result->total();
  4344. $responseData = [
  4345. 'rows' => $rows,
  4346. 'count' => $count,
  4347. ];
  4348. return Result::success($responseData);
  4349. }
  4350. public function getComplaintInfo(array $data): array
  4351. {
  4352. $result = Complaint::where('id', $data['id'])->first();
  4353. if (empty($result)) {
  4354. return Result::error("查询失败", 0);
  4355. }
  4356. return Result::success($result);
  4357. }
  4358. public function readComplaint(array $data): array
  4359. {
  4360. $result = Complaint::where('id', $data['id'])->first();
  4361. if (empty($result)) {
  4362. return Result::error("查询失败", 0);
  4363. }
  4364. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4365. $re_user_ids = json_decode($result['re_user_ids'], true);
  4366. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4367. //如果已经存在,就不再添加
  4368. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4369. $read_id = json_decode($result['read_id'], true);
  4370. if (!is_array($read_id)) {
  4371. $read_id = [];
  4372. }
  4373. if (!in_array($data['user_id'], $read_id)) {
  4374. $read_id[] = $data['user_id'];
  4375. $result['read_id'] = json_encode($read_id);
  4376. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4377. }
  4378. } else {
  4379. //如果不存在,就添加
  4380. $result['read_id'] = json_encode([$data['user_id']]);
  4381. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4382. }
  4383. }
  4384. return Result::success($result);
  4385. }
  4386. public function addComplaint(array $data): array
  4387. {
  4388. date_default_timezone_set('Asia/Shanghai');
  4389. $data['created_at'] = date('Y-m-d H:i:s');
  4390. $data['updated_at'] = date('Y-m-d H:i:s');
  4391. $this->sendMessage([
  4392. 'talk_type' => 800,
  4393. 'title' => $data['title'],
  4394. 'content' => '提交了审核',
  4395. 'messageType' => 6,
  4396. ]);
  4397. $result = Complaint::create($data);
  4398. return Result::success($result);
  4399. }
  4400. public function updateComplaint(array $data): array
  4401. {
  4402. date_default_timezone_set('Asia/Shanghai');
  4403. $data['updated_at'] = date('Y-m-d H:i:s');
  4404. $user_id = $data['user_id'] ?? 0;
  4405. $type_id = $data['type_id'] ?? 0;
  4406. unset($data['user_id']);
  4407. unset($data['type_id']);
  4408. $this->sendMessage([
  4409. 'talk_type' => 800,
  4410. 'title' => $data['title'],
  4411. 'content' => '提交了审核',
  4412. 'messageType' => 6,
  4413. ]);
  4414. $result = Complaint::where('id', $data['id'])->update($data);
  4415. return Result::success($result);
  4416. }
  4417. public function deleteComplaint(array $data): array
  4418. {
  4419. $result = Complaint::where('id', $data['id'])->delete();
  4420. return Result::success($result);
  4421. }
  4422. public function getComplainInfo(array $data): array
  4423. {
  4424. $result = Complaint::where('id', $data['id'])->first();
  4425. if (empty($result)) {
  4426. return Result::error("查询失败", 0);
  4427. }
  4428. return Result::success($result);
  4429. }
  4430. public function updateComplaintStatus(array $data): array
  4431. {
  4432. date_default_timezone_set('Asia/Shanghai');
  4433. $data['updated_at'] = date('Y-m-d H:i:s');
  4434. $user_id = $data['user_id'] ?? 0;
  4435. $type_id = $data['type_id'] ?? 0;
  4436. unset($data['user_id']);
  4437. unset($data['type_id']);
  4438. //处理, 写入处理人
  4439. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4440. $data['real_deal_user'] = $user_id;
  4441. }
  4442. //如果是deal 23,则判断是不是处理人
  4443. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4444. $complaintInof = Complaint::where('id', $data['id'])
  4445. ->where('real_deal_user', $user_id)
  4446. ->first();
  4447. if (empty($complaintInof)) {
  4448. return Result::error("处理人错误", 0);
  4449. }
  4450. }
  4451. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4452. if ($data['status'] == 1) {
  4453. $this->sendMessage([
  4454. 'talk_type' => 800,
  4455. 'title' => $complaintInfo['title'],
  4456. 'content' => '提交了审核',
  4457. 'messageType' => 6,
  4458. ]);
  4459. }
  4460. if ($data['status'] == 2 && !isset($data['deal'])) {
  4461. $this->sendMessage([
  4462. 'talk_type' => 801,
  4463. 'title' => $complaintInfo['title'],
  4464. 'content' => '审核通过',
  4465. 'messageType' => 6,
  4466. 'user_id' => $complaintInfo['user_id'],
  4467. ]);
  4468. $this->sendMessage([
  4469. 'talk_type' => 802,
  4470. 'title' => $complaintInfo['title'],
  4471. 'content' => '待处理',
  4472. 'messageType' => 6,
  4473. 'user_id' => $complaintInfo['re_user_ids'],
  4474. ]);
  4475. }
  4476. if ($data['status'] == 3 && !isset($data['deal'])) {
  4477. $this->sendMessage([
  4478. 'talk_type' => 801,
  4479. 'title' => $complaintInfo['title'],
  4480. 'content' => '审核拒绝',
  4481. 'messageType' => 6,
  4482. 'user_id' => $complaintInfo['user_id'],
  4483. ]);
  4484. }
  4485. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4486. $this->sendMessage([
  4487. 'talk_type' => 802,
  4488. 'title' => $complaintInfo['title'],
  4489. 'content' => '处理中',
  4490. 'messageType' => 6,
  4491. 'user_id' => $complaintInfo['re_user_ids'],
  4492. ]);
  4493. }
  4494. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4495. $this->sendMessage([
  4496. 'talk_type' => 802,
  4497. 'title' => $complaintInfo['title'],
  4498. 'content' => '不予处理',
  4499. 'messageType' => 6,
  4500. 'user_id' => $complaintInfo['re_user_ids'],
  4501. ]);
  4502. }
  4503. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4504. $this->sendMessage([
  4505. 'talk_type' => 802,
  4506. 'title' => $complaintInfo['title'],
  4507. 'content' => '已完结',
  4508. 'messageType' => 6,
  4509. 'user_id' => $complaintInfo['re_user_ids'],
  4510. ]);
  4511. }
  4512. $result = complaint::where('id', $data['id'])->update($data);
  4513. return Result::success($result);
  4514. }
  4515. public function updateGoodStatus(array $data): array
  4516. {
  4517. $user_id = $data['user_id'] ?? 0;
  4518. $type_id = $data['type_id'] ?? 0;
  4519. unset($data['user_id']);
  4520. unset($data['type_id']);
  4521. $goodInfo = Good::where('id', $data['id'])->first();
  4522. if ($data['status'] == 2) {
  4523. $this->sendMessage([
  4524. 'talk_type' => 201,
  4525. 'title' => $goodInfo['name'],
  4526. 'content' => '审核通过',
  4527. 'messageType' => 3,
  4528. 'user_id' => $goodInfo['user_id'],
  4529. ]);
  4530. }
  4531. if ($data['status'] == 3) {
  4532. $this->sendMessage([
  4533. 'talk_type' => 201,
  4534. 'title' => $goodInfo['name'],
  4535. 'content' => '审核拒绝',
  4536. 'messageType' => 3,
  4537. 'user_id' => $goodInfo['user_id'],
  4538. ]);
  4539. }
  4540. if ($data['status'] == 1) {
  4541. $this->sendMessage([
  4542. 'talk_type' => 200,
  4543. 'title' => $goodInfo['name'],
  4544. 'content' => '提交了审核',
  4545. 'messageType' => 3,
  4546. ]);
  4547. }
  4548. $result = Good::where('id', $data['id'])->update($data);
  4549. return Result::success($result);
  4550. }
  4551. public function updateJobHuntingStatus(array $data): array
  4552. {
  4553. $user_id = $data['user_id'] ?? 0;
  4554. $type_id = $data['type_id'] ?? 0;
  4555. unset($data['user_id']);
  4556. unset($data['type_id']);
  4557. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4558. if ($data['status'] == 2) {
  4559. $this->sendMessage([
  4560. 'talk_type' => 601,
  4561. 'title' => $jogHuntingInfo['name'],
  4562. 'content' => '审核通过',
  4563. 'messageType' => 11,
  4564. 'user_id' => $jogHuntingInfo['user_id'],
  4565. ]);
  4566. }
  4567. if ($data['status'] == 3) {
  4568. $this->sendMessage([
  4569. 'talk_type' => 601,
  4570. 'title' => $jogHuntingInfo['name'],
  4571. 'content' => '审核拒绝',
  4572. 'messageType' => 11,
  4573. 'user_id' => $jogHuntingInfo['user_id'],
  4574. ]);
  4575. }
  4576. if ($data['status'] == 1) {
  4577. $this->sendMessage([
  4578. 'talk_type' => 600,
  4579. 'title' => $jogHuntingInfo['name'],
  4580. 'content' => '提交了审核',
  4581. 'messageType' => 11,
  4582. ]);
  4583. }
  4584. $result = JobHunting::where('id', $data['id'])->update($data);
  4585. return Result::success($result);
  4586. }
  4587. public function updateNoticeStatus(array $data): array
  4588. {
  4589. $user_id = $data['user_id'] ?? 0;
  4590. $type_id = $data['type_id'] ?? 0;
  4591. unset($data['user_id']);
  4592. unset($data['type_id']);
  4593. //查询公告
  4594. $notice = Notice::where('id', $data['id'])->first();
  4595. if (empty($notice)) {
  4596. return Result::error("公告不存在", 0);
  4597. }
  4598. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4599. if ($data['status'] == 2 && $notice['is_group'] == 1 && $notice['status'] == 1 && empty($notice['group_id'])) {
  4600. //chat_group
  4601. $group_id = PublicData::uuid();
  4602. $groupData = [
  4603. 'id' => $group_id,
  4604. 'creator_id' => $notice['user_id'],
  4605. 'group_name' => $notice['group_name'] ?? '',
  4606. 'profile' => $notice['profile'] ?? 0,
  4607. ];
  4608. var_dump($groupData, '-----------------groupData-------');
  4609. $groupResult = ChatGroups::insertGetId($groupData);
  4610. var_dump($groupResult, '-----------------groupid-------');
  4611. $groupMemberData = [
  4612. 'id' => PublicData::uuid(),
  4613. 'user_id' => $notice['user_id'],
  4614. 'group_id' => $group_id,
  4615. 'leader' => 2,
  4616. ];
  4617. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4618. //$chat_ids 去除掉$data['user_id']
  4619. $chat_ids = json_decode($notice['re_user_ids'], true);
  4620. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4621. //插入群成员表
  4622. $groupMemberDataUser = [];
  4623. $chatData = [];
  4624. foreach ($chat_ids as $key => $value) {
  4625. $groupMemberDataUser[] = [
  4626. 'id' => PublicData::uuid(),
  4627. 'user_id' => $value,
  4628. 'group_id' => $group_id,
  4629. 'leader' => 1,
  4630. ];
  4631. $chatData[] = [
  4632. 'user_id' => $value,
  4633. 'msg_type' => 1,
  4634. 'receiver_id' => $group_id,
  4635. 'content' => '通过通知创建群聊',
  4636. 'group_receiver_id' => $notice['user_id'],
  4637. 'action' => 'recieved',
  4638. 'created_at' => date('Y-m-d H:i:s'),
  4639. ];
  4640. }
  4641. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4642. ChatGroupsMember::insert($groupMemberDataUser);
  4643. //插入一条管理员聊天记录
  4644. $chatData[] = [
  4645. 'user_id' => $notice['user_id'],
  4646. 'msg_type' => 1,
  4647. 'receiver_id' => $group_id,
  4648. 'content' => '通过通知创建群聊',
  4649. 'group_receiver_id' => $notice['user_id'],
  4650. 'action' => 'said',
  4651. 'created_at' => date('Y-m-d H:i:s'),
  4652. ];
  4653. var_dump($chatData, '-----------------chatData-------');
  4654. $chatResult = ChatRecords::insert($chatData);
  4655. //更新result的 group_id
  4656. $data['group_id'] = $group_id;
  4657. Notice::where(['id' => $data['id']])->update($data);
  4658. }
  4659. $result = Notice::where('id', $data['id'])->update($data);
  4660. $noticeInfo = Notice::where('id', $data['id'])->first();
  4661. if ($data['status'] == 2) {
  4662. $this->sendMessage([
  4663. 'talk_type' => 701,
  4664. 'title' => $noticeInfo['title'],
  4665. 'content' => '审核通过',
  4666. 'messageType' => 3,
  4667. 'user_id' => $noticeInfo['user_id'],
  4668. ]);
  4669. }
  4670. if ($data['status'] == 3) {
  4671. $this->sendMessage([
  4672. 'talk_type' => 701,
  4673. 'title' => $noticeInfo['title'],
  4674. 'content' => '审核拒绝',
  4675. 'messageType' => 3,
  4676. 'user_id' => $noticeInfo['user_id'],
  4677. ]);
  4678. }
  4679. if ($data['status'] == 1) {
  4680. $this->sendMessage([
  4681. 'talk_type' => 700,
  4682. 'title' => $noticeInfo['title'],
  4683. 'content' => '提交了审核',
  4684. 'messageType' => 3,
  4685. ]);
  4686. }
  4687. return Result::success($result);
  4688. }
  4689. public function getDUser(array $data): array
  4690. {
  4691. if (!empty($data['ids'])) {
  4692. $user = User::whereIn('id', $data['ids'])->getall();
  4693. if (empty($user)) {
  4694. return Result::error('无数据', 0);
  4695. }
  4696. return Result::success($user);
  4697. }
  4698. $where = [];
  4699. if (!empty($data['department_id'])) {
  4700. $where['department_id'] = $data['department_id'];
  4701. }
  4702. if (!empty($data['city_id'])) {
  4703. $where['city_id'] = $data['city_id'];
  4704. }
  4705. $result = User::where('type_id', 2)
  4706. ->where('status', 1)
  4707. ->where($where)
  4708. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4709. ->get();
  4710. if (empty($result)) {
  4711. return Result::error("查询失败", 0);
  4712. }
  4713. return Result::success($result);
  4714. }
  4715. /**
  4716. * 验证导航名称是否重复
  4717. * @return void
  4718. */
  4719. public function checkCategoryName(array $data): array
  4720. {
  4721. $result = Category::when($data, function ($query) use ($data) {
  4722. if (isset($data['name']) && $data['name']) {
  4723. $query->where("name", $data['name']);
  4724. }
  4725. if (isset($data['id']) && $data['id']) {
  4726. $query->where("id", "!=", $data['id']);
  4727. }
  4728. })->first();
  4729. if ($result) {
  4730. return Result::error("已存在");
  4731. } else {
  4732. return Result::success();
  4733. }
  4734. }
  4735. //20250226 产品列表
  4736. // 20250306 -------招聘--------fr
  4737. /*
  4738. * 招聘列表
  4739. * */
  4740. public function getJobRecruitingList(array $data): array
  4741. {
  4742. $where = [];
  4743. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4744. if ($data['checkout'] == 0) {
  4745. $job_status = [0, 2];
  4746. } else {
  4747. $job_status = [1];
  4748. }
  4749. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4750. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4751. }
  4752. $user = User::where('id', $data['user_id'])->first();
  4753. if (empty($user)) {
  4754. return Result::error("用户不存在", 0);
  4755. }
  4756. // 3:企业会员
  4757. if ($user['type_id'] == 3) {
  4758. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4759. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4760. }
  4761. // 如果 $where 为空,则不添加 where 条件
  4762. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4763. return $query->where($where);
  4764. })
  4765. ->whereIn('job_recruiting.status', $job_status)
  4766. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4767. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4768. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4769. ->orderBy("updated_at", "desc")
  4770. ->offset(($data['page'] - 1) * $data['page_size'])
  4771. ->limit($data['page_size'])
  4772. ->get()
  4773. ->all();
  4774. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4775. return $query->where($where);
  4776. })
  4777. ->whereIn('job_recruiting.status', $job_status)
  4778. ->count();
  4779. if (empty($result)) {
  4780. return Result::error("暂无招聘信息", 0);
  4781. }
  4782. return Result::success($result);
  4783. }
  4784. /*
  4785. * 招聘信息添加
  4786. * */
  4787. public function addJobRecruiting(array $data): array
  4788. {
  4789. // return Result::success($data);
  4790. $user = User::where('user.id', $data['user_id'])
  4791. ->where('user.status', 1)
  4792. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4793. ->select(
  4794. 'user.type_id',
  4795. 'user.mobile',
  4796. 'user.email',
  4797. 'user_info.business_name',
  4798. 'user_info.company_hy_id',
  4799. 'user_info.company_nature',
  4800. 'user_info.company_size',
  4801. 'user_info.introduction',
  4802. 'user_info.real_name',
  4803. 'user_info.company_url',
  4804. 'user_info.address_arr_id',
  4805. 'user_info.address'
  4806. )
  4807. ->first();
  4808. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4809. return Result::error("用户不存在", 0);
  4810. }
  4811. $web = Website::where('id', $data['website_id'])->first();
  4812. if (empty($web)) {
  4813. return Result::error("网站不存在", 0);
  4814. }
  4815. // return Result::success($user);
  4816. $data['action_id'] = $data['user_id'];
  4817. $data['user_type'] = $user['type_id'];
  4818. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4819. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4820. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4821. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4822. // 公司地址 管理员必填
  4823. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4824. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4825. // 管理员-企业相关信息
  4826. $company = [
  4827. // 'user_id' => $data['user_id']?? null,
  4828. 'business_name' => $data['business_name'] ?? null,
  4829. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4830. 'company_size' => $data['company_size'] ?? null,
  4831. 'company_nature' => $data['company_nature'] ?? null,
  4832. 'introduction' => $data['introduction'] ?? null,
  4833. 'real_name' => $data['real_name'] ?? null,
  4834. 'mobile' => $data['mobile'] ?? null,
  4835. 'company_url' => $data['company_url'] ?? null,
  4836. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4837. 'address' => $data['address'] ?? null,
  4838. 'email' => $data['email'] ?? null,
  4839. ];
  4840. //去掉相关企业信息
  4841. $job = array_diff_key($data, array_flip(array_keys($company)));
  4842. Db::beginTransaction();
  4843. try {
  4844. // 先添加职位相关信息
  4845. if ($user['type_id'] == 10000) {
  4846. $job['status'] = 1;
  4847. }
  4848. if (empty($data['experience']) || $data['experience'] == '') {
  4849. $job['experience'] = null;
  4850. } else {
  4851. $job['experience'] = $data['experience'];
  4852. }
  4853. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  4854. $this->sendMessage([
  4855. 'talk_type' => 500,
  4856. 'title' => $data['title'],
  4857. 'content' => '提交了审核',
  4858. 'messageType' => 10,
  4859. ]);
  4860. }
  4861. $jobId = JobRecruiting::insertGetId($job);
  4862. if (empty($jobId)) {
  4863. Db::rollBack();
  4864. return Result::error("添加失败");
  4865. }
  4866. // 添加公司信息
  4867. $company['user_id'] = $data['user_id'] ?? null;
  4868. $company['job_id'] = $jobId;
  4869. $company['user_type'] = $user['type_id'] ?? null;
  4870. $company['website_id'] = $data['website_id'] ?? null;
  4871. if ($user['type_id'] == 10000) {
  4872. // 管理员添加企业信息
  4873. // return Result::success($company);
  4874. $companyId = JobCompany::insertGetId($company);
  4875. if (empty($companyId)) {
  4876. Db::rollBack();
  4877. return Result::error("添加失败");
  4878. }
  4879. } else {
  4880. // 企业会员添加企业信息
  4881. $company = [
  4882. 'user_id' => $data['user_id'] ?? null,
  4883. 'business_name' => $user['business_name'] ?? null,
  4884. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4885. 'company_size' => $user['company_size'] ?? null,
  4886. 'company_nature' => $user['company_nature'] ?? null,
  4887. 'introduction' => $user['introduction'] ?? null,
  4888. 'real_name' => $user['real_name'] ?? null,
  4889. 'mobile' => $user['mobile'] ?? null,
  4890. 'company_url' => $user['company_url'] ?? null,
  4891. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4892. 'address' => $user['address'] ?? null,
  4893. 'email' => $user['email'] ?? null,
  4894. 'website_id' => $data['website_id'] ?? null,
  4895. 'user_type' => $user['type_id'] ?? null,
  4896. 'job_id' => $jobId,
  4897. ];
  4898. $companyId = JobCompany::insertGetId($company);
  4899. if (empty($companyId)) {
  4900. Db::rollBack();
  4901. return Result::error("添加失败");
  4902. }
  4903. // return Result::success($company);
  4904. }
  4905. Db::commit();
  4906. } catch (\Exception $e) {
  4907. Db::rollBack();
  4908. return Result::error($e->getMessage(), 0);
  4909. }
  4910. $result = [
  4911. 'job_id' => $jobId,
  4912. 'company_id' => $companyId,
  4913. ];
  4914. if (empty($result)) {
  4915. return Result::error("添加失败", 0);
  4916. }
  4917. return Result::success($result);
  4918. }
  4919. /*
  4920. * 获取招聘信息详情
  4921. * */
  4922. public function getJobRecruitingInfo(array $data): array
  4923. {
  4924. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4925. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4926. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4927. ->select(
  4928. 'job_recruiting.*',
  4929. 'website.website_name as website_name',
  4930. 'job_company.business_name',
  4931. 'job_company.company_hy_id',
  4932. 'job_company.company_size',
  4933. 'job_company.company_nature',
  4934. 'job_company.introduction',
  4935. 'job_company.real_name',
  4936. 'job_company.mobile',
  4937. 'job_company.company_url',
  4938. 'job_company.address_arr_id',
  4939. 'job_company.address',
  4940. 'job_company.email'
  4941. )
  4942. ->first();
  4943. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4944. if (!empty($cityId)) {
  4945. if (isset($cityId[1]) && $cityId[1] != null) {
  4946. $city = District::where('id', $cityId[1])->first(['name']);
  4947. } else {
  4948. $city = District::where('id', $cityId[0])->first(['name']);
  4949. }
  4950. $result['city'] = $city['name'] ?? '';
  4951. }
  4952. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4953. if (is_array($addressId) && !empty($addressId)) {
  4954. $address = District::whereIn('id', $addressId)
  4955. ->orderBy('level', 'asc')
  4956. ->get(['name'])
  4957. ->pluck('name')
  4958. ->implode('');
  4959. // $job->address_name = $address ?? '';
  4960. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4961. }
  4962. if (empty($result)) {
  4963. return Result::error("招聘信息不存在", 0);
  4964. }
  4965. // return Result::success($job);
  4966. return Result::success($result);
  4967. }
  4968. /*
  4969. * 修改招聘信息
  4970. * */
  4971. public function upJobRecruiting(array $data): array
  4972. {
  4973. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4974. // return Result::success($job);
  4975. if (empty($job)) {
  4976. return Result::error("招聘信息不存在", 0);
  4977. }
  4978. $user = User::where('id', $data['user_id'])->first();
  4979. // return Result::success($user);
  4980. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4981. return Result::error("用户不存在", 0);
  4982. }
  4983. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4984. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4985. }
  4986. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4987. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4988. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4989. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4990. // 公司地址 管理员必填
  4991. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4992. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4993. // 管理员-企业相关信息
  4994. $company = [
  4995. 'business_name' => $data['business_name'] ?? null,
  4996. 'company_hy_id' => $data['hy_id'] ?? null,
  4997. 'company_size' => $data['company_size'] ?? null,
  4998. 'company_nature' => $data['company_nature'] ?? null,
  4999. 'introduction' => $data['introduction'] ?? null,
  5000. 'real_name' => $data['real_name'] ?? null,
  5001. 'mobile' => $data['mobile'] ?? null,
  5002. 'company_url' => $data['company_url'] ?? null,
  5003. 'address_arr_id' => $data['address_arr_id'] ?? null,
  5004. 'address' => $data['address'] ?? null,
  5005. 'email' => $data['email'] ?? null,
  5006. ];
  5007. //去掉相关企业信息
  5008. $data = array_diff_key($data, array_flip(array_keys($company)));
  5009. $jobId = $data['id'];
  5010. $web = $data['website_id'];
  5011. $data['action_id'] = $data['user_id'];
  5012. unset($data['user_id']);
  5013. unset($data['user_type']);
  5014. unset($data['id']);
  5015. unset($data['website_id']);
  5016. // return Result::success($data);
  5017. Db::beginTransaction();
  5018. try {
  5019. // 管理员修改招聘信息
  5020. if ($user['type_id'] == 10000) {
  5021. $data['website_id'] = $web;
  5022. $company['website_id'] = $data['website_id'];
  5023. $data['status'] = 1;
  5024. } else {
  5025. $data['status'] = 0;
  5026. }
  5027. if (empty($data['experience']) || $data['experience'] == '') {
  5028. $job['experience'] = null;
  5029. } else {
  5030. $job['experience'] = $data['experience'];
  5031. }
  5032. // Db::rollBack();
  5033. // return Result::success($company);
  5034. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5035. $this->sendMessage([
  5036. 'talk_type' => 500,
  5037. 'title' => $data['title'],
  5038. 'content' => '提交了审核',
  5039. 'messageType' => 10,
  5040. ]);
  5041. }
  5042. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5043. if (empty($result['job'])) {
  5044. Db::rollBack();
  5045. return Result::error("修改招聘信息失败");
  5046. }
  5047. // 管理员修改企业相关信息
  5048. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5049. if (empty($result['company'])) {
  5050. Db::rollBack();
  5051. return Result::error("修改企业相关信息失败");
  5052. }
  5053. Db::commit();
  5054. // return Result::success($result);
  5055. } catch (\Exception $e) {
  5056. Db::rollBack();
  5057. return Result::error($e->getMessage(), 0);
  5058. }
  5059. return Result::success($result);
  5060. }
  5061. /*
  5062. * 招聘信息删除
  5063. * */
  5064. public function delJobRecruiting(array $data): array
  5065. {
  5066. $user = User::where('id', $data['user_id'])->first();
  5067. if (empty($user)) {
  5068. return Result::error("用户不存在", 0);
  5069. }
  5070. $job = JobRecruiting::where('id', $data['id'])->first();
  5071. if (empty($job)) {
  5072. return Result::error("招聘信息不存在", 0);
  5073. }
  5074. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5075. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5076. }
  5077. Db::beginTransaction();
  5078. try {
  5079. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5080. if (empty($result['job'])) {
  5081. Db::rollBack();
  5082. return Result::error("删除招聘信息失败");
  5083. }
  5084. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5085. if (empty($result['company'])) {
  5086. Db::rollBack();
  5087. return Result::error("删除企业相关信息失败");
  5088. }
  5089. Db::commit();
  5090. } catch (\Exception $e) {
  5091. Db::rollBack();
  5092. return Result::error($e->getMessage(), 0);
  5093. }
  5094. return Result::success($result);
  5095. }
  5096. /*
  5097. * 获取公司信息
  5098. * */
  5099. public function getJobCompany(array $data): array
  5100. {
  5101. $user = User::where('user.id', $data['user_id'])
  5102. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5103. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5104. ->first();
  5105. // return Result::success($user);
  5106. if (empty($user)) {
  5107. return Result::error("用户不存在", 0);
  5108. }
  5109. if ($user['type_id'] == 3) {
  5110. $result = [
  5111. // 'id' => 0,
  5112. 'user_id' => $data['user_id'],
  5113. 'website_id' => $data['website_id'],
  5114. 'business_name' => $user['business_name'], // 企业名称
  5115. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5116. 'company_nature' => $user['company_nature'], // 公司性质
  5117. 'company_size' => $user['company_size'], // 公司规模
  5118. 'introduction' => $user['introduction'], // 公司简介
  5119. 'real_name' => $user['real_name'], // 企业联系人
  5120. 'mobile' => $user['mobile'], // 企业联系电话
  5121. 'company_url' => $user['company_url'], // 企业网址
  5122. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5123. 'address' => $user['address'], // 企业地址
  5124. 'email' => $user['email'], // 企业邮箱
  5125. ];
  5126. } else {
  5127. return Result::error("用户类型错误", 0);
  5128. }
  5129. if (empty($result)) {
  5130. return Result::error("公司信息不存在", 0);
  5131. }
  5132. return Result::success($result);
  5133. }
  5134. /*
  5135. * 修改公司信息
  5136. * */
  5137. public function upJobCompany(array $data): array
  5138. {
  5139. // return Result::success($data);
  5140. $user = User::where('user.id', $data['user_id'])
  5141. ->where('user.status', 1)
  5142. ->select('user.user_name', 'user.type_id')
  5143. ->first();
  5144. if (empty($user)) {
  5145. return Result::error("用户不存在", 0);
  5146. }
  5147. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5148. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5149. $company = [
  5150. 'business_name' => $data['business_name'], // 企业名称
  5151. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5152. 'company_nature' => $data['company_nature'], // 公司性质
  5153. 'company_size' => $data['company_size'], // 公司规模
  5154. 'introduction' => $data['introduction'], // 公司简介
  5155. // 'real_name' => $data['real_name'], // 企业联系人
  5156. 'company_url' => $data['company_url'], // 企业网址
  5157. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5158. 'address' => $data['address'], // 企业详细地址
  5159. // 'email' => $data['email'], // 企业邮箱
  5160. ];
  5161. if ($user['type_id'] == 3) {
  5162. Db::beginTransaction();
  5163. try {
  5164. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5165. 'business_name' => $data['business_name'], // 企业名称
  5166. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5167. 'company_nature' => $data['company_nature'], // 公司性质
  5168. 'company_size' => $data['company_size'], // 公司规模
  5169. 'introduction' => $data['introduction'], // 公司简介
  5170. // 'real_name' => $data['real_name'], // 企业联系人
  5171. 'company_url' => $data['company_url'], // 企业网址
  5172. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5173. 'address' => $data['address'], // 企业详细地址
  5174. ]);
  5175. if (empty($result['userinfo'])) {
  5176. Db::rollBack();
  5177. return Result::error('修改企业会员信息失败!');
  5178. }
  5179. $result['user'] = User::where('id', $data['user_id'])->update([
  5180. 'email' => $data['email'], // 企业邮箱
  5181. ]);
  5182. if (empty($result['user'])) {
  5183. Db::rollBack();
  5184. return Result::error('修改个人中心信息失败!');
  5185. }
  5186. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5187. if (!empty($job_company)) {
  5188. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5189. if (empty($result['job_company'])) {
  5190. Db::rollBack();
  5191. return Result::error('修改企业会员信息失败!');
  5192. }
  5193. }
  5194. Db::commit();
  5195. return Result::success($result);
  5196. } catch (\Exception $e) {
  5197. Db::rollBack();
  5198. return Result::error($e->getMessage(), 0);
  5199. }
  5200. } else {
  5201. return Result::error("用户类型错误", 0);
  5202. }
  5203. }
  5204. /*
  5205. * 获取省-市
  5206. * */
  5207. public function getJobRecruitingArea(array $data): array
  5208. {
  5209. if (isset($data['pid']) && $data['pid'] != null) {
  5210. $result = District::where('pid', $data['pid'])->get()->all();
  5211. } else {
  5212. $result = District::where('level', 1)->get()->all();
  5213. }
  5214. if (empty($result)) {
  5215. return Result::error("暂无此省市", 0);
  5216. }
  5217. return Result::success($result);
  5218. }
  5219. /*
  5220. * 获取行业分类
  5221. * */
  5222. public function getIndustry(array $data): array
  5223. {
  5224. $result = JobIndustry::get()->all();
  5225. if (empty($result)) {
  5226. return Result::error("暂无行业分类", 0);
  5227. }
  5228. return Result::success($result);
  5229. }
  5230. /*
  5231. * 获取职位
  5232. * */
  5233. public function getPositionList(array $data): array
  5234. {
  5235. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5236. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5237. } else {
  5238. $result = JobPosition::where('zwpid', 0)->get()->all();
  5239. }
  5240. if (empty($result)) {
  5241. return Result::error("暂无此职位", 0);
  5242. }
  5243. return Result::success($result);
  5244. }
  5245. /*
  5246. * 获取工作性质-菜单
  5247. * */
  5248. public function getJobNature(array $data): array
  5249. {
  5250. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5251. if (empty($result)) {
  5252. return Result::error("暂无工作性质", 0);
  5253. }
  5254. return Result::success($result);
  5255. }
  5256. /*
  5257. * 获取工作经验-菜单
  5258. * */
  5259. public function getExperience(array $data): array
  5260. {
  5261. $result = JobEnum::where('egroup', 'years')->get()->all();
  5262. if (empty($result)) {
  5263. return Result::error("暂无工作经验", 0);
  5264. }
  5265. return Result::success($result);
  5266. }
  5267. /*
  5268. * 获取学历-菜单
  5269. * */
  5270. public function getEducation(array $data): array
  5271. {
  5272. $result = JobEnum::where('egroup', 'education')->get()->all();
  5273. if (empty($result)) {
  5274. return Result::error("暂无学历", 0);
  5275. }
  5276. return Result::success($result);
  5277. }
  5278. /*
  5279. * 获取薪资-菜单
  5280. * */
  5281. public function getSalary(array $data): array
  5282. {
  5283. $result = JobEnum::where('egroup', 'income')->get()->all();
  5284. if (empty($result)) {
  5285. return Result::error("暂无薪资", 0);
  5286. }
  5287. return Result::success($result);
  5288. }
  5289. /*
  5290. * 获取语言-菜单
  5291. * */
  5292. public function getLanguage(array $data): array
  5293. {
  5294. $result = JobEnum::where('egroup', 'language')->get()->all();
  5295. if (empty($result)) {
  5296. return Result::error("暂无语言", 0);
  5297. }
  5298. return Result::success($result);
  5299. }
  5300. /*
  5301. * 获取掌握程度-菜单
  5302. * */
  5303. public function getLevel(array $data): array
  5304. {
  5305. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5306. if (empty($result)) {
  5307. return Result::error("暂无工作性质", 0);
  5308. }
  5309. return Result::success($result);
  5310. }
  5311. // 公司信息
  5312. /*
  5313. * 获取公司性质-菜单
  5314. * */
  5315. public function getCompanyNature(array $data): array
  5316. {
  5317. $result = JobNature::get()->all();
  5318. if (empty($result)) {
  5319. return Result::error("暂无公司性质", 0);
  5320. }
  5321. return Result::success($result);
  5322. }
  5323. /*
  5324. * 获取公司规模-菜单
  5325. * */
  5326. public function getCompanySize(array $data): array
  5327. {
  5328. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5329. if (empty($result)) {
  5330. return Result::error("暂无公司规模", 0);
  5331. }
  5332. return Result::success($result);
  5333. }
  5334. /*
  5335. * 招聘信息审核
  5336. * */
  5337. public function checkJobRecruiting(array $data): array
  5338. {
  5339. $user = User::where('id', $data['user_id'])->first();
  5340. if (empty($user)) {
  5341. return Result::error("用户不存在", 0);
  5342. }
  5343. $job = JobRecruiting::where('id', $data['id'])->first();
  5344. if (empty($job)) {
  5345. return Result::error("招聘信息不存在", 0);
  5346. }
  5347. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5348. if ($user['type_id'] != 10000) {
  5349. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5350. }
  5351. // 驳回原因
  5352. if ($data['status'] == 2) {
  5353. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5354. }
  5355. $data['action_id'] = $data['user_id'];
  5356. unset($data['user_id']);
  5357. if ($data['status'] == 1) {
  5358. $this->sendMessage([
  5359. 'talk_type' => 501,
  5360. 'title' => $job['title'],
  5361. 'content' => '审核通过',
  5362. 'messageType' => 10,
  5363. 'user_id' => $job['user_id'],
  5364. ]);
  5365. }
  5366. if ($data['status'] == 2) {
  5367. $this->sendMessage([
  5368. 'talk_type' => 501,
  5369. 'title' => $job['title'],
  5370. 'content' => '审核拒绝',
  5371. 'messageType' => 10,
  5372. 'user_id' => $job['user_id'],
  5373. ]);
  5374. }
  5375. if ($data['status'] == 0) {
  5376. $this->sendMessage([
  5377. 'talk_type' => 500,
  5378. 'title' => $job['title'],
  5379. 'content' => '提交了审核',
  5380. 'messageType' => 10,
  5381. ]);
  5382. }
  5383. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5384. if (empty($result)) {
  5385. return Result::error("审核失败", 0);
  5386. }
  5387. return Result::success($result);
  5388. }
  5389. public function myApplyList(array $data): array
  5390. {
  5391. var_dump($data, '------参数');
  5392. $user = User::where('id', $data['user_id'])->first();
  5393. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5394. return Result::error("用户不存在", 0);
  5395. }
  5396. // 1:个人会员 职场机会
  5397. if ($user['type_id'] == 1) {
  5398. $where['user_id'] = $user['id'];
  5399. }
  5400. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5401. $query->where('user_id', $user['id']);
  5402. })
  5403. ->pluck('recruit_id');
  5404. $where = [];
  5405. if (isset($data['salary']) && $data['salary'] != null) {
  5406. $where['job_recruiting.salary'] = $data['salary'];
  5407. }
  5408. if (isset($data['experience']) && $data['experience'] != null) {
  5409. $where['job_recruiting.experience'] = $data['experience'];
  5410. }
  5411. if (isset($data['business_name']) && $data['business_name'] != null) {
  5412. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5413. }
  5414. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5415. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5416. ->where($where);
  5417. // ->count();
  5418. $count = $query->count();
  5419. $query = clone $query;
  5420. $job = $query
  5421. ->leftJoin('job_enum as income_enum', function ($join) {
  5422. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5423. ->where('income_enum.egroup', 'income');
  5424. })
  5425. ->leftJoin('job_enum as years_enum', function ($join) {
  5426. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5427. ->where('years_enum.egroup', 'years');
  5428. })
  5429. // ->where($where)
  5430. ->orderBy('job_recruiting.updated_at', 'desc')
  5431. ->select(
  5432. 'job_recruiting.id',
  5433. 'job_recruiting.title',
  5434. 'job_company.business_name',
  5435. 'income_enum.evalue as salary_evalue',
  5436. 'income_enum.ename as salary_ename',
  5437. 'years_enum.evalue as experience_evalue',
  5438. 'years_enum.ename as experience_ename',
  5439. 'job_recruiting.updated_at'
  5440. )
  5441. ->offset(($data['page'] - 1) * $data['pageSize'])
  5442. ->limit($data['pageSize'])
  5443. ->get()
  5444. ->all();
  5445. if (empty($job)) {
  5446. return Result::error("暂无招聘信息", 0);
  5447. }
  5448. $result = [
  5449. 'row' => $job,
  5450. 'count' => $count,
  5451. ];
  5452. return Result::success($result);
  5453. }
  5454. public function readJobApply(array $data): array
  5455. {
  5456. $result = JobApply::where('id', $data['id'])->first();
  5457. if (empty($result)) {
  5458. return Result::error("查询失败", 0);
  5459. }
  5460. $result = JobApply::where('id', $data['id'])->update([
  5461. 'status' => 2,
  5462. ]);
  5463. return Result::success($result);
  5464. }
  5465. /*
  5466. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5467. * */
  5468. public function getRecruitingList(array $data): array
  5469. {
  5470. $user = User::where('id', $data['user_id'])->first();
  5471. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5472. return Result::error("用户不存在", 0);
  5473. }
  5474. // 1:个人会员 职场机会
  5475. if ($user['type_id'] == 1) {
  5476. $where['user_id'] = $user['id'];
  5477. }
  5478. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5479. $query->where('receiver_id', $user['id']);
  5480. })
  5481. ->pluck('recruit_id');
  5482. // return Result::success($recruitingId);
  5483. $where = [];
  5484. if (isset($data['salary']) && $data['salary'] != null) {
  5485. $where['job_recruiting.salary'] = $data['salary'];
  5486. }
  5487. if (isset($data['experience']) && $data['experience'] != null) {
  5488. $where['job_recruiting.experience'] = $data['experience'];
  5489. }
  5490. if (isset($data['business_name']) && $data['business_name'] != null) {
  5491. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5492. }
  5493. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5494. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5495. ->where($where);
  5496. // ->count();
  5497. $count = $query->count();
  5498. $query = clone $query;
  5499. $job = $query
  5500. ->leftJoin('job_enum as income_enum', function ($join) {
  5501. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5502. ->where('income_enum.egroup', 'income');
  5503. })
  5504. ->leftJoin('job_enum as years_enum', function ($join) {
  5505. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5506. ->where('years_enum.egroup', 'years');
  5507. })
  5508. // ->where($where)
  5509. ->orderBy('job_recruiting.updated_at', 'desc')
  5510. ->select(
  5511. 'job_recruiting.id',
  5512. 'job_recruiting.title',
  5513. 'job_company.business_name',
  5514. 'income_enum.evalue as salary_evalue',
  5515. 'income_enum.ename as salary_ename',
  5516. 'years_enum.evalue as experience_evalue',
  5517. 'years_enum.ename as experience_ename',
  5518. 'job_recruiting.updated_at'
  5519. )
  5520. ->offset(($data['page'] - 1) * $data['pageSize'])
  5521. ->limit($data['pageSize'])
  5522. ->get()
  5523. ->all();
  5524. if (empty($job)) {
  5525. return Result::error("暂无招聘信息", 0);
  5526. }
  5527. $result = [
  5528. 'row' => $job,
  5529. 'count' => $count,
  5530. ];
  5531. return Result::success($result);
  5532. }
  5533. /*
  5534. * 获取企业会员-招聘信息列表
  5535. * */
  5536. public function getRecruitingInfo(array $data): array
  5537. {
  5538. $user = User::where('id', $data['user_id'])->first();
  5539. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5540. return Result::error("用户不存在", 0);
  5541. }
  5542. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5543. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5544. ->select(
  5545. 'job_recruiting.*',
  5546. 'job_company.business_name',
  5547. 'job_company.company_hy_id',
  5548. 'job_company.company_size',
  5549. 'job_company.company_nature',
  5550. 'job_company.introduction',
  5551. 'job_company.real_name',
  5552. 'job_company.mobile',
  5553. 'job_company.company_url',
  5554. 'job_company.address_arr_id',
  5555. 'job_company.address',
  5556. 'job_company.email'
  5557. )
  5558. ->get();
  5559. if (empty($recruiting)) {
  5560. return Result::error("暂无招聘信息", 0);
  5561. }
  5562. return Result::success($recruiting);
  5563. }
  5564. /*
  5565. * 获取企业会员-我的沟通
  5566. * */
  5567. public function getJobResumeList(array $data): array
  5568. {
  5569. $user = User::where('id', $data['user_id'])->first();
  5570. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5571. return Result::error("用户不存在", 0);
  5572. }
  5573. $where = [];
  5574. if (isset($data['salary']) && $data['salary'] != null) {
  5575. $where['job_hunting.salary'] = $data['salary'];
  5576. }
  5577. if (isset($data['user_name']) && $data['user_name'] != null) {
  5578. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5579. }
  5580. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5581. $query->where('job_resume.user_id', $user['id']);
  5582. })
  5583. ->when(!empty($where), function ($query) use ($where) {
  5584. $query->where($where);
  5585. })
  5586. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5587. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5588. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5589. ->select('job_resume.hunt_id', 'job_resume.recruit_id', 'job_hunting.id', 'job_hunting.salary', 'job_hunting.city_id', 'job_hunting.updated_at', 'job_recruiting.jtzw_id', 'user.user_name');
  5590. $count = $job->count();
  5591. if ($count == 0) {
  5592. return Result::error("暂无沟通记录", 0);
  5593. }
  5594. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5595. ->offset(($data['page'] - 1) * $data['pageSize'])
  5596. ->limit($data['pageSize'])
  5597. ->get();
  5598. if (empty($jobs)) {
  5599. return Result::error("暂无沟通记录", 0);
  5600. }
  5601. $result['row'] = $this->processJob($jobs, '');
  5602. $result['count'] = $count;
  5603. return Result::success($result);
  5604. }
  5605. public function readJobResume(array $data): array
  5606. {
  5607. $result = JobResume::where('id', $data['id'])->first();
  5608. if (empty($result)) {
  5609. return Result::error("查询失败", 0);
  5610. }
  5611. $result = JobResume::where('id', $data['id'])->update([
  5612. 'status' => 2,
  5613. ]);
  5614. return Result::success($result);
  5615. }
  5616. // 20250306 招聘
  5617. //20250422 书刊音像
  5618. public function addBook(array $data): array
  5619. {
  5620. $user_id = $data['user_id'] ?? 0;
  5621. $type_id = $data['type_id'] ?? 0;
  5622. // $website_id = $data['website_id'] ?? 0;
  5623. // unset($data['user_id']);
  5624. unset($data['type_id']);
  5625. // unset($data['website_id']);
  5626. //处理数组
  5627. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5628. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5629. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5630. if ($data['img_url'] == '') {
  5631. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5632. preg_match_all($reg, $data['detail'], $matches);
  5633. if (isset($matches[1][0])) {
  5634. //截取varchar240
  5635. $data['img_url'] = substr($matches[1][0], 0, 240);
  5636. }
  5637. }
  5638. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5639. //提取标题+内容中的关键词
  5640. $data['keyword'] = $data['title'];
  5641. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5642. Jieba::init(); // 初始化 jieba-php
  5643. Finalseg::init();
  5644. $segList = Jieba::cut($data['keyword']);
  5645. $segList1 = array_slice($segList, 0, 8);
  5646. $data['keyword'] = implode(',', $segList1);
  5647. }
  5648. if ($data['description'] == '') {
  5649. //提取内容中的描述
  5650. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5651. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5652. }
  5653. var_dump($data, '--');
  5654. if ($data['status'] == 1) {
  5655. $this->sendMessage([
  5656. 'talk_type' => 400,
  5657. 'title' => $data['title'],
  5658. 'content' => '提交了审核',
  5659. 'messageType' => 7,
  5660. ]);
  5661. }
  5662. $result = Book::insertGetId($data);
  5663. if (empty($result)) {
  5664. return Result::error("添加失败", 0);
  5665. }
  5666. return Result::success($result);
  5667. }
  5668. public function getBookList(array $data): array
  5669. {
  5670. $where = [];
  5671. if (!empty($data["title"])) {
  5672. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5673. }
  5674. if (!empty($data['website_name'])) {
  5675. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5676. }
  5677. if (!empty($data['status'])) {
  5678. $where[] = ['book.status', '=', $data['status']];
  5679. }
  5680. $user_id = $data['user_id'];
  5681. $type_id = $data['type_id'];
  5682. // $type_id = 4;
  5683. var_dump($type_id, '------1--------');
  5684. if ($type_id != 10000) {
  5685. $where[] = ['book.user_id', '=', $user_id];
  5686. }
  5687. var_dump(!empty($data['status1']), '=-===1');
  5688. $result = Book::where($where)
  5689. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5690. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5691. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5692. ->when(isset($data['status1']), function ($query) use ($data) {
  5693. $query->whereIn('book.status', [1, 3]);
  5694. })
  5695. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5696. ->orderBy("updated_at", "desc")
  5697. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5698. if (empty($result)) {
  5699. return Result::error("暂无数据", 0);
  5700. }
  5701. // 取出数据
  5702. $rows = $result->items();
  5703. $count = $result->total();
  5704. $responseData = [
  5705. 'rows' => $rows,
  5706. 'count' => $count,
  5707. ];
  5708. return Result::success($responseData);
  5709. }
  5710. public function deleteBook(array $data): array
  5711. {
  5712. $result = Book::where('id', $data['id'])->delete();
  5713. if (empty($result)) {
  5714. return Result::error("删除失败", 0);
  5715. }
  5716. return Result::success($result);
  5717. }
  5718. public function updateBook(array $data): array
  5719. {
  5720. // $user_id = $data['user_id'] ?? 0;
  5721. $type_id = $data['type_id'] ?? 0;
  5722. // $website_id = $data['website_id'] ?? 0;
  5723. unset($data['user_id']);
  5724. unset($data['type_id']);
  5725. // unset($data['website_id']);
  5726. //处理数组
  5727. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5728. if ($data['img_url'] == '') {
  5729. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5730. preg_match_all($reg, $data['detail'], $matches);
  5731. if (isset($matches[1][0])) {
  5732. //截取varchar240
  5733. $data['img_url'] = substr($matches[1][0], 0, 240);
  5734. }
  5735. }
  5736. if ($data['keyword'] == '') {
  5737. //提取标题+内容中的关键词
  5738. $data['keyword'] = $data['title'];
  5739. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5740. Jieba::init(); // 初始化 jieba-php
  5741. Finalseg::init();
  5742. $segList = Jieba::cut($data['keyword']);
  5743. $segList1 = array_slice($segList, 0, 8);
  5744. $data['keyword'] = implode(',', $segList1);
  5745. }
  5746. if ($data['description'] == '') {
  5747. //提取内容中的描述
  5748. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5749. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5750. }
  5751. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5752. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5753. if ($data['status'] == 1) {
  5754. $this->sendMessage([
  5755. 'talk_type' => 400,
  5756. 'title' => $data['title'],
  5757. 'content' => '提交了审核',
  5758. 'messageType' => 7,
  5759. ]);
  5760. }
  5761. $result = Book::where("id", $data["id"])->update($data);
  5762. if (empty($result)) {
  5763. return Result::error("更新失败", 0);
  5764. }
  5765. return Result::success($result);
  5766. }
  5767. public function getBookInfo(array $data): array
  5768. {
  5769. $result = Book::where("id", $data["id"])->first();
  5770. if (empty($result)) {
  5771. return Result::error("获取失败", 0);
  5772. }
  5773. return Result::success($result);
  5774. }
  5775. public function updateBookStatus(array $data): array
  5776. {
  5777. //审核
  5778. unset($data['user_id']);
  5779. $bookInfo = Book::where("id", $data["id"])->first();
  5780. var_dump($bookInfo, '----');
  5781. if ($data['status'] == 2) {
  5782. $this->sendMessage([
  5783. 'talk_type' => 401,
  5784. 'title' => $bookInfo['title'],
  5785. 'content' => '审核通过',
  5786. 'messageType' => 7,
  5787. 'user_id' => $bookInfo['user_id'],
  5788. ]);
  5789. }
  5790. if ($data['status'] == 3) {
  5791. $this->sendMessage([
  5792. 'talk_type' => 401,
  5793. 'title' => $bookInfo['title'],
  5794. 'content' => '审核拒绝',
  5795. 'messageType' => 7,
  5796. 'user_id' => $bookInfo['user_id'],
  5797. ]);
  5798. }
  5799. if ($data['status'] == 1) {
  5800. $this->sendMessage([
  5801. 'talk_type' => 400,
  5802. 'title' => $bookInfo['title'],
  5803. 'content' => '提交了审核',
  5804. 'messageType' => 7,
  5805. // 'user_id'=>$bookInfo['user_id'],
  5806. ]);
  5807. }
  5808. $result = Book::where("id", $data["id"])->update($data);
  5809. if (empty($result)) {
  5810. return Result::error("更新失败", 0);
  5811. }
  5812. return Result::success($result);
  5813. }
  5814. //20250422 书刊音像
  5815. /**
  5816. * 贴身宝贝
  5817. * @param array $data
  5818. * @return array
  5819. */
  5820. public function getWebsiteTsbb(array $data): array
  5821. {
  5822. $month = $data['month'] ?? date('m');
  5823. $day = $data['day'] ?? date('d');
  5824. // 使用缓存键
  5825. $cacheKey = "tsbb_data_{$month}_{$day}";
  5826. // 尝试从缓存获取数据
  5827. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5828. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5829. if ($cachedData = $cache->get($cacheKey)) {
  5830. return Result::success(unserialize($cachedData));
  5831. }
  5832. //查询老黄历
  5833. try {
  5834. $date = date('Y-m-d');
  5835. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5836. // 使用 curl 替代 file_get_contents
  5837. $ch = curl_init();
  5838. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5839. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5840. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5841. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5842. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5843. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36');
  5844. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5845. 'Accept: application/json',
  5846. 'Content-Type: application/json',
  5847. 'Referer: https://www.36jxs.com/'
  5848. ]);
  5849. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5850. curl_setopt($ch, CURLOPT_ENCODING, '');
  5851. $almanacResponse = curl_exec($ch);
  5852. var_dump("====:", $almanacResponse);
  5853. if (curl_errno($ch)) {
  5854. var_dump('Curl error:', curl_error($ch));
  5855. throw new \Exception('Curl error: ' . curl_error($ch));
  5856. }
  5857. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5858. curl_close($ch);
  5859. if ($almanacResponse === false) {
  5860. throw new \Exception('Failed to fetch almanac data');
  5861. }
  5862. $almanacData = json_decode($almanacResponse, true);
  5863. if (json_last_error() !== JSON_ERROR_NONE) {
  5864. throw new \Exception('Failed to parse almanac data');
  5865. }
  5866. $almanacInfo = $almanacData['data'] ?? [];
  5867. } catch (\Exception $e) {
  5868. var_dump('Exception:', $e->getMessage());
  5869. $almanacInfo = [];
  5870. }
  5871. // 获取历史上的今天数据
  5872. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5873. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5874. ->orderBy('year', 'asc')
  5875. ->select("title", "id", "year", DB::raw('1 as type'))
  5876. ->limit(16)
  5877. ->get();
  5878. // 获取节日数据 - 从今天开始获取未来4条
  5879. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5880. ->orderBy('showtime', 'asc')
  5881. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5882. ->limit(16)
  5883. ->get();
  5884. //说文解字
  5885. $chartacterList = Character::orderBy('updated_at', 'desc')
  5886. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5887. ->limit(6)
  5888. ->get();
  5889. //谜语沙龙
  5890. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5891. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5892. ->limit(4)
  5893. ->get();
  5894. //成语欣赏
  5895. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5896. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5897. ->limit(32)
  5898. ->get();
  5899. //名联赏析
  5900. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5901. ->select("id", "first", "second", DB::raw('6 as type'))
  5902. ->limit(6)
  5903. ->get();
  5904. // 获取分类文章数据
  5905. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5906. ->pluck('category_id')
  5907. ->toArray();
  5908. $articlesList = [];
  5909. foreach ($categoryIds as $catid) {
  5910. // 先查有图片的
  5911. $withImg = DB::table('article')
  5912. ->where('status', 1)
  5913. ->where('catid', $catid)
  5914. ->whereNotNull('imgurl')
  5915. ->where('imgurl', '!=', '')
  5916. ->orderBy('updated_at', 'desc')
  5917. ->limit(6)
  5918. ->get();
  5919. $count = $withImg->count();
  5920. if ($count < 6) {
  5921. // 不足6条再查无图片的补足
  5922. $withoutImg = DB::table('article')
  5923. ->where('status', 1)
  5924. ->where('catid', $catid)
  5925. ->where(function ($q) {
  5926. $q->whereNull('imgurl')->orWhere('imgurl', '');
  5927. })
  5928. ->orderBy('updated_at', 'desc')
  5929. ->limit(6 - $count)
  5930. ->get();
  5931. $articles = $withImg->concat($withoutImg);
  5932. } else {
  5933. $articles = $withImg;
  5934. }
  5935. // 组装
  5936. $category = \App\Model\Category::find($catid);
  5937. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  5938. $articlesList[] = [
  5939. 'category_name' => $category ? $category->name : '',
  5940. 'catid' => $catid,
  5941. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  5942. 'type' => 100,
  5943. 'list' => $articles->map(function ($item) {
  5944. return [
  5945. 'id' => $item->id,
  5946. 'title' => $item->title,
  5947. 'imgurl' => $item->imgurl,
  5948. 'created_at' => $item->created_at
  5949. ];
  5950. })->values()
  5951. ];
  5952. }
  5953. $result = [
  5954. 'almanac' => $almanacInfo,
  5955. 'historyTodayList' => [
  5956. 'category_name' => '历史上的今天',
  5957. 'list' => $historyTodayList,
  5958. 'type' => 1
  5959. ],
  5960. 'festivalList' => [
  5961. 'category_name' => '节日预告',
  5962. 'list' => $festivalList,
  5963. 'type' => 2
  5964. ],
  5965. 'chartacterList' => [
  5966. 'category_name' => '说文解字',
  5967. 'list' => $chartacterList,
  5968. 'type' => 3
  5969. ],
  5970. 'coupletList' => [
  5971. 'category_name' => '名联赏析',
  5972. 'list' => $coupletList,
  5973. 'type' => 6
  5974. ],
  5975. 'riddletList' => [
  5976. 'category_name' => '谜语沙龙',
  5977. 'list' => $riddletList,
  5978. 'type' => 4
  5979. ],
  5980. 'idiomList' => [
  5981. 'category_name' => '成语欣赏',
  5982. 'list' => $idiomList,
  5983. 'type' => 5
  5984. ],
  5985. 'articlesList' => $articlesList
  5986. ];
  5987. // 缓存结果,设置1小时过期
  5988. $cache->set($cacheKey, serialize($result), 3600);
  5989. return Result::success($result);
  5990. }
  5991. /**
  5992. * 获取资讯列表
  5993. */
  5994. public function getWebsiteTsbbList(array $data): array
  5995. {
  5996. $page = $data['page'] ?? 1;
  5997. $pageSize = $data['pageSize'] ?? 10;
  5998. // 如果没有传入月份和日期,则使用今天的日期
  5999. $month = $data['month'] ?? date('m');
  6000. $day = $data['day'] ?? date('d');
  6001. $total = 0;
  6002. $result = [];
  6003. $data['type'] = intval($data['type']);
  6004. var_dump("接收参数:", $data);
  6005. switch ($data['type']) {
  6006. case 1:
  6007. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6008. // 当前月份之后的数据
  6009. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6010. // 或者当前月份且日期大于等于当前日期的数据
  6011. ->orWhere(function ($q) use ($month, $day) {
  6012. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6013. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6014. });
  6015. })
  6016. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6017. $total = $query->count();
  6018. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6019. ->offset(($page - 1) * $pageSize)
  6020. ->limit($pageSize)
  6021. ->get();
  6022. break;
  6023. case 2:
  6024. $query = Festival::where(function ($q) use ($month, $day) {
  6025. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6026. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6027. ->orWhere(function ($q) use ($month, $day) {
  6028. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6029. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6030. });
  6031. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6032. $total = $query->count();
  6033. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6034. ->offset(($page - 1) * $pageSize)
  6035. ->limit($pageSize)
  6036. ->get();
  6037. break;
  6038. case 3:
  6039. $query = Character::orderBy("updated_at", "desc");
  6040. $total = $query->count();
  6041. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6042. ->offset(($page - 1) * $pageSize)
  6043. ->limit($pageSize)
  6044. ->get();
  6045. break;
  6046. case 4:
  6047. $query = Riddle::orderBy("updated_at", "desc");
  6048. $total = $query->count();
  6049. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6050. ->offset(($page - 1) * $pageSize)
  6051. ->limit($pageSize)
  6052. ->get();
  6053. break;
  6054. case 5:
  6055. $query = Idiom::orderBy("updated_at", "desc");
  6056. $total = $query->count();
  6057. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6058. ->offset(($page - 1) * $pageSize)
  6059. ->limit($pageSize)
  6060. ->get();
  6061. break;
  6062. case 6:
  6063. $query = Couplet::orderBy("updated_at", "desc");
  6064. $total = $query->count();
  6065. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6066. ->offset(($page - 1) * $pageSize)
  6067. ->limit($pageSize)
  6068. ->get();
  6069. break;
  6070. default:
  6071. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6072. $total = $query->count();
  6073. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6074. ->offset(($page - 1) * $pageSize)
  6075. ->limit($pageSize)
  6076. ->get();
  6077. }
  6078. return Result::success([
  6079. 'list' => $result,
  6080. 'total' => $total,
  6081. 'page' => (int)$page,
  6082. 'pageSize' => (int)$pageSize,
  6083. 'month' => $month,
  6084. 'day' => $day
  6085. ]);
  6086. }
  6087. /**
  6088. * 1:历史上的今天
  6089. * 2:节日
  6090. * 3:文章
  6091. *
  6092. * 资讯详情信息
  6093. */
  6094. public function getWebsiteTsbbDetail(array $data): array
  6095. {
  6096. $data['type'] = intval($data['type']);
  6097. switch ($data['type']) {
  6098. case 1:
  6099. $result = HistoryToday::where("id", $data['id'])->first();
  6100. break;
  6101. case 2:
  6102. $result = Festival::where("id", $data['id'])->first();
  6103. break;
  6104. case 3:
  6105. $result = Character::where("id", $data['id'])->first();
  6106. break;
  6107. case 4:
  6108. $result = Riddle::where("id", $data['id'])->first();
  6109. break;
  6110. case 5:
  6111. $result = Idiom::where("id", $data['id'])->first();
  6112. break;
  6113. case 6:
  6114. $result = Couplet::where("id", $data['id'])->first();
  6115. break;
  6116. default:
  6117. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6118. break;
  6119. }
  6120. return Result::success($result);
  6121. }
  6122. /**
  6123. * 农网导航首页数据
  6124. */
  6125. public function getWebsiteNwHomeList(array $data): array
  6126. {
  6127. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6128. ->pluck('category_id')
  6129. ->toArray();
  6130. // 使用子查询优化
  6131. $articlesList = DB::table('article')
  6132. ->select([
  6133. 'article.id',
  6134. 'article.title',
  6135. 'article.imgurl',
  6136. 'article.created_at',
  6137. 'category.name as category_name',
  6138. 'category.id as category_id',
  6139. 'website_category.aLIas_pinyin as pinyin',
  6140. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6141. DB::raw('100 as type')
  6142. ])
  6143. ->join('category', 'article.catid', '=', 'category.id')
  6144. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6145. ->leftJoin('website_category as parent_wc', function ($join) {
  6146. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6147. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6148. })
  6149. ->where('website_category.website_id', $data['website_id'])
  6150. ->where('article.status', 1)
  6151. ->whereIn('category.id', $categoryIds)
  6152. ->orderBy('article.created_at', 'desc')
  6153. ->get()
  6154. ->groupBy('category_id')
  6155. ->map(function ($group) {
  6156. // 确保第一条数据有图片
  6157. $firstWithImage = $group->first(function ($item) {
  6158. return !empty($item->imgurl);
  6159. });
  6160. if ($firstWithImage) {
  6161. // 如果有带图片的文章,将其放在第一位
  6162. $group = $group->filter(function ($item) use ($firstWithImage) {
  6163. return $item->id !== $firstWithImage->id;
  6164. })->prepend($firstWithImage);
  6165. }
  6166. return [
  6167. 'category_name' => $group->first()->category_name,
  6168. 'catid' => $group->first()->category_id,
  6169. 'pinyin' => $group->first()->pinyin,
  6170. 'parent_pinyin' => $group->first()->parent_pinyin,
  6171. 'list' => $group->take(4)->map(function ($item) {
  6172. return [
  6173. 'id' => $item->id,
  6174. 'title' => $item->title,
  6175. ];
  6176. })->values()
  6177. ];
  6178. })
  6179. ->values()
  6180. ->toArray();
  6181. return Result::success($articlesList);
  6182. }
  6183. /**
  6184. * 企业管理
  6185. * @param array $data
  6186. * @return array
  6187. */
  6188. public function getCompanyList(array $data): array
  6189. {
  6190. // return Result::success($data);
  6191. $where = [];
  6192. $user = User::where('id', $data['user_id'])->first();
  6193. if (empty($user)) {
  6194. return Result::error('用户不存在!');
  6195. }
  6196. if ($user['type_id'] != 10000) {
  6197. $where['user_id'] = $data['user_id'];
  6198. }
  6199. if (isset($data['title']) && !empty($data['title'])) {
  6200. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6201. }
  6202. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6203. array_push($where, ['website.id', $data['website_id']]);
  6204. }
  6205. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6206. if ($data['ischeck'] == 1) {
  6207. if (isset($data['status']) && $data['status'] != '') {
  6208. array_push($where, ['company.status', $data['status']]);
  6209. $query = Company::where($where);
  6210. } else {
  6211. $query = Company::whereIn('company.status', [0, 2]);
  6212. }
  6213. } else {
  6214. $query = Company::where('company.status', 1);
  6215. }
  6216. }
  6217. $result = $query->where($where)
  6218. ->leftJoin('website_category', function ($query) {
  6219. $query->on('website_category.category_id', '=', 'company.category_id')
  6220. ->on('website_category.website_id', '=', 'company.website_id');
  6221. })
  6222. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6223. ->select(
  6224. 'company.id',
  6225. 'company.title',
  6226. 'company.website_id',
  6227. 'company.category_id',
  6228. 'website.website_name',
  6229. 'website_category.alias as category_name',
  6230. 'company.status',
  6231. 'company.updated_at',
  6232. 'company.user_id'
  6233. )
  6234. ->orderBy('company.updated_at', 'desc')
  6235. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6236. if ($result->isEmpty()) {
  6237. return Result::error("暂无企业", 0);
  6238. }
  6239. return Result::success($result);
  6240. }
  6241. /**
  6242. * 添加企业
  6243. * @param array $data
  6244. * @return array
  6245. */
  6246. public function addCompany(array $data): array
  6247. {
  6248. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6249. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6250. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6251. $data['cat_arr_id'] = json_encode($car_arr_id);
  6252. } else {
  6253. $data['cat_arr_id'] = '';
  6254. }
  6255. if ($data['imgurl'] == '') {
  6256. //content中提取图片第一个图,正则提取
  6257. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6258. preg_match_all($reg, $data['content'], $matches);
  6259. if (isset($matches[1][0])) {
  6260. //截取varchar240
  6261. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6262. }
  6263. }
  6264. if ($data['keyword'] == '') {
  6265. //提取标题+内容中的关键词
  6266. $data['keyword'] = $data['title'];
  6267. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6268. Jieba::init(); // 初始化 jieba-php
  6269. Finalseg::init();
  6270. $segList = Jieba::cut($data['keyword']);
  6271. $segList1 = array_slice($segList, 0, 8);
  6272. $data['keyword'] = implode(',', $segList1);
  6273. }
  6274. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6275. //提取内容中的描述
  6276. $content = $data['content'];
  6277. // 去除 <style> 和 <script> 标签及其内容
  6278. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6279. // 去除所有 HTML 标签
  6280. $content = strip_tags($content);
  6281. // 去除 HTML 实体
  6282. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6283. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6284. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6285. // 去除多余空白
  6286. $content = preg_replace('/\s+/u', '', $content);
  6287. // 截取 100 个字符
  6288. $data['introduce'] = mb_substr($content, 0, 100);
  6289. }
  6290. $user = User::where('id', $data['user_id'])->first();
  6291. if (empty($user)) {
  6292. return Result::error('用户不存在!');
  6293. }
  6294. if ($user['type_id'] == 10000) {
  6295. $data['status'] = 1;
  6296. }
  6297. if (isset($data['level']) && $data['level'] != null) {
  6298. $data['level'] = intval($data['level']);
  6299. } else {
  6300. $data['level'] = null;
  6301. }
  6302. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6303. $this->sendMessage([
  6304. 'talk_type' => 900,
  6305. 'title' => $data['title'],
  6306. 'content' => '提交了审核',
  6307. 'messageType' => 8,
  6308. ]);
  6309. }
  6310. $result = Company::insertGetId($data);
  6311. if ($result) {
  6312. return Result::success($result);
  6313. } else {
  6314. return Result::error('添加失败');
  6315. }
  6316. }
  6317. /**
  6318. * 更新企业
  6319. * @param array $data
  6320. * @return array
  6321. */
  6322. public function upCompany(array $data): array
  6323. {
  6324. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6325. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6326. $data['cat_arr_id'] = json_encode($car_arr_id);
  6327. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6328. } else {
  6329. $data['cat_arr_id'] = '';
  6330. }
  6331. if ($data['imgurl'] == '') {
  6332. //content中提取图片第一个图,正则提取
  6333. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6334. preg_match_all($reg, $data['content'], $matches);
  6335. if (isset($matches[1][0])) {
  6336. //截取varchar
  6337. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6338. }
  6339. }
  6340. if ($data['keyword'] == '') {
  6341. //提取标题+内容中的关键词
  6342. $data['keyword'] = $data['title'];
  6343. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6344. Jieba::init(); // 初始化 jieba-php
  6345. Finalseg::init();
  6346. $segList = Jieba::cut($data['keyword']);
  6347. $segList1 = array_slice($segList, 0, 8);
  6348. $data['keyword'] = implode(',', $segList1);
  6349. }
  6350. if ($data['introduce'] == '') {
  6351. //提取内容中的描述
  6352. $content = $data['content'];
  6353. // 去除 <style> 和 <script> 标签及其内容
  6354. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6355. // 去除所有 HTML 标签
  6356. $content = strip_tags($content);
  6357. // 去除 HTML 实体
  6358. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6359. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6360. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6361. // 去除多余空白
  6362. $content = preg_replace('/\s+/u', '', $content);
  6363. // 截取 100 个字符
  6364. $data['introduce'] = mb_substr($content, 0, 100);
  6365. }
  6366. if (isset($data['level']) && $data['level'] != null) {
  6367. $data['level'] = intval($data['level']);
  6368. } else {
  6369. $data['level'] = null;
  6370. }
  6371. $user = User::where('id', $data['user_id'])->first();
  6372. if (empty($user)) {
  6373. return Result::error('用户不存在!');
  6374. }
  6375. if ($user['type_id'] == 10000) {
  6376. $data['status'] = 1;
  6377. } else {
  6378. $data['status'] = 0;
  6379. }
  6380. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6381. $this->sendMessage([
  6382. 'talk_type' => 900,
  6383. 'title' => $data['title'],
  6384. 'content' => '提交了审核',
  6385. 'messageType' => 8,
  6386. ]);
  6387. }
  6388. $result = Company::where('id', $data['id'])->update($data);
  6389. if ($result) {
  6390. return Result::success($result);
  6391. } else {
  6392. return Result::error('修改失败');
  6393. }
  6394. }
  6395. /**
  6396. * 删除企业
  6397. * @param array $data
  6398. * @return array
  6399. */
  6400. public function delCompany(array $data): array
  6401. {
  6402. $result = Company::where('id', $data['id'])->delete();
  6403. if ($result) {
  6404. return Result::success($result);
  6405. } else {
  6406. return Result::error('删除失败');
  6407. }
  6408. }
  6409. /**
  6410. * 审核企业
  6411. * @param array $data
  6412. * @return array
  6413. */
  6414. public function checkCompany(array $data): array
  6415. {
  6416. $user = User::where('id', $data['user_id'])->first();
  6417. if (empty($user)) {
  6418. return Result::error('用户不存在!');
  6419. }
  6420. $company = Company::where('id', $data['id'])->first();
  6421. if (empty($company)) {
  6422. return Result::error('企业不存在!');
  6423. }
  6424. // 状态:0:未审核 1:已审核 2:已拒绝
  6425. if ($data['status'] == 2 || $data['status'] == '2') {
  6426. $this->sendMessage([
  6427. 'talk_type' => 901,
  6428. 'title' => $company['title'],
  6429. 'content' => '审核拒绝',
  6430. 'messageType' => 8,
  6431. 'user_id' => $company['user_id'],
  6432. ]);
  6433. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6434. } else {
  6435. if ($data['status'] == 1) {
  6436. $this->sendMessage([
  6437. 'talk_type' => 901,
  6438. 'title' => $company['title'],
  6439. 'content' => '审核通过',
  6440. 'messageType' => 8,
  6441. 'user_id' => $company['user_id'],
  6442. ]);
  6443. } else if ($data['status'] == 0) {
  6444. $this->sendMessage([
  6445. 'talk_type' => 900,
  6446. 'title' => $company['title'],
  6447. 'content' => '提交了审核',
  6448. 'messageType' => 8,
  6449. ]);
  6450. }
  6451. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6452. }
  6453. if (empty($result)) {
  6454. return Result::error('审核失败!');
  6455. } else {
  6456. return Result::success($result);
  6457. }
  6458. }
  6459. /**
  6460. * 获取企业信息
  6461. * @param array $data
  6462. * @return array
  6463. */
  6464. public function getCompanyInfo(array $data): array
  6465. {
  6466. $result = Company::where('id', $data['id'])->first();
  6467. $city_arr = json_decode($result['city_arr_id']);
  6468. $result['city_name'] = District::whereIn('id', $city_arr)
  6469. ->pluck('name')
  6470. ->implode('-');
  6471. if (empty($result)) {
  6472. return Result::error('企业不存在!');
  6473. } else {
  6474. return Result::success($result);
  6475. }
  6476. }
  6477. /**
  6478. * @param array $data
  6479. * @return array
  6480. */
  6481. public function getWebsiteCompany(array $data): array
  6482. {
  6483. $categorys = json_decode($data['id'], true);
  6484. $category_arr = $this->processArticlePro($data['website_id']);
  6485. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6486. $catiall = $category_arr['catiall'];
  6487. $categoryIds = $category_arr['categoryIds'];
  6488. // return Result::success($category_arr);
  6489. foreach ($categorys as $key => $value) {
  6490. if (array_key_exists('level', $value)) {
  6491. $parts = explode(',', $value['level']);
  6492. $level = $parts[0] ?? null;
  6493. $imgnum = $parts[1] ?? null;
  6494. $textnum = $parts[2] ?? null;
  6495. if (!empty($textnum) && $textnum > 0) {
  6496. $text_num = Company::where('level', $level)
  6497. ->whereIn('category_id', $categoryIds)
  6498. ->where('status', 1)
  6499. ->select(
  6500. 'company.id',
  6501. 'company.title',
  6502. 'company.description',
  6503. 'company.updated_at',
  6504. 'company.category_id',
  6505. 'company.cat_arr_id'
  6506. )
  6507. ->orderBy('updated_at', 'desc')
  6508. ->limit($textnum)
  6509. ->get()->all();
  6510. }
  6511. if (!empty($imgnum) && $imgnum > 0) {
  6512. $img_num = Company::where('level', $level)
  6513. ->whereIn('category_id', $categoryIds)
  6514. ->where('status', 1)
  6515. ->where('imgurl', '!=', '')
  6516. ->whereNotNull('imgurl')
  6517. ->select(
  6518. 'company.id',
  6519. 'company.title',
  6520. 'company.description',
  6521. 'company.updated_at',
  6522. 'company.imgurl as imgs',
  6523. 'company.category_id',
  6524. 'company.cat_arr_id'
  6525. )
  6526. ->orderBy('updated_at', 'desc')
  6527. ->limit($imgnum)
  6528. ->get()->all();
  6529. }
  6530. }
  6531. if (array_key_exists('id', $value)) {
  6532. $parts = explode(',', $value['id']);
  6533. $category_id = $parts[0] ?? null;
  6534. $imgnum = $parts[1] ?? null;
  6535. $textnum = $parts[2] ?? null;
  6536. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6537. if (!empty($textnum) && $textnum > 0) {
  6538. $text_num = Company::whereIn('category_id', $category_arr)
  6539. // ->where('website_id', $data['website_id'])
  6540. ->where('status', 1)
  6541. ->select(
  6542. 'company.id',
  6543. 'company.title',
  6544. 'company.description',
  6545. 'company.updated_at',
  6546. 'company.category_id',
  6547. 'company.cat_arr_id'
  6548. )
  6549. ->orderBy('updated_at', 'desc')
  6550. ->limit($textnum)
  6551. ->get()->all();
  6552. }
  6553. if (!empty($imgnum) && $imgnum > 0) {
  6554. $img_num = Company::whereIn('category_id', $category_arr)
  6555. // ->where('website_id', $data['website_id'])
  6556. ->where('status', 1)
  6557. ->where('imgurl', '!=', '')
  6558. ->whereNotNull('imgurl')
  6559. ->select(
  6560. 'company.id',
  6561. 'company.title',
  6562. 'company.description',
  6563. 'company.updated_at',
  6564. 'company.imgurl as imgs',
  6565. 'company.category_id',
  6566. 'company.cat_arr_id'
  6567. )
  6568. ->orderBy('updated_at', 'desc')
  6569. ->limit($imgnum)
  6570. ->get()->all();
  6571. }
  6572. }
  6573. if (!empty($text_num)) {
  6574. foreach ($text_num as $k => $v) {
  6575. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6576. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6577. }
  6578. }
  6579. if (!empty($img_num)) {
  6580. foreach ($img_num as $k => $v) {
  6581. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6582. $imgurl = json_decode($v['imgs'], true);
  6583. if (!empty($imgurl)) {
  6584. $img_num[$k]->imgurl = $imgurl[0];
  6585. }
  6586. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6587. }
  6588. }
  6589. $company[$key]['img_num'] = $img_num ?? [];
  6590. $company[$key]['text_num'] = $text_num ?? [];
  6591. }
  6592. if (empty($company)) {
  6593. return Result::error("暂无相关企业信息", 0);
  6594. }
  6595. return Result::success($company);
  6596. }
  6597. /**
  6598. * @param array $data
  6599. * @return array
  6600. */
  6601. public function getWebsiteCompanyList(array $data): array
  6602. {
  6603. $where['website_id'] = $data['website_id'];
  6604. $where['status'] = 1;
  6605. $categoryIds = [];
  6606. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6607. $category_id = $data['category_id'];
  6608. }
  6609. $category_arr = $this->processArticlePro($data['website_id']);
  6610. $categoryIds = $category_arr['categoryIds'];
  6611. // return Result::success($cat_1st_arr);
  6612. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  6613. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  6614. })
  6615. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  6616. $query->whereIn('category_id', $categoryIds);
  6617. })
  6618. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  6619. $query->where('category_id', $category_id);
  6620. })
  6621. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6622. ->orderBy('updated_at', 'desc')
  6623. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6624. if (empty($company)) {
  6625. return Result::error("暂无相关公司信息", 0);
  6626. }
  6627. $result = [
  6628. 'count' => $company->total(),
  6629. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  6630. ];
  6631. return Result::success($result);
  6632. }
  6633. /**
  6634. * 获取项目列表
  6635. * @param array $data
  6636. * @return array
  6637. */
  6638. public function getProjectList(array $data): array
  6639. {
  6640. $where = [];
  6641. $user = User::where('id', $data['user_id'])->first();
  6642. if (empty($user)) {
  6643. return Result::error('用户不存在!');
  6644. }
  6645. if ($user->type_id != 10000) {
  6646. array_push($where, ['project.user_id', $data['user_id']]);
  6647. }
  6648. $query = Project::query();
  6649. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6650. array_push($where, ['project.website_id', $data['website_id']]);
  6651. }
  6652. if (isset($data['title']) && !empty($data['title'])) {
  6653. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6654. }
  6655. if ($data['status'] != 3) {
  6656. array_push($where, ['project.status', $data['status']]);
  6657. }
  6658. $query = Project::where($where)
  6659. ->when($data['status'] == 3, function ($query) {
  6660. $query->whereIn('project.status', [0, 2]);
  6661. });
  6662. $count = $query->clone()
  6663. ->count();
  6664. $rows = $query->clone()
  6665. ->leftJoin('website', 'project.website_id', 'website.id')
  6666. ->leftJoin('website_category', function ($join) {
  6667. $join->on('project.website_id', '=', 'website_category.website_id')
  6668. ->on('project.category_id', '=', 'website_category.category_id');
  6669. })
  6670. ->select(
  6671. 'project.id',
  6672. 'project.title',
  6673. 'project.updated_at',
  6674. 'project.status',
  6675. 'website.website_name',
  6676. 'website_category.alias as category_name',
  6677. 'project.website_id',
  6678. 'project.user_id'
  6679. )
  6680. ->orderBy('project.updated_at', 'desc')
  6681. ->offset(($data['page'] - 1) * $data['pageSize'])
  6682. ->limit($data['pageSize'])
  6683. ->get();
  6684. if ($rows->isEmpty()) {
  6685. return Result::error("暂无相关项目信息", 0);
  6686. }
  6687. $result = [
  6688. 'count' => $count,
  6689. 'rows' => $rows,
  6690. ];
  6691. return Result::success($result);
  6692. }
  6693. /**
  6694. * 添加项目
  6695. * @param array $data
  6696. * @return array
  6697. */
  6698. public function addProject(array $data): array
  6699. {
  6700. $user = User::where('id', $data['user_id'])->first();
  6701. if (empty($user)) {
  6702. return Result::error("暂无相关用户信息", 0);
  6703. }
  6704. if ($user->type_id == 10000) {
  6705. $data['status'] = 1;
  6706. } else {
  6707. $data['status'] = 0;
  6708. }
  6709. if ($data['keyword'] == '') {
  6710. //提取标题+内容中的关键词
  6711. $data['keyword'] = $data['title'];
  6712. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6713. Jieba::init(); // 初始化 jieba-php
  6714. Finalseg::init();
  6715. $segList = Jieba::cut($data['keyword']);
  6716. $segList1 = array_slice($segList, 0, 8);
  6717. $data['keyword'] = implode(',', $segList1);
  6718. }
  6719. if ($data['description'] == '') {
  6720. //提取内容中的描述
  6721. // var_dump(11111);
  6722. //提取内容中的描述
  6723. $content = $data['introduce'];
  6724. // 去除 <style> 和 <script> 标签及其内容
  6725. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6726. // 去除所有 HTML 标签
  6727. $content = strip_tags($content);
  6728. // 去除 HTML 实体
  6729. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6730. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6731. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6732. // 去除多余空白
  6733. $content = preg_replace('/\s+/u', '', $content);
  6734. // 截取 100 个字符
  6735. $data['description'] = mb_substr($content, 0, 100);
  6736. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6737. }
  6738. if ($data['status'] == 0) {
  6739. $this->sendMessage([
  6740. 'talk_type' => 1000,
  6741. 'title' => $data['title'],
  6742. 'content' => '提交了审核',
  6743. 'messageType' => 9,
  6744. ]);
  6745. }
  6746. $project = Project::insertGetId($data);
  6747. if (empty($project)) {
  6748. return Result::error("暂无相关项目信息", 0);
  6749. }
  6750. return Result::success($project);
  6751. }
  6752. /**
  6753. * 更新项目
  6754. * @param array $data
  6755. * @return array
  6756. */
  6757. public function upProject(array $data): array
  6758. {
  6759. $project = Project::where('id', $data['id'])->first();
  6760. if (empty($project)) {
  6761. return Result::error("暂无相关项目信息", 0);
  6762. }
  6763. $id = $data['id'];
  6764. unset($data['id']);
  6765. $user = User::where('id', $data['user_id'])->first();
  6766. if (empty($user)) {
  6767. return Result::error("暂无相关用户信息", 0);
  6768. }
  6769. if ($user->type_id == 10000) {
  6770. $data['status'] = 1;
  6771. } else {
  6772. $data['status'] = 0;
  6773. }
  6774. unset($data['user_id']);
  6775. if ($data['keyword'] == '') {
  6776. //提取标题+内容中的关键词
  6777. $data['keyword'] = $data['title'];
  6778. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6779. Jieba::init(); // 初始化 jieba-php
  6780. Finalseg::init();
  6781. $segList = Jieba::cut($data['keyword']);
  6782. $segList1 = array_slice($segList, 0, 8);
  6783. $data['keyword'] = implode(',', $segList1);
  6784. }
  6785. if ($data['description'] == '') {
  6786. //提取内容中的描述
  6787. // var_dump(11111);
  6788. //提取内容中的描述
  6789. $content = $data['introduce'];
  6790. // 去除 <style> 和 <script> 标签及其内容
  6791. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6792. // 去除所有 HTML 标签
  6793. $content = strip_tags($content);
  6794. // 去除 HTML 实体
  6795. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6796. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6797. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6798. // 去除多余空白
  6799. $content = preg_replace('/\s+/u', '', $content);
  6800. // 截取 100 个字符
  6801. $data['description'] = mb_substr($content, 0, 100);
  6802. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6803. }
  6804. if ($data['status'] == 0) {
  6805. $this->sendMessage([
  6806. 'talk_type' => 1000,
  6807. 'title' => $data['title'],
  6808. 'content' => '提交了审核',
  6809. 'messageType' => 9,
  6810. ]);
  6811. }
  6812. $result = Project::where('id', $id)->update($data);
  6813. if (empty($result)) {
  6814. return Result::error("更新失败", 0);
  6815. }
  6816. return Result::success($result);
  6817. }
  6818. /**
  6819. * 删除项目
  6820. * @param array $data
  6821. * @return array
  6822. */
  6823. public function delProject(array $data): array
  6824. {
  6825. $user = User::where('id', $data['user_id'])->first();
  6826. if (empty($user)) {
  6827. return Result::error("暂无相关用户信息", 0);
  6828. }
  6829. $project = Project::where('id', $data['id'])->first();
  6830. if (empty($project)) {
  6831. return Result::error("暂无相关项目信息", 0);
  6832. }
  6833. $result = Project::where('id', $data['id'])->delete();
  6834. if (empty($result)) {
  6835. return Result::error("删除失败", 0);
  6836. }
  6837. return Result::success($result);
  6838. }
  6839. /**
  6840. * 审核项目
  6841. * @param array $data
  6842. * @return array
  6843. */
  6844. public function checkProject(array $data): array
  6845. {
  6846. $user = User::where('id', $data['user_id'])->first();
  6847. if (empty($user)) {
  6848. return Result::error("暂无相关用户信息", 0);
  6849. }
  6850. // 0:未审核; 1:已审核; 2:已拒绝;
  6851. if ($user->type_id != 10000) {
  6852. if ($data['status'] == 1 || $data['status'] == 2) {
  6853. return Result::error("此用户权限不足", 0);
  6854. }
  6855. }
  6856. $project = Project::where('id', $data['id'])->first();
  6857. if (empty($project)) {
  6858. return Result::error("暂无相关项目信息", 0);
  6859. }
  6860. if ($data['status'] == 2) {
  6861. $this->sendMessage([
  6862. 'talk_type' => 1001,
  6863. 'title' => $project['title'],
  6864. 'content' => '审核拒绝',
  6865. 'messageType' => 9,
  6866. 'user_id' => $project['user_id'],
  6867. ]);
  6868. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  6869. } else {
  6870. if ($data['status'] == 1) {
  6871. $this->sendMessage([
  6872. 'talk_type' => 1001,
  6873. 'title' => $project['title'],
  6874. 'content' => '审核通过',
  6875. 'messageType' => 9,
  6876. 'user_id' => $project['user_id'],
  6877. ]);
  6878. } else if ($data['status'] == 0) {
  6879. $this->sendMessage([
  6880. 'talk_type' => 1000,
  6881. 'title' => $project['title'],
  6882. 'content' => '提交了审核',
  6883. 'messageType' => 9,
  6884. ]);
  6885. }
  6886. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  6887. }
  6888. if (empty($result)) {
  6889. return Result::error("审核失败", 0);
  6890. }
  6891. return Result::success($result);
  6892. }
  6893. /**
  6894. * 获取项目详情
  6895. * @param array $data
  6896. * @return array
  6897. */
  6898. public function getProjectInfo(array $data): array
  6899. {
  6900. $project = Project::where('id', $data['id'])->first();
  6901. if (empty($project)) {
  6902. return Result::error("暂无相关项目信息", 0);
  6903. }
  6904. return Result::success($project);
  6905. }
  6906. public function getWebsiteCompanyInfo(array $data): array
  6907. {
  6908. $company = Company::where('id', $data['id'])
  6909. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  6910. ->where('status', 1)
  6911. // ->where('website_id', $data['website_id'])
  6912. ->select('company.*', 'job_industry.hyname as hy_name')
  6913. ->first();
  6914. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  6915. switch ($company->jobnature_id) {
  6916. case null:
  6917. $company->jobnature_name = '';
  6918. break;
  6919. case 0:
  6920. $company->jobnature_name = '市场监督';
  6921. break;
  6922. case 1:
  6923. $company->jobnature_name = '信访纪检';
  6924. break;
  6925. case 2:
  6926. $company->jobnature_name = '公检法司';
  6927. break;
  6928. case 3:
  6929. $company->jobnature_name = '高关注机构';
  6930. break;
  6931. default:
  6932. $company->jobnature_name = '';
  6933. break;
  6934. }
  6935. $city_arr = $company->city_arr_id;
  6936. if (!empty($city_arr)) {
  6937. $city_arr = json_decode($city_arr, true);
  6938. $cityNames = District::whereIn('id', $city_arr)
  6939. ->pluck('name')
  6940. ->implode('-');
  6941. $company->city_name = $cityNames;
  6942. } else {
  6943. $company->city_name = '';
  6944. }
  6945. if (empty($company)) {
  6946. return Result::error("暂无相关公司信息", 0);
  6947. }
  6948. return Result::success($company);
  6949. }
  6950. public function getMSG(array $data): array
  6951. {
  6952. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  6953. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  6954. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  6955. $result = [];
  6956. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  6957. //最近的5篇已审的文章
  6958. $apply_articale = Article::where('status', 1)
  6959. ->where('admin_user_id', $user_id)
  6960. ->orderBy('updated_at', 'desc')
  6961. // ->limit(5)
  6962. ->get();
  6963. //获取5条用户的已审核商品
  6964. $good = Good::where('status', 2)
  6965. ->where('user_id', $user_id)
  6966. ->orderBy('updated_at', 'desc')
  6967. // ->limit(5)
  6968. ->get();
  6969. //获取5条用户待审核的公告
  6970. $notice = Notice::where('status', 2)
  6971. ->where('user_id', $user_id)
  6972. ->orderBy('updated_at', 'desc')
  6973. ->limit(5)->get();
  6974. //获取5条用户的待审核投诉
  6975. $complaint = Complaint::where('status', 2)
  6976. ->where('user_id', $user_id)
  6977. ->orderBy('updated_at', 'desc')
  6978. // ->limit(5)
  6979. ->get();
  6980. //获取5条用户的book
  6981. $book = Book::where('status', 2)
  6982. ->where('user_id', $user_id)
  6983. ->orderBy('updated_at', 'desc')
  6984. // ->limit(5)
  6985. ->get();
  6986. //获取5条用户的求职
  6987. //获取5条用户的求职 1
  6988. $job_hunting = JobHunting::where('job_hunting.status', 2)
  6989. ->where('job_hunting.user_id', $user_id)
  6990. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  6991. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  6992. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6993. ->orderBy('updated_at', 'desc')
  6994. // ->limit(5)
  6995. ->get();
  6996. //获取5条用户的求职 2
  6997. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  6998. ->where('job_recruiting.user_id', $user_id)
  6999. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7000. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7001. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7002. ->orderBy('updated_at', 'desc')
  7003. // ->limit(5)
  7004. ->get();
  7005. //人才库 1
  7006. $job_apply = JobApply::where('job_apply.status', 1)
  7007. ->where('job_apply.receiver_id', $user_id)
  7008. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7009. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7010. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7011. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7012. ->select('job_recruiting', 'job_recruiting.', '', '')
  7013. ->select('job_apply.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name', 'job_recruiting.title as job_name')
  7014. ->orderBy('updated_at', 'desc')
  7015. // ->limit(5)
  7016. ->get();
  7017. // 职场机会 2
  7018. $job_resume = JobResume::where('job_resume.status', 1)
  7019. ->where('job_resume.receiver_id', $user_id)
  7020. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7021. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7022. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7023. ->select('job_resume.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name')
  7024. ->orderBy('updated_at', 'desc')
  7025. // ->limit(5)
  7026. ->get();
  7027. //获取5条用户待处理的投诉
  7028. $complaint_deal = Complaint::where('status', 2)
  7029. ->where('deal', 1)
  7030. ->whereJsonContains('re_user_ids', $user_id)
  7031. ->orderBy('updated_at', 'desc')
  7032. // ->limit(5)
  7033. ->get();
  7034. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7035. $complany = Company::where('status', 1)
  7036. ->where('user_id', $user_id)
  7037. ->orderBy('updated_at', 'desc')
  7038. // ->limit(5)
  7039. ->get();
  7040. //获取5条单聊未读聊天消息
  7041. // $chat = ChatRecords::where('is_read', 0)
  7042. // ->where('user_id', $user_id)
  7043. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7044. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7045. // ->where('action', 'recieved')
  7046. // ->where('talk_type', 1)
  7047. // ->orderBy('created_at', 'desc')
  7048. // // ->limit(5)
  7049. // ->get();
  7050. //获取5条未读群聊信息
  7051. // $chat_group = ChatRecords::where('is_read', 0)
  7052. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7053. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7054. // ->where('user_id', $user_id)
  7055. // ->where('talk_type', 2)
  7056. // ->orderBy('created_at', 'desc')
  7057. // // ->limit(5)
  7058. // ->get();
  7059. //获取5条用户的待审核项目
  7060. $project = Project::where('status', 1)
  7061. ->where('user_id', $user_id)
  7062. ->orderBy('updated_at', 'desc')
  7063. // ->limit(5)
  7064. ->get();
  7065. // count($chat) + count($chat_group) +
  7066. $count = count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume) + count($complaint_deal)
  7067. + count($complany)
  7068. + count($project)
  7069. // + count($chat) + count($chat_group)
  7070. ;
  7071. $result = [
  7072. 'apply_articale' => $apply_articale,
  7073. // 'chat' => $chat,
  7074. // 'chat_group' => $chat_group,
  7075. 'good' => $good,
  7076. 'notice' => $notice,
  7077. 'complaint' => $complaint,
  7078. 'book' => $book,
  7079. 'job_hunting' => $job_hunting,
  7080. 'job_recruiting' => $job_recruiting,
  7081. 'job_apply' => $job_apply,
  7082. 'job_resume' => $job_resume,
  7083. 'complaint_deal' => $complaint_deal,
  7084. 'complany' => $complany,
  7085. 'project' => $project,
  7086. 'count' => $count,
  7087. ];
  7088. } elseif ($type_id == 12) {
  7089. //最近的5篇已审的文章
  7090. $apply_articale = Article::where('status', 1)
  7091. ->where('admin_user_id', $user_id)
  7092. ->limit(5)->get();
  7093. //获取5条单聊未读聊天消息
  7094. $chat = ChatRecords::where('is_read', 0)
  7095. ->where('user_id', $user_id)
  7096. ->where('talk_type', 1)
  7097. ->orderBy('created_at', 'desc')
  7098. ->limit(5)->get();
  7099. //获取5条未读群聊信息
  7100. $chat_group = ChatRecords::where('is_read', 0)
  7101. ->where('user_id', $user_id)
  7102. ->where('talk_type', 2)
  7103. ->orderBy('created_at', 'desc')
  7104. ->limit(5)->get();
  7105. //获取5条用户的已审核商品
  7106. $good = Good::where('status', 2)
  7107. ->where('user_id', $user_id)
  7108. ->orderBy('updated_at', 'desc')
  7109. ->limit(5)->get();
  7110. //获取5条用户的book
  7111. $book = Book::where('status', 2)
  7112. ->where('user_id', $user_id)
  7113. ->orderBy('updated_at', 'desc')
  7114. ->limit(5)->get();
  7115. //获取5条用户的求职
  7116. //获取5条用户的求职 1
  7117. //count($chat) + count($chat_group)
  7118. $count = count($apply_articale) + count($good);
  7119. $result = [
  7120. 'apply_articale' => $apply_articale,
  7121. 'chat' => $chat,
  7122. 'chat_group' => $chat_group,
  7123. 'good' => $good,
  7124. 'book' => $book,
  7125. 'count' => $count,
  7126. ];
  7127. } elseif ($type_id == 13) {
  7128. //最近的5篇已审的文章
  7129. $apply_articale = Article::where('status', 1)
  7130. ->where('admin_user_id', $user_id)
  7131. ->limit(5)->get();
  7132. //获取5条单聊未读聊天消息
  7133. $chat = ChatRecords::where('is_read', 0)
  7134. ->where('user_id', $user_id)
  7135. ->where('talk_type', 1)
  7136. ->orderBy('created_at', 'desc')
  7137. ->limit(5)->get();
  7138. //获取5条未读群聊信息
  7139. $chat_group = ChatRecords::where('is_read', 0)
  7140. ->where('user_id', $user_id)
  7141. ->where('talk_type', 2)
  7142. ->orderBy('created_at', 'desc')
  7143. ->limit(5)->get();
  7144. //获取5条用户的已审核商品
  7145. $good = Good::where('status', 2)
  7146. ->where('user_id', $user_id)
  7147. ->orderBy('updated_at', 'desc')
  7148. ->limit(5)->get();
  7149. //count($chat) + count($chat_group) +
  7150. $count = count($apply_articale) + count($good);
  7151. $result = [
  7152. 'apply_articale' => $apply_articale,
  7153. 'chat' => $chat,
  7154. 'chat_group' => $chat_group,
  7155. 'good' => $good,
  7156. 'count' => $count,
  7157. ];
  7158. } elseif ($type_id == 14) {
  7159. //最近的5篇已审的文章
  7160. $apply_articale = Article::where('status', 1)
  7161. ->where('admin_user_id', $user_id)
  7162. // ->limit(5)
  7163. ->get();
  7164. //获取5条用户的已审核商品
  7165. $good = Good::where('status', 2)
  7166. ->where('user_id', $user_id)
  7167. ->orderBy('updated_at', 'desc')
  7168. // ->limit(5)
  7169. ->get();
  7170. $count = count($apply_articale) + count($good);
  7171. $result = [
  7172. 'apply_articale' => $apply_articale,
  7173. 'chat' => '',
  7174. 'chat_group' => '',
  7175. 'good' => $good,
  7176. 'count' => $count,
  7177. ];
  7178. } elseif ($type_id == 10000) {
  7179. //获取未审核的5篇文章
  7180. $apply_articale = Article::where('status', 0)
  7181. ->orderBy('updated_at', 'desc')
  7182. // ->limit(5)
  7183. ->get();
  7184. //获取5条单聊未读聊天消息
  7185. //获取5条单聊未读聊天消息
  7186. // $chat = ChatRecords::where('is_read', 0)
  7187. // ->where('user_id', $user_id)
  7188. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7189. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7190. // ->where('action', 'recieved')
  7191. // ->where('talk_type', 1)
  7192. // ->orderBy('created_at', 'desc')
  7193. // // ->limit(5)
  7194. // ->get();
  7195. // //获取5条未读群聊信息
  7196. // $chat_group = ChatRecords::where('is_read', 0)
  7197. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7198. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7199. // ->where('user_id', $user_id)
  7200. // ->where('talk_type', 2)
  7201. // ->orderBy('created_at', 'desc')
  7202. // // ->limit(5)
  7203. // ->get();
  7204. //获取5条用户的已审核商品
  7205. $good = Good::where('status', 1)
  7206. // ->where('user_id', $user_id)
  7207. ->orderBy('updated_at', 'desc')
  7208. // ->limit(5)
  7209. ->get();
  7210. //获取5条用户待审核的公告
  7211. $notice = Notice::where('status', 1)
  7212. ->orderBy('updated_at', 'desc')
  7213. // ->limit(5)
  7214. ->get();
  7215. //获取5条用户的待审核投诉
  7216. $complaint = Complaint::where('status', 1)
  7217. ->orderBy('updated_at', 'desc')
  7218. // ->limit(5)
  7219. ->get();
  7220. //获取5条用户的book
  7221. $book = Book::where('status', 1)
  7222. ->orderBy('updated_at', 'desc')
  7223. // ->limit(5)
  7224. ->get();
  7225. //获取5条用户的求职 1
  7226. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7227. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7228. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7229. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7230. ->orderBy('updated_at', 'desc')
  7231. // ->limit(5)
  7232. ->get();
  7233. //获取5条用户的求职 2
  7234. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7235. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7236. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7237. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7238. ->orderBy('updated_at', 'desc')
  7239. // ->limit(5)
  7240. ->get();
  7241. //人才库 1
  7242. $job_apply = JobApply::where('job_apply.status', 1)
  7243. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7244. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7245. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7246. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7247. ->select('job_apply.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name', 'job_recruiting.title as job_name')
  7248. ->orderBy('updated_at', 'desc')
  7249. // ->limit(5)
  7250. ->get();
  7251. // 职场机会 2
  7252. $job_resume = JobResume::where('job_resume.status', 1)
  7253. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7254. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7255. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7256. ->select('job_resume.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name')
  7257. ->orderBy('updated_at', 'desc')
  7258. // ->limit(5)
  7259. ->get();
  7260. //待审核数据com pro
  7261. $complany = Company::where('status', 0)
  7262. ->orderBy('updated_at', 'desc')
  7263. // ->limit(5)
  7264. ->get();
  7265. $project = Project::where('status', 0)
  7266. ->orderBy('updated_at', 'desc')
  7267. // ->limit(5)
  7268. ->get();
  7269. $count =
  7270. // count($chat) +
  7271. // count($chat_group) +
  7272. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7273. + count($job_apply)
  7274. + count($job_resume)
  7275. + count($complany)
  7276. + count($project);
  7277. $result = [
  7278. 'apply_articale' => $apply_articale,
  7279. // 'chat' => $chat,
  7280. // 'chat_group' => $chat_group,
  7281. 'good' => $good,
  7282. 'notice' => $notice,
  7283. 'complaint' => $complaint,
  7284. 'book' => $book,
  7285. 'job_hunting' => $job_hunting,
  7286. 'job_recruiting' => $job_recruiting,
  7287. 'job_apply' => $job_apply,
  7288. 'job_resume' => $job_resume,
  7289. 'complany' => $complany,
  7290. 'project' => $project,
  7291. 'count' => $count,
  7292. ];
  7293. } elseif ($type_id == 20000) {
  7294. }
  7295. var_dump($type_id, '-----------------test---------');
  7296. return Result::success($result);
  7297. }
  7298. /**
  7299. * @param array $data
  7300. * @return array
  7301. */
  7302. public function getWebsiteProject(array $data): array
  7303. {
  7304. $categorys = json_decode($data['id'], true);
  7305. if (!empty($categorys)) {
  7306. $category_arr = $this->processArticlePro($data['website_id']);
  7307. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7308. $catiall = $category_arr['catiall'];
  7309. // return Result::success($catiall);
  7310. foreach ($categorys as $key => $val) {
  7311. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7312. $level = explode(',', $val['level'])[0];
  7313. $imgnum = explode(',', $val['level'])[1] ?? null;
  7314. $textnum = explode(',', $val['level'])[2] ?? null;
  7315. if ($level == 1) {
  7316. if (!empty($textnum) && $textnum > 0) {
  7317. $text_num = Project::where('level', $level)
  7318. ->where('website_id', $data['website_id'])
  7319. ->where('status', 1)
  7320. ->select(
  7321. 'project.id',
  7322. 'project.title',
  7323. 'project.description',
  7324. 'project.updated_at',
  7325. 'project.category_id',
  7326. 'project.cat_arr_id'
  7327. )
  7328. ->orderBy('updated_at', 'desc')
  7329. ->limit($textnum)
  7330. ->get()->all();
  7331. }
  7332. if (!empty($imgnum) && $imgnum > 0) {
  7333. $img_num = Project::where('level', $level)
  7334. ->where('website_id', $data['website_id'])
  7335. ->where('status', 1)
  7336. ->where('imgurl', '!=', '')
  7337. ->whereNotNull('imgurl')
  7338. ->select(
  7339. 'project.id',
  7340. 'project.title',
  7341. 'project.description',
  7342. 'project.updated_at',
  7343. 'project.imgurl as imgs',
  7344. 'project.category_id',
  7345. 'project.cat_arr_id'
  7346. )
  7347. ->orderBy('updated_at', 'desc')
  7348. ->limit($imgnum)
  7349. ->get()->all();
  7350. }
  7351. } else {
  7352. if (!empty($textnum) && $textnum > 0) {
  7353. $text_num = Project::where('website_id', $data['website_id'])
  7354. ->where('status', 1)
  7355. ->select(
  7356. 'project.id',
  7357. 'project.title',
  7358. 'project.description',
  7359. 'project.updated_at',
  7360. 'project.category_id',
  7361. 'project.cat_arr_id',
  7362. 'project.website_id',
  7363. 'project.updated_at',
  7364. 'project.created_at'
  7365. )
  7366. ->orderBy('updated_at', 'desc')
  7367. ->limit($textnum)
  7368. ->get()->all();
  7369. }
  7370. if (!empty($imgnum) && $imgnum > 0) {
  7371. $img_num = Project::where('website_id', $data['website_id'])
  7372. ->where('status', 1)
  7373. ->where('imgurl', '!=', '')
  7374. ->whereNotNull('imgurl')
  7375. ->select(
  7376. 'project.id',
  7377. 'project.title',
  7378. 'project.description',
  7379. 'project.updated_at',
  7380. 'project.imgurl as imgs',
  7381. 'project.category_id',
  7382. 'project.cat_arr_id'
  7383. )
  7384. ->orderBy('updated_at', 'desc')
  7385. ->limit($imgnum)
  7386. ->get()->all();
  7387. }
  7388. }
  7389. }
  7390. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7391. $category_ids = explode(',', $val['id'])[0];
  7392. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7393. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7394. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7395. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7396. $text_num = Project::whereIn('category_id', $category_arr)
  7397. ->where('website_id', $data['website_id'])
  7398. ->where('status', 1)
  7399. ->select(
  7400. 'project.id',
  7401. 'project.title',
  7402. 'project.description',
  7403. 'project.updated_at',
  7404. 'project.category_id',
  7405. 'project.cat_arr_id'
  7406. )
  7407. ->orderBy('updated_at', 'desc')
  7408. ->limit($cat_textnum)
  7409. ->get()->all();
  7410. }
  7411. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7412. $img_num = Project::whereIn('category_id', $category_arr)
  7413. ->where('website_id', $data['website_id'])
  7414. ->where('status', 1)
  7415. ->where('imgurl', '!=', '')
  7416. ->whereNotNull('imgurl')
  7417. ->select(
  7418. 'project.id',
  7419. 'project.title',
  7420. 'project.description',
  7421. 'project.updated_at',
  7422. 'project.imgurl as imgs',
  7423. 'project.category_id',
  7424. 'project.cat_arr_id'
  7425. )
  7426. ->orderBy('updated_at', 'desc')
  7427. ->limit($cat_imgnum)
  7428. ->get()->all();
  7429. }
  7430. }
  7431. if (!empty($img_num)) {
  7432. foreach ($img_num as $k => $v) {
  7433. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7434. $imgurl = json_decode($v['imgs'], true);
  7435. if (!empty($imgurl)) {
  7436. $img_num[$k]->imgurl = $imgurl[0];
  7437. }
  7438. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7439. }
  7440. }
  7441. if (!empty($text_num)) {
  7442. foreach ($text_num as $k => $v) {
  7443. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7444. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7445. }
  7446. }
  7447. $project[$key]['img_num'] = $img_num ?? [];
  7448. $project[$key]['text_num'] = $text_num ?? [];
  7449. }
  7450. }
  7451. if (empty($project)) {
  7452. return Result::error("暂无相关项目信息", 0);
  7453. }
  7454. return Result::success($project);
  7455. }
  7456. /**
  7457. * @param array $data
  7458. * @return array
  7459. */
  7460. public function getWebsiteProjectInfo(array $data): array
  7461. {
  7462. $project = Project::where('id', $data['id'])
  7463. ->where('status', 1)
  7464. ->where('website_id', $data['website_id'])
  7465. ->select('project.*')
  7466. ->first();
  7467. if (empty($project)) {
  7468. return Result::error("暂无相关项目信息", 0);
  7469. }
  7470. return Result::success($project);
  7471. }
  7472. /**
  7473. * @param array $data
  7474. * @return array
  7475. */
  7476. public function getWebsiteProjectList(array $data): array
  7477. {
  7478. $where = [];
  7479. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7480. $where['category_id'] = $data['category_id'];
  7481. }
  7482. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7483. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7484. }
  7485. $query = Project::where($where)
  7486. ->where('status', 1)
  7487. ->where('website_id', $data['website_id'])
  7488. ->select(
  7489. 'project.id',
  7490. 'project.title',
  7491. 'project.description',
  7492. 'project.imgurl as imgs',
  7493. 'project.category_id',
  7494. 'project.cat_arr_id'
  7495. )
  7496. ->orderBy('updated_at', 'desc');
  7497. $count = $query->count();
  7498. $project = $query->clone()
  7499. ->offset(($data['page'] - 1) * $data['pageSize'])
  7500. ->limit($data['pageSize'])
  7501. ->get()->all();
  7502. if (empty($project)) {
  7503. return Result::error("暂无相关项目信息", 0);
  7504. }
  7505. $categorys = $this->processArticlePro($data['website_id']);
  7506. $catiall = $categorys['catiall'];
  7507. foreach ($project as $key => $val) {
  7508. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7509. if (!empty($val['imgs'])) {
  7510. $imgurl = json_decode($val['imgs'], true);
  7511. if (!empty($imgurl)) {
  7512. $project[$key]->imgurl = $imgurl[0];
  7513. }
  7514. } else {
  7515. $project[$key]->imgurl = '';
  7516. }
  7517. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7518. }
  7519. $result = [
  7520. 'rows' => $project,
  7521. 'count' => $count,
  7522. ];
  7523. return Result::success($result);
  7524. }
  7525. /**
  7526. * @param array $data
  7527. * @return array
  7528. */
  7529. public function getWebsiteCategoryJob(array $data): array
  7530. {
  7531. $categorys = json_decode($data['id'], true);
  7532. if (!empty($categorys)) {
  7533. $category_arr = $this->processArticlePro($data['website_id']);
  7534. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7535. $catiall = $category_arr['catiall'];
  7536. foreach ($categorys as $key => $val) {
  7537. if (isset($val['id']) && !empty($val['id'])) {
  7538. $catid = explode(',', $val['id'])[0] ?? null;
  7539. $type = explode(',', $val['id'])[1] ?? null;
  7540. $textnum = explode(',', $val['id'])[2] ?? null;
  7541. }
  7542. // 4:招聘;5:求职;
  7543. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7544. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7545. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7546. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7547. ->where('job_recruiting.status', 1)
  7548. ->where('job_recruiting.website_id', $data['website_id'])
  7549. ->select(
  7550. 'job_recruiting.id',
  7551. 'job_recruiting.title',
  7552. 'job_company.business_name',
  7553. 'job_recruiting.updated_at',
  7554. 'job_recruiting.cat_arr_id'
  7555. )
  7556. ->orderBy('job_recruiting.updated_at', 'desc')
  7557. ->limit($textnum)
  7558. ->get()->all();
  7559. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7560. // 状态 审核状态,1待审核2已审核3已拒绝
  7561. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7562. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7563. ->where('job_hunting.status', 2)
  7564. ->where('job_hunting.website_id', $data['website_id'])
  7565. ->select(
  7566. 'job_hunting.id',
  7567. 'job_hunting.name',
  7568. 'job_hunting.cat_arr_id',
  7569. 'job_position.zwname as job_name',
  7570. 'job_hunting.updated_at'
  7571. )
  7572. ->orderBy('updated_at', 'desc')
  7573. ->limit($textnum)
  7574. ->get()->all();
  7575. } else {
  7576. $job = [];
  7577. }
  7578. // var_dump($catid.'222uuuuuuu'.$key);
  7579. if (!empty($job)) {
  7580. foreach ($job as $k => $value) {
  7581. if (isset($value->cat_arr_id)) {
  7582. $catArr = json_decode($value->cat_arr_id, true);
  7583. $catId = end($catArr);
  7584. } else {
  7585. continue;
  7586. }
  7587. if (isset($catiall[$catId])) {
  7588. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7589. }
  7590. }
  7591. }
  7592. // var_dump($catid.'xxxxx'.$key);
  7593. $result[$key] = $job ?? [];
  7594. }
  7595. }
  7596. if (empty($result)) {
  7597. return Result::error("暂无相关分类信息", 0);
  7598. }
  7599. return Result::success($result);
  7600. }
  7601. /**
  7602. * 发送消息
  7603. * @param array $messageData
  7604. * @return void
  7605. */
  7606. public function sendMessage($messageData)
  7607. {
  7608. $msg = [
  7609. 'talk_type' => $messageData['talk_type'],
  7610. 'title' => $messageData['title'],
  7611. 'content' => $messageData['content'],
  7612. 'messageType' => $messageData['messageType'],
  7613. 'user_id' => $messageData['user_id'] ?? '',
  7614. 'time' => microtime(),
  7615. ];
  7616. $message = new MqProducer($msg);
  7617. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7618. $producer->produce($message);
  7619. }
  7620. }