NewsService.php 222 KB

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