NewsService.php 232 KB

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