NewsService.php 205 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663
  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 Illuminate\Support\Facades\Cache;
  55. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  56. class NewsService implements NewsServiceInterface
  57. {
  58. #[Inject]
  59. protected Redis $redis;
  60. /**
  61. * 获取导航池列表
  62. * @param array $data
  63. * @return array
  64. */
  65. public function getCategoryList(array $data): array
  66. {
  67. $search = $data['name'] ?? '';
  68. $page = (int)($data['page'] ?? 1);
  69. $perPage = (int)($data['pageSize'] ?? 10);
  70. // 1. 查出所有匹配的分类id
  71. if ($search) {
  72. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  73. if (empty($matchedIds)) {
  74. return Result::success(['rows' => [], 'total' => 0]);
  75. }
  76. // 2. 递归查所有父级,直到一级分类
  77. $idsStr = implode(',', $matchedIds);
  78. $sql = "
  79. WITH RECURSIVE parents AS (
  80. SELECT * FROM category WHERE id IN ($idsStr)
  81. UNION ALL
  82. SELECT c.* FROM category c
  83. INNER JOIN parents p ON c.id = p.pid
  84. )
  85. SELECT * FROM parents
  86. ";
  87. $parents = Db::select($sql);
  88. $parentIds = [];
  89. foreach ($parents as $row) {
  90. if ($row->pid == 0) {
  91. $parentIds[] = $row->id;
  92. }
  93. }
  94. $parentIds = array_unique($parentIds);
  95. } else {
  96. // 没有搜索,一级分类就是根
  97. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  98. }
  99. // 3. 一级分类分页
  100. $total = count($parentIds);
  101. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  102. if (empty($parentIds)) {
  103. return Result::success(['rows' => [], 'total' => $total]);
  104. }
  105. // 4. 递归查所有子孙
  106. $idsStr = implode(',', $parentIds);
  107. $sql = "
  108. WITH RECURSIVE subcategories AS (
  109. SELECT * FROM category WHERE id IN ($idsStr)
  110. UNION ALL
  111. SELECT c.* FROM category c
  112. INNER JOIN subcategories s ON c.pid = s.id
  113. )
  114. SELECT * FROM subcategories ORDER BY updated_at DESC
  115. ";
  116. $allCategories = Db::select($sql);
  117. // 5. 组装树结构
  118. $categoryMap = [];
  119. foreach ($allCategories as $cat) {
  120. $cat = (array)$cat;
  121. $cat['children'] = [];
  122. $categoryMap[$cat['id']] = $cat;
  123. }
  124. foreach ($categoryMap as $id => &$cat) {
  125. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  126. $categoryMap[$cat['pid']]['children'][] = &$cat;
  127. }
  128. }
  129. unset($cat);
  130. $categoryTree = [];
  131. foreach ($parentIds as $id) {
  132. if (isset($categoryMap[$id])) {
  133. $categoryTree[] = $categoryMap[$id];
  134. }
  135. }
  136. return Result::success([
  137. 'rows' => $categoryTree,
  138. 'total' => $total,
  139. ]);
  140. }
  141. private function findMatchedCategories($search)
  142. {
  143. if ($search) {
  144. return Category::where('name', 'like', "%{$search}%")
  145. ->orderBy('updated_at', 'desc')
  146. ->get();
  147. }
  148. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  149. ->get();
  150. }
  151. private function findAllParents($categories)
  152. {
  153. $allCategories = [];
  154. foreach ($categories as $category) {
  155. $parentId = $category->pid;
  156. while ($parentId > 0) {
  157. $parent = Category::find($parentId);
  158. if ($parent) {
  159. $allCategories[$parent->id] = $parent;
  160. $parentId = $parent->pid;
  161. } else {
  162. break;
  163. }
  164. }
  165. $allCategories[$category->id] = $category;
  166. }
  167. return array_values($allCategories);
  168. }
  169. private function buildCategoryTree($category, $allRequiredCategories)
  170. {
  171. $categoryData = $category->toArray();
  172. $children = [];
  173. foreach ($allRequiredCategories as $c) {
  174. if ($c->pid === $category->id) {
  175. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  176. }
  177. }
  178. if (!empty($children)) {
  179. $categoryData['children'] = $children;
  180. }
  181. return $categoryData;
  182. }
  183. public function myCategoryList(array $data): array
  184. {
  185. $sszq = $data['sszq'] ?? '';
  186. unset($data['sszq']);
  187. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  188. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  189. $where[] = [
  190. 'pid',
  191. '=',
  192. $data['pid'],
  193. ];
  194. if (isset($data['name'])) {
  195. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  196. }
  197. var_dump($where);
  198. //根据分类id,从category表中取出分类信息
  199. $result = Category::where($where)
  200. ->whereIn('category.id', $catorytids)
  201. ->select('category.*', 'category.id as category_id')->get();
  202. if (empty($result)) {
  203. return Result::error("没有栏目数据");
  204. }
  205. return Result::success($result);
  206. }
  207. /**
  208. * @param array $data
  209. * @return array
  210. */
  211. public function categoryList(array $data): array
  212. {
  213. $where[] = [
  214. 'pid',
  215. '=',
  216. $data['pid']
  217. ];
  218. if (isset($data['name'])) {
  219. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  220. }
  221. var_dump($where);
  222. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  223. if (empty($result)) {
  224. return Result::error("没有栏目数据");
  225. }
  226. return Result::success($result);
  227. }
  228. /**
  229. * @param array $data
  230. * @return array
  231. */
  232. public function addCategory(array $data): array
  233. {
  234. if (isset($data['id'])) {
  235. unset($data['id']);
  236. }
  237. $id = Category::insertGetId($data);
  238. if (empty($id)) {
  239. return Result::error("添加失败");
  240. }
  241. return Result::success(['id' => $id]);
  242. }
  243. /**
  244. * @param array $data
  245. * @return array
  246. */
  247. public function delCategory(array $data): array
  248. {
  249. Db::beginTransaction();
  250. try {
  251. $categoryList = Category::where(['pid' => $data['id']])->get();
  252. if ($categoryList->toArray()) {
  253. Db::rollBack();
  254. return Result::error("分类下面有子分类不能删除");
  255. }
  256. $articleList = Article::where(['catid' => $data['id']])->get();
  257. if ($articleList->toArray()) {
  258. Db::rollBack();
  259. return Result::error("分类下面有资讯不能删除");
  260. }
  261. $result = Category::where($data)->delete();
  262. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  263. if (!$result) {
  264. return Result::error("删除失败");
  265. }
  266. return Result::success($result);
  267. Db::commit();
  268. } catch (\Exception $e) {
  269. Db::rollBack();
  270. return Result::error("删除失败");
  271. }
  272. }
  273. /**
  274. * @param array $data
  275. * @return array
  276. */
  277. public function updateCategory(array $data): array
  278. {
  279. $where = [
  280. 'id' => $data['id'],
  281. ];
  282. $result = Category::where($where)->update($data);
  283. if ($result) {
  284. return Result::success($result);
  285. } else {
  286. return Result::error("更新失败");
  287. }
  288. }
  289. /**
  290. * 获取导航池信息
  291. * @param array $data
  292. * @return array
  293. */
  294. public function getCategoryInfo(array $data): array
  295. {
  296. $where = [
  297. 'id' => $data['id'],
  298. ];
  299. $result = Category::where($where)->first();
  300. if ($result) {
  301. return Result::success($result);
  302. } else {
  303. return Result::error("更新失败");
  304. }
  305. }
  306. /**
  307. * @param array $data
  308. * @return array
  309. */
  310. public function getArticleList(array $data): array
  311. {
  312. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  313. $type_id = $data['type_id'];
  314. unset($data['type_id']);
  315. $user_id = $data['user_id'];
  316. unset($data['user_id']);
  317. $where = [];
  318. $status1 = [];
  319. if (isset($data['id']) && $data['id']) {
  320. array_push($where, ['article.id', '=', $data['id']]);
  321. }
  322. if (isset($data['title']) && $data['title']) {
  323. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  324. }
  325. if (isset($data['category_name']) && $data['category_name']) {
  326. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  327. }
  328. if (isset($data['author']) && $data['author']) {
  329. array_push($where, ['article.author', '=', $data['author']]);
  330. }
  331. if (isset($data['islink']) && $data['islink'] !== "") {
  332. array_push($where, ['article.islink', '=', $data['islink']]);
  333. }
  334. if (isset($data['status']) && $data['status'] !== "") {
  335. array_push($where, ['article.status', '=', $data['status']]);
  336. }
  337. if (isset($data['status1'])) {
  338. $status1 = json_decode(($data['status1']));
  339. }
  340. //不是管理员展示个人数据;
  341. if ($type_id != 10000) {
  342. $where[] = ['article.admin_user_id', '=', $user_id];
  343. }
  344. $rep = Article::where($where)
  345. ->whereNotIn('article.status', [404])
  346. ->when($status1, function ($query) use ($status1) {
  347. if (isset($status1) && $status1) {
  348. $query->whereIn('article.status', $status1);
  349. }
  350. })
  351. ->leftJoin('category', 'article.catid', 'category.id')
  352. ->leftJoin('website_category', function ($join) {
  353. $join->on('article.web_site_id', '=', 'website_category.website_id')
  354. ->on('article.catid', '=', 'website_category.category_id');
  355. })
  356. ->select("article.*", "category.name as category_name", "website_category.alias")
  357. ->orderBy("article.updated_at", "desc")
  358. ->limit($data['pageSize'])
  359. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  360. $count = Article::where($where)->whereNotIn('article.status', [404])
  361. ->when($status1, function ($query) use ($status1) {
  362. if (isset($status1) && $status1) {
  363. $query->whereIn('article.status', $status1);
  364. }
  365. })
  366. ->leftJoin('category', 'article.catid', 'category.id')->count();
  367. $data = [
  368. 'rows' => $rep->toArray(),
  369. 'count' => $count,
  370. ];
  371. if (empty($rep)) {
  372. return Result::error("没有信息数据");
  373. }
  374. return Result::success($data);
  375. }
  376. /**
  377. * @param array $data
  378. * @return array
  379. */
  380. public function addArticle(array $data): array
  381. {
  382. var_dump($data, '----------12-----------1');
  383. unset($data['user_type']);
  384. unset($data['nav_add_pool_id']);
  385. // unset($data['commend_id']);
  386. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  387. Db::beginTransaction();
  388. try {
  389. //处理投票
  390. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  391. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  392. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  393. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  394. unset($data['is_survey']);
  395. unset($data['survey_name']);
  396. unset($data['suvey_array']);
  397. // unset($data['website_id']);
  398. // unset($data['web_site_id']);
  399. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  400. if ($data['hits'] == '') {
  401. $data['hits'] = 0;
  402. }
  403. if ($data['is_original'] == '') {
  404. $data['is_original'] = 0;
  405. }
  406. if ($data['status'] == '') {
  407. $data['status'] = 0;
  408. }
  409. $articleData = $data;
  410. unset($articleData['content']);
  411. //自动处理缩略图、关键字、描述
  412. if ($articleData['imgurl'] == '') {
  413. //如果没有图,设置level=0
  414. $levelArr = json_decode($articleData['level'], true);
  415. var_dump($levelArr, '----------levelArr-----------1');
  416. //content中提取图片第一个图,正则提取
  417. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  418. preg_match_all($reg, $data['content'], $matches);
  419. if (isset($matches[1][0])) {
  420. //截取varchar240
  421. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  422. //如果有图,设置level=3
  423. if (!in_array(3, $levelArr)) {
  424. $levelArr[] = 3;
  425. }
  426. $articleData['level'] = json_encode($levelArr);
  427. } else {
  428. if (!in_array(0, $levelArr)) {
  429. $levelArr[] = 0;
  430. }
  431. $articleData['level'] = json_encode($levelArr);
  432. }
  433. }
  434. var_dump($articleData['level'], '----------$articleData[level]----------1');
  435. if ($articleData['keyword'] == '') {
  436. //提取标题+内容中的关键词
  437. $articleData['keyword'] = $data['title'];
  438. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  439. Jieba::init(); // 初始化 jieba-php
  440. Finalseg::init();
  441. $segList = Jieba::cut($articleData['keyword']);
  442. $segList1 = array_slice($segList, 0, 8);
  443. $articleData['keyword'] = implode(',', $segList1);
  444. }
  445. if ($articleData['introduce'] == '') {
  446. //提取内容中的描述
  447. $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  448. }
  449. $id = Article::insertGetId($articleData);
  450. $articleDataContent = [
  451. 'article_id' => $id,
  452. 'content' => $data['content'],
  453. ];
  454. ArticleData::insertGetId($articleDataContent);
  455. //处理投票
  456. if ($is_survey == 1) {
  457. //生成年月日时分秒+8位随机数
  458. $uuid = date('YmdHis') . rand(10000000, 99999999);
  459. var_dump($suvey_array, 'suvey_array________');
  460. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  461. var_dump($suveys_array, '---------------------1');
  462. var_dump($suvey_array, '---------------------2');
  463. $suvey_data = [];
  464. foreach ($suveys_array as $key => $value) {
  465. if ($value == '') {
  466. continue;
  467. }
  468. if (is_array($value)) {
  469. $suvey_data[] = [
  470. 'sur_id' => $uuid,
  471. 'art_id' => $id,
  472. 'website_id' => $website_id ?? 2,
  473. 'survey_name' => $survey_name,
  474. 'choice_name' => $value[1],
  475. 'is_other' => 1,
  476. 'other_id' => 0,
  477. 'results' => 0,
  478. ];
  479. } else {
  480. $suvey_data[] = [
  481. 'sur_id' => $uuid,
  482. 'art_id' => $id,
  483. 'website_id' => $website_id ?? 2,
  484. 'survey_name' => $survey_name,
  485. 'choice_name' => $value,
  486. 'is_other' => 0,
  487. 'other_id' => 0,
  488. 'results' => 0,
  489. ];
  490. }
  491. if (empty($suvey_data)) {
  492. throw new \Exception("投票数据为空");
  493. }
  494. }
  495. $result = ArticleSurvey::insert($suvey_data);
  496. if (!$result) {
  497. throw new \Exception("投票失败,ArticleSurvey插入失败");
  498. }
  499. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  500. if (!$result) {
  501. throw new \Exception("投票失败,更新主表失败");
  502. }
  503. }
  504. Db::commit();
  505. return Result::success(['id' => $id]);
  506. } catch (\Throwable $ex) {
  507. Db::rollBack();
  508. var_dump($ex->getMessage());
  509. return Result::error("创建失败", 0);
  510. }
  511. }
  512. /**
  513. * @param array $data
  514. * @return array
  515. */
  516. public function delArticle(array $data): array
  517. {
  518. $result = Article::where($data)->delete();
  519. //survey投票删除
  520. articleSurvey::where(['art_id' => $data['id']])->delete();
  521. if (!$result) {
  522. return Result::error("删除失败");
  523. }
  524. return Result::success($result);
  525. }
  526. /**
  527. * @param array $data
  528. * @return array
  529. */
  530. public function updateArticle(array $data): array
  531. {
  532. var_dump($data, '----------12-----------1');
  533. Db::beginTransaction();
  534. unset($data['user_type']);
  535. // unset($data['web_site_id']);
  536. unset($data['nav_add_pool_id']);
  537. try {
  538. //处理投票
  539. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  540. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  541. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  542. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  543. unset($data['is_survey']);
  544. unset($data['survey_name']);
  545. unset($data['suvey_array']);
  546. unset($data['website_id']);
  547. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  548. if ($data['hits'] == '') {
  549. $data['hits'] = 0;
  550. }
  551. if ($data['is_original'] == '') {
  552. $data['is_original'] = 0;
  553. }
  554. if ($data['status'] == '') {
  555. $data['status'] = 0;
  556. }
  557. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  558. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  559. $articleData = $data;
  560. unset($articleData['content']);
  561. unset($articleData['status_name']);
  562. unset($articleData['name']);
  563. unset($articleData['content']);
  564. unset($articleData['pid_arr']);
  565. unset($articleData['pid']);
  566. //自动处理缩略图、关键字、描述
  567. if ($articleData['imgurl'] == '') {
  568. //如果没有图,设置level=0
  569. $levelArr = json_decode($articleData['level'], true);
  570. var_dump($levelArr, '----------levelArr-----------1');
  571. //content中提取图片第一个图,正则提取
  572. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  573. preg_match_all($reg, $data['content'], $matches);
  574. if (isset($matches[1][0])) {
  575. //截取varchar240
  576. // 截取到第一个<
  577. $articleData['imgurl'] = $matches[1][0];
  578. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  579. $pos = strpos($articleData['imgurl'], '"');
  580. if ($pos !== false) {
  581. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  582. }
  583. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  584. //如果有图,设置level=3
  585. if (!in_array(3, $levelArr)) {
  586. $levelArr[] = 3;
  587. }
  588. $articleData['level'] = json_encode($levelArr);
  589. } else {
  590. if (!in_array(0, $levelArr)) {
  591. $levelArr[] = 0;
  592. }
  593. $articleData['level'] = json_encode($levelArr);
  594. }
  595. }
  596. var_dump($articleData['level'], '----------$articleData[level]----------1');
  597. if ($articleData['keyword'] == '') {
  598. //提取标题+内容中的关键词
  599. $articleData['keyword'] = $data['title'];
  600. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  601. Jieba::init(); // 初始化 jieba-php
  602. Finalseg::init();
  603. $segList = Jieba::cut($articleData['keyword']);
  604. $segList1 = array_slice($segList, 0, 8);
  605. $articleData['keyword'] = implode(',', $segList1);
  606. }
  607. if ($articleData['introduce'] == '') {
  608. //提取内容中的描述
  609. $articleData['introduce'] = substr(preg_replace('/\s+/', '', strip_tags($data['content'])), 0, 100);
  610. // substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  611. }
  612. $id = Article::where(['id' => $data['id']])->update($articleData);
  613. $articleDataContent = [
  614. 'content' => $data['content'],
  615. ];
  616. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  617. //处理投票
  618. $id = $data['id'];
  619. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  620. var_dump($suvey_array, 'suvey_array________delete');
  621. //处理投票
  622. if ($is_survey == 1) {
  623. //生成年月日时分秒+8位随机数
  624. $uuid = date('YmdHis') . rand(10000000, 99999999);
  625. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  626. var_dump($suveys_array, '---------------------1');
  627. $suvey_data = [];
  628. if (is_array($suveys_array)) {
  629. foreach ($suveys_array as $key => $value) {
  630. if ($value == '') {
  631. continue;
  632. }
  633. if (is_array($value)) {
  634. $suvey_data[] = [
  635. 'sur_id' => $uuid,
  636. 'art_id' => $id,
  637. 'website_id' => $website_id ?? 2,
  638. 'survey_name' => $survey_name,
  639. 'choice_name' => $value[1],
  640. 'is_other' => 1,
  641. 'other_id' => 0,
  642. 'results' => 0,
  643. ];
  644. } else {
  645. $suvey_data[] = [
  646. 'sur_id' => $uuid,
  647. 'art_id' => $id,
  648. 'website_id' => $website_id ?? 2,
  649. 'survey_name' => $survey_name,
  650. 'choice_name' => $value,
  651. 'is_other' => 0,
  652. 'other_id' => 0,
  653. 'results' => 0,
  654. ];
  655. }
  656. if (empty($suvey_data)) {
  657. throw new \Exception("投票数据为空");
  658. }
  659. }
  660. }
  661. $result = ArticleSurvey::insert($suvey_data);
  662. if (!$result) {
  663. throw new \Exception("投票失败");
  664. }
  665. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  666. if (!$result) {
  667. throw new \Exception("投票失败");
  668. }
  669. } else {
  670. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  671. }
  672. Db::commit();
  673. return Result::success([]);
  674. } catch (\Throwable $ex) {
  675. Db::rollBack();
  676. var_dump($ex->getMessage());
  677. return Result::error("更新失败" . $ex->getMessage(), 0);
  678. }
  679. }
  680. /**
  681. * 更新资讯状态
  682. * @param array $data
  683. * @return array
  684. */
  685. public function upArticleStatus(array $data): array
  686. {
  687. $result = Article::where(['id' => $data['id']])->update($data);
  688. if ($result) {
  689. return Result::success();
  690. } else {
  691. return Result::error("更新状态失败", 0);
  692. }
  693. }
  694. /**
  695. * 获取新闻详情
  696. * @param array $data
  697. * @return array
  698. */
  699. public function getArticleInfo(array $data): array
  700. {
  701. $where = [
  702. 'article.id' => $data['id'],
  703. // 'article.status' => 1,
  704. ];
  705. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  706. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  707. $info = $result;
  708. // var_dump($info, 'info');
  709. $info['survey_array'] = $articleSurvey;
  710. if ($result) {
  711. return Result::success($info);
  712. } else {
  713. return Result::error("查询失败", 0);
  714. }
  715. }
  716. /**
  717. * 获取头条新闻
  718. * @param array $data
  719. * @return array
  720. */
  721. public function getWebsiteArticlett(array $data): array
  722. {
  723. // return Result::success($data['website_id']);
  724. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  725. $category = array_values(array_unique($category->toArray()));
  726. $web['website_id'] = $data['website_id'];
  727. if ($category) {
  728. $where = [
  729. 'status' => 1,
  730. ];
  731. var_dump($data, 'data-----------------');
  732. // level=7 根据文章key来匹配文章
  733. if (isset($data['level']) && $data['level'] == 7) {
  734. // 根据文章id获取key
  735. // $data['id'] = 50142;
  736. if (isset($data['id']) && !empty($data['id'])) {
  737. $keyword = Article::where('id', $data['id'])->value('keyword');
  738. $keywordArray = explode(',', $keyword);
  739. $whereL7 = [];
  740. foreach ($keywordArray as $k => $v) {
  741. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  742. }
  743. // 原始查询
  744. $result['level7'] = Article::where($whereL7)
  745. ->when(!empty($data['imgnum']), function ($query) use ($data) {
  746. $query->where('article.imgurl', '!=', '')
  747. ->select('article.*')
  748. ->offset($data['placeid'])
  749. ->limit($data['imgnum']);
  750. })
  751. ->when(!empty($data['textnum']), function ($query) use ($data) {
  752. $query->select('article.*')
  753. ->offset($data['placeid'])
  754. ->limit($data['textnum']);
  755. })
  756. ->orderBy('updated_at', 'desc')
  757. ->get();
  758. $result['level7'] = $this->processArticle($result['level7'], $web);
  759. if (empty($result)) {
  760. return Result::success();
  761. }
  762. return Result::success($result);
  763. } else {
  764. return Result::error("参数错误level=7,id不能为空", 0);
  765. }
  766. }
  767. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  768. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  769. var_dump($where, 'where-----------------');
  770. // 初始化基础查询
  771. $query = Article::where($where)
  772. ->whereIn("catid", $category)
  773. ->where(function ($query) use ($data) {
  774. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  775. ->orWhereNull("ignore_ids");
  776. });
  777. // 处理 level 相关查询条件
  778. $query->when($data['level'] == 5, function ($query) {
  779. $query->inRandomOrder()
  780. ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  781. })->when($data['level'] == 4, function ($query) {
  782. $query->orderBy("article.updated_at", "desc");
  783. })->when(!empty($data['level']), function ($query) use ($data) {
  784. if ($data['level'] != 4 && $data['level'] != 5) {
  785. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  786. ->orderBy("article.updated_at", "desc");
  787. }
  788. });
  789. // 初始化结果数组
  790. $result = [];
  791. // $input = $data['website_id'];
  792. // 处理图片新闻查询
  793. if (!empty($data['imgnum'])) {
  794. // 原错误提示表明 cleanBindings 方法需要传入数组类型的参数,而实际传入了 null。
  795. // 这里克隆查询构建器,确保绑定参数为数组,避免该错误。
  796. $imgQuery = clone $query;
  797. if ($imgQuery->getBindings() === null) {
  798. $imgQuery->setBindings([]);
  799. }
  800. $result['img'] = $imgQuery->where('article.imgurl', '!=', '')
  801. ->select(
  802. 'article.id',
  803. 'article.title',
  804. 'article.imgurl',
  805. 'article.author',
  806. 'article.updated_at',
  807. 'article.introduce',
  808. 'article.islink',
  809. 'article.linkurl',
  810. 'article.copyfrom',
  811. 'article.cat_arr_id',
  812. 'article.catid'
  813. )
  814. ->offset($data['placeid'])
  815. ->limit($data['imgnum'])
  816. ->get();
  817. $result['img'] = $this->processArticles($result['img'], $web);
  818. }
  819. // 处理文字新闻查询
  820. if (!empty($data['textnum'])) {
  821. $textQuery = clone $query;
  822. $result['text'] = $textQuery
  823. ->select(
  824. 'article.id',
  825. 'article.title',
  826. 'article.imgurl',
  827. 'article.author',
  828. 'article.updated_at',
  829. 'article.introduce',
  830. 'article.islink',
  831. 'article.linkurl',
  832. 'article.copyfrom',
  833. 'article.cat_arr_id',
  834. 'article.catid'
  835. )
  836. ->offset($data['placeid'])
  837. ->limit($data['textnum'])
  838. ->get();
  839. $result['text'] = $this->processArticles($result['text'], $web);
  840. }
  841. if (empty($result) || count($result) == 0) {
  842. return Result::error("暂无头条新闻");
  843. }
  844. return Result::success($result);
  845. } else {
  846. return Result::error("本网站下暂无相关栏目", 0);
  847. }
  848. }
  849. /**
  850. * 获取模块新闻
  851. * @param array $data
  852. * @return array
  853. */
  854. public function getWebsiteModelArticles(array $data): array
  855. {
  856. $catid = $data['catid'];
  857. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  858. $category = $category->toArray();
  859. if (!empty($category)) {
  860. $where = [
  861. 'status' => 1,
  862. 'catid' => $catid,
  863. ];
  864. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  865. // 1:文字新闻;2:轮播图;3:图文;
  866. // 级别:0:未分类
  867. // 3:推荐图片
  868. if ($data['level'] == 1) {
  869. $data['level'] = 0;
  870. }
  871. $result = Article::where($where)
  872. ->where(function ($query) use ($data) {
  873. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  874. ->orWhereNull("level")
  875. ->orWhereRaw("level = '[]'");
  876. })
  877. ->where(function ($query) use ($data) {
  878. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  879. ->orWhereNull("ignore_ids");
  880. })
  881. ->orderBy("updated_at", "desc")
  882. ->offset($placeid)
  883. ->limit($data['pagesize'])
  884. ->get();
  885. if (empty($result)) {
  886. return Result::error("此栏目暂无相关新闻", 0);
  887. }
  888. } else {
  889. return Result::error("此网站暂无此栏目", 0);
  890. }
  891. return Result::success($result);
  892. }
  893. /**
  894. *获取新闻列表
  895. * @param array $data
  896. * @return array
  897. */
  898. public function getWebsiteArticleList(array $data): array
  899. {
  900. // return Result::success($data);
  901. $where[] = ['status', '=', 1];
  902. if (isset($data['catid']) && !empty($data['catid'])) {
  903. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  904. array_push($where, ['catid', '=', $data['catid']]);
  905. if (empty($category)) {
  906. return Result::error("此网站暂无此栏目", 0);
  907. }
  908. }
  909. // return Result::success($where);
  910. $rep = Article::where($where)
  911. ->where(function ($query) use ($data) {
  912. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  913. ->orWhereNull("ignore_ids");
  914. })
  915. ->select(
  916. 'article.id',
  917. 'article.title',
  918. 'article.imgurl',
  919. 'article.author',
  920. 'article.updated_at',
  921. 'article.introduce',
  922. 'article.islink',
  923. 'article.linkurl',
  924. 'article.copyfrom',
  925. 'article.cat_arr_id',
  926. 'article.catid'
  927. )
  928. ->orderBy("updated_at", "desc")
  929. ->offset(($data['page'] - 1) * $data['pageSize'])
  930. ->limit($data['pageSize'])
  931. ->get();
  932. $web['website_id'] = $data['website_id'];
  933. $rep = $this->processArticles($rep, $web);
  934. $count = Article::where($where)
  935. ->where(function ($query) use ($data) {
  936. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  937. ->orWhereNull("ignore_ids");
  938. })->count();
  939. $data = [
  940. 'rows' => $rep->toArray(),
  941. 'count' => $count,
  942. ];
  943. if (empty($rep)) {
  944. return Result::error("没有信息数据");
  945. }
  946. return Result::success($data);
  947. }
  948. /**
  949. * 前端-获取新闻详情
  950. * @param array $data
  951. * @return array
  952. */
  953. public function selectWebsiteArticleInfo(array $data): array
  954. {
  955. $where = [
  956. 'article.id' => $data['id'],
  957. 'article.status' => 1,
  958. ];
  959. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")
  960. ->where(function ($query) use ($data) {
  961. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  962. ->orWhereNull("ignore_ids");
  963. })
  964. ->first();
  965. if (empty($result)) {
  966. return Result::error("暂无此新闻!", 0);
  967. }
  968. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  969. ->select('website_category.*', 'website.website_name', 'website.suffix')
  970. ->where('website_category.website_id', $data['website_id'])
  971. ->where(['website_category.category_id' => $result['catid']])
  972. ->first();
  973. if (empty($category)) {
  974. return Result::error("查询失败", 0);
  975. }
  976. //手动推荐文章
  977. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  978. $commendArticle = Article::whereIn('id', $commend_ids)
  979. ->where('status', 1)
  980. ->select('id', 'title', 'catid', 'imgurl', 'hits', 'created_at')
  981. ->orderBy('updated_at', 'desc')
  982. ->limit(5)
  983. ->get();
  984. $result['category_id'] = $category['category_id'];
  985. $result['cat_name'] = $category['alias'];
  986. $result['website_name'] = $category['website_name'] ?? "";
  987. $result['suffix'] = $category['suffix'] ?? "";
  988. $result['commendArticle'] = $commendArticle;
  989. return Result::success($result);
  990. }
  991. /**
  992. * 前端-获取网站调查问卷
  993. * @param array $data
  994. * @return array
  995. */
  996. public function getWebsiteSurvey(array $data): array
  997. {
  998. if (isset($data['website_id']) && !empty($data['website_id'])) {
  999. $website = Website::where('id', $data['website_id'])->first();
  1000. if (empty($website)) {
  1001. return Result::error("暂无此网站", 0);
  1002. }
  1003. }
  1004. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1005. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1006. if (empty($article)) {
  1007. return Result::error("暂无此文章", 0);
  1008. }
  1009. // return Result::error($data,0);
  1010. $where['art_id'] = $data['art_id'];
  1011. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1012. } else {
  1013. $survey = Article::where(function ($query) {
  1014. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1015. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1016. })
  1017. ->where('status', 1)
  1018. ->where('is_survey', 1)
  1019. ->select('survey_id')
  1020. ->orderBy('updated_at', 'desc')
  1021. ->first();
  1022. if (empty($survey)) {
  1023. return Result::error("暂无调查问卷", 0);
  1024. }
  1025. $where['sur_id'] = $survey['survey_id'];
  1026. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1027. }
  1028. // return Result::success($where);
  1029. $result = ArticleSurvey::where($where)
  1030. ->where(function ($query) {
  1031. $query->where('is_other', 0)
  1032. ->orWhere(function ($subQuery) {
  1033. $subQuery->where('is_other', 1)
  1034. ->where('other_id', 0);
  1035. });
  1036. })
  1037. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1038. ->select('article_survey.*', 'article.survey_type')
  1039. ->get()->all();
  1040. if (empty($result)) {
  1041. return Result::error("此文章暂无调查问卷", 0);
  1042. }
  1043. return Result::success($result);
  1044. }
  1045. /**
  1046. * 前端-添加网站调查问卷选项
  1047. * @param array $data
  1048. * @return array
  1049. */
  1050. public function addWebsiteSurveyOption(array $data): array
  1051. {
  1052. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1053. $website = Website::where('id', $data['website_id'])->first();
  1054. if (empty($website)) {
  1055. return Result::error("暂无此网站", 0);
  1056. }
  1057. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1058. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1059. if (empty($survey)) {
  1060. return Result::error("此调查问卷不可添加选项", 0);
  1061. }
  1062. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1063. $choice = [
  1064. 'art_id' => $survey['art_id'],
  1065. 'website_id' => $data['website_id'],
  1066. 'survey_name' => $survey['survey_name'],
  1067. 'choice_name' => $data['choice_name'],
  1068. 'sur_id' => $survey['sur_id'],
  1069. 'is_other' => 1,
  1070. 'other_id' => $survey['id'],
  1071. ];
  1072. $result = ArticleSurvey::insertGetId($choice);
  1073. if (empty($result)) {
  1074. return Result::error("添加失败", 0);
  1075. }
  1076. return Result::success($result);
  1077. }
  1078. }
  1079. return Result::error("添加失败", 0);
  1080. }
  1081. return Result::error("添加失败", 0);
  1082. }
  1083. /**
  1084. * 前端-调查问卷投票
  1085. * @param array $data
  1086. * @return array
  1087. */
  1088. public function addWebsiteSurveyVote(array $data): array
  1089. {
  1090. // return Result::success($data);
  1091. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1092. $website = Website::where('id', $data['website_id'])->first();
  1093. if (empty($website)) {
  1094. return Result::error("暂无此网站", 0);
  1095. }
  1096. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1097. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1098. // return Result::success($survey);
  1099. if (empty($is_survey)) {
  1100. return Result::error("此调查问卷不存在", 0);
  1101. }
  1102. // return Result::success($survey);
  1103. // 调查问卷类型
  1104. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1105. //多选 若是json型则转化成数组类型
  1106. if (strpos($data['choice_id'], '[') === 0) {
  1107. $data['choice_id'] = json_decode($data['choice_id'], true);
  1108. } else {
  1109. // 单选 也转换成数组
  1110. $data['choice_id'] = [$data['choice_id']];
  1111. }
  1112. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1113. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1114. // ->where('website_id',$data['website_id'])
  1115. ->where('is_other', 1)
  1116. ->where('other_id', 0)
  1117. ->first();
  1118. if (!empty($other)) {
  1119. return Result::error("请选择已有的选项!", 0);
  1120. }
  1121. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1122. // ->where('website_id',$data['website_id'])
  1123. ->where('is_other', 1)
  1124. ->where('other_id', '!=', 0)
  1125. ->first();
  1126. // return Result::success($choice['other']);
  1127. $choice_id = $data['choice_id'];
  1128. if (!empty($choice['other'])) {
  1129. // array_push($data['choice_id'],$choice['other']['other_id']);
  1130. if (!empty($choice_id)) {
  1131. $key = array_search($choice['other']['id'], $choice_id);
  1132. if ($key !== false) {
  1133. unset($choice_id[$key]);
  1134. $choice_id = array_values($choice_id);
  1135. }
  1136. array_push($choice_id, $choice['other']['other_id']);
  1137. } else {
  1138. $choice_id[0] = $choice['other']['other_id'];
  1139. }
  1140. array_push($data['choice_id'], $choice['other']['other_id']);
  1141. }
  1142. // return Result::success($data);
  1143. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1144. // ->where('website_id',$data['website_id'])
  1145. ->increment('results', 1);
  1146. if (empty($choice)) {
  1147. return Result::error("请选择已有的选项!", 0);
  1148. }
  1149. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1150. // ->where('website_id',$data['website_id'])
  1151. ->where('other_id', 0)
  1152. ->get();
  1153. $survey['choice'] = $choice_id;
  1154. return Result::success($survey);
  1155. }
  1156. return Result::error("参数必填!");
  1157. }
  1158. return Result::error("此调查问卷不存在", 0);
  1159. }
  1160. return Result::error("参数必填!");
  1161. }
  1162. /**
  1163. * 后端-获取网站调查问卷列表
  1164. * @param array $data
  1165. * @return array
  1166. */
  1167. public function getSurveyList(array $data): array
  1168. {
  1169. $where = [];
  1170. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1171. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1172. }
  1173. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1174. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1175. }
  1176. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1177. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1178. }
  1179. // return Result::success($where);
  1180. if (!empty($where)) {
  1181. $query = Article::where($where)->where(function ($q) {
  1182. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1183. });
  1184. } else {
  1185. $query = Article::where(function ($q) {
  1186. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1187. });
  1188. }
  1189. $count = $query->count();
  1190. $survey = $query->orderByDesc('id')
  1191. ->limit($data['pageSize'])
  1192. ->offset(($data['page'] - 1) * $data['pageSize'])
  1193. ->get();
  1194. if (empty($survey->toArray())) {
  1195. return Result::error("暂无调查问卷!", 0);
  1196. }
  1197. $result = [
  1198. 'rows' => $survey,
  1199. 'count' => $count,
  1200. ];
  1201. return Result::success($result);
  1202. }
  1203. /**
  1204. * 后端-获取网站调查问卷详情
  1205. * @param array $data
  1206. * @return array
  1207. */
  1208. public function getSurveyInfo(array $data): array
  1209. {
  1210. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1211. $where = ['sur_id' => $data['sur_id']];
  1212. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1213. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1214. ->select('article_survey.*', 'article.survey_type')
  1215. ->get()->all();
  1216. if (empty($choose)) {
  1217. return Result::error("此调查问卷不存在", 0);
  1218. }
  1219. $resultsArray = array_column($choose, 'results');
  1220. $total = array_sum($resultsArray);
  1221. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1222. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1223. // $total = 0;
  1224. if (!empty($other)) {
  1225. $total = $total + $other['results'];
  1226. $other['choice_name'] = '(其他)';
  1227. if (!empty($others)) {
  1228. $other['hasChildren'] = true;
  1229. // array_push($other,['hasChildren','=',true]);
  1230. $other['children'] = $others;
  1231. $other_choices = [$other->toArray()];
  1232. $mer_choice = array_merge($choose, $other_choices);
  1233. $value_choice = array_values($mer_choice);
  1234. } else {
  1235. // return Result::error('1111');
  1236. $other_choices = [$other->toArray()];
  1237. $other_choices = array_merge($choose, $other_choices);
  1238. $value_choice = array_values($other_choices);
  1239. // return Result::success($result);
  1240. }
  1241. } else {
  1242. $value_choice = $choose;
  1243. }
  1244. $result = [
  1245. 'choose' => $value_choice,
  1246. 'total' => $total,
  1247. ];
  1248. }
  1249. return Result::success($result);
  1250. }
  1251. /**
  1252. * 前端-搜索新闻列表
  1253. * @param array $data
  1254. * @return array
  1255. */
  1256. public function selectWebsiteArticle(array $data): array
  1257. {
  1258. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1259. $query = Article::where('status', 1)
  1260. ->whereIn('catid', $category)
  1261. ->where(function ($query) use ($data) {
  1262. $query->where(function ($subQuery) use ($data) {
  1263. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1264. })->orWhereNull("ignore_ids");
  1265. });
  1266. // return Result::success($all_articles);
  1267. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1268. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1269. }
  1270. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1271. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1272. }
  1273. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1274. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1275. }
  1276. // 计算总数
  1277. $count = $query->count();
  1278. // 分页查询
  1279. $articles = $query
  1280. ->select(
  1281. 'article.id',
  1282. 'article.title',
  1283. 'article.imgurl',
  1284. 'article.author',
  1285. 'article.updated_at',
  1286. 'article.introduce',
  1287. 'article.islink',
  1288. 'article.linkurl',
  1289. 'article.copyfrom',
  1290. 'article.cat_arr_id',
  1291. 'article.catid',
  1292. 'article.department_arr_id',
  1293. 'article.city_arr_id',
  1294. )
  1295. ->orderBy("updated_at", "desc")
  1296. ->offset(($data['page'] - 1) * $data['pageSize'])
  1297. ->limit($data['pageSize'])
  1298. ->get();
  1299. $web['website_id'] = $data['website_id'];
  1300. $articles = $this->processArticles($articles, $web);
  1301. if (empty($articles)) {
  1302. return Result::error("没有符合条件的资讯数据");
  1303. }
  1304. $result = [
  1305. 'rows' => $articles,
  1306. 'count' => $count,
  1307. ];
  1308. return Result::success($result);
  1309. }
  1310. /**
  1311. * 模块新闻加强版
  1312. * @param array $data
  1313. * @return array
  1314. */
  1315. public function getWebsiteCatidArticle(array $data): array
  1316. {
  1317. $where = [
  1318. 'website_category.category_id' => $data['catid'],
  1319. 'website_category.website_id' => $data['website_id'],
  1320. ];
  1321. // $category = WebsiteCategory::where($where);
  1322. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1323. $child_catnum = $data['child_catnum'] ?? 1;
  1324. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1325. $childCategoryIds = array_column($category['child'], 'category_id');
  1326. if (empty($childCategoryIds)) {
  1327. return Result::error("暂无子栏目", 0);
  1328. }
  1329. $imgArticles = [];
  1330. $textArticles = [];
  1331. // return Result::success($childCategoryIds);
  1332. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1333. // 初始化子分类图片新闻和文字新闻数组
  1334. // 查询所有子级栏目的图文新闻
  1335. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1336. ->where(function ($query) use ($data) {
  1337. $query->where(function ($subQuery) use ($data) {
  1338. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1339. })->orWhereNull("ignore_ids");
  1340. })
  1341. ->where('status', 1)
  1342. ->where('imgurl', '!=', '')
  1343. ->select('*')
  1344. ->orderBy('updated_at', 'desc')
  1345. ->limit($data['child_imgnum'])
  1346. ->get();
  1347. }
  1348. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1349. // 查询所有子级栏目的文字新闻
  1350. $textArticles = Article::where('catid', $childCategoryIds[0])
  1351. ->where('status', 1)
  1352. ->where(function ($query) use ($data) {
  1353. $query->where(function ($subQuery) use ($data) {
  1354. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1355. })->orWhereNull("ignore_ids");
  1356. })
  1357. ->select('*')
  1358. ->orderBy('updated_at', 'desc')
  1359. ->limit($data['child_textnum'])
  1360. ->get();
  1361. }
  1362. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1363. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1364. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1365. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1366. return $child;
  1367. }, $category['child']);
  1368. }
  1369. // }
  1370. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1371. $category['img'] = WebsiteCategory::where($where)
  1372. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1373. ->where('article.status', 1)
  1374. ->where('article.imgurl', '!=', '')
  1375. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1376. ->orderBy('article.updated_at', 'desc')
  1377. ->limit($data['img_num'])
  1378. ->get();
  1379. }
  1380. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1381. $category['text'] = WebsiteCategory::where($where)
  1382. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1383. ->where('article.status', 1)
  1384. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1385. ->orderBy('article.updated_at', 'desc')
  1386. ->limit($data['text_num'])
  1387. ->get();
  1388. }
  1389. // $category = $category->get();
  1390. if (empty($category)) {
  1391. return Result::error("查询失败", 0);
  1392. }
  1393. return Result::success($category);
  1394. }
  1395. /**
  1396. * 模块新闻加强版
  1397. * @param array $data
  1398. * @return array
  1399. */
  1400. public function getWebsiteAllArticle(array $data): array
  1401. {
  1402. // $redisKey = 'website_cache';
  1403. // $this->redis->hSet($redisKey, $data['website_id'], json_encode($data));
  1404. // $result = $this->redis->sadd($redisKey);
  1405. // 使用缓存键
  1406. // $cacheKey = $data['website_id'];
  1407. // // 尝试从缓存获取数据
  1408. $container = \Hyperf\Context\ApplicationContext::getContainer();
  1409. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  1410. // 修正传入的字符串,将单引号替换为双引号
  1411. $input['id'] = $data['id'];
  1412. $input['website_id'] = $data['website_id'];
  1413. // 将 JSON 字符串转换为 PHP 数组
  1414. $items = json_decode($input['id'], true);
  1415. if (!is_array($items)) {
  1416. return Result::error("无效的JSON格式", 0);
  1417. }
  1418. $website = [
  1419. 'website_id' => $input['website_id'],
  1420. ];
  1421. foreach ($items as $key => $item) {
  1422. if (isset($item['parent']) && $item['parent'] !== "") {
  1423. $parentParams = explode(',', $item['parent']);
  1424. if (isset($parentParams) && $parentParams[0] !== "") {
  1425. $parentCatId[$key] = $parentParams[0];
  1426. }
  1427. } else {
  1428. return Result::error("缺少必需参数错误", 0);
  1429. }
  1430. }
  1431. $pid = WebsiteCategory::whereIn('category_id', $parentCatId)->where($website)->pluck('pid')->toArray();
  1432. // return Result::success($pid);
  1433. if (!empty($pid)) {
  1434. $pid = array_values(array_unique($pid));
  1435. if (count($pid) == 1) {
  1436. $cacheKey = $data['website_id'] . ',' . $pid[0];
  1437. } else {
  1438. return Result::error("参数传递错误", 0);
  1439. }
  1440. }
  1441. // return Result::success($cacheKey);
  1442. if ($cachedData = $cache->get($cacheKey)) {
  1443. return Result::success(unserialize($cachedData));
  1444. }
  1445. try {
  1446. // 提前缓存常用查询结果,减少重复查询
  1447. $categoryCache = [];
  1448. $childCategoryCache = [];
  1449. // 使用 array_map 处理每个元素
  1450. $result = array_map(function ($item) use ($website, &$categoryCache, &$childCategoryCache) {
  1451. $resultItem = [
  1452. 'alias' => null,
  1453. 'category_id' => null,
  1454. 'pinyin' => null,
  1455. 'imgnum' => [],
  1456. 'textnum' => [],
  1457. 'child' => []
  1458. ];
  1459. // 处理父级栏目
  1460. if (isset($item['parent']) && $item['parent'] !== 'undefined' && $item['parent'] !== "") {
  1461. $parentParams = explode(',', $item['parent']);
  1462. if (count($parentParams) !== 3) {
  1463. return Result::error("父级栏目:缺少必需参数错误", 0);
  1464. }
  1465. list($parentCatId, $parentImgNum, $parentTextNum) = $parentParams;
  1466. $cacheKey = "parent_{$parentCatId}_{$website['website_id']}";
  1467. if (!isset($categoryCache[$cacheKey])) {
  1468. // 查询栏目名称
  1469. $categoryCache[$cacheKey] = WebsiteCategory::where('category_id', $parentCatId)
  1470. ->where($website)
  1471. ->first(['alias', 'category_id', 'aLIas_pinyin', 'type']);
  1472. }
  1473. $category = $categoryCache[$cacheKey];
  1474. if (!empty($category)) {
  1475. $resultItem['alias'] = $category->alias;
  1476. $resultItem['category_id'] = $category->category_id;
  1477. $resultItem['pinyin'] = $category->aLIas_pinyin;
  1478. // 查询图片新闻
  1479. if (!empty($parentImgNum)) {
  1480. $resultItem['imgnum'] = $this->fetchArticles($parentCatId, $website, (int)$parentImgNum, true);
  1481. }
  1482. // 查询文字新闻
  1483. if (!empty($parentTextNum)) {
  1484. $resultItem['textnum'] = $this->fetchArticles($parentCatId, $website, (int)$parentTextNum, false);
  1485. }
  1486. }
  1487. }
  1488. // 处理子级栏目
  1489. if (isset($item['child']) && $item['child'] !== 'undefined' && $item['child'] !== "") {
  1490. $childParams = explode(',', $item['child']);
  1491. if (count($childParams) !== 3) {
  1492. return Result::error("子级栏目:缺少必需参数错误", 0);
  1493. }
  1494. list($childCatId, $childImgNum, $childTextNum) = $childParams;
  1495. $cacheKey = "child_{$childCatId}_{$website['website_id']}";
  1496. if (!isset($childCategoryCache[$cacheKey])) {
  1497. // 查询子栏目信息
  1498. $childCategoryCache[$cacheKey] = WebsiteCategory::where($website)
  1499. ->where("category_id", $childCatId)
  1500. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($childCatId) . "') = 1")
  1501. ->first(['alias', 'category_id', 'aLIas_pinyin', 'pid', 'category_arr_id as cat_arr_id']);
  1502. }
  1503. $childCategory = $childCategoryCache[$cacheKey];
  1504. if (!empty($childCategory)) {
  1505. $childCategory = $this->processArticles($childCategory, $website);
  1506. // 查询此层级的所有子栏目
  1507. $allChildCategories = WebsiteCategory::where($website)
  1508. ->where("pid", $childCategory['pid'])
  1509. ->get(['alias', 'category_id', 'aLIas_pinyin', 'pid', 'category_arr_id as cat_arr_id']);
  1510. $allChildCategories = $this->processArticles($allChildCategories, $website);
  1511. $childResult = [
  1512. 'alias' => $childCategory->alias,
  1513. 'category_id' => $childCategory->category_id,
  1514. 'pinyin' => $childCategory->aLIas_pinyin,
  1515. 'all_childcat' => $allChildCategories,
  1516. 'imgnum' => [],
  1517. 'textnum' => []
  1518. ];
  1519. // 查询子栏目图片新闻
  1520. if (!empty($childImgNum)) {
  1521. $childResult['imgnum'] = $this->fetchArticles($childCatId, $website, (int)$childImgNum, true);
  1522. }
  1523. // 查询子栏目文字新闻
  1524. if (!empty($childTextNum)) {
  1525. $childResult['textnum'] = $this->fetchArticles($childCatId, $website, (int)$childTextNum, false);
  1526. }
  1527. $resultItem['child'] = $childResult;
  1528. }
  1529. }
  1530. return $resultItem;
  1531. }, $items);
  1532. $cache->set($cacheKey, serialize($result), 86400);
  1533. return Result::success($result);
  1534. } catch (\Exception $e) {
  1535. // 记录错误日志
  1536. return Result::error("获取网站文章失败: " . $e->getMessage());
  1537. }
  1538. }
  1539. /**
  1540. * 辅助方法:获取文章列表
  1541. */
  1542. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1543. {
  1544. sleep(1);
  1545. $query = Article::where('article.status', 1)
  1546. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1547. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1548. ->where(function ($query) use ($website) {
  1549. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1550. })
  1551. ->leftJoin('website_category', function ($join) use ($website) {
  1552. $join->on('article.catid', '=', 'website_category.category_id')
  1553. ->where('website_category.website_id', '=', $website['website_id']);
  1554. })
  1555. ->select(
  1556. 'article.id',
  1557. 'article.title',
  1558. 'article.imgurl',
  1559. 'article.author',
  1560. 'article.updated_at',
  1561. 'article.introduce',
  1562. 'article.islink',
  1563. 'article.linkurl',
  1564. 'article.copyfrom',
  1565. 'article.cat_arr_id',
  1566. 'article.catid',
  1567. 'website_category.alias as category_name'
  1568. )
  1569. ->orderBy('updated_at', 'desc')
  1570. ->limit($limit);
  1571. // 如果是图片文章,添加图片URL条件
  1572. if ($isImageArticle) {
  1573. $query->where('imgurl', '!=', '');
  1574. } else {
  1575. // 文字文章不需要imgurl字段
  1576. $query->addSelect('article.introduce');
  1577. }
  1578. $articles = $query->get();
  1579. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1580. }
  1581. /**
  1582. * 乡村网-获取特殊新闻模块
  1583. * @param array $data
  1584. * @return array
  1585. */
  1586. public function getWebsiteArticles(array $data): array
  1587. {
  1588. $input['id'] = $data['id'];
  1589. $input['website_id'] = $data['website_id'];
  1590. $data = json_decode($input['id'], true);
  1591. // 使用 array_map 处理每个元素
  1592. $result = array_map(function ($item) use ($input) {
  1593. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1594. $website = [
  1595. 'website_id' => $input['website_id']
  1596. ];
  1597. // 查询栏目名称
  1598. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1599. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1600. if (empty($category)) {
  1601. $imgArticles = [];
  1602. $textArticles = [];
  1603. // return Result::error("暂无此栏目",0);
  1604. } else {
  1605. $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1606. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin . '/' : null;
  1607. // return Result::success($website);
  1608. // 查询图片新闻
  1609. // 合并查询条件
  1610. $baseQuery = Article::where(function ($query) use ($website) {
  1611. $query->where(function ($subQuery) use ($website) {
  1612. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1613. })->orWhereNull("ignore_ids");
  1614. })
  1615. ->where('article.status', 1)
  1616. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1617. ->where('website_category.website_id', $website['website_id']);
  1618. // 查询文字新闻
  1619. $textArticles = clone $baseQuery;
  1620. $textArticles = $textArticles->whereIn('catid', $child_category)
  1621. ->select(
  1622. 'article.id',
  1623. 'article.title',
  1624. // 'article.imgurl',
  1625. 'article.author',
  1626. 'article.updated_at',
  1627. 'article.introduce',
  1628. 'article.islink',
  1629. 'article.linkurl',
  1630. 'article.copyfrom',
  1631. 'website_category.category_id',
  1632. 'website_category.alias',
  1633. 'website_category.aLIas_pinyin'
  1634. )
  1635. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1636. ->orderBy('article.updated_at', 'desc')
  1637. ->limit($parentTextNum)
  1638. ->get()
  1639. ->all();
  1640. if (empty($textArticles)) {
  1641. $textArticles = clone $baseQuery;
  1642. $textArticles = $textArticles->where('catid', $parentCatId)
  1643. ->select(
  1644. 'article.id',
  1645. 'article.title',
  1646. // 'article.imgurl',
  1647. 'article.author',
  1648. 'article.updated_at',
  1649. 'article.introduce',
  1650. 'article.islink',
  1651. 'article.linkurl',
  1652. 'article.copyfrom',
  1653. 'website_category.category_id',
  1654. 'website_category.alias',
  1655. 'website_category.aLIas_pinyin'
  1656. )
  1657. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1658. ->orderBy('article.updated_at', 'desc')
  1659. ->limit($parentTextNum)
  1660. ->get()
  1661. ->all();
  1662. }
  1663. // 查询图片新闻
  1664. $imgArticles = clone $baseQuery;
  1665. $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid', $child_category)
  1666. ->select(
  1667. 'article.id',
  1668. 'article.title',
  1669. 'article.imgurl',
  1670. 'article.author',
  1671. 'article.updated_at',
  1672. 'article.introduce',
  1673. 'article.islink',
  1674. 'article.linkurl',
  1675. 'article.copyfrom',
  1676. 'website_category.category_id',
  1677. 'website_category.alias',
  1678. 'website_category.aLIas_pinyin'
  1679. )
  1680. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1681. ->orderBy('article.updated_at', 'desc')
  1682. ->limit($parentImgNum)
  1683. ->get()
  1684. ->all();
  1685. if (empty($imgArticles)) {
  1686. $imgArticles = clone $baseQuery;
  1687. $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid', $parentCatId)
  1688. ->select(
  1689. 'article.id',
  1690. 'article.title',
  1691. 'article.imgurl',
  1692. 'article.author',
  1693. 'article.updated_at',
  1694. 'article.introduce',
  1695. 'article.islink',
  1696. 'article.linkurl',
  1697. 'article.copyfrom',
  1698. 'website_category.category_id',
  1699. 'website_category.alias',
  1700. 'website_category.aLIas_pinyin'
  1701. )
  1702. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1703. ->orderBy('article.updated_at', 'desc')
  1704. ->limit($parentImgNum)
  1705. ->get()
  1706. ->all();
  1707. }
  1708. }
  1709. $resultItem = [
  1710. 'alias' => $category ? $category->alias : null,
  1711. 'category_id' => $parentCatId,
  1712. 'pinyin' => $pinyin ? $pinyin : null,
  1713. 'imgnum' => $imgArticles ?? [],
  1714. 'textnum' => $textArticles ?? [],
  1715. ];
  1716. return $resultItem;
  1717. }, $data);
  1718. return Result::success($result);
  1719. }
  1720. // 封装处理商品的路由问题
  1721. function processGoods($goods, $data)
  1722. {
  1723. return $goods->map(function ($good) use ($data) {
  1724. $catid = $good->catid ?? 0;
  1725. // $pinyin = '';
  1726. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1727. if (!empty($category->pid) && $category->pid != 0) {
  1728. $level = json_decode($category->category_arr_id);
  1729. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1730. ->whereIn('category_id', $level)
  1731. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1732. ->get(['aLIas_pinyin'])
  1733. ->pluck('aLIas_pinyin')
  1734. ->implode('/');
  1735. } else {
  1736. $pinyin = $category->aLIas_pinyin ?? '';
  1737. }
  1738. if (isset($good->city_id) && !empty($good->city_id)) {
  1739. $city = District::where('id', $good->city_id)->first(['name']);
  1740. $good->city_name = $city->name ?? '';
  1741. }
  1742. // 解析imgurl JSON并取第一条数据
  1743. $imgUrls = json_decode($good->imgurl, true);
  1744. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1745. $good->pinyin = $pinyin;
  1746. return $good;
  1747. });
  1748. }
  1749. /**
  1750. * 获取商城首页-根据栏目id
  1751. * @param array $data
  1752. * @return array
  1753. * */
  1754. function getWebsiteCatidshop(array $data): array
  1755. {
  1756. $input['catid'] = $data['catid'];
  1757. $input['website_id'] = $data['website_id'];
  1758. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1759. $result = array_map(function ($item) use ($input) {
  1760. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1761. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1762. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1763. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1764. if (empty($category) || $category->type != 2) {
  1765. return Result::error("暂无此栏目", 0);
  1766. } else {
  1767. $website['website_id'] = $input['website_id'];
  1768. $goods = Good::where('good.status', 2)
  1769. ->where('good.website_id', $website['website_id'])
  1770. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1771. ->select(
  1772. 'good.id',
  1773. 'good.name',
  1774. 'good.imgurl',
  1775. 'good.description',
  1776. 'good.updated_at',
  1777. 'good.catid',
  1778. 'good.type_id',
  1779. 'good.price',
  1780. 'good.com',
  1781. 'good.level',
  1782. 'good.unit'
  1783. )
  1784. ->orderBy('updated_at', 'desc')
  1785. ->offset($goodStart)
  1786. ->limit($goodNum);
  1787. $all_goods = $goods->get();
  1788. $all_goods = $this->processGoods($all_goods, $website);
  1789. }
  1790. return $all_goods ?? [];
  1791. }
  1792. }, $data);
  1793. return Result::success($result);
  1794. }
  1795. /**
  1796. * 获取商品模块
  1797. * @param array $data
  1798. * @return array
  1799. * */
  1800. public function getWebsiteshop(array $data): array
  1801. {
  1802. $input['id'] = $data['id'];
  1803. $input['website_id'] = $data['website_id'];
  1804. $catid = $data['catid'];
  1805. $data = json_decode($input['id'] ?? '', true) ?? [];
  1806. $result['goods'] = array_map(function ($item) use ($input) {
  1807. // 检查parent元素是否存在且不是undefined
  1808. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  1809. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  1810. $website = $input['website_id'];
  1811. $query = Good::where('good.status', 2)
  1812. ->where('good.website_id', $website);
  1813. switch ($Levelid) {
  1814. case 1:
  1815. case 2:
  1816. case 3:
  1817. $goods = $query->where(function ($q) use ($Levelid) {
  1818. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  1819. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  1820. });
  1821. break;
  1822. case 4:
  1823. $goods = $query;
  1824. break;
  1825. case 5:
  1826. $goods = $query->where('type_id', 1);
  1827. break;
  1828. case 6:
  1829. $goods = $query->where('type_id', 2);
  1830. break;
  1831. default:
  1832. return [];
  1833. }
  1834. $all_goods = $goods
  1835. ->select(
  1836. 'good.id',
  1837. 'good.name',
  1838. 'good.imgurl',
  1839. 'good.description',
  1840. 'good.updated_at',
  1841. 'good.catid',
  1842. 'good.type_id',
  1843. 'good.price',
  1844. 'good.level',
  1845. 'good.website_id'
  1846. )
  1847. ->orderBy('updated_at', 'desc')
  1848. ->offset($goodStart)
  1849. ->limit($goodNum)
  1850. ->get();
  1851. $web['website_id'] = $website;
  1852. $all_goods = $this->processGoods($all_goods, $web);
  1853. }
  1854. return $all_goods;
  1855. }, $data);
  1856. $website = $input['website_id'];
  1857. $result['article'] = Article::where(function ($query) use ($website) {
  1858. $query->where(function ($subQuery) use ($website) {
  1859. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  1860. })->orWhereNull("ignore_ids");
  1861. })
  1862. ->where('catid', $catid)
  1863. ->where('article.status', 1)
  1864. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  1865. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  1866. ->orderBy('article.updated_at', 'desc')
  1867. ->first();
  1868. return Result::success($result);
  1869. }
  1870. /**
  1871. * 获取商品分类
  1872. * @param array $data
  1873. * @return array
  1874. * */
  1875. public function getWebsiteshopCat(array $data): array
  1876. {
  1877. $website = $data['website_id'];
  1878. $category = WebsiteCategory::where('website_id', $website)
  1879. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  1880. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  1881. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  1882. ->orderBy('sort')
  1883. ->get();
  1884. $cat = $category->map(function ($item) use ($website) {
  1885. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  1886. $pid = $item->pid ?? 0;
  1887. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  1888. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  1889. ->where('website_id', $website)
  1890. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  1891. ->get(['aLIas_pinyin'])
  1892. ->pluck('aLIas_pinyin')
  1893. ->implode('/');
  1894. } else {
  1895. $pinyin = $item->aLIas_pinyin ?? '';
  1896. }
  1897. $item->pinyin = $pinyin;
  1898. });
  1899. if (empty($category)) {
  1900. return Result::error("栏目查询失败", 0);
  1901. }
  1902. $cat_tree = Result::buildMenuTree($category);
  1903. $web['website_id'] = $website;
  1904. $goods = Good::where('website_id', $website)
  1905. ->where('status', 2)
  1906. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  1907. ->latest('updated_at')
  1908. ->offset(($data['page'] - 1) * $data['pageSize'])
  1909. ->limit($data['pageSize'])
  1910. ->get();
  1911. if (!empty($goods)) {
  1912. if ($goods->count() > 1 && !empty($goods)) {
  1913. $goods = $this->processGoods($goods, $web);
  1914. }
  1915. } else {
  1916. $goods = [];
  1917. }
  1918. $result = [
  1919. 'category' => $cat_tree,
  1920. 'goods' => $goods,
  1921. ];
  1922. // $resul['goods'] = $goods;
  1923. if (empty($result)) {
  1924. return Result::error("查询失败", 0);
  1925. }
  1926. return Result::success($result);
  1927. }
  1928. /*
  1929. * 获取商品列表
  1930. * @param array $data
  1931. * @return array
  1932. * */
  1933. public function getWebsiteshopList(array $data): array
  1934. {
  1935. // return Result::success($data);
  1936. $where = [
  1937. 'status' => 2,
  1938. 'website_id' => $data['website_id'],
  1939. ];
  1940. if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  1941. return Result::error("查询失败", 0);
  1942. }
  1943. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  1944. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  1945. $data['catid'] = $category->category_id ?? 0;
  1946. }
  1947. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1948. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  1949. }
  1950. if (isset($data['type_id']) && !empty($data['type_id'])) {
  1951. array_push($where, ['type_id', $data['type_id']]);
  1952. }
  1953. $query = Good::where($where)
  1954. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  1955. $query->where(function ($q) use ($data) {
  1956. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  1957. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  1958. });
  1959. })
  1960. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  1961. $query->where(function ($q) use ($data) {
  1962. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  1963. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  1964. });
  1965. })
  1966. ->select(
  1967. 'good.id',
  1968. 'good.name',
  1969. 'good.imgurl',
  1970. 'good.description',
  1971. 'good.updated_at',
  1972. 'good.com',
  1973. 'good.catid',
  1974. 'good.type_id',
  1975. 'good.website_id',
  1976. 'good.cat_arr_id',
  1977. 'good.created_at',
  1978. 'good.city_id'
  1979. )
  1980. ->latest('updated_at');
  1981. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  1982. // 获取 type_id 为 1 的数据
  1983. $result['type1'] = $this->processGoods(
  1984. $query->clone()
  1985. ->where('type_id', 1)
  1986. ->offset(($data['page'] - 1) * $data['pageSize'])
  1987. ->limit($data['pageSize'])
  1988. ->get(),
  1989. $data
  1990. );
  1991. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  1992. // 获取 type_id 为 2 的数据
  1993. $result['type2'] = $this->processGoods(
  1994. $query->clone()
  1995. ->where('type_id', 2)
  1996. ->offset(($data['page'] - 1) * $data['pageSize'])
  1997. ->limit($data['pageSize'])
  1998. ->get(),
  1999. $data
  2000. );
  2001. if (empty($result)) {
  2002. return Result::error("查询失败", 0);
  2003. }
  2004. return Result::success($result);
  2005. }
  2006. /**
  2007. * 获取商品详情
  2008. * @param array $data
  2009. * @return array
  2010. * */
  2011. public function getWebsiteshopInfo(array $data): array
  2012. {
  2013. $where = [
  2014. 'good.status' => 2,
  2015. 'good.website_id' => $data['website_id'],
  2016. 'good.id' => $data['id'],
  2017. ];
  2018. $goods = Good::where($where)
  2019. ->where('good.id', $data['id'])
  2020. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2021. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2022. ->first();
  2023. if (empty($goods)) {
  2024. return Result::error("查询失败", 0);
  2025. }
  2026. $goods->imgurl = json_decode($goods->imgurl, true);
  2027. return Result::success($goods);
  2028. }
  2029. /**
  2030. * 封装处理文章的路由问题
  2031. * */
  2032. function processArticles($articles, $data)
  2033. {
  2034. // 检查 $articles 是否为数组或可迭代对象
  2035. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2036. return $articles->map(function ($article) use ($data) {
  2037. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2038. $catid = $article->cat_arr_id ?? '';
  2039. }
  2040. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2041. $catid = $article->category_arr_id ?? '';
  2042. }
  2043. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2044. $level = json_decode($catid, true);
  2045. if (!is_array($level)) {
  2046. return $article;
  2047. } else {
  2048. $level = array_map('intval', $level);
  2049. }
  2050. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2051. ->where($data)
  2052. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2053. ->pluck('aLIas_pinyin')
  2054. ->implode('/');
  2055. $article->pinyin = $pinyin ?? '';
  2056. return $article;
  2057. });
  2058. } else {
  2059. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2060. $catid = $articles->cat_arr_id ?? '';
  2061. $level = json_decode($catid, true);
  2062. if (!is_array($level)) {
  2063. return $articles;
  2064. } else {
  2065. $level = array_map('intval', $level);
  2066. }
  2067. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2068. ->where($data)
  2069. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2070. ->pluck('aLIas_pinyin')
  2071. ->implode('/');
  2072. $articles->pinyin = $pinyin ?? '';
  2073. return $articles;
  2074. }
  2075. }
  2076. // 封装处理由问题
  2077. function processJob($job, $data)
  2078. {
  2079. return $job->map(function ($job) use ($data) {
  2080. $category = $job->cat_arr_id ?? '';
  2081. $cityid = $job->city_arr_id ?? '';
  2082. $city = json_decode($cityid, true);
  2083. $pinyin = '';
  2084. $level = json_decode($category, true);
  2085. // 路由
  2086. if (!empty($level) && is_array($level)) {
  2087. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2088. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2089. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2090. ->get(['aLIas_pinyin'])
  2091. ->pluck('aLIas_pinyin')
  2092. ->implode('/');
  2093. if (empty($pinyin)) {
  2094. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2095. }
  2096. $job->pinyin = $pinyin;
  2097. }
  2098. // 取职位-城市 市??省
  2099. if (!empty($city) && is_array($city)) {
  2100. if (isset($city[1]) && !empty($city[1])) {
  2101. $city = District::where('id', $city[1])->first(['name']);
  2102. $job->city_name = $city->name ?? '';
  2103. } else if (isset($city[0]) && !empty($city[0])) {
  2104. $city = District::where('id', $city[0])->first(['name']);
  2105. $job->city_name = $city->name ?? '';
  2106. } else {
  2107. $job->city_name = '全国';
  2108. }
  2109. }
  2110. // 获取简历最后一级地区
  2111. if (isset($job->city_id) && !empty($job->city_id)) {
  2112. $city = District::where('id', $job->city_id)->first(['name']);
  2113. $job->hunt_cityname = $city->name ?? '';
  2114. }
  2115. // 组合详细地址
  2116. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2117. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2118. if (is_array($address_id) && !empty($address_id)) {
  2119. $address = District::whereIn('id', $address_id)
  2120. ->orderBy('level', 'asc')
  2121. ->get(['name'])
  2122. ->pluck('name')
  2123. ->implode('');
  2124. // $job->address_name = $address ?? '';
  2125. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2126. }
  2127. }
  2128. // 取行业
  2129. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2130. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2131. if (!empty($job->industry)) {
  2132. $query->where('hyid', $job->industry);
  2133. } else if (!empty($job->hy_id)) {
  2134. $query->where('hyid', $job->hy_id);
  2135. } else if (!empty($job->company_hy_id)) {
  2136. $query->where('hyid', $job->company_hy_id);
  2137. } else {
  2138. $query->where('hyid', $job->job_industry);
  2139. }
  2140. })->first(['hyname']);
  2141. $job->hy_name = $hy_name->hyname ?? '';
  2142. }
  2143. // 取职位类别
  2144. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2145. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2146. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2147. $job->zw_name = $zw_name->zwname ?? '';
  2148. }
  2149. // 取具体职位
  2150. 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))) {
  2151. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2152. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2153. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2154. }
  2155. // 取工作经验
  2156. if (isset($job->experience) && !empty($job->experience)) {
  2157. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2158. $job->experience_name = $experience->ename ?? '';
  2159. }
  2160. // 取学历
  2161. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2162. $education = $job->educational ?? $job->school_education;
  2163. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2164. $job->education_name = $education->ename ?? '';
  2165. }
  2166. // 语言
  2167. if (isset($job->language) && !empty($job->language)) {
  2168. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2169. $job->language_name = $language->ename ?? '';
  2170. }
  2171. // 薪资
  2172. if (isset($job->salary) && !empty($job->salary)) {
  2173. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2174. $job->salary_name = $salary->ename ?? '';
  2175. }
  2176. // 职位性质
  2177. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2178. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2179. $job->job_nature_name = $job_nature->ename ?? '';
  2180. }
  2181. // 公司规模
  2182. if (isset($job->company_size) && !empty($job->company_size)) {
  2183. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2184. $job->company_size_name = $company_size->ename ?? '';
  2185. }
  2186. // 公司性质
  2187. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2188. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2189. $job->company_nature_name = $company_nature->nature_name ?? '';
  2190. }
  2191. // $job->pinyin = $pinyin;
  2192. return $job;
  2193. });
  2194. }
  2195. /**
  2196. * 获取书籍模块
  2197. * @param array $data
  2198. * @return array
  2199. * */
  2200. public function getWebsiteBook(array $data): array
  2201. {
  2202. $input['id'] = $data['id'];
  2203. $input['website_id'] = $data['website_id'];
  2204. // 将 JSON 字符串转换为 PHP 数组
  2205. $data = json_decode($input['id'], true);
  2206. // 使用 array_map 处理每个元素
  2207. $result = array_map(function ($item) use ($input) {
  2208. // 检查parent元素是否存在且不是undefined
  2209. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2210. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2211. $website = [
  2212. 'website_id' => $input['website_id'],
  2213. ];
  2214. // 查询栏目名称
  2215. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2216. if (empty($category)) {
  2217. $parent_alias = '';
  2218. $parent_pinyin = null;
  2219. $imgBooks = [];
  2220. $textBooks = [];
  2221. } else {
  2222. $parent_alias = $category->alias ?? '';
  2223. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2224. // 查找子分类ID数组
  2225. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2226. array_push($childCategoryIds, $parentCatId);
  2227. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2228. if ($parentImgNum != 0) {
  2229. // 查询图片新闻
  2230. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2231. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2232. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2233. })
  2234. ->where('book.status', 2)
  2235. ->where('book.img_url', '!=', '')
  2236. ->leftJoin('website_category', function ($join) use ($website) {
  2237. $join->on('book.cat_id', '=', 'website_category.category_id')
  2238. ->where('website_category.website_id', '=', $website['website_id']);
  2239. })
  2240. ->select(
  2241. 'book.id',
  2242. 'book.title',
  2243. 'book.img_url',
  2244. 'book.price',
  2245. 'book.market_price',
  2246. 'book.description',
  2247. 'book.cat_id',
  2248. 'book.description',
  2249. 'book.updated_at',
  2250. 'website_category.alias as category_name',
  2251. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2252. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2253. )
  2254. ->orderBy('updated_at', 'desc')
  2255. ->limit($parentImgNum)
  2256. ->get()->all();
  2257. // 查询文字新闻
  2258. }
  2259. if ($parentTextNum != 0) {
  2260. $textBooks = [];
  2261. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2262. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2263. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2264. })
  2265. ->where('book.status', 2)
  2266. ->leftJoin('website_category', function ($join) use ($website) {
  2267. $join->on('book.cat_id', '=', 'website_category.category_id')
  2268. ->where('website_category.website_id', '=', $website['website_id']);
  2269. })
  2270. ->select(
  2271. 'book.id',
  2272. 'book.title',
  2273. 'book.img_url',
  2274. 'book.price',
  2275. 'book.market_price',
  2276. 'book.description',
  2277. 'book.cat_id',
  2278. 'book.description',
  2279. 'book.updated_at',
  2280. 'website_category.alias as category_name',
  2281. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2282. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2283. )
  2284. ->orderBy('updated_at', 'desc')
  2285. ->limit($parentTextNum)
  2286. ->get()->all();
  2287. }
  2288. }
  2289. }
  2290. $resultItem = [
  2291. 'alias' => $parent_alias ?? '',
  2292. 'category_id' => $parentCatId ?? 0,
  2293. 'pinyin' => $parent_pinyin ?? null,
  2294. 'imgnum' => $imgBooks ?? [],
  2295. 'textnum' => $textBooks ?? [],
  2296. ];
  2297. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2298. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2299. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2300. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2301. ->get()->all();
  2302. if (!empty($childCategory)) {
  2303. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2304. // 查询子栏目名称
  2305. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2306. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2307. ->first();
  2308. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2309. $childImgArticles = [];
  2310. $childTextArticles = [];
  2311. $resultItem['child'] = [];
  2312. } else {
  2313. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2314. // 查询子栏目图片新闻
  2315. $childImgArticles = Book::where('cat_id', $childCatId)
  2316. ->where('status', 2)
  2317. ->where('img_url', '!=', '')
  2318. ->leftJoin('website_category', function ($join) use ($website) {
  2319. $join->on('book.cat_id', '=', 'website_category.category_id')
  2320. ->where('website_category.website_id', '=', $website['website_id']);
  2321. })
  2322. ->select(
  2323. 'book.id',
  2324. 'book.title',
  2325. 'book.img_url',
  2326. 'book.price',
  2327. 'book.market_price',
  2328. 'book.description',
  2329. 'book.cat_id',
  2330. 'book.description',
  2331. 'book.updated_at',
  2332. DB::raw("'$child_pinyin' as pinyin")
  2333. )
  2334. ->orderBy('updated_at', 'desc')
  2335. ->limit($childImgNum)
  2336. ->get()->all();
  2337. // 查询子栏目文字新闻
  2338. $childTextArticles = Book::where('cat_id', $childCatId)
  2339. ->where('status', 2)
  2340. ->leftJoin('website_category', function ($join) use ($website) {
  2341. $join->on('book.cat_id', '=', 'website_category.category_id')
  2342. ->where('website_category.website_id', '=', $website['website_id']);
  2343. })
  2344. ->select(
  2345. 'book.id',
  2346. 'book.title',
  2347. 'book.img_url',
  2348. 'book.price',
  2349. 'book.market_price',
  2350. 'book.description',
  2351. 'book.cat_id',
  2352. 'book.description',
  2353. 'book.updated_at',
  2354. DB::raw("'$child_pinyin' as pinyin")
  2355. )
  2356. ->orderBy('updated_at', 'desc')
  2357. ->limit($childTextNum)
  2358. ->get()->all();
  2359. $resultItem['child'] = [
  2360. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2361. 'category_id' => $childCatId,
  2362. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2363. 'all_childcat' => $childCategory,
  2364. 'imgnum' => $childImgArticles,
  2365. 'textnum' => $childTextArticles,
  2366. ];
  2367. }
  2368. }
  2369. } else {
  2370. $resultItem['child'] = [];
  2371. }
  2372. return $resultItem;
  2373. }, $data);
  2374. return Result::success($result);
  2375. }
  2376. /**
  2377. * 获取书刊列表
  2378. * @param array $data
  2379. * @return array
  2380. * */
  2381. public function getWebsiteBookList(array $data): array
  2382. {
  2383. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2384. if (empty($web)) {
  2385. return Result::error("查询失败", 0);
  2386. }
  2387. $catid = $data['id'];
  2388. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2389. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2390. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2391. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2392. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2393. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2394. ->where('pid', $category['pid'])
  2395. ->select(
  2396. 'category_id',
  2397. 'alias',
  2398. 'aLIas_pinyin',
  2399. 'pid',
  2400. 'sort',
  2401. 'is_url',
  2402. 'web_url',
  2403. 'seo_title',
  2404. 'seo_keywords',
  2405. 'seo_description',
  2406. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2407. )
  2408. ->orderBy('sort')
  2409. ->get()->all();
  2410. if (empty($category)) {
  2411. return Result::error("查询失败", 0);
  2412. }
  2413. $query = Book::where('book.status', 2)
  2414. ->where('book.website_id', $data['website_id'])
  2415. ->where('book.cat_id', $catid)
  2416. ->select(
  2417. 'book.id',
  2418. 'book.title',
  2419. 'book.img_url',
  2420. 'book.description',
  2421. 'book.updated_at',
  2422. 'book.cat_id',
  2423. DB::raw("'$pinyin' as pinyin")
  2424. )
  2425. ->orderBy('book.updated_at', 'desc');
  2426. $count = $query->count();
  2427. $query = clone $query;
  2428. $Book = $query
  2429. ->limit($data['pageSize'])
  2430. ->offset(($data['page'] - 1) * $data['pageSize'])
  2431. ->get()->all();
  2432. $result = [
  2433. 'category' => $categorys,
  2434. 'books' => $Book,
  2435. 'count' => $count,
  2436. ];
  2437. // if(empty($result)){
  2438. // return Result::error("查询失败", 0);
  2439. // }
  2440. return Result::success($result);
  2441. }
  2442. /**
  2443. * 获取书刊详情
  2444. * @param array $data
  2445. * @return array
  2446. * */
  2447. public function getWebsiteBookInfo(array $data): array
  2448. {
  2449. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2450. if (empty($web)) {
  2451. return Result::error("查询失败", 0);
  2452. }
  2453. $book = Book::where('status', 2)
  2454. ->where('website_id', $data['website_id'])
  2455. ->where('id', $data['id'])
  2456. ->select(
  2457. 'book.*',
  2458. )
  2459. ->orderBy('updated_at', 'desc')
  2460. ->first();
  2461. if (empty($book)) {
  2462. return Result::error("查询失败", 0);
  2463. }
  2464. // 先查询当前分类的 pid
  2465. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2466. ->where('category_id', $book['cat_id'])
  2467. ->first(['pid', 'category_id']);
  2468. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2469. if (!empty($carpid)) {
  2470. if ($carpid->pid != 0) {
  2471. $pid = $carpid['pid'];
  2472. // $parent_pinyin = '';
  2473. } else {
  2474. $pid = $carpid['category_id'];
  2475. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2476. }
  2477. }
  2478. $categorys = $query->where('pid', $pid)
  2479. ->select(
  2480. 'category_id',
  2481. 'alias',
  2482. 'aLIas_pinyin',
  2483. 'pid',
  2484. 'sort',
  2485. 'is_url',
  2486. 'web_url',
  2487. 'category_arr_id as cat_arr_id',
  2488. )
  2489. ->orderBy('sort')
  2490. ->get();
  2491. $category = $this->processArticle($categorys, $data);
  2492. $result = [
  2493. 'category' => $category,
  2494. 'books' => $book,
  2495. ];
  2496. return Result::success($result);
  2497. }
  2498. /**
  2499. * 尝试
  2500. * @param array $data
  2501. * @return array
  2502. * */
  2503. public function test(array $data): array
  2504. {
  2505. $input['id'] = $data['id'];
  2506. $input['website_id'] = $data['website_id'];
  2507. // 将 JSON 字符串转换为 PHP 数组
  2508. $data = json_decode($input['id'], true);
  2509. $result = [];
  2510. $article = $data;
  2511. $result = array_map(function ($item) use ($input) {
  2512. $website = [
  2513. 'website_id' => $input['website_id'],
  2514. ];
  2515. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2516. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2517. $parent = [
  2518. 0 => $category['category_id'] ?? [],
  2519. 1 => $parentImgNum ?? [],
  2520. 2 => $parentTextNum ?? [],
  2521. ];
  2522. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2523. $child = [];
  2524. $resultItem = [
  2525. // 'alias' => $parent_alias ?? '',
  2526. 'category_id' => $parentCatId ?? 0,
  2527. 'pinyin' => $parentImgNum ?? null,
  2528. 'imgnum' => $parentTextNum ?? [],
  2529. // 'textnum' => $textArticles ?? [],
  2530. ];
  2531. return $parent;
  2532. }, $data);
  2533. return Result::success($result);
  2534. // });
  2535. }
  2536. /**
  2537. * 封装处理文章的路由问题
  2538. * */
  2539. function processArticle($article, $data)
  2540. {
  2541. return $article->map(function ($article) use ($data) {
  2542. $catid = $article->cat_arr_id ?? '';
  2543. $level = json_decode($catid, true);
  2544. $pinyin = '';
  2545. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2546. if (!empty($level) && is_array($level)) {
  2547. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2548. ->where('website_id', $data['website_id'])
  2549. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2550. ->get(['aLIas_pinyin'])
  2551. ->pluck('aLIas_pinyin')
  2552. ->implode('/');
  2553. } else {
  2554. $pinyin = '';
  2555. }
  2556. $article->pinyin = $pinyin;
  2557. return $article;
  2558. });
  2559. }
  2560. /**
  2561. * c端-获取招工招聘下拉选框
  2562. * @param array $data
  2563. * @return array
  2564. * */
  2565. public function getWebsiteJobSelect(array $data): array
  2566. {
  2567. $web = Website::where('id', $data['website_id'])->first();
  2568. if (empty($web)) {
  2569. return Result::error("该网站不存在", 0);
  2570. }
  2571. $hy = JobIndustry::get()->all();
  2572. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2573. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2574. $result = [
  2575. 'hy' => $hy,
  2576. 'zw' => $zw,
  2577. 'jtzw' => $jtzw,
  2578. ];
  2579. if (empty($result)) {
  2580. return Result::error("查询失败", 0);
  2581. }
  2582. return Result::success($result);
  2583. }
  2584. /**
  2585. * c端-获取招工招聘
  2586. * @param array $data
  2587. * @return array
  2588. * */
  2589. public function getWebsiteJob(array $data): array
  2590. {
  2591. $web = Website::where('id', $data['website_id'])->first();
  2592. if (empty($web)) {
  2593. return Result::error("该网站不存在", 0);
  2594. }
  2595. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2596. ->where('job_hunting.website_id', $data['website_id'])
  2597. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2598. $query->where(function ($q) use ($data) {
  2599. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2600. });
  2601. })
  2602. ->select(
  2603. 'job_hunting.id',
  2604. 'job_hunting.cat_arr_id',
  2605. 'job_hunting.job_name_get',
  2606. 'job_hunting.industry',
  2607. 'job_hunting.name',
  2608. 'job_hunting.sexy',
  2609. 'job_hunting.origin',
  2610. 'job_hunting.city_arr_id',
  2611. 'job_hunting.experience',
  2612. 'job_hunting.updated_at',
  2613. 'job_hunting.salary'
  2614. )
  2615. ->orderBy('updated_at', 'desc')
  2616. ->limit($data['job1_num'])
  2617. ->get();
  2618. $web['website_id'] = $data['website_id'];
  2619. if (empty($job_hunting)) {
  2620. $job_huntings = "未查询到相关简历信息";
  2621. } else {
  2622. $job_huntings = $this->processJob($job_hunting, $web);
  2623. }
  2624. // 0:待审核 1:已通过 2:已拒绝
  2625. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2626. ->where('job_recruiting.website_id', $data['website_id'])
  2627. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2628. $query->where(function ($q) use ($data) {
  2629. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2630. });
  2631. })
  2632. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2633. ->select(
  2634. 'job_recruiting.id',
  2635. 'job_recruiting.cat_arr_id',
  2636. 'job_recruiting.title',
  2637. 'job_recruiting.jtzw_id',
  2638. 'job_recruiting.hy_id',
  2639. 'job_recruiting.city_arr_id',
  2640. 'job_recruiting.due_data',
  2641. 'job_recruiting.updated_at',
  2642. 'job_recruiting.experience',
  2643. 'job_recruiting.educational',
  2644. 'job_recruiting.salary',
  2645. 'job_recruiting.zw_id',
  2646. 'job_company.business_name'
  2647. )
  2648. ->orderBy('updated_at', 'desc')
  2649. ->limit($data['job2_num'])
  2650. ->get();
  2651. if (empty($job_recruiting->toArray())) {
  2652. $job_recruitings = "未查询到相关职位信息";
  2653. } else {
  2654. $job_recruitings = $this->processJob($job_recruiting, $web);
  2655. }
  2656. $result = [
  2657. 'job_hunting' => $job_huntings,
  2658. 'job_recuiting' => $job_recruitings,
  2659. ];
  2660. return Result::success($result);
  2661. }
  2662. /**
  2663. * c端-获取招工招聘列表
  2664. * @param array $data
  2665. * @return array
  2666. * */
  2667. public function getWebsiteJobList(array $data): array
  2668. {
  2669. $recruit_where = [];
  2670. $hunt_where = [];
  2671. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2672. if (empty($web)) {
  2673. return Result::error("此网站不存在", 0);
  2674. }
  2675. $website_id['website_id'] = $data['website_id'];
  2676. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2677. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2678. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2679. }
  2680. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2681. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2682. }
  2683. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2684. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2685. }
  2686. $query = JobRecruiting::where('job_recruiting.status', 1)
  2687. ->where('job_recruiting.website_id', $data['website_id'])
  2688. ->where($recruit_where)
  2689. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2690. $query->where(function ($q) use ($data) {
  2691. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2692. });
  2693. })
  2694. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2695. $query->where(function ($q) use ($data) {
  2696. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2697. });
  2698. })
  2699. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2700. ->select(
  2701. 'job_recruiting.id',
  2702. 'job_recruiting.hy_id',
  2703. 'job_recruiting.title',
  2704. 'job_recruiting.zw_id',
  2705. 'job_recruiting.educational',
  2706. 'job_recruiting.jtzw_id',
  2707. 'job_recruiting.city_arr_id',
  2708. 'job_recruiting.due_data',
  2709. 'job_recruiting.experience',
  2710. 'job_recruiting.cat_arr_id',
  2711. 'job_recruiting.updated_at',
  2712. 'job_company.business_name'
  2713. )
  2714. ->orderBy('updated_at', 'desc');
  2715. $recruit_count = $query->count();
  2716. $query = clone $query;
  2717. $JobRecruiting = $query
  2718. ->offset(($data['page'] - 1) * $data['pageSize'])
  2719. ->limit($data['pageSize'])
  2720. ->get();
  2721. if (empty($JobRecruiting)) {
  2722. $JobRecruiting = "暂无相关职位信息";
  2723. } else {
  2724. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2725. }
  2726. }
  2727. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2728. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2729. array_push($hunt_where, ['job', $data['zw_id']]);
  2730. }
  2731. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2732. array_push($hunt_where, ['job_name_get', $data['jtzw_id']]);
  2733. }
  2734. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2735. array_push($hunt_where, ['industry', $data['hy_id']]);
  2736. }
  2737. $query = JobHunting::where('status', 2)
  2738. ->where('job_hunting.website_id', $data['website_id'])
  2739. ->where($hunt_where)
  2740. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2741. $query->where(function ($q) use ($data) {
  2742. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2743. });
  2744. })
  2745. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  2746. $query->where(function ($q) use ($data) {
  2747. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  2748. });
  2749. })
  2750. ->select('id', 'sexy', 'experience', 'origin', 'industry', 'name', 'job', 'job_name_get', 'city_arr_id', 'cat_arr_id', 'created_at', 'updated_at')
  2751. ->orderBy('updated_at', 'desc');
  2752. $hunt_count = $query->count();
  2753. $query = clone $query;
  2754. $JobHunting = $query
  2755. ->offset(($data['page'] - 1) * $data['pageSize'])
  2756. ->limit($data['pageSize'])
  2757. ->get();
  2758. if (empty($JobHunting)) {
  2759. $JobRecruiting = "暂无相关简历信息";
  2760. } else {
  2761. $JobHunting = $this->processJob($JobHunting, $website_id);
  2762. }
  2763. }
  2764. $result = [
  2765. 'JobRecruiting' => $JobRecruiting ?? [],
  2766. 'recruit_count' => $recruit_count ?? 0,
  2767. 'JobHunting' => $JobHunting ?? [],
  2768. 'hunt_count' => $hunt_count ?? 0,
  2769. ];
  2770. return Result::success($result);
  2771. }
  2772. /**
  2773. * c端-获取招工招聘详情
  2774. * @param array $data
  2775. * @return array
  2776. * */
  2777. public function getWebsiteJobInfo(array $data): array
  2778. {
  2779. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2780. if (empty($web)) {
  2781. return Result::error("该网站不存在", 0);
  2782. }
  2783. $webid = [
  2784. 'website_id' => $data['website_id'],
  2785. ];
  2786. // 职位相关信息
  2787. if ($data['type'] == 1) {
  2788. $query = JobRecruiting::where('status', 1)
  2789. ->where('website_id', $data['website_id'])
  2790. ->select('*');
  2791. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2792. $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();
  2793. if (!empty($company)) {
  2794. $result['company'] = $this->processJob($company, $webid);
  2795. }
  2796. $other_job = JobRecruiting::where('status', 1)
  2797. ->where('website_id', $data['website_id'])
  2798. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  2799. ->where('id', '!=', $data['id'])
  2800. ->where('user_id', '=', $job[0]['user_id'])
  2801. ->limit($data['pageSize'])
  2802. ->get();
  2803. if (!empty($other_job)) {
  2804. $result['other_job'] = $this->processJob($other_job, $webid);
  2805. }
  2806. } else {
  2807. // 简历相关信息
  2808. $job = JobHunting::where('job_hunting.status', 2)
  2809. ->where('job_hunting.website_id', $data['website_id'])
  2810. ->where('job_hunting.id', $data['id'])
  2811. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2812. ->select('job_hunting.*', 'user_name')
  2813. ->get();
  2814. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  2815. if (!empty($resume->toArray())) {
  2816. $result['resume'] = 1;
  2817. } else {
  2818. $result['resume'] = 0;
  2819. }
  2820. }
  2821. if (empty($job->toArray())) {
  2822. return Result::error("id参数错误", 0);
  2823. }
  2824. if (!empty($job[0]['job_experience'])) {
  2825. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  2826. if (!empty($job_experience)) {
  2827. // $hy = [];
  2828. foreach ($job_experience as $key => $value) {
  2829. // $id = $value['id'];
  2830. $hy[$key] = $value['job_industry'];
  2831. $zw_id[$key] = $value['job_typename'];
  2832. $jtzw_id[$key] = $value['job_name'];
  2833. }
  2834. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  2835. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  2836. // 先将关联表转换为索引数组,提高查找效率
  2837. $hyLookup = [];
  2838. foreach ($hy_table as $item) {
  2839. $hyLookup[$item['hyid']] = $item['hyname'];
  2840. }
  2841. $zwLookup = [];
  2842. foreach ($zw_table as $item) {
  2843. $zwLookup[$item['zwid']] = $item['zwname'];
  2844. }
  2845. foreach ($job_experience as $key => &$value) {
  2846. // 处理行业名称
  2847. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  2848. $value['hy_name'] = $hyLookup[$hy[$key]];
  2849. }
  2850. // 处理职位名称
  2851. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  2852. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  2853. }
  2854. // 处理具体职位名称
  2855. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  2856. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  2857. }
  2858. }
  2859. // 释放引用,防止意外修改后续代码
  2860. unset($value);
  2861. }
  2862. $result['job_experience'] = $job_experience ?? [];
  2863. }
  2864. if (!empty($job[0]['education_experience'])) {
  2865. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  2866. if (!empty($education_experience)) {
  2867. foreach ($education_experience as $key => $value) {
  2868. // $id = $value['id'];
  2869. $education[$key] = $value['school_education'];
  2870. }
  2871. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  2872. // // 先将关联表转换为索引数组,提高查找效率
  2873. $educationLookup = [];
  2874. foreach ($education_table as $item) {
  2875. $educationLookup[$item['evalue']] = $item['ename'];
  2876. }
  2877. foreach ($education_experience as $key => &$value) {
  2878. // 处理学历名称
  2879. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  2880. $value['education_name'] = $educationLookup[$education[$key]];
  2881. }
  2882. }
  2883. }
  2884. $result['education_experience'] = $job_experience ?? [];
  2885. }
  2886. $result['job'] = $this->processJob($job, $webid);
  2887. // // 返现对应的栏目
  2888. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  2889. $category = WebsiteCategory::where('website_id', $data['website_id'])
  2890. ->whereIn('category_id', $catid)
  2891. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  2892. ->orderBy('pid')->get()->all();
  2893. if (!empty($category)) {
  2894. $result['category'] = $category;
  2895. }
  2896. $result['job'] = $job;
  2897. $result['job_experience'] = $job_experience ?? [];
  2898. $result['education_experience'] = $education_experience ?? [];
  2899. if (empty($result)) {
  2900. return Result::error("参数错误", 0);
  2901. }
  2902. return Result::success($result);
  2903. }
  2904. /**
  2905. * c端-申请职位
  2906. * @param array $data
  2907. * @return array
  2908. * */
  2909. public function getWebsiteJobApply(array $data): array
  2910. {
  2911. // 首先验证网站是否存在
  2912. // return Result::success($data);
  2913. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2914. if (empty($web)) {
  2915. return Result::error("该网站不存在", 0);
  2916. }
  2917. // 验证用户是否存在且为个人会员/管理员
  2918. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2919. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2920. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  2921. return Result::error("用户不存在", 0);
  2922. }
  2923. // 去除重复元素和空元素,并保持原始顺序
  2924. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  2925. return !empty($value);
  2926. }));
  2927. // 验证职位是否存在 1:审核通过
  2928. $recruiting = JobRecruiting::where('status', 1)
  2929. ->where('website_id', $data['website_id'])
  2930. ->whereIn('id', $data['recruit_id'])
  2931. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  2932. if (empty($recruiting)) {
  2933. return Result::error("该职位不存在", 0);
  2934. }
  2935. // 简历是否存在
  2936. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  2937. if (empty($hunt_id)) {
  2938. return Result::error("该简历不存在", 0);
  2939. }
  2940. $data['hunt_id'] = $hunt_id['hunt_id'];
  2941. // // 验证是否已投递过该职位
  2942. $apply = JobApply::where('user_id', $data['user_id'])
  2943. ->where('hunt_id', $data['hunt_id'])
  2944. ->where('website_id', $data['website_id'])
  2945. ->whereIn('recruit_id', $data['recruit_id'])
  2946. ->get(['recruit_id']);
  2947. if (!empty($apply->toArray())) {
  2948. return Result::error("您已投递过该职位!");
  2949. }
  2950. $insertData = array_map(function ($recruiting) use ($data) {
  2951. return [
  2952. 'user_id' => $data['user_id'],
  2953. 'hunt_id' => $data['hunt_id'],
  2954. 'website_id' => $data['website_id'],
  2955. 'recruit_id' => $recruiting['recruit_id'],
  2956. 'receiver_id' => $recruiting['receiver_id'],
  2957. 'status' => 1,
  2958. ];
  2959. }, $recruiting);
  2960. // 批量插入数据
  2961. $result = JobApply::insert($insertData);
  2962. if (empty($result)) {
  2963. return Result::error("投递失败", 0);
  2964. }
  2965. return Result::success($result);
  2966. }
  2967. /**
  2968. * 招工招聘-沟通简历
  2969. * @param array $data
  2970. * @return array
  2971. * */
  2972. public function getWebsiteJobResume(array $data): array
  2973. {
  2974. // 首先验证网站是否存在
  2975. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2976. if (empty($web)) {
  2977. return Result::error("该网站不存在", 0);
  2978. }
  2979. // return Result::success($data);
  2980. // 验证用户是否存在且为企业会员/管理员
  2981. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2982. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2983. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2984. return Result::error("用户不存在", 0);
  2985. }
  2986. // 去除重复元素和空元素,并保持原始顺序
  2987. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  2988. return !empty($value);
  2989. }));
  2990. // 验证简历是否存在
  2991. $hunting = JobHunting::where('status', 2)
  2992. ->where('website_id', $data['website_id'])
  2993. ->whereIn('id', $data['hunt_id'])
  2994. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  2995. if (empty($hunting)) {
  2996. return Result::error("该简历不存在", 0);
  2997. }
  2998. // 验证是否已沟通过该简历
  2999. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3000. ->where('recruit_id', $data['recruit_id'])
  3001. ->where('website_id', $data['website_id'])
  3002. ->whereIn('hunt_id', $data['hunt_id'])
  3003. ->get(['hunt_id']);
  3004. if (!empty($remuse->toArray())) {
  3005. return Result::error("您已沟通过该简历!");
  3006. }
  3007. // 准备要插入的数据数组
  3008. $insertData = array_map(function ($hunting) use ($data) {
  3009. return [
  3010. 'user_id' => $data['user_id'],
  3011. 'recruit_id' => $data['recruit_id'],
  3012. 'website_id' => $data['website_id'],
  3013. 'hunt_id' => $hunting['hunt_id'],
  3014. 'receiver_id' => $hunting['receiver_id'],
  3015. 'status' => 1,
  3016. ];
  3017. }, $hunting);
  3018. // 批量插入数据
  3019. $result = JobRemuse::insert($insertData);
  3020. if (empty($result)) {
  3021. return Result::error("沟通失败", 0);
  3022. }
  3023. return Result::success($result);
  3024. }
  3025. /**
  3026. * 招工招聘 -我的职位(企业会员)
  3027. * @param array $data
  3028. * @return array
  3029. */
  3030. public function getWebsiteJobRecruiting(array $data): array
  3031. {
  3032. $web = Website::where('id', $data['website_id'])->first('id');
  3033. if (empty($web)) {
  3034. return Result::error("该网站不存在", 0);
  3035. }
  3036. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3037. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3038. return Result::error("用户暂无权限!", 0);
  3039. }
  3040. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3041. $result = JobRecruiting::where('website_id', $data['website_id'])
  3042. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3043. $query->where('user_id', $user['id']);
  3044. })
  3045. ->where('status', 1)
  3046. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3047. ->orderBy('updated_at', 'desc')
  3048. ->limit($data['pageSize'])
  3049. ->get();
  3050. if (empty($result)) {
  3051. return Result::error("暂无相关职位信息", 0);
  3052. }
  3053. return Result::success($result);
  3054. }
  3055. /**
  3056. * c端 - 验证路由
  3057. * @param array $data
  3058. * @return array
  3059. */
  3060. /**
  3061. * c端 - 验证路由
  3062. * @param array $data
  3063. * @return array
  3064. */
  3065. public function checkWebsiteRoute(array $data): array
  3066. {
  3067. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3068. if (empty($web)) {
  3069. return Result::error("该网站不存在", 0);
  3070. }
  3071. if(isset($data['other_route']) && !empty($data['other_route'])) {
  3072. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3073. if (empty($whiteRouterInfo)) {
  3074. return Result::error("非法路径地址", 0);
  3075. }else{
  3076. return Result::success($whiteRouterInfo->toArray());
  3077. }
  3078. } else {
  3079. // 验证栏目路由
  3080. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3081. ->where('aLIas_pinyin', $data['last_route'])
  3082. ->first();
  3083. if (empty($last_category)) {
  3084. return Result::error("该栏目不存在", 0);
  3085. }
  3086. if (isset($data['id']) && !empty($data['id'])) {
  3087. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3088. switch ($last_category['type']) {
  3089. case 1:
  3090. // 文章
  3091. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3092. $article = Article::where('status', 1)
  3093. ->where('id', $data['id'])
  3094. ->where(function ($query) use ($data) {
  3095. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3096. ->orWhereNull("ignore_ids");
  3097. })
  3098. ->first(['cat_arr_id']);
  3099. if (empty($article)) {
  3100. return Result::error("该文章不存在", 0);
  3101. }
  3102. // return Result::success($article);
  3103. break;
  3104. case 2:
  3105. // 商品
  3106. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3107. $article = Good::where('website_id', $data['website_id'])
  3108. ->where('status', 2)
  3109. ->where('id', $data['id'])
  3110. ->first(['cat_arr_id']);
  3111. if (empty($article)) {
  3112. return Result::error("该商品不存在", 0);
  3113. }
  3114. break;
  3115. case 3:
  3116. // 书刊信息
  3117. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3118. $article = Book::where('website_id', $data['website_id'])
  3119. ->where('status', 2)
  3120. ->where('id', $data['id'])
  3121. ->first(['id', 'cat_arr_id']);
  3122. if (empty($article)) {
  3123. return Result::error("该书刊不存在", 0);
  3124. }
  3125. break;
  3126. case 4:
  3127. // 招聘
  3128. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核;(只有企业会员需要审核)',
  3129. $article = JobRecruiting::where('website_id', $data['website_id'])
  3130. ->where('status', 1)
  3131. ->where('id', $data['id'])
  3132. ->first(['cat_arr_id']);
  3133. if (empty($article)) {
  3134. return Result::error("该招聘不存在", 0);
  3135. }
  3136. break;
  3137. case 5:
  3138. // 求职
  3139. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3140. $article = JobHunting::where('website_id', $data['website_id'])
  3141. ->where('status', 2)
  3142. ->where('id', $data['id'])
  3143. ->first(['cat_arr_id']);
  3144. if (empty($article)) {
  3145. return Result::error("该求职不存在", 0);
  3146. }
  3147. break;
  3148. case 6:
  3149. // 招工招聘
  3150. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3151. $article = JobRecruiting::where('website_id', $data['website_id'])
  3152. ->where('status', 1)
  3153. ->where('id', $data['id'])
  3154. ->first(['cat_arr_id']);
  3155. if (empty($article)) {
  3156. $article = JobHunting::where('website_id', $data['website_id'])
  3157. ->where('status', 2)
  3158. ->where('id', $data['id'])
  3159. ->first(['cat_arr_id']);
  3160. }
  3161. if (empty($article)) {
  3162. return Result::error("该招工招聘不存在", 0);
  3163. }
  3164. break;
  3165. default:
  3166. return Result::error("该数据不存在", 0);
  3167. break;
  3168. }
  3169. $catid = json_decode($article['cat_arr_id'], true);
  3170. if (empty($catid)) {
  3171. return Result::error("该数据不存在", 0);
  3172. }
  3173. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3174. ->orderByRaw('FIELD(category_id, ' . implode(',', $catid) . ')')
  3175. ->whereIn('category_id', $catid)
  3176. ->pluck('aLIas_pinyin')
  3177. ->implode('/');
  3178. }
  3179. if ($last_category['pid'] != 0) {
  3180. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3181. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3182. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr) . ')')
  3183. ->whereIn('category_id', $cat_arr)
  3184. ->pluck('aLIas_pinyin')
  3185. ->implode('/');
  3186. } else {
  3187. $pinyin = $last_category['aLIas_pinyin'];
  3188. }
  3189. if (empty($pinyin) || $pinyin != $data['all_route']) {
  3190. return Result::error('非法路径!');
  3191. } else {
  3192. return Result::success($pinyin);
  3193. }
  3194. }
  3195. }
  3196. /**
  3197. * 招工招聘 - 获取推荐职位
  3198. * @param array $data
  3199. * @return array
  3200. */
  3201. public function getWebsiteLevelJob(array $data): array
  3202. {
  3203. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3204. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3205. ->where('job_recruiting.status', 1)
  3206. ->where('job_level', $data['job_level'])
  3207. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3208. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3209. ->orderBy('job_recruiting.updated_at', 'desc')
  3210. ->limit($data['pageSize'])
  3211. ->get();
  3212. $web = ['website_id' => $data['website_id']];
  3213. if (!empty($job)) {
  3214. $result = $this->processJob($job, $web);
  3215. }
  3216. if (empty($result)) {
  3217. return Result::error("暂无相关职位信息", 0);
  3218. }
  3219. return Result::success($result);
  3220. }
  3221. /**
  3222. * 验证导航名称是否重复
  3223. * @return void
  3224. */
  3225. //20250226 产品列表
  3226. public function getGoodList(array $data): array
  3227. {
  3228. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3229. unset($data['type_id']);
  3230. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3231. $where = [];
  3232. if ($type_id != '10000') {
  3233. $where = [
  3234. 'good.user_id' => $user_id,
  3235. ];
  3236. }
  3237. //类型
  3238. if (isset($data['type_id']) && $data['type_id']) {
  3239. $where = [
  3240. 'type_id' => $data['type_id'],
  3241. ];
  3242. }
  3243. //名称
  3244. if (isset($data['name']) && $data['name']) {
  3245. $where = [
  3246. 'good.name' => $data['name'],
  3247. ];
  3248. }
  3249. //status
  3250. if (isset($data['status']) && $data['status'] != '') {
  3251. $where = [
  3252. 'good.status' => $data['status'],
  3253. ];
  3254. }
  3255. //status1
  3256. // if (isset($data['status1']) && $data['status1'] == 1) {
  3257. // $status1 = 1;
  3258. // }
  3259. $where1 = [];
  3260. //website_id
  3261. // if (isset($data['website_id']) && $data['website_id']) {
  3262. // $where1 = [
  3263. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3264. // ];
  3265. // }
  3266. // website_name
  3267. if (isset($data['website_name']) && $data['website_name']) {
  3268. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3269. }
  3270. // catid
  3271. if (isset($data['category_name']) && $data['category_name']) {
  3272. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3273. }
  3274. // $result = Good::where($where)
  3275. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3276. $result = Good::where($where)
  3277. ->when(!empty($where1), function ($query) use ($where1) {
  3278. return $query->where($where1);
  3279. })
  3280. //status 1待审核2已审核3已拒绝
  3281. ->when(isset($data['status1']), function ($query) {
  3282. return $query->whereIn('good.status', [1, 3]);
  3283. })
  3284. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3285. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3286. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3287. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3288. ->orderBy("updated_at", "desc")
  3289. ->limit($data['page_size'])
  3290. ->offset(($data['page'] - 1) * $data['page_size'])
  3291. ->get();
  3292. $count = Good::where($where)
  3293. ->when(!empty($where1), function ($query) use ($where1) {
  3294. return $query->where($where1);
  3295. })
  3296. //status 1待审核2已审核3已拒绝
  3297. ->when(isset($data['status1']), function ($query) {
  3298. return $query->whereIn('good.status', [1, 3]);
  3299. })
  3300. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3301. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3302. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3303. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3304. ->orderBy("updated_at", "desc")->count();
  3305. $data = [
  3306. 'rows' => $result->toArray(),
  3307. 'count' => $count,
  3308. ];
  3309. if (empty($result)) {
  3310. return Result::error("此栏目暂无相关产品", 0);
  3311. }
  3312. return Result::success($data);
  3313. }
  3314. public function getGoodInfo(array $data): array
  3315. {
  3316. $result = Good::where('id', $data['id'])->first();
  3317. if (empty($result)) {
  3318. return Result::error("此产品不存在", 0);
  3319. }
  3320. return Result::success($result);
  3321. }
  3322. public function addGood(array $data): array
  3323. {
  3324. // unset($data['city_arr_id']);
  3325. // unset($data['cat_arr_id']);
  3326. $data['city_id'] = end($data['city_arr_id']);
  3327. $data['catid'] = end($data['cat_arr_id']);
  3328. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3329. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3330. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3331. unset($data['imgUrl']);
  3332. if (isset($data['price']) && $data['price'] == '') {
  3333. $data['price'] = 0;
  3334. }
  3335. $result = Good::insert($data);
  3336. if (empty($result)) {
  3337. return Result::error("添加失败", 0);
  3338. }
  3339. return Result::success($result);
  3340. }
  3341. public function updateGood(array $data): array
  3342. {
  3343. $data['city_id'] = end($data['city_arr_id']);
  3344. $data['catid'] = end($data['cat_arr_id']);
  3345. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3346. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3347. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3348. //设置东八区
  3349. date_default_timezone_set('Asia/Shanghai');
  3350. $data['updated_at'] = date('Y-m-d H:i:s');
  3351. if (isset($data['price']) && $data['price'] == '') {
  3352. $data['price'] = 0;
  3353. }
  3354. $result = Good::where('id', $data['id'])->update($data);
  3355. if (empty($result)) {
  3356. return Result::error("更新失败", 0);
  3357. }
  3358. return Result::success($result);
  3359. }
  3360. public function delGood(array $data): array
  3361. {
  3362. $result = Good::where('id', $data['id'])->delete();
  3363. if (empty($result)) {
  3364. return Result::error("删除失败", 0);
  3365. }
  3366. return Result::success($result);
  3367. }
  3368. //20250226 产品列表
  3369. //20250306 求职信息
  3370. public function getJobHuntingList(array $data): array
  3371. {
  3372. $where = [];
  3373. if (isset($data['username']) && !empty($data['username'])) {
  3374. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3375. }
  3376. //status 1待审核2已审核3已拒绝
  3377. if (isset($data['status']) && $data['status'] != '') {
  3378. $where = [
  3379. 'job_hunting.status' => $data['status'],
  3380. ];
  3381. }
  3382. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3383. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3384. unset($data['type_id']);
  3385. if ($type_id != '10000') {
  3386. $where[] = ['job_hunting.user_id', '=', $user_id];
  3387. }
  3388. $result = JobHunting::where($where)
  3389. ->when(!empty($data['status1']), function ($query) use ($data) {
  3390. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3391. })
  3392. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3393. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3394. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3395. ->orderBy("updated_at", "desc")
  3396. ->limit($data['page_size'])
  3397. ->offset(($data['page'] - 1) * $data['page_size'])
  3398. ->get();
  3399. if (empty($result)) {
  3400. return Result::error("查询失败", 0);
  3401. }
  3402. $count = JobHunting::where($where)
  3403. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3404. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3405. ->count();
  3406. $data = [
  3407. 'rows' => $result->toArray(),
  3408. 'count' => $count,
  3409. ];
  3410. return Result::success($data);
  3411. }
  3412. public function getJobHuntingApply(array $data): array
  3413. {
  3414. var_dump($data, '-----------------test--------1-');
  3415. $where = [];
  3416. if (isset($data['username']) && !empty($data['username'])) {
  3417. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3418. }
  3419. if (isset($data['salary']) && !empty($data['salary'])) {
  3420. $where[] = [
  3421. 'job_hunting.salary',
  3422. '=',
  3423. $data['salary'],
  3424. ];
  3425. }
  3426. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3427. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3428. unset($data['type_id']);
  3429. if ($type_id != '10000') {
  3430. $where[] = ['job_apply.user_id', '=', $user_id];
  3431. }
  3432. var_dump($where, '-----------------test---------');
  3433. $result = jobApply::where($where)
  3434. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3435. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3436. // })
  3437. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3438. ->where('job_enum.egroup', '=', 'income')
  3439. ->where('job_hunting.status', 2) //已审核
  3440. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3441. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3442. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3443. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3444. //职位----是申请职位
  3445. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3446. ->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')
  3447. ->orderBy("job_hunting.updated_at", "desc")
  3448. ->limit($data['page_size'])
  3449. ->offset(($data['page'] - 1) * $data['page_size'])
  3450. ->get();
  3451. if (empty($result)) {
  3452. return Result::error("查询失败", 0);
  3453. }
  3454. $count = jobApply::where($where)
  3455. ->where('job_enum.egroup', '=', 'income')
  3456. ->where('job_hunting.status', 2) //已审核
  3457. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3458. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3459. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3460. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3461. //职位----是申请职位
  3462. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3463. ->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')
  3464. ->count();
  3465. $data = [
  3466. 'rows' => $result->toArray(),
  3467. 'count' => $count,
  3468. ];
  3469. return Result::success($data);
  3470. }
  3471. public function addJobHunting(array $data): array
  3472. {
  3473. date_default_timezone_set('Asia/Shanghai');
  3474. unset($data['company_name']);
  3475. unset($data['job_industry']);
  3476. unset($data['job_name']);
  3477. unset($data['department']);
  3478. unset($data['job_timeList']);
  3479. unset($data['job_content']);
  3480. unset($data['job_typename']); //不知道这是啥,
  3481. $data['created_at'] = date('Y-m-d H:i:s');
  3482. $data['updated_at'] = date('Y-m-d H:i:s');
  3483. //根据用户 user_id 只能添加一次
  3484. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3485. if (!empty($result)) {
  3486. return Result::error("您已添加过求职信息", 0);
  3487. }
  3488. var_dump($result, '-----------------test---------');
  3489. $result = JobHunting::create($data);
  3490. if (empty($result)) {
  3491. return Result::error("添加失败", 0);
  3492. }
  3493. return Result::success($result);
  3494. }
  3495. public function delJobHunting(array $data): array
  3496. {
  3497. $result = JobHunting::where('id', $data['id'])->delete();
  3498. if (empty($result)) {
  3499. return Result::error("删除失败", 0);
  3500. }
  3501. return Result::success($result);
  3502. }
  3503. public function updateJobHunting(array $data): array
  3504. {
  3505. //设置东八区
  3506. date_default_timezone_set('Asia/Shanghai');
  3507. unset($data['company_name']);
  3508. unset($data['job_industry']);
  3509. unset($data['job_name']);
  3510. unset($data['department']);
  3511. unset($data['job_timeList']);
  3512. unset($data['job_content']);
  3513. unset($data['job_typename']); //不知道这是啥,
  3514. $data['created_at'] = date('Y-m-d H:i:s');
  3515. $data['updated_at'] = date('Y-m-d H:i:s');
  3516. $result = JobHunting::where('id', $data['id'])->update($data);
  3517. if (empty($result)) {
  3518. return Result::error("更新失败", 0);
  3519. }
  3520. return Result::success($result);
  3521. }
  3522. public function getJobHuntingInfo(array $data): array
  3523. {
  3524. $result = JobHunting::where('id', $data['id'])->first();
  3525. if (empty($result)) {
  3526. return Result::error("查询失败", 0);
  3527. }
  3528. return Result::success($result);
  3529. }
  3530. public function getJobHuntingData(array $data): array
  3531. {
  3532. $jobEnum = JobEnum::get();
  3533. $jobIndustry = JobIndustry::get();
  3534. $jobNature = JobNature::get();
  3535. $jobPosition = JobPosition::get();
  3536. $data = [
  3537. 'jobEnum' => $jobEnum,
  3538. 'jobIndustry' => $jobIndustry,
  3539. 'jobNature' => $jobNature,
  3540. 'jobPosition' => $jobPosition,
  3541. ];
  3542. return Result::success($data);
  3543. }
  3544. public function delJobHuntingInfo(array $data): array
  3545. {
  3546. $result = JobHunting::where('id', $data['id'])->delete();
  3547. return Result::success();
  3548. }
  3549. //20250324 通知,公告,消息
  3550. public function delNotice(array $data): array
  3551. {
  3552. $result = Notice::where('id', $data['id'])->delete();
  3553. if ($result) {
  3554. return Result::success();
  3555. } else {
  3556. return Result::error("删除失败", 0);
  3557. }
  3558. }
  3559. public function getNoticeInfo(array $data): array
  3560. {
  3561. $result = Notice::where('id', $data['id'])->first();
  3562. if (empty($result)) {
  3563. return Result::error("查询失败", 0);
  3564. }
  3565. return Result::success($result);
  3566. }
  3567. public function addNotice(array $data): array
  3568. {
  3569. date_default_timezone_set('Asia/Shanghai');
  3570. $data['created_at'] = date('Y-m-d H:i:s');
  3571. $data['updated_at'] = date('Y-m-d H:i:s');
  3572. $user_id = UserInfo::
  3573. //city_id不是null
  3574. whereNotNull('city_id')
  3575. ->whereNotNull('department_id')
  3576. ->where(function ($query) use ($data) {
  3577. $query->where(function ($subQuery) use ($data) {
  3578. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3579. });
  3580. })
  3581. ->where(function ($query) use ($data) {
  3582. $query->where(function ($subQuery) use ($data) {
  3583. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3584. });
  3585. })
  3586. ->pluck('user_id')->toArray();
  3587. $user_id = array_unique($user_id);
  3588. $chat_ids = $user_id;
  3589. $user_id = json_encode($user_id);
  3590. $data['re_user_ids'] = $user_id;
  3591. $result = Notice::insertGetId($data);
  3592. if ($result && $data['is_group'] == 1) {
  3593. //chat_group
  3594. $group_id = PublicData::uuid();
  3595. $groupData = [
  3596. 'id' => $group_id,
  3597. 'creator_id' => $data['user_id'],
  3598. 'group_name' => $data['group_name'] ?? '',
  3599. 'profile' => $data['profile'] ?? 0,
  3600. ];
  3601. var_dump($groupData, '-----------------groupData-------');
  3602. $groupResult = ChatGroups::insertGetId($groupData);
  3603. var_dump($groupResult, '-----------------groupid-------');
  3604. $groupMemberData = [
  3605. 'id' => PublicData::uuid(),
  3606. 'user_id' => $data['user_id'],
  3607. 'group_id' => $group_id,
  3608. 'leader' => 2,
  3609. ];
  3610. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  3611. //$chat_ids 去除掉$data['user_id']
  3612. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  3613. //插入群成员表
  3614. $groupMemberDataUser = [];
  3615. $chatData = [];
  3616. foreach ($chat_ids as $key => $value) {
  3617. $groupMemberDataUser[] = [
  3618. 'id' => PublicData::uuid(),
  3619. 'user_id' => $value,
  3620. 'group_id' => $group_id,
  3621. 'leader' => 1,
  3622. ];
  3623. $chatData[] = [
  3624. 'user_id' => $value,
  3625. 'msg_type' => 1,
  3626. 'receiver_id' => $group_id,
  3627. 'content' => '通过通知创建群聊',
  3628. 'group_receiver_id' => $data['user_id'],
  3629. 'action' => 'recieved',
  3630. 'created_at' => date('Y-m-d H:i:s'),
  3631. ];
  3632. }
  3633. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  3634. ChatGroupsMember::insert($groupMemberDataUser);
  3635. //插入一条管理员聊天记录
  3636. $chatData[] = [
  3637. 'user_id' => $data['user_id'],
  3638. 'msg_type' => 1,
  3639. 'receiver_id' => $group_id,
  3640. 'content' => '通过通知创建群聊',
  3641. 'group_receiver_id' => $data['user_id'],
  3642. 'action' => 'said',
  3643. 'created_at' => date('Y-m-d H:i:s'),
  3644. ];
  3645. var_dump($chatData, '-----------------chatData-------');
  3646. $chatResult = ChatRecords::insert($chatData);
  3647. //更新result的 group_id
  3648. $data['group_id'] = $group_id;
  3649. Notice::where(['id' => $result])->update($data);
  3650. }
  3651. if (empty($result)) {
  3652. return Result::error("添加失败", 0);
  3653. }
  3654. return Result::success($result);
  3655. }
  3656. public function updateNotice(array $data): array
  3657. {
  3658. date_default_timezone_set('Asia/Shanghai');
  3659. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  3660. $user_id = UserInfo::
  3661. //city_id不是null
  3662. whereNotNull('city_id')
  3663. ->whereNotNull('department_id')
  3664. ->where(function ($query) use ($data) {
  3665. $query->where(function ($subQuery) use ($data) {
  3666. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3667. });
  3668. })
  3669. ->where(function ($query) use ($data) {
  3670. $query->where(function ($subQuery) use ($data) {
  3671. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3672. });
  3673. })
  3674. ->pluck('user_id')->toArray();
  3675. $user_id = array_unique($user_id);
  3676. $user_id = json_encode($user_id);
  3677. $data['re_user_ids'] = $user_id;
  3678. $data['updated_at'] = date('Y-m-d H:i:s');
  3679. $result = Notice::where('id', $data['id'])->update($data);
  3680. return Result::success($result);
  3681. }
  3682. public function getNoticeList(array $data): array
  3683. {
  3684. $where = [];
  3685. //title
  3686. if (isset($data['title']) && !empty($data['title'])) {
  3687. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  3688. }
  3689. //level
  3690. if (isset($data['level']) && !empty($data['level'])) {
  3691. $where[] = ['notice.level', '=', $data['level']];
  3692. }
  3693. //status
  3694. if (isset($data['status']) && !empty($data['status'])) {
  3695. $where[] = ['notice.status', '=', $data['status']];
  3696. }
  3697. var_dump($data, '-----------------test---------');
  3698. if ($data['type_id'] == 10000) {
  3699. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3700. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3701. })
  3702. ->where($where)
  3703. ->orderBy('updated_at', 'desc')
  3704. ->limit($data['page_size'])
  3705. ->offset(($data['page'] - 1) * $data['page_size'])
  3706. ->get();
  3707. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3708. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3709. })
  3710. ->where($where)
  3711. ->orderBy('updated_at', 'desc')
  3712. ->count();
  3713. } else {
  3714. $result = Notice::where($where)
  3715. // ->where('user_id', $data['user_id'])
  3716. ->Where(function ($query) use ($data) {
  3717. $query->Where(function ($q) use ($data) {
  3718. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3719. ->orWhere('notice.user_id', $data['user_id']);
  3720. });
  3721. })
  3722. ->orderBy('updated_at', 'desc')
  3723. ->limit($data['page_size'])
  3724. ->offset(($data['page'] - 1) * $data['page_size'])
  3725. ->get();
  3726. $total = Notice::where($where)
  3727. // ->where('user_id', $data['user_id'])
  3728. ->Where(function ($query) use ($data) {
  3729. $query->Where(function ($q) use ($data) {
  3730. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3731. ->orWhere('notice.user_id', $data['user_id']);
  3732. });
  3733. })
  3734. ->count();
  3735. }
  3736. if (empty($result)) {
  3737. return Result::error("查询失败", 0);
  3738. }
  3739. $data = [
  3740. 'rows' => $result,
  3741. 'count' => $total,
  3742. ];
  3743. return Result::success($data);
  3744. }
  3745. public function getNoticeDetail(array $data): array
  3746. {
  3747. $result = Notice::where('id', $data['id'])->first();
  3748. if (empty($result)) {
  3749. return Result::error("查询失败", 0);
  3750. }
  3751. return Result::success($result);
  3752. }
  3753. public function deleteNotice(array $data): array
  3754. {
  3755. $notice = Notice::where('id', $data['id'])->first();
  3756. if (empty($notice)) {
  3757. return Result::error("删除失败", 0);
  3758. }
  3759. $chat_group_id = $notice->group_id;
  3760. if ($chat_group_id) {
  3761. //删除群聊
  3762. ChatGroups::where('id', $chat_group_id)->delete();
  3763. //删除群成员
  3764. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  3765. //删除群聊记录
  3766. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  3767. }
  3768. $result = Notice::where('id', $data['id'])->delete();
  3769. return Result::success($result);
  3770. }
  3771. public function getMSG(array $data): array
  3772. {
  3773. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  3774. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3775. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  3776. $result = [];
  3777. if ($type_id == 1) {
  3778. //最近的5篇已审的文章
  3779. $apply_articale = Article::where('status', 1)
  3780. ->where('admin_user_id', $user_id)
  3781. ->orderBy('updated_at', 'desc')
  3782. ->limit(5)->get();
  3783. //获取5条单聊未读聊天消息
  3784. $chat = ChatRecords::where('is_read', 0)
  3785. ->where('user_id', $user_id)
  3786. ->where('talk_type', 1)
  3787. ->orderBy('created_at', 'desc')
  3788. ->limit(5)->get();
  3789. //获取5条未读群聊信息
  3790. $chat_group = ChatRecords::where('is_read', 0)
  3791. ->where('user_id', $user_id)
  3792. ->where('talk_type', 2)
  3793. ->orderBy('created_at', 'desc')
  3794. ->limit(5)->get();
  3795. //获取5条用户的已审核商品
  3796. $good = Good::where('status', 2)
  3797. ->where('user_id', $user_id)
  3798. ->orderBy('updated_at', 'desc')
  3799. ->limit(5)->get();
  3800. //获取5条用户待审核的公告
  3801. $notice = Notice::where('status', 2)
  3802. ->where('user_id', $user_id)
  3803. ->orderBy('updated_at', 'desc')
  3804. ->limit(5)->get();
  3805. //获取5条用户的待审核投诉
  3806. $complaint = Complaint::where('status', 2)
  3807. ->where('user_id', $user_id)
  3808. ->orderBy('updated_at', 'desc')
  3809. ->limit(5)->get();
  3810. //获取5条用户的book
  3811. $book = Book::where('status', 2)
  3812. ->where('user_id', $user_id)
  3813. ->orderBy('updated_at', 'desc')
  3814. ->limit(5)->get();
  3815. //获取5条用户的求职
  3816. //获取5条用户的求职 1
  3817. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3818. ->where('job_hunting.user_id', $user_id)
  3819. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3820. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3821. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3822. ->orderBy('updated_at', 'desc')
  3823. ->limit(5)->get();
  3824. //获取5条用户的求职 2
  3825. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3826. ->where('job_recruiting.user_id', $user_id)
  3827. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3828. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3829. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3830. ->orderBy('updated_at', 'desc')
  3831. ->limit(5)->get();
  3832. //人才库 1
  3833. $job_apply = JobApply::where('job_apply.status', 1)
  3834. ->where('job_apply.receiver_id', $user_id)
  3835. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3836. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3837. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3838. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3839. ->select('job_recruiting', 'job_recruiting.', '', '')
  3840. ->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')
  3841. ->orderBy('updated_at', 'desc')
  3842. ->limit(5)->get();
  3843. // 职场机会 2
  3844. $job_resume = JobResume::where('job_resume.status', 1)
  3845. ->where('job_resume.receiver_id', $user_id)
  3846. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3847. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3848. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3849. ->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')
  3850. ->orderBy('updated_at', 'desc')
  3851. ->limit(5)->get();
  3852. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume);
  3853. $result = [
  3854. 'apply_articale' => $apply_articale,
  3855. 'chat' => $chat,
  3856. 'chat_group' => $chat_group,
  3857. 'good' => $good,
  3858. 'notice' => $notice,
  3859. 'complaint' => $complaint,
  3860. 'book' => $book,
  3861. 'job_hunting' => $job_hunting,
  3862. 'job_recruiting' => $job_recruiting,
  3863. 'job_apply' => $job_apply,
  3864. 'job_resume' => $job_resume,
  3865. 'count' => $count,
  3866. ];
  3867. } elseif ($type_id == 2) {
  3868. //最近的5篇已审的文章
  3869. $apply_articale = Article::where('status', 1)
  3870. ->where('admin_user_id', $user_id)
  3871. ->limit(5)->get();
  3872. //获取5条单聊未读聊天消息
  3873. $chat = ChatRecords::where('is_read', 0)
  3874. ->where('user_id', $user_id)
  3875. ->where('talk_type', 1)
  3876. ->orderBy('created_at', 'desc')
  3877. ->limit(5)->get();
  3878. //获取5条未读群聊信息
  3879. $chat_group = ChatRecords::where('is_read', 0)
  3880. ->where('user_id', $user_id)
  3881. ->where('talk_type', 2)
  3882. ->orderBy('created_at', 'desc')
  3883. ->limit(5)->get();
  3884. //获取5条用户的已审核商品
  3885. $good = Good::where('status', 2)
  3886. ->where('user_id', $user_id)
  3887. ->orderBy('updated_at', 'desc')
  3888. ->limit(5)->get();
  3889. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  3890. $result = [
  3891. 'apply_articale' => $apply_articale,
  3892. 'chat' => $chat,
  3893. 'chat_group' => $chat_group,
  3894. 'good' => $good,
  3895. 'count' => $count,
  3896. ];
  3897. } elseif ($type_id == 3) {
  3898. //最近的5篇已审的文章
  3899. $apply_articale = Article::where('status', 1)
  3900. ->where('admin_user_id', $user_id)
  3901. ->limit(5)->get();
  3902. //获取5条单聊未读聊天消息
  3903. $chat = ChatRecords::where('is_read', 0)
  3904. ->where('user_id', $user_id)
  3905. ->where('talk_type', 1)
  3906. ->orderBy('created_at', 'desc')
  3907. ->limit(5)->get();
  3908. //获取5条未读群聊信息
  3909. $chat_group = ChatRecords::where('is_read', 0)
  3910. ->where('user_id', $user_id)
  3911. ->where('talk_type', 2)
  3912. ->orderBy('created_at', 'desc')
  3913. ->limit(5)->get();
  3914. //获取5条用户的已审核商品
  3915. $good = Good::where('status', 2)
  3916. ->where('user_id', $user_id)
  3917. ->orderBy('updated_at', 'desc')
  3918. ->limit(5)->get();
  3919. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  3920. $result = [
  3921. 'apply_articale' => $apply_articale,
  3922. 'chat' => $chat,
  3923. 'chat_group' => $chat_group,
  3924. 'good' => $good,
  3925. 'count' => $count,
  3926. ];
  3927. } elseif ($type_id == 4) {
  3928. //最近的5篇已审的文章
  3929. $apply_articale = Article::where('status', 1)
  3930. ->where('admin_user_id', $user_id)
  3931. ->limit(5)->get();
  3932. //获取5条用户的已审核商品
  3933. $good = Good::where('status', 2)
  3934. ->where('user_id', $user_id)
  3935. ->orderBy('updated_at', 'desc')
  3936. ->limit(5)->get();
  3937. $count = count($apply_articale) + count($good);
  3938. $result = [
  3939. 'apply_articale' => $apply_articale,
  3940. 'chat' => '',
  3941. 'chat_group' => '',
  3942. 'good' => $good,
  3943. 'count' => $count,
  3944. ];
  3945. } elseif ($type_id == 10000) {
  3946. //获取未审核的5篇文章
  3947. $apply_articale = Article::where('status', 0)
  3948. ->orderBy('updated_at', 'desc')
  3949. ->limit(5)->get();
  3950. //获取5条单聊未读聊天消息
  3951. $chat = ChatRecords::where('is_read', 0)
  3952. ->where('user_id', $user_id)
  3953. ->where('talk_type', 1)
  3954. ->orderBy('created_at', 'desc')
  3955. ->limit(5)->get();
  3956. //获取5条未读群聊信息
  3957. $chat_group = ChatRecords::where('is_read', 0)
  3958. ->where('user_id', $user_id)
  3959. ->where('talk_type', 2)
  3960. ->orderBy('created_at', 'desc')
  3961. ->limit(5)->get();
  3962. //获取5条用户的已审核商品
  3963. $good = Good::where('status', 1)
  3964. // ->where('user_id', $user_id)
  3965. ->orderBy('updated_at', 'desc')
  3966. ->limit(5)->get();
  3967. //获取5条用户待审核的公告
  3968. $notice = Notice::where('status', 1)
  3969. ->orderBy('updated_at', 'desc')
  3970. ->limit(5)->get();
  3971. //获取5条用户的待审核投诉
  3972. $complaint = Complaint::where('status', 1)
  3973. ->orderBy('updated_at', 'desc')
  3974. ->limit(5)->get();
  3975. //获取5条用户的book
  3976. $book = Book::where('status', 1)
  3977. ->orderBy('updated_at', 'desc')
  3978. ->limit(5)->get();
  3979. //获取5条用户的求职 1
  3980. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3981. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3982. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3983. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3984. ->orderBy('updated_at', 'desc')
  3985. ->limit(5)->get();
  3986. //获取5条用户的求职 2
  3987. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3988. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3989. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3990. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3991. ->orderBy('updated_at', 'desc')
  3992. ->limit(5)->get();
  3993. //人才库 1
  3994. $job_apply = JobApply::where('job_apply.status', 1)
  3995. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3996. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3997. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3998. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3999. ->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')
  4000. ->orderBy('updated_at', 'desc')
  4001. ->limit(5)->get();
  4002. // 职场机会 2
  4003. $job_resume = JobResume::where('job_resume.status', 1)
  4004. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  4005. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  4006. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  4007. ->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')
  4008. ->orderBy('updated_at', 'desc')
  4009. ->limit(5)->get();
  4010. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume);
  4011. $result = [
  4012. 'apply_articale' => $apply_articale,
  4013. 'chat' => $chat,
  4014. 'chat_group' => $chat_group,
  4015. 'good' => $good,
  4016. 'notice' => $notice,
  4017. 'complaint' => $complaint,
  4018. 'book' => $book,
  4019. 'job_hunting' => $job_hunting,
  4020. 'job_recruiting' => $job_recruiting,
  4021. 'job_apply' => $job_apply,
  4022. 'job_resume' => $job_resume,
  4023. 'count' => $count,
  4024. ];
  4025. } elseif ($type_id == 20000) {
  4026. }
  4027. var_dump($type_id, '-----------------test---------');
  4028. return Result::success($result);
  4029. }
  4030. public function getComplaintList(array $data): array
  4031. {
  4032. var_dump($data, '00000001000000000000');
  4033. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4034. unset($data['type_id']);
  4035. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4036. $where = [];
  4037. if ($type_id != 10000 && empty($data['deal_user'])) {
  4038. $where['complaint.user_id'] = $user_id;
  4039. }
  4040. if (!empty($data['title'])) {
  4041. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4042. }
  4043. if (!empty($data['department_id'])) {
  4044. $where['complaint.department_id'] = $data['department_id'];
  4045. }
  4046. if (!empty($data['deal'])) {
  4047. $where['complaint.deal'] = $data['deal'];
  4048. }
  4049. if (!empty($data['status'])) {
  4050. $where['complaint.status'] = $data['status'];
  4051. }
  4052. var_dump(!empty($data['deal_user']), '----------1');
  4053. var_dump($where, '----------2');
  4054. $result = Complaint::where($where)
  4055. ->when(!empty($data['status1']), function ($query) use ($data) {
  4056. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4057. })
  4058. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4059. //json re_user_ids data[user_id]是不是在里面
  4060. $query->Where(function ($q) use ($data) {
  4061. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4062. ->where('complaint.status', 2);
  4063. });
  4064. })
  4065. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4066. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4067. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4068. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4069. ->orderBy('updated_at', 'desc')
  4070. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4071. //sql输出
  4072. if (empty($result)) {
  4073. return Result::error("暂无投诉信息", 0);
  4074. }
  4075. // 取出数据
  4076. $rows = $result->items();
  4077. $count = $result->total();
  4078. $responseData = [
  4079. 'rows' => $rows,
  4080. 'count' => $count,
  4081. ];
  4082. return Result::success($responseData);
  4083. }
  4084. public function getComplaintInfo(array $data): array
  4085. {
  4086. $result = Complaint::where('id', $data['id'])->first();
  4087. if (empty($result)) {
  4088. return Result::error("查询失败", 0);
  4089. }
  4090. return Result::success($result);
  4091. }
  4092. public function addComplaint(array $data): array
  4093. {
  4094. date_default_timezone_set('Asia/Shanghai');
  4095. $data['created_at'] = date('Y-m-d H:i:s');
  4096. $data['updated_at'] = date('Y-m-d H:i:s');
  4097. $result = Complaint::create($data);
  4098. return Result::success($result);
  4099. }
  4100. public function updateComplaint(array $data): array
  4101. {
  4102. date_default_timezone_set('Asia/Shanghai');
  4103. $data['updated_at'] = date('Y-m-d H:i:s');
  4104. $user_id = $data['user_id'] ?? 0;
  4105. $type_id = $data['type_id'] ?? 0;
  4106. unset($data['user_id']);
  4107. unset($data['type_id']);
  4108. $result = Complaint::where('id', $data['id'])->update($data);
  4109. return Result::success($result);
  4110. }
  4111. public function deleteComplaint(array $data): array
  4112. {
  4113. $result = Complaint::where('id', $data['id'])->delete();
  4114. return Result::success($result);
  4115. }
  4116. public function getComplainInfo(array $data): array
  4117. {
  4118. $result = Complaint::where('id', $data['id'])->first();
  4119. if (empty($result)) {
  4120. return Result::error("查询失败", 0);
  4121. }
  4122. return Result::success($result);
  4123. }
  4124. public function updateComplaintStatus(array $data): array
  4125. {
  4126. date_default_timezone_set('Asia/Shanghai');
  4127. $data['updated_at'] = date('Y-m-d H:i:s');
  4128. $user_id = $data['user_id'] ?? 0;
  4129. $type_id = $data['type_id'] ?? 0;
  4130. unset($data['user_id']);
  4131. unset($data['type_id']);
  4132. //处理, 写入处理人
  4133. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4134. $data['real_deal_user'] = $user_id;
  4135. }
  4136. //如果是deal 23,则判断是不是处理人
  4137. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4138. $complaintInof = Complaint::where('id', $data['id'])
  4139. ->where('real_deal_user', $user_id)
  4140. ->first();
  4141. if (empty($complaintInof)) {
  4142. return Result::error("处理人错误", 0);
  4143. }
  4144. }
  4145. $result = complaint::where('id', $data['id'])->update($data);
  4146. return Result::success($result);
  4147. }
  4148. public function updateGoodStatus(array $data): array
  4149. {
  4150. $user_id = $data['user_id'] ?? 0;
  4151. $type_id = $data['type_id'] ?? 0;
  4152. unset($data['user_id']);
  4153. unset($data['type_id']);
  4154. $result = Good::where('id', $data['id'])->update($data);
  4155. return Result::success($result);
  4156. }
  4157. public function updateJobHuntingStatus(array $data): array
  4158. {
  4159. $user_id = $data['user_id'] ?? 0;
  4160. $type_id = $data['type_id'] ?? 0;
  4161. unset($data['user_id']);
  4162. unset($data['type_id']);
  4163. $result = JobHunting::where('id', $data['id'])->update($data);
  4164. return Result::success($result);
  4165. }
  4166. public function updateNoticeStatus(array $data): array
  4167. {
  4168. $user_id = $data['user_id'] ?? 0;
  4169. $type_id = $data['type_id'] ?? 0;
  4170. unset($data['user_id']);
  4171. unset($data['type_id']);
  4172. $result = Notice::where('id', $data['id'])->update($data);
  4173. return Result::success($result);
  4174. }
  4175. public function getDUser(array $data): array
  4176. {
  4177. if (!empty($data['ids'])) {
  4178. $user = User::whereIn('id', $data['ids'])->getall();
  4179. if (empty($user)) {
  4180. return Result::error('无数据', 0);
  4181. }
  4182. return Result::success($user);
  4183. }
  4184. $where = [];
  4185. if (!empty($data['department_id'])) {
  4186. $where['department_id'] = $data['department_id'];
  4187. }
  4188. if (!empty($data['city_id'])) {
  4189. $where['city_id'] = $data['city_id'];
  4190. }
  4191. $result = User::where('type_id', 2)
  4192. ->where('status', 1)
  4193. ->where('id', $data['id'])
  4194. ->first(['cat_arr_id']);
  4195. if (empty($article)) {
  4196. $article = JobHunting::where('website_id', $data['website_id'])
  4197. ->where('status', 2)
  4198. ->where('id', $data['id'])
  4199. ->first(['cat_arr_id']);
  4200. }
  4201. if (empty($article)) {
  4202. return Result::error("该招工招聘不存在", 0);
  4203. }
  4204. }
  4205. /**
  4206. * 验证导航名称是否重复
  4207. * @return void
  4208. */
  4209. public function checkCategoryName(array $data): array
  4210. {
  4211. $result = Category::when($data, function ($query) use ($data) {
  4212. if (isset($data['name']) && $data['name']) {
  4213. $query->where("name", $data['name']);
  4214. }
  4215. if (isset($data['id']) && $data['id']) {
  4216. $query->where("id", "!=", $data['id']);
  4217. }
  4218. })->first();
  4219. if ($result) {
  4220. return Result::error("已存在");
  4221. } else {
  4222. return Result::success();
  4223. }
  4224. }
  4225. //20250226 产品列表
  4226. // 20250306 -------招聘--------fr
  4227. /*
  4228. * 招聘列表
  4229. * */
  4230. public function getJobRecruitingList(array $data): array
  4231. {
  4232. $where = [];
  4233. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4234. if ($data['checkout'] == 0) {
  4235. $job_status = [0, 2];
  4236. } else {
  4237. $job_status = [1];
  4238. }
  4239. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4240. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4241. }
  4242. $user = User::where('id', $data['user_id'])->first();
  4243. if (empty($user)) {
  4244. return Result::error("用户不存在", 0);
  4245. }
  4246. // 3:企业会员
  4247. if ($user['type_id'] == 3) {
  4248. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4249. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4250. }
  4251. // 如果 $where 为空,则不添加 where 条件
  4252. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4253. return $query->where($where);
  4254. })
  4255. ->whereIn('job_recruiting.status', $job_status)
  4256. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4257. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4258. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4259. ->orderBy("updated_at", "desc")
  4260. ->offset(($data['page'] - 1) * $data['page_size'])
  4261. ->limit($data['page_size'])
  4262. ->get()
  4263. ->all();
  4264. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4265. return $query->where($where);
  4266. })
  4267. ->whereIn('job_recruiting.status', $job_status)
  4268. ->count();
  4269. if (empty($result)) {
  4270. return Result::error("暂无招聘信息", 0);
  4271. }
  4272. return Result::success($result);
  4273. }
  4274. /*
  4275. * 招聘信息添加
  4276. * */
  4277. public function addJobRecruiting(array $data): array
  4278. {
  4279. // return Result::success($data);
  4280. $user = User::where('user.id', $data['user_id'])
  4281. ->where('user.status', 1)
  4282. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4283. ->select(
  4284. 'user.type_id',
  4285. 'user.mobile',
  4286. 'user.email',
  4287. 'user_info.business_name',
  4288. 'user_info.company_hy_id',
  4289. 'user_info.company_nature',
  4290. 'user_info.company_size',
  4291. 'user_info.introduction',
  4292. 'user_info.real_name',
  4293. 'user_info.company_url',
  4294. 'user_info.address_arr_id',
  4295. 'user_info.address'
  4296. )
  4297. ->first();
  4298. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4299. return Result::error("用户不存在", 0);
  4300. }
  4301. $web = Website::where('id', $data['website_id'])->first();
  4302. if (empty($web)) {
  4303. return Result::error("网站不存在", 0);
  4304. }
  4305. // return Result::success($user);
  4306. $data['action_id'] = $data['user_id'];
  4307. $data['user_type'] = $user['type_id'];
  4308. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4309. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4310. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4311. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4312. // 公司地址 管理员必填
  4313. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4314. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4315. // 管理员-企业相关信息
  4316. $company = [
  4317. // 'user_id' => $data['user_id']?? null,
  4318. 'business_name' => $data['business_name'] ?? null,
  4319. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4320. 'company_size' => $data['company_size'] ?? null,
  4321. 'company_nature' => $data['company_nature'] ?? null,
  4322. 'introduction' => $data['introduction'] ?? null,
  4323. 'real_name' => $data['real_name'] ?? null,
  4324. 'mobile' => $data['mobile'] ?? null,
  4325. 'company_url' => $data['company_url'] ?? null,
  4326. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4327. 'address' => $data['address'] ?? null,
  4328. 'email' => $data['email'] ?? null,
  4329. ];
  4330. //去掉相关企业信息
  4331. $job = array_diff_key($data, array_flip(array_keys($company)));
  4332. Db::beginTransaction();
  4333. try {
  4334. // 先添加职位相关信息
  4335. if ($user['type_id'] == 10000) {
  4336. $job['status'] = 1;
  4337. }
  4338. if (empty($data['experience']) || $data['experience'] == '') {
  4339. $job['experience'] = null;
  4340. } else {
  4341. $job['experience'] = $data['experience'];
  4342. }
  4343. $jobId = JobRecruiting::insertGetId($job);
  4344. if (empty($jobId)) {
  4345. Db::rollBack();
  4346. return Result::error("添加失败");
  4347. }
  4348. // 添加公司信息
  4349. $company['user_id'] = $data['user_id'] ?? null;
  4350. $company['job_id'] = $jobId;
  4351. $company['user_type'] = $user['type_id'] ?? null;
  4352. $company['website_id'] = $data['website_id'] ?? null;
  4353. if ($user['type_id'] == 10000) {
  4354. // 管理员添加企业信息
  4355. // return Result::success($company);
  4356. $companyId = JobCompany::insertGetId($company);
  4357. if (empty($companyId)) {
  4358. Db::rollBack();
  4359. return Result::error("添加失败");
  4360. }
  4361. } else {
  4362. // 企业会员添加企业信息
  4363. $company = [
  4364. 'user_id' => $data['user_id'] ?? null,
  4365. 'business_name' => $user['business_name'] ?? null,
  4366. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4367. 'company_size' => $user['company_size'] ?? null,
  4368. 'company_nature' => $user['company_nature'] ?? null,
  4369. 'introduction' => $user['introduction'] ?? null,
  4370. 'real_name' => $user['real_name'] ?? null,
  4371. 'mobile' => $user['mobile'] ?? null,
  4372. 'company_url' => $user['company_url'] ?? null,
  4373. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4374. 'address' => $user['address'] ?? null,
  4375. 'email' => $user['email'] ?? null,
  4376. 'website_id' => $data['website_id'] ?? null,
  4377. 'user_type' => $user['type_id'] ?? null,
  4378. 'job_id' => $jobId,
  4379. ];
  4380. $companyId = JobCompany::insertGetId($company);
  4381. if (empty($companyId)) {
  4382. Db::rollBack();
  4383. return Result::error("添加失败");
  4384. }
  4385. // return Result::success($company);
  4386. }
  4387. Db::commit();
  4388. } catch (\Exception $e) {
  4389. Db::rollBack();
  4390. return Result::error($e->getMessage(), 0);
  4391. }
  4392. $result = [
  4393. 'job_id' => $jobId,
  4394. 'company_id' => $companyId,
  4395. ];
  4396. if (empty($result)) {
  4397. return Result::error("添加失败", 0);
  4398. }
  4399. return Result::success($result);
  4400. }
  4401. /*
  4402. * 获取招聘信息详情
  4403. * */
  4404. public function getJobRecruitingInfo(array $data): array
  4405. {
  4406. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4407. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4408. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4409. ->select(
  4410. 'job_recruiting.*',
  4411. 'website.website_name as website_name',
  4412. 'job_company.business_name',
  4413. 'job_company.company_hy_id',
  4414. 'job_company.company_size',
  4415. 'job_company.company_nature',
  4416. 'job_company.introduction',
  4417. 'job_company.real_name',
  4418. 'job_company.mobile',
  4419. 'job_company.company_url',
  4420. 'job_company.address_arr_id',
  4421. 'job_company.address',
  4422. 'job_company.email'
  4423. )
  4424. ->first();
  4425. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4426. if (!empty($cityId)) {
  4427. if (isset($cityId[1]) && $cityId[1] != null) {
  4428. $city = District::where('id', $cityId[1])->first(['name']);
  4429. } else {
  4430. $city = District::where('id', $cityId[0])->first(['name']);
  4431. }
  4432. $result['city'] = $city['name'] ?? '';
  4433. }
  4434. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4435. if (is_array($addressId) && !empty($addressId)) {
  4436. $address = District::whereIn('id', $addressId)
  4437. ->orderBy('level', 'asc')
  4438. ->get(['name'])
  4439. ->pluck('name')
  4440. ->implode('');
  4441. // $job->address_name = $address ?? '';
  4442. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4443. }
  4444. if (empty($result)) {
  4445. return Result::error("招聘信息不存在", 0);
  4446. }
  4447. // return Result::success($job);
  4448. return Result::success($result);
  4449. }
  4450. /*
  4451. * 修改招聘信息
  4452. * */
  4453. public function upJobRecruiting(array $data): array
  4454. {
  4455. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4456. // return Result::success($job);
  4457. if (empty($job)) {
  4458. return Result::error("招聘信息不存在", 0);
  4459. }
  4460. $user = User::where('id', $data['user_id'])->first();
  4461. // return Result::success($user);
  4462. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4463. return Result::error("用户不存在", 0);
  4464. }
  4465. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4466. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4467. }
  4468. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4469. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4470. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4471. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4472. // 公司地址 管理员必填
  4473. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4474. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4475. // 管理员-企业相关信息
  4476. $company = [
  4477. 'business_name' => $data['business_name'] ?? null,
  4478. 'company_hy_id' => $data['hy_id'] ?? null,
  4479. 'company_size' => $data['company_size'] ?? null,
  4480. 'company_nature' => $data['company_nature'] ?? null,
  4481. 'introduction' => $data['introduction'] ?? null,
  4482. 'real_name' => $data['real_name'] ?? null,
  4483. 'mobile' => $data['mobile'] ?? null,
  4484. 'company_url' => $data['company_url'] ?? null,
  4485. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4486. 'address' => $data['address'] ?? null,
  4487. 'email' => $data['email'] ?? null,
  4488. ];
  4489. //去掉相关企业信息
  4490. $data = array_diff_key($data, array_flip(array_keys($company)));
  4491. $jobId = $data['id'];
  4492. $web = $data['website_id'];
  4493. $data['action_id'] = $data['user_id'];
  4494. unset($data['user_id']);
  4495. unset($data['user_type']);
  4496. unset($data['id']);
  4497. unset($data['website_id']);
  4498. // return Result::success($data);
  4499. Db::beginTransaction();
  4500. try {
  4501. // 管理员修改招聘信息
  4502. if ($user['type_id'] == 10000) {
  4503. $data['website_id'] = $web;
  4504. $company['website_id'] = $data['website_id'];
  4505. $data['status'] = 1;
  4506. } else {
  4507. $data['status'] = 0;
  4508. }
  4509. if (empty($data['experience']) || $data['experience'] == '') {
  4510. $job['experience'] = null;
  4511. } else {
  4512. $job['experience'] = $data['experience'];
  4513. }
  4514. // Db::rollBack();
  4515. // return Result::success($company);
  4516. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4517. if (empty($result['job'])) {
  4518. Db::rollBack();
  4519. return Result::error("修改招聘信息失败");
  4520. }
  4521. // 管理员修改企业相关信息
  4522. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4523. if (empty($result['company'])) {
  4524. Db::rollBack();
  4525. return Result::error("修改企业相关信息失败");
  4526. }
  4527. Db::commit();
  4528. // return Result::success($result);
  4529. } catch (\Exception $e) {
  4530. Db::rollBack();
  4531. return Result::error($e->getMessage(), 0);
  4532. }
  4533. return Result::success($result);
  4534. }
  4535. /*
  4536. * 招聘信息删除
  4537. * */
  4538. public function delJobRecruiting(array $data): array
  4539. {
  4540. $user = User::where('id', $data['user_id'])->first();
  4541. if (empty($user)) {
  4542. return Result::error("用户不存在", 0);
  4543. }
  4544. $job = JobRecruiting::where('id', $data['id'])->first();
  4545. if (empty($job)) {
  4546. return Result::error("招聘信息不存在", 0);
  4547. }
  4548. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4549. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4550. }
  4551. Db::beginTransaction();
  4552. try {
  4553. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4554. if (empty($result['job'])) {
  4555. Db::rollBack();
  4556. return Result::error("删除招聘信息失败");
  4557. }
  4558. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4559. if (empty($result['company'])) {
  4560. Db::rollBack();
  4561. return Result::error("删除企业相关信息失败");
  4562. }
  4563. Db::commit();
  4564. } catch (\Exception $e) {
  4565. Db::rollBack();
  4566. return Result::error($e->getMessage(), 0);
  4567. }
  4568. return Result::success($result);
  4569. }
  4570. /*
  4571. * 获取公司信息
  4572. * */
  4573. public function getJobCompany(array $data): array
  4574. {
  4575. $user = User::where('user.id', $data['user_id'])
  4576. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4577. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4578. ->first();
  4579. // return Result::success($user);
  4580. if (empty($user)) {
  4581. return Result::error("用户不存在", 0);
  4582. }
  4583. if ($user['type_id'] == 3) {
  4584. $result = [
  4585. // 'id' => 0,
  4586. 'user_id' => $data['user_id'],
  4587. 'website_id' => $data['website_id'],
  4588. 'business_name' => $user['business_name'], // 企业名称
  4589. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4590. 'company_nature' => $user['company_nature'], // 公司性质
  4591. 'company_size' => $user['company_size'], // 公司规模
  4592. 'introduction' => $user['introduction'], // 公司简介
  4593. 'real_name' => $user['real_name'], // 企业联系人
  4594. 'mobile' => $user['mobile'], // 企业联系电话
  4595. 'company_url' => $user['company_url'], // 企业网址
  4596. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4597. 'address' => $user['address'], // 企业地址
  4598. 'email' => $user['email'], // 企业邮箱
  4599. ];
  4600. } else {
  4601. return Result::error("用户类型错误", 0);
  4602. }
  4603. if (empty($result)) {
  4604. return Result::error("公司信息不存在", 0);
  4605. }
  4606. return Result::success($result);
  4607. }
  4608. /*
  4609. * 修改公司信息
  4610. * */
  4611. public function upJobCompany(array $data): array
  4612. {
  4613. // return Result::success($data);
  4614. $user = User::where('user.id', $data['user_id'])
  4615. ->where('user.status', 1)
  4616. ->select('user.user_name', 'user.type_id')
  4617. ->first();
  4618. if (empty($user)) {
  4619. return Result::error("用户不存在", 0);
  4620. }
  4621. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4622. $company = [
  4623. 'business_name' => $data['business_name'], // 企业名称
  4624. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4625. 'company_nature' => $data['company_nature'], // 公司性质
  4626. 'company_size' => $data['company_size'], // 公司规模
  4627. 'introduction' => $data['introduction'], // 公司简介
  4628. // 'real_name' => $data['real_name'], // 企业联系人
  4629. 'company_url' => $data['company_url'], // 企业网址
  4630. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4631. 'address' => $data['address'], // 企业详细地址
  4632. ];
  4633. if ($user['type_id'] == 3) {
  4634. Db::beginTransaction();
  4635. try {
  4636. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  4637. 'business_name' => $data['business_name'], // 企业名称
  4638. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4639. 'company_nature' => $data['company_nature'], // 公司性质
  4640. 'company_size' => $data['company_size'], // 公司规模
  4641. 'introduction' => $data['introduction'], // 公司简介
  4642. // 'real_name' => $data['real_name'], // 企业联系人
  4643. 'company_url' => $data['company_url'], // 企业网址
  4644. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4645. 'address' => $data['address'], // 企业详细地址
  4646. ]);
  4647. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  4648. Db::commit();
  4649. } catch (\Exception $e) {
  4650. Db::rollBack();
  4651. return Result::error($e->getMessage(), 0);
  4652. }
  4653. } else {
  4654. return Result::error("用户类型错误", 0);
  4655. }
  4656. if (empty($result)) {
  4657. return Result::error("修改失败", 0);
  4658. }
  4659. return Result::success($result);
  4660. }
  4661. /*
  4662. * 获取省-市
  4663. * */
  4664. public function getJobRecruitingArea(array $data): array
  4665. {
  4666. if (isset($data['pid']) && $data['pid'] != null) {
  4667. $result = District::where('pid', $data['pid'])->get()->all();
  4668. } else {
  4669. $result = District::where('level', 1)->get()->all();
  4670. }
  4671. if (empty($result)) {
  4672. return Result::error("暂无此省市", 0);
  4673. }
  4674. return Result::success($result);
  4675. }
  4676. /*
  4677. * 获取行业分类
  4678. * */
  4679. public function getIndustry(array $data): array
  4680. {
  4681. $result = JobIndustry::get()->all();
  4682. if (empty($result)) {
  4683. return Result::error("暂无行业分类", 0);
  4684. }
  4685. return Result::success($result);
  4686. }
  4687. /*
  4688. * 获取职位
  4689. * */
  4690. public function getPositionList(array $data): array
  4691. {
  4692. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  4693. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  4694. } else {
  4695. $result = JobPosition::where('zwpid', 0)->get()->all();
  4696. }
  4697. if (empty($result)) {
  4698. return Result::error("暂无此职位", 0);
  4699. }
  4700. return Result::success($result);
  4701. }
  4702. /*
  4703. * 获取工作性质-菜单
  4704. * */
  4705. public function getJobNature(array $data): array
  4706. {
  4707. $result = JobEnum::where('egroup', 'nature')->get()->all();
  4708. if (empty($result)) {
  4709. return Result::error("暂无工作性质", 0);
  4710. }
  4711. return Result::success($result);
  4712. }
  4713. /*
  4714. * 获取工作经验-菜单
  4715. * */
  4716. public function getExperience(array $data): array
  4717. {
  4718. $result = JobEnum::where('egroup', 'years')->get()->all();
  4719. if (empty($result)) {
  4720. return Result::error("暂无工作经验", 0);
  4721. }
  4722. return Result::success($result);
  4723. }
  4724. /*
  4725. * 获取学历-菜单
  4726. * */
  4727. public function getEducation(array $data): array
  4728. {
  4729. $result = JobEnum::where('egroup', 'education')->get()->all();
  4730. if (empty($result)) {
  4731. return Result::error("暂无学历", 0);
  4732. }
  4733. return Result::success($result);
  4734. }
  4735. /*
  4736. * 获取薪资-菜单
  4737. * */
  4738. public function getSalary(array $data): array
  4739. {
  4740. $result = JobEnum::where('egroup', 'income')->get()->all();
  4741. if (empty($result)) {
  4742. return Result::error("暂无薪资", 0);
  4743. }
  4744. return Result::success($result);
  4745. }
  4746. /*
  4747. * 获取语言-菜单
  4748. * */
  4749. public function getLanguage(array $data): array
  4750. {
  4751. $result = JobEnum::where('egroup', 'language')->get()->all();
  4752. if (empty($result)) {
  4753. return Result::error("暂无语言", 0);
  4754. }
  4755. return Result::success($result);
  4756. }
  4757. /*
  4758. * 获取掌握程度-菜单
  4759. * */
  4760. public function getLevel(array $data): array
  4761. {
  4762. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  4763. if (empty($result)) {
  4764. return Result::error("暂无工作性质", 0);
  4765. }
  4766. return Result::success($result);
  4767. }
  4768. // 公司信息
  4769. /*
  4770. * 获取公司性质-菜单
  4771. * */
  4772. public function getCompanyNature(array $data): array
  4773. {
  4774. $result = JobNature::get()->all();
  4775. if (empty($result)) {
  4776. return Result::error("暂无公司性质", 0);
  4777. }
  4778. return Result::success($result);
  4779. }
  4780. /*
  4781. * 获取公司规模-菜单
  4782. * */
  4783. public function getCompanySize(array $data): array
  4784. {
  4785. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  4786. if (empty($result)) {
  4787. return Result::error("暂无公司规模", 0);
  4788. }
  4789. return Result::success($result);
  4790. }
  4791. /*
  4792. * 招聘信息审核
  4793. * */
  4794. public function checkJobRecruiting(array $data): array
  4795. {
  4796. $user = User::where('id', $data['user_id'])->first();
  4797. if (empty($user)) {
  4798. return Result::error("用户不存在", 0);
  4799. }
  4800. $job = JobRecruiting::where('id', $data['id'])->first();
  4801. if (empty($job)) {
  4802. return Result::error("招聘信息不存在", 0);
  4803. }
  4804. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  4805. if ($user['type_id'] != 10000) {
  4806. return Result::error("用户暂无权限审核此招聘信息!", 0);
  4807. }
  4808. // 驳回原因
  4809. if ($data['status'] == 2) {
  4810. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  4811. }
  4812. $data['action_id'] = $data['user_id'];
  4813. unset($data['user_id']);
  4814. $result = JobRecruiting::where('id', $data['id'])->update($data);
  4815. if (empty($result)) {
  4816. return Result::error("审核失败", 0);
  4817. }
  4818. return Result::success($result);
  4819. }
  4820. public function myApplyList(array $data): array
  4821. {
  4822. var_dump($data, '------参数');
  4823. $user = User::where('id', $data['user_id'])->first();
  4824. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4825. return Result::error("用户不存在", 0);
  4826. }
  4827. // 1:个人会员 职场机会
  4828. if ($user['type_id'] == 1) {
  4829. $where['user_id'] = $user['id'];
  4830. }
  4831. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  4832. $query->where('user_id', $user['id']);
  4833. })
  4834. ->pluck('recruit_id');
  4835. $where = [];
  4836. if (isset($data['salary']) && $data['salary'] != null) {
  4837. $where['job_recruiting.salary'] = $data['salary'];
  4838. }
  4839. if (isset($data['experience']) && $data['experience'] != null) {
  4840. $where['job_recruiting.experience'] = $data['experience'];
  4841. }
  4842. if (isset($data['business_name']) && $data['business_name'] != null) {
  4843. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4844. }
  4845. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4846. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4847. ->where($where);
  4848. // ->count();
  4849. $count = $query->count();
  4850. $query = clone $query;
  4851. $job = $query
  4852. ->leftJoin('job_enum as income_enum', function ($join) {
  4853. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4854. ->where('income_enum.egroup', 'income');
  4855. })
  4856. ->leftJoin('job_enum as years_enum', function ($join) {
  4857. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4858. ->where('years_enum.egroup', 'years');
  4859. })
  4860. // ->where($where)
  4861. ->orderBy('job_recruiting.updated_at', 'desc')
  4862. ->select(
  4863. 'job_recruiting.id',
  4864. 'job_recruiting.title',
  4865. 'job_company.business_name',
  4866. 'income_enum.evalue as salary_evalue',
  4867. 'income_enum.ename as salary_ename',
  4868. 'years_enum.evalue as experience_evalue',
  4869. 'years_enum.ename as experience_ename',
  4870. 'job_recruiting.updated_at'
  4871. )
  4872. ->offset(($data['page'] - 1) * $data['pageSize'])
  4873. ->limit($data['pageSize'])
  4874. ->get()
  4875. ->all();
  4876. if (empty($job)) {
  4877. return Result::error("暂无招聘信息", 0);
  4878. }
  4879. $result = [
  4880. 'row' => $job,
  4881. 'count' => $count,
  4882. ];
  4883. return Result::success($result);
  4884. }
  4885. /*
  4886. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  4887. * */
  4888. public function getRecruitingList(array $data): array
  4889. {
  4890. $user = User::where('id', $data['user_id'])->first();
  4891. if(empty($user) || ($user['type_id']!= 10000 && $user['type_id']!= 1)){
  4892. return Result::error("用户不存在", 0);
  4893. }
  4894. // 1:个人会员 职场机会
  4895. if($user['type_id'] == 1){
  4896. $where['user_id'] = $user['id'];
  4897. }
  4898. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  4899. $query->where('receiver_id', $user['id']);
  4900. })
  4901. ->pluck('recruit_id');
  4902. // return Result::success($recruitingId);
  4903. $where = [];
  4904. if(isset($data['salary']) && $data['salary']!=null){
  4905. $where['job_recruiting.salary'] = $data['salary'];
  4906. }
  4907. if(isset($data['experience']) && $data['experience']!=null){
  4908. $where['job_recruiting.experience'] = $data['experience'];
  4909. }
  4910. if(isset($data['business_name']) && $data['business_name']!=null){
  4911. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4912. }
  4913. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4914. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4915. ->where($where);
  4916. // ->count();
  4917. $count = $query->count();
  4918. $query = clone $query;
  4919. $job = $query
  4920. ->leftJoin('job_enum as income_enum', function ($join) {
  4921. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4922. ->where('income_enum.egroup', 'income');
  4923. })
  4924. ->leftJoin('job_enum as years_enum', function ($join) {
  4925. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4926. ->where('years_enum.egroup', 'years');
  4927. })
  4928. // ->where($where)
  4929. ->orderBy('job_recruiting.updated_at', 'desc')
  4930. ->select('job_recruiting.id','job_recruiting.title', 'job_company.business_name',
  4931. 'income_enum.evalue as salary_evalue', 'income_enum.ename as salary_ename',
  4932. 'years_enum.evalue as experience_evalue', 'years_enum.ename as experience_ename'
  4933. ,'job_recruiting.updated_at')
  4934. ->offset(($data['page'] - 1) * $data['pageSize'])
  4935. ->limit($data['pageSize'])
  4936. ->get()
  4937. ->all();
  4938. if (empty($job)) {
  4939. return Result::error("暂无招聘信息", 0);
  4940. }
  4941. $result = [
  4942. 'row' => $job,
  4943. 'count' => $count,
  4944. ];
  4945. return Result::success($result);
  4946. }
  4947. /*
  4948. * 获取企业会员-招聘信息列表
  4949. * */
  4950. public function getRecruitingInfo(array $data): array
  4951. {
  4952. $user = User::where('id', $data['user_id'])->first();
  4953. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4954. return Result::error("用户不存在", 0);
  4955. }
  4956. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  4957. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4958. ->select(
  4959. 'job_recruiting.*',
  4960. 'job_company.business_name',
  4961. 'job_company.company_hy_id',
  4962. 'job_company.company_size',
  4963. 'job_company.company_nature',
  4964. 'job_company.introduction',
  4965. 'job_company.real_name',
  4966. 'job_company.mobile',
  4967. 'job_company.company_url',
  4968. 'job_company.address_arr_id',
  4969. 'job_company.address',
  4970. 'job_company.email'
  4971. )
  4972. ->get();
  4973. if (empty($recruiting)) {
  4974. return Result::error("暂无招聘信息", 0);
  4975. }
  4976. return Result::success($recruiting);
  4977. }
  4978. /*
  4979. * 获取企业会员-我的沟通
  4980. * */
  4981. public function getJobResumeList(array $data): array
  4982. {
  4983. $user = User::where('id', $data['user_id'])->first();
  4984. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  4985. return Result::error("用户不存在", 0);
  4986. }
  4987. $where = [];
  4988. if (isset($data['salary']) && $data['salary'] != null) {
  4989. $where['job_hunting.salary'] = $data['salary'];
  4990. }
  4991. if (isset($data['user_name']) && $data['user_name'] != null) {
  4992. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  4993. }
  4994. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  4995. $query->where('job_resume.user_id', $user['id']);
  4996. })
  4997. ->when(!empty($where), function ($query) use ($where) {
  4998. $query->where($where);
  4999. })
  5000. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5001. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5002. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5003. ->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');
  5004. $count = $job->count();
  5005. if ($count == 0) {
  5006. return Result::error("暂无沟通记录", 0);
  5007. }
  5008. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5009. ->offset(($data['page'] - 1) * $data['pageSize'])
  5010. ->limit($data['pageSize'])
  5011. ->get();
  5012. if (empty($jobs)) {
  5013. return Result::error("暂无沟通记录", 0);
  5014. }
  5015. $result['row'] = $this->processJob($jobs, '');
  5016. $result['count'] = $count;
  5017. return Result::success($result);
  5018. }
  5019. // 20250306 招聘
  5020. //20250422 书刊音像
  5021. public function addBook(array $data): array
  5022. {
  5023. // $user_id = $data['user_id'] ?? 0;
  5024. $type_id = $data['type_id'] ?? 0;
  5025. // $website_id = $data['website_id'] ?? 0;
  5026. // unset($data['user_id']);
  5027. unset($data['type_id']);
  5028. // unset($data['website_id']);
  5029. //处理数组
  5030. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5031. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5032. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5033. if ($data['img_url'] == '') {
  5034. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5035. preg_match_all($reg, $data['detail'], $matches);
  5036. if (isset($matches[1][0])) {
  5037. //截取varchar240
  5038. $data['img_url'] = substr($matches[1][0], 0, 240);
  5039. }
  5040. }
  5041. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5042. //提取标题+内容中的关键词
  5043. $data['keyword'] = $data['title'];
  5044. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5045. Jieba::init(); // 初始化 jieba-php
  5046. Finalseg::init();
  5047. $segList = Jieba::cut($data['keyword']);
  5048. $segList1 = array_slice($segList, 0, 8);
  5049. $data['keyword'] = implode(',', $segList1);
  5050. }
  5051. if ($data['description'] == '') {
  5052. //提取内容中的描述
  5053. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  5054. }
  5055. var_dump($data, '--');
  5056. $result = Book::insertGetId($data);
  5057. if (empty($result)) {
  5058. return Result::error("添加失败", 0);
  5059. }
  5060. return Result::success($result);
  5061. }
  5062. public function getBookList(array $data): array
  5063. {
  5064. $where = [];
  5065. if (!empty($data["title"])) {
  5066. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5067. }
  5068. if (!empty($data['website_name'])) {
  5069. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5070. }
  5071. if (!empty($data['status'])) {
  5072. $where[] = ['book.status', '=', $data['status']];
  5073. }
  5074. $user_id = $data['user_id'];
  5075. $type_id = $data['type_id'];
  5076. // $type_id = 4;
  5077. var_dump($type_id, '------1--------');
  5078. if ($type_id != 10000) {
  5079. $where[] = ['book.user_id', '=', $user_id];
  5080. }
  5081. var_dump(!empty($data['status1']), '=-===1');
  5082. $result = Book::where($where)
  5083. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5084. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5085. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5086. ->when(isset($data['status1']), function ($query) use ($data) {
  5087. $query->whereIn('book.status', [1, 3]);
  5088. })
  5089. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5090. ->orderBy("updated_at", "desc")
  5091. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5092. if (empty($result)) {
  5093. return Result::error("暂无数据", 0);
  5094. }
  5095. // 取出数据
  5096. $rows = $result->items();
  5097. $count = $result->total();
  5098. $responseData = [
  5099. 'rows' => $rows,
  5100. 'count' => $count,
  5101. ];
  5102. return Result::success($responseData);
  5103. }
  5104. public function deleteBook(array $data): array
  5105. {
  5106. $result = Book::where('id', $data['id'])->delete();
  5107. if (empty($result)) {
  5108. return Result::error("删除失败", 0);
  5109. }
  5110. return Result::success($result);
  5111. }
  5112. public function updateBook(array $data): array
  5113. {
  5114. // $user_id = $data['user_id'] ?? 0;
  5115. $type_id = $data['type_id'] ?? 0;
  5116. // $website_id = $data['website_id'] ?? 0;
  5117. unset($data['user_id']);
  5118. unset($data['type_id']);
  5119. // unset($data['website_id']);
  5120. //处理数组
  5121. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5122. if ($data['img_url'] == '') {
  5123. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5124. preg_match_all($reg, $data['detail'], $matches);
  5125. if (isset($matches[1][0])) {
  5126. //截取varchar240
  5127. $data['img_url'] = substr($matches[1][0], 0, 240);
  5128. }
  5129. }
  5130. if ($data['keyword'] == '') {
  5131. //提取标题+内容中的关键词
  5132. $data['keyword'] = $data['title'];
  5133. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5134. Jieba::init(); // 初始化 jieba-php
  5135. Finalseg::init();
  5136. $segList = Jieba::cut($data['keyword']);
  5137. $segList1 = array_slice($segList, 0, 8);
  5138. $data['keyword'] = implode(',', $segList1);
  5139. }
  5140. if ($data['description'] == '') {
  5141. //提取内容中的描述
  5142. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  5143. }
  5144. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5145. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5146. $result = Book::where("id", $data["id"])->update($data);
  5147. if (empty($result)) {
  5148. return Result::error("更新失败", 0);
  5149. }
  5150. return Result::success($result);
  5151. }
  5152. public function getBookInfo(array $data): array
  5153. {
  5154. $result = Book::where("id", $data["id"])->first();
  5155. if (empty($result)) {
  5156. return Result::error("获取失败", 0);
  5157. }
  5158. return Result::success($result);
  5159. }
  5160. public function updateBookStatus(array $data): array
  5161. {
  5162. //审核
  5163. unset($data['user_id']);
  5164. $result = Book::where("id", $data["id"])->update($data);
  5165. if (empty($result)) {
  5166. return Result::error("更新失败", 0);
  5167. }
  5168. return Result::success($result);
  5169. }
  5170. //20250422 书刊音像
  5171. /**
  5172. * 贴身宝贝
  5173. * @param array $data
  5174. * @return array
  5175. */
  5176. public function getWebsiteTsbb(array $data): array
  5177. {
  5178. $month = $data['month'] ?? date('m');
  5179. $day = $data['day'] ?? date('d');
  5180. // 使用缓存键
  5181. $cacheKey = "tsbb_data_{$month}_{$day}";
  5182. // 尝试从缓存获取数据
  5183. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5184. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5185. if ($cachedData = $cache->get($cacheKey)) {
  5186. return Result::success(unserialize($cachedData));
  5187. }
  5188. //查询老黄历
  5189. try {
  5190. $date = date('Y-m-d');
  5191. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5192. // 使用 curl 替代 file_get_contents
  5193. $ch = curl_init();
  5194. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5195. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5196. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5197. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5198. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5199. 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');
  5200. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5201. 'Accept: application/json',
  5202. 'Content-Type: application/json',
  5203. 'Referer: https://www.36jxs.com/'
  5204. ]);
  5205. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5206. curl_setopt($ch, CURLOPT_ENCODING, '');
  5207. $almanacResponse = curl_exec($ch);
  5208. var_dump("====:", $almanacResponse);
  5209. if (curl_errno($ch)) {
  5210. var_dump('Curl error:', curl_error($ch));
  5211. throw new \Exception('Curl error: ' . curl_error($ch));
  5212. }
  5213. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5214. curl_close($ch);
  5215. if ($almanacResponse === false) {
  5216. throw new \Exception('Failed to fetch almanac data');
  5217. }
  5218. $almanacData = json_decode($almanacResponse, true);
  5219. if (json_last_error() !== JSON_ERROR_NONE) {
  5220. throw new \Exception('Failed to parse almanac data');
  5221. }
  5222. $almanacInfo = $almanacData['data'] ?? [];
  5223. } catch (\Exception $e) {
  5224. var_dump('Exception:', $e->getMessage());
  5225. $almanacInfo = [];
  5226. }
  5227. // 获取历史上的今天数据
  5228. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5229. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5230. ->orderBy('year', 'asc')
  5231. ->select("title", "id", "year", DB::raw('1 as type'))
  5232. ->limit(16)
  5233. ->get();
  5234. // 获取节日数据 - 从今天开始获取未来4条
  5235. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5236. ->orderBy('showtime', 'asc')
  5237. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5238. ->limit(16)
  5239. ->get();
  5240. //说文解字
  5241. $chartacterList = Character::orderBy('updated_at', 'desc')
  5242. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5243. ->limit(6)
  5244. ->get();
  5245. //谜语沙龙
  5246. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5247. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5248. ->limit(4)
  5249. ->get();
  5250. //成语欣赏
  5251. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5252. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5253. ->limit(32)
  5254. ->get();
  5255. //名联赏析
  5256. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5257. ->select("id", "first", "second", DB::raw('6 as type'))
  5258. ->limit(6)
  5259. ->get();
  5260. // 获取分类文章数据
  5261. $categoryIds = [627, 628, 629, 630, 631, 632, 633, 634, 635, 636];
  5262. // 使用子查询优化
  5263. $articlesList = DB::table('article')
  5264. ->select([
  5265. 'article.id',
  5266. 'article.title',
  5267. 'article.imgurl',
  5268. 'article.created_at',
  5269. 'category.name as category_name',
  5270. 'category.id as category_id',
  5271. 'website_category.aLIas_pinyin as pinyin',
  5272. DB::raw('100 as type')
  5273. ])
  5274. ->join('category', 'article.catid', '=', 'category.id')
  5275. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  5276. ->where('website_category.website_id',$data['website_id'])
  5277. ->where('article.status', 1)
  5278. ->whereIn('category.id', $categoryIds)
  5279. // ->whereRaw('article.created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY)')
  5280. ->orderBy('article.created_at', 'desc')
  5281. ->get()
  5282. ->groupBy('category_id')
  5283. ->map(function ($group) {
  5284. // 确保第一条数据有图片
  5285. $firstWithImage = $group->first(function ($item) {
  5286. return !empty($item->imgurl);
  5287. });
  5288. if ($firstWithImage) {
  5289. // 如果有带图片的文章,将其放在第一位
  5290. $group = $group->filter(function ($item) use ($firstWithImage) {
  5291. return $item->id !== $firstWithImage->id;
  5292. })->prepend($firstWithImage);
  5293. }
  5294. return [
  5295. 'category_name' => $group->first()->category_name,
  5296. 'catid' => $group->first()->category_id,
  5297. 'pinyin' => $group->first()->pinyin,
  5298. 'type' => 100,
  5299. 'list' => $group->take(6)->map(function ($item) {
  5300. return [
  5301. 'id' => $item->id,
  5302. 'title' => $item->title,
  5303. 'imgurl' => $item->imgurl,
  5304. 'created_at' => $item->created_at
  5305. ];
  5306. })->values()
  5307. ];
  5308. })
  5309. ->values()
  5310. ->toArray();
  5311. $result = [
  5312. 'almanac' => $almanacInfo,
  5313. 'historyTodayList' => [
  5314. 'category_name' => '历史上的今天',
  5315. 'list' => $historyTodayList,
  5316. 'type' => 1
  5317. ],
  5318. 'festivalList' => [
  5319. 'category_name' => '节日预告',
  5320. 'list' => $festivalList,
  5321. 'type' => 2
  5322. ],
  5323. 'chartacterList' => [
  5324. 'category_name' => '说文解字',
  5325. 'list' => $chartacterList,
  5326. 'type' => 3
  5327. ],
  5328. 'coupletList' => [
  5329. 'category_name' => '名联赏析',
  5330. 'list' => $coupletList,
  5331. 'type' => 6
  5332. ],
  5333. 'riddletList' => [
  5334. 'category_name' => '谜语沙龙',
  5335. 'list' => $riddletList,
  5336. 'type' => 4
  5337. ],
  5338. 'idiomList' => [
  5339. 'category_name' => '成语欣赏',
  5340. 'list' => $idiomList,
  5341. 'type' => 5
  5342. ],
  5343. 'articlesList' => $articlesList
  5344. ];
  5345. // 缓存结果,设置1小时过期
  5346. $cache->set($cacheKey, serialize($result), 3600);
  5347. return Result::success($result);
  5348. }
  5349. /**
  5350. * 获取资讯列表
  5351. */
  5352. public function getWebsiteTsbbList(array $data): array
  5353. {
  5354. $page = $data['page'] ?? 1;
  5355. $pageSize = $data['pageSize'] ?? 10;
  5356. // 如果没有传入月份和日期,则使用今天的日期
  5357. $month = $data['month'] ?? date('m');
  5358. $day = $data['day'] ?? date('d');
  5359. $total = 0;
  5360. $result = [];
  5361. $data['type'] = intval($data['type']);
  5362. var_dump("接收参数:", $data);
  5363. switch ($data['type']) {
  5364. case 1:
  5365. $query = HistoryToday::where(function ($q) use ($month, $day) {
  5366. // 当前月份之后的数据
  5367. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  5368. // 或者当前月份且日期大于等于当前日期的数据
  5369. ->orWhere(function ($q) use ($month, $day) {
  5370. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5371. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  5372. });
  5373. })
  5374. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  5375. $total = $query->count();
  5376. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  5377. ->offset(($page - 1) * $pageSize)
  5378. ->limit($pageSize)
  5379. ->get();
  5380. break;
  5381. case 2:
  5382. $query = Festival::where(function ($q) use ($month, $day) {
  5383. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  5384. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  5385. ->orWhere(function ($q) use ($month, $day) {
  5386. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  5387. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  5388. });
  5389. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  5390. $total = $query->count();
  5391. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  5392. ->offset(($page - 1) * $pageSize)
  5393. ->limit($pageSize)
  5394. ->get();
  5395. break;
  5396. case 3:
  5397. $query = Character::orderBy("updated_at", "desc");
  5398. $total = $query->count();
  5399. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  5400. ->offset(($page - 1) * $pageSize)
  5401. ->limit($pageSize)
  5402. ->get();
  5403. break;
  5404. case 4:
  5405. $query = Riddle::orderBy("updated_at", "desc");
  5406. $total = $query->count();
  5407. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  5408. ->offset(($page - 1) * $pageSize)
  5409. ->limit($pageSize)
  5410. ->get();
  5411. break;
  5412. case 5:
  5413. $query = Idiom::orderBy("updated_at", "desc");
  5414. $total = $query->count();
  5415. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  5416. ->offset(($page - 1) * $pageSize)
  5417. ->limit($pageSize)
  5418. ->get();
  5419. break;
  5420. case 6:
  5421. $query = Couplet::orderBy("updated_at", "desc");
  5422. $total = $query->count();
  5423. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  5424. ->offset(($page - 1) * $pageSize)
  5425. ->limit($pageSize)
  5426. ->get();
  5427. break;
  5428. default:
  5429. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  5430. $total = $query->count();
  5431. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  5432. ->offset(($page - 1) * $pageSize)
  5433. ->limit($pageSize)
  5434. ->get();
  5435. }
  5436. return Result::success([
  5437. 'list' => $result,
  5438. 'total' => $total,
  5439. 'page' => (int)$page,
  5440. 'pageSize' => (int)$pageSize,
  5441. 'month' => $month,
  5442. 'day' => $day
  5443. ]);
  5444. }
  5445. /**
  5446. * 1:历史上的今天
  5447. * 2:节日
  5448. * 3:文章
  5449. *
  5450. * 资讯详情信息
  5451. */
  5452. public function getWebsiteTsbbDetail(array $data): array
  5453. {
  5454. $data['type'] = intval($data['type']);
  5455. switch ($data['type']) {
  5456. case 1:
  5457. $result = HistoryToday::where("id", $data['id'])->first();
  5458. break;
  5459. case 2:
  5460. $result = Festival::where("id", $data['id'])->first();
  5461. break;
  5462. case 3:
  5463. $result = Character::where("id", $data['id'])->first();
  5464. break;
  5465. case 4:
  5466. $result = Riddle::where("id", $data['id'])->first();
  5467. break;
  5468. case 5:
  5469. $result = Idiom::where("id", $data['id'])->first();
  5470. break;
  5471. case 6:
  5472. $result = Couplet::where("id", $data['id'])->first();
  5473. break;
  5474. default:
  5475. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  5476. break;
  5477. }
  5478. return Result::success($result);
  5479. }
  5480. }