NewsService.php 222 KB

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