NewsService.php 223 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240
  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. * 模块新闻加强plus版
  1386. * @param array $data
  1387. * @return array
  1388. */
  1389. public function getWebsiteAllArticle(array $data): array
  1390. {
  1391. // 修正传入的字符串,将单引号替换为双引号
  1392. $input['id'] = $data['id'];
  1393. $input['website_id'] = $data['website_id'];
  1394. // 将 JSON 字符串转换为 PHP 数组
  1395. $data = json_decode($input['id'], true);
  1396. // 使用 array_map 处理每个元素
  1397. $result = array_map(function ($item) use ($input) {
  1398. // 检查parent元素是否存在且不是undefined
  1399. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  1400. $count = explode(',', $item['parent']);
  1401. if (count($count) != 3) {
  1402. return Result::error("父级栏目:缺少必需参数错误", 0);
  1403. }
  1404. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1405. $website = [
  1406. 'website_id' => $input['website_id'],
  1407. ];
  1408. // 查询栏目名称
  1409. $categroy = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin', 'type']);
  1410. // 查询图片新闻
  1411. if (isset($parentImgNum) && $parentImgNum != 0 && !empty($categroy)) {
  1412. $imgArticles = Article::where('article.status', 1)
  1413. ->where(function ($query) use ($parentCatId) {
  1414. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  1415. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  1416. })
  1417. ->where(function ($query) use ($website) {
  1418. $query->where(function ($subQuery) use ($website) {
  1419. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0")
  1420. ->orWhereNull("ignore_ids");
  1421. });
  1422. })
  1423. ->where('imgurl', '!=', '')
  1424. ->leftJoin('website_category', function ($join) use ($website) {
  1425. $join->on('article.catid', '=', 'website_category.category_id')
  1426. ->where('website_category.website_id', '=', $website['website_id']);
  1427. })
  1428. ->select(
  1429. 'article.id',
  1430. 'article.title',
  1431. 'article.imgurl',
  1432. 'article.author',
  1433. 'article.updated_at',
  1434. 'article.introduce',
  1435. 'article.islink',
  1436. 'article.linkurl',
  1437. 'article.copyfrom',
  1438. 'article.cat_arr_id',
  1439. 'article.catid',
  1440. 'website_category.alias as category_name',
  1441. )
  1442. ->orderBy('updated_at', 'desc')
  1443. ->limit($parentImgNum)
  1444. ->get();
  1445. //调取封装路由的方法,处理新闻路由
  1446. if (!empty($imgArticles)) {
  1447. $imgArticles = $this->processArticles($imgArticles, $website);
  1448. }
  1449. }
  1450. // 查询文字新闻
  1451. if (isset($parentTextNum) && $parentTextNum != 0 && !empty($categroy)) {
  1452. $textArticles = [];
  1453. $textArticles = Article::where('article.status', 1)
  1454. ->where(function ($query) use ($parentCatId) {
  1455. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  1456. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  1457. })
  1458. ->where(function ($query) use ($website) {
  1459. $query->where(function ($subQuery) use ($website) {
  1460. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0")
  1461. ->orWhereNull("ignore_ids");
  1462. });
  1463. })
  1464. ->leftJoin('website_category', function ($join) use ($website) {
  1465. $join->on('article.catid', '=', 'website_category.category_id')
  1466. ->where('website_category.website_id', '=', $website['website_id']);
  1467. })
  1468. ->select(
  1469. 'article.id',
  1470. 'article.title',
  1471. 'article.author',
  1472. 'article.updated_at',
  1473. 'article.cat_arr_id',
  1474. 'article.introduce',
  1475. 'article.islink',
  1476. 'article.linkurl',
  1477. 'article.copyfrom',
  1478. 'article.catid',
  1479. 'website_category.alias as category_name',
  1480. )
  1481. ->orderBy('updated_at', 'desc')
  1482. ->limit($parentTextNum)
  1483. ->get();
  1484. if (!empty($textArticles)) {
  1485. $textArticles = $this->processArticles($textArticles, $website);
  1486. }
  1487. }
  1488. }
  1489. $resultItem = [
  1490. 'alias' => $categroy ? $categroy->alias : null,
  1491. 'category_id' => $categroy ? $categroy->category_id : null,
  1492. 'pinyin' => $categroy ? $categroy->aLIas_pinyin : null,
  1493. 'imgnum' => $imgArticles ?? [],
  1494. 'textnum' => $textArticles ?? [],
  1495. ];
  1496. // 子级栏目
  1497. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  1498. $count = explode(',', $item['child']);
  1499. if (count($count) != 3) {
  1500. return Result::error("子级栏目:缺少必需参数错误", 0);
  1501. }
  1502. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  1503. $childCategory = WebsiteCategory::where($website)
  1504. ->where("category_id", $childCatId)
  1505. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($childCatId) . "') = 1")
  1506. ->first(['alias', 'category_id', 'aLIas_pinyin', 'pid', 'category_arr_id as cat_arr_id']);
  1507. if (!empty($childCategory)) {
  1508. $childCategory = $this->processArticles($childCategory, $website);
  1509. // 查询此层级的所有子栏目
  1510. $all_childcat = WebsiteCategory::where($website)
  1511. ->where("pid", $childCategory['pid'])
  1512. // ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($childCatId)."') = 1")
  1513. ->get(['alias', 'category_id', 'aLIas_pinyin', 'pid', 'category_arr_id as cat_arr_id']);
  1514. $all_childcat = $this->processArticles($all_childcat, $website);
  1515. // 查询子栏目图片新闻
  1516. if (isset($childImgNum) && $childImgNum != 0) {
  1517. $childImgArticles = Article::where(function ($query) use ($childCatId) {
  1518. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$childCatId\"')")
  1519. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$childCatId')");
  1520. })
  1521. ->where('status', 1)
  1522. ->where(function ($query) use ($website) {
  1523. $query->where(function ($subQuery) use ($website) {
  1524. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1525. })->orWhereNull("ignore_ids");
  1526. })
  1527. ->select(
  1528. 'article.id',
  1529. 'article.title',
  1530. 'article.imgurl',
  1531. 'article.author',
  1532. 'article.updated_at',
  1533. 'article.introduce',
  1534. 'article.islink',
  1535. 'article.linkurl',
  1536. 'article.catid',
  1537. 'article.cat_arr_id',
  1538. 'article.copyfrom',
  1539. )
  1540. ->where('imgurl', '!=', '')
  1541. ->orderBy('updated_at', 'desc')
  1542. ->limit($childImgNum)
  1543. ->get();
  1544. $childImgArticles = $this->processArticles($childImgArticles, $website);
  1545. }
  1546. // 查询子栏目文字新闻
  1547. if (isset($childTextNum) && $childTextNum != 0) {
  1548. $childTextArticles = Article::where(function ($query) use ($childCatId) {
  1549. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$childCatId\"')")
  1550. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$childCatId')");
  1551. })
  1552. ->where('status', 1)
  1553. ->where(function ($query) use ($website) {
  1554. $query->where(function ($subQuery) use ($website) {
  1555. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1556. })->orWhereNull("ignore_ids");
  1557. })
  1558. ->select(
  1559. 'article.id',
  1560. 'article.title',
  1561. 'article.author',
  1562. 'article.updated_at',
  1563. 'article.introduce',
  1564. 'article.islink',
  1565. 'article.linkurl',
  1566. 'article.catid',
  1567. 'article.cat_arr_id',
  1568. 'article.copyfrom',
  1569. )
  1570. ->orderBy('updated_at', 'desc')
  1571. ->limit($childTextNum)
  1572. ->get();
  1573. $childTextArticles = $this->processArticles($childTextArticles, $website);
  1574. }
  1575. }
  1576. $resultItem['child'] = [
  1577. 'alias' => $childCategory ? $childCategory->alias : null,
  1578. 'category_id' => $childCategory ? $childCategory->category_id : null,
  1579. 'pinyin' => $childCategory ? $childCategory->pinyin : null,
  1580. 'all_childcat' => $all_childcat ?? [],
  1581. 'imgnum' => $childImgArticles ?? [],
  1582. 'textnum' => $childTextArticles ?? [],
  1583. ];
  1584. } else {
  1585. $resultItem['child'] = [];
  1586. }
  1587. return $resultItem;
  1588. }, $data);
  1589. return Result::success($result);
  1590. // return Result::success($data);
  1591. }
  1592. /**
  1593. * 乡村网-获取特殊新闻模块
  1594. * @param array $data
  1595. * @return array
  1596. */
  1597. public function getWebsiteArticles(array $data): array
  1598. {
  1599. $input['id'] = $data['id'];
  1600. $input['website_id'] = $data['website_id'];
  1601. $data = json_decode($input['id'], true);
  1602. // 使用 array_map 处理每个元素
  1603. $result = array_map(function ($item) use ($input) {
  1604. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1605. $website = [
  1606. 'website_id' => $input['website_id']
  1607. ];
  1608. // 查询栏目名称
  1609. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1610. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1611. if (empty($category)) {
  1612. $imgArticles = [];
  1613. $textArticles = [];
  1614. // return Result::error("暂无此栏目",0);
  1615. } else {
  1616. $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1617. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin . '/' : null;
  1618. // return Result::success($website);
  1619. // 查询图片新闻
  1620. // 合并查询条件
  1621. $baseQuery = Article::where(function ($query) use ($website) {
  1622. $query->where(function ($subQuery) use ($website) {
  1623. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1624. })->orWhereNull("ignore_ids");
  1625. })
  1626. ->where('article.status', 1)
  1627. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1628. ->where('website_category.website_id', $website['website_id']);
  1629. // 查询文字新闻
  1630. $textArticles = clone $baseQuery;
  1631. $textArticles = $textArticles->whereIn('catid', $child_category)
  1632. ->select(
  1633. 'article.id',
  1634. 'article.title',
  1635. // 'article.imgurl',
  1636. 'article.author',
  1637. 'article.updated_at',
  1638. 'article.introduce',
  1639. 'article.islink',
  1640. 'article.linkurl',
  1641. 'article.copyfrom',
  1642. 'website_category.category_id',
  1643. 'website_category.alias',
  1644. 'website_category.aLIas_pinyin'
  1645. )
  1646. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1647. ->orderBy('article.updated_at', 'desc')
  1648. ->limit($parentTextNum)
  1649. ->get()
  1650. ->all();
  1651. if (empty($textArticles)) {
  1652. $textArticles = clone $baseQuery;
  1653. $textArticles = $textArticles->where('catid', $parentCatId)
  1654. ->select(
  1655. 'article.id',
  1656. 'article.title',
  1657. // 'article.imgurl',
  1658. 'article.author',
  1659. 'article.updated_at',
  1660. 'article.introduce',
  1661. 'article.islink',
  1662. 'article.linkurl',
  1663. 'article.copyfrom',
  1664. 'website_category.category_id',
  1665. 'website_category.alias',
  1666. 'website_category.aLIas_pinyin'
  1667. )
  1668. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1669. ->orderBy('article.updated_at', 'desc')
  1670. ->limit($parentTextNum)
  1671. ->get()
  1672. ->all();
  1673. }
  1674. // 查询图片新闻
  1675. $imgArticles = clone $baseQuery;
  1676. $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid', $child_category)
  1677. ->select(
  1678. 'article.id',
  1679. 'article.title',
  1680. 'article.imgurl',
  1681. 'article.author',
  1682. 'article.updated_at',
  1683. 'article.introduce',
  1684. 'article.islink',
  1685. 'article.linkurl',
  1686. 'article.copyfrom',
  1687. 'website_category.category_id',
  1688. 'website_category.alias',
  1689. 'website_category.aLIas_pinyin'
  1690. )
  1691. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1692. ->orderBy('article.updated_at', 'desc')
  1693. ->limit($parentImgNum)
  1694. ->get()
  1695. ->all();
  1696. if (empty($imgArticles)) {
  1697. $imgArticles = clone $baseQuery;
  1698. $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid', $parentCatId)
  1699. ->select(
  1700. 'article.id',
  1701. 'article.title',
  1702. 'article.imgurl',
  1703. 'article.author',
  1704. 'article.updated_at',
  1705. 'article.introduce',
  1706. 'article.islink',
  1707. 'article.linkurl',
  1708. 'article.copyfrom',
  1709. 'website_category.category_id',
  1710. 'website_category.alias',
  1711. 'website_category.aLIas_pinyin'
  1712. )
  1713. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1714. ->orderBy('article.updated_at', 'desc')
  1715. ->limit($parentImgNum)
  1716. ->get()
  1717. ->all();
  1718. }
  1719. }
  1720. $resultItem = [
  1721. 'alias' => $category ? $category->alias : null,
  1722. 'category_id' => $parentCatId,
  1723. 'pinyin' => $pinyin ? $pinyin : null,
  1724. 'imgnum' => $imgArticles ?? [],
  1725. 'textnum' => $textArticles ?? [],
  1726. ];
  1727. return $resultItem;
  1728. }, $data);
  1729. return Result::success($result);
  1730. }
  1731. // 封装处理商品的路由问题
  1732. function processGoods($goods, $data)
  1733. {
  1734. return $goods->map(function ($good) use ($data) {
  1735. $catid = $good->catid ?? 0;
  1736. // $pinyin = '';
  1737. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1738. if (!empty($category->pid) && $category->pid != 0) {
  1739. $level = json_decode($category->category_arr_id);
  1740. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1741. ->whereIn('category_id', $level)
  1742. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1743. ->get(['aLIas_pinyin'])
  1744. ->pluck('aLIas_pinyin')
  1745. ->implode('/');
  1746. } else {
  1747. $pinyin = $category->aLIas_pinyin ?? '';
  1748. }
  1749. if (isset($good->city_id) && !empty($good->city_id)) {
  1750. $city = District::where('id', $good->city_id)->first(['name']);
  1751. $good->city_name = $city->name ?? '';
  1752. }
  1753. // 解析imgurl JSON并取第一条数据
  1754. $imgUrls = json_decode($good->imgurl, true);
  1755. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1756. $good->pinyin = $pinyin;
  1757. return $good;
  1758. });
  1759. }
  1760. /**
  1761. * 获取商城首页-根据栏目id
  1762. * @param array $data
  1763. * @return array
  1764. * */
  1765. function getWebsiteCatidshop(array $data): array
  1766. {
  1767. $input['catid'] = $data['catid'];
  1768. $input['website_id'] = $data['website_id'];
  1769. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1770. $result = array_map(function ($item) use ($input) {
  1771. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1772. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1773. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1774. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1775. if (empty($category) || $category->type != 2) {
  1776. return Result::error("暂无此栏目", 0);
  1777. } else {
  1778. $website['website_id'] = $input['website_id'];
  1779. $goods = Good::where('good.status', 2)
  1780. ->where('good.website_id', $website['website_id'])
  1781. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1782. ->select(
  1783. 'good.id',
  1784. 'good.name',
  1785. 'good.imgurl',
  1786. 'good.description',
  1787. 'good.updated_at',
  1788. 'good.catid',
  1789. 'good.type_id',
  1790. 'good.price',
  1791. 'good.com',
  1792. 'good.level',
  1793. 'good.unit'
  1794. )
  1795. ->orderBy('updated_at', 'desc')
  1796. ->offset($goodStart)
  1797. ->limit($goodNum);
  1798. $all_goods = $goods->get();
  1799. $all_goods = $this->processGoods($all_goods, $website);
  1800. }
  1801. return $all_goods ?? [];
  1802. }
  1803. }, $data);
  1804. return Result::success($result);
  1805. }
  1806. /**
  1807. * 获取商品模块
  1808. * @param array $data
  1809. * @return array
  1810. * */
  1811. public function getWebsiteshop(array $data): array
  1812. {
  1813. $input['id'] = $data['id'];
  1814. $input['website_id'] = $data['website_id'];
  1815. $catid = $data['catid'];
  1816. $data = json_decode($input['id'] ?? '', true) ?? [];
  1817. $result['goods'] = array_map(function ($item) use ($input) {
  1818. // 检查parent元素是否存在且不是undefined
  1819. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  1820. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  1821. $website = $input['website_id'];
  1822. $query = Good::where('good.status', 2)
  1823. ->where('good.website_id', $website);
  1824. switch ($Levelid) {
  1825. case 1:
  1826. case 2:
  1827. case 3:
  1828. $goods = $query->where(function ($q) use ($Levelid) {
  1829. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  1830. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  1831. });
  1832. break;
  1833. case 4:
  1834. $goods = $query;
  1835. break;
  1836. case 5:
  1837. $goods = $query->where('type_id', 1);
  1838. break;
  1839. case 6:
  1840. $goods = $query->where('type_id', 2);
  1841. break;
  1842. default:
  1843. return [];
  1844. }
  1845. $all_goods = $goods
  1846. ->select(
  1847. 'good.id',
  1848. 'good.name',
  1849. 'good.imgurl',
  1850. 'good.description',
  1851. 'good.updated_at',
  1852. 'good.catid',
  1853. 'good.type_id',
  1854. 'good.price',
  1855. 'good.level',
  1856. 'good.website_id'
  1857. )
  1858. ->orderBy('updated_at', 'desc')
  1859. ->offset($goodStart)
  1860. ->limit($goodNum)
  1861. ->get();
  1862. $web['website_id'] = $website;
  1863. $all_goods = $this->processGoods($all_goods, $web);
  1864. }
  1865. return $all_goods;
  1866. }, $data);
  1867. $website = $input['website_id'];
  1868. $result['article'] = Article::where(function ($query) use ($website) {
  1869. $query->where(function ($subQuery) use ($website) {
  1870. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  1871. })->orWhereNull("ignore_ids");
  1872. })
  1873. ->where('catid', $catid)
  1874. ->where('article.status', 1)
  1875. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  1876. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  1877. ->orderBy('article.updated_at', 'desc')
  1878. ->first();
  1879. return Result::success($result);
  1880. }
  1881. /**
  1882. * 获取商品分类
  1883. * @param array $data
  1884. * @return array
  1885. * */
  1886. public function getWebsiteshopCat(array $data): array
  1887. {
  1888. $website = $data['website_id'];
  1889. $category = WebsiteCategory::where('website_id', $website)
  1890. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  1891. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  1892. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id')
  1893. ->orderBy('sort')
  1894. ->get();
  1895. $cat = $category->map(function ($item) use ($website) {
  1896. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  1897. $pid = $item->pid ?? 0;
  1898. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  1899. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  1900. ->where('website_id', $website)
  1901. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  1902. ->get(['aLIas_pinyin'])
  1903. ->pluck('aLIas_pinyin')
  1904. ->implode('/');
  1905. } else {
  1906. $pinyin = $item->aLIas_pinyin ?? '';
  1907. }
  1908. $item->pinyin = $pinyin;
  1909. });
  1910. if (empty($category)) {
  1911. return Result::error("栏目查询失败", 0);
  1912. }
  1913. $cat_tree = Result::buildMenuTree($category);
  1914. $web['website_id'] = $website;
  1915. $goods = Good::where('website_id', $website)
  1916. ->where('status', 2)
  1917. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  1918. ->latest('updated_at')
  1919. ->offset(($data['page'] - 1) * $data['pageSize'])
  1920. ->limit($data['pageSize'])
  1921. ->get();
  1922. if (!empty($goods)) {
  1923. if ($goods->count() > 1 && !empty($goods)) {
  1924. $goods = $this->processGoods($goods, $web);
  1925. }
  1926. } else {
  1927. $goods = [];
  1928. }
  1929. $result = [
  1930. 'category' => $cat_tree,
  1931. 'goods' => $goods,
  1932. ];
  1933. // $resul['goods'] = $goods;
  1934. if (empty($result)) {
  1935. return Result::error("查询失败", 0);
  1936. }
  1937. return Result::success($result);
  1938. }
  1939. /*
  1940. * 获取商品列表
  1941. * @param array $data
  1942. * @return array
  1943. * */
  1944. public function getWebsiteshopList(array $data): array
  1945. {
  1946. // return Result::success($data);
  1947. $where = [
  1948. 'status' => 2,
  1949. 'website_id' => $data['website_id'],
  1950. ];
  1951. if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  1952. return Result::error("查询失败", 0);
  1953. }
  1954. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  1955. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  1956. $data['catid'] = $category->category_id ?? 0;
  1957. }
  1958. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1959. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  1960. }
  1961. if (isset($data['type_id']) && !empty($data['type_id'])) {
  1962. array_push($where, ['type_id', $data['type_id']]);
  1963. }
  1964. $query = Good::where($where)
  1965. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  1966. $query->where(function ($q) use ($data) {
  1967. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  1968. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  1969. });
  1970. })
  1971. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  1972. $query->where(function ($q) use ($data) {
  1973. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  1974. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  1975. });
  1976. })
  1977. ->select(
  1978. 'good.id',
  1979. 'good.name',
  1980. 'good.imgurl',
  1981. 'good.description',
  1982. 'good.updated_at',
  1983. 'good.com',
  1984. 'good.catid',
  1985. 'good.type_id',
  1986. 'good.website_id',
  1987. 'good.cat_arr_id',
  1988. 'good.created_at',
  1989. 'good.city_id'
  1990. )
  1991. ->latest('updated_at');
  1992. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  1993. // 获取 type_id 为 1 的数据
  1994. $result['type1'] = $this->processGoods(
  1995. $query->clone()
  1996. ->where('type_id', 1)
  1997. ->offset(($data['page'] - 1) * $data['pageSize'])
  1998. ->limit($data['pageSize'])
  1999. ->get(),
  2000. $data
  2001. );
  2002. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2003. // 获取 type_id 为 2 的数据
  2004. $result['type2'] = $this->processGoods(
  2005. $query->clone()
  2006. ->where('type_id', 2)
  2007. ->offset(($data['page'] - 1) * $data['pageSize'])
  2008. ->limit($data['pageSize'])
  2009. ->get(),
  2010. $data
  2011. );
  2012. if (empty($result)) {
  2013. return Result::error("查询失败", 0);
  2014. }
  2015. return Result::success($result);
  2016. }
  2017. /**
  2018. * 获取商品详情
  2019. * @param array $data
  2020. * @return array
  2021. * */
  2022. public function getWebsiteshopInfo(array $data): array
  2023. {
  2024. $where = [
  2025. 'good.status' => 2,
  2026. 'good.website_id' => $data['website_id'],
  2027. 'good.id' => $data['id'],
  2028. ];
  2029. $goods = Good::where($where)
  2030. ->where('good.id', $data['id'])
  2031. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2032. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2033. ->first();
  2034. if (empty($goods)) {
  2035. return Result::error("查询失败", 0);
  2036. }
  2037. $goods->imgurl = json_decode($goods->imgurl, true);
  2038. return Result::success($goods);
  2039. }
  2040. /**
  2041. * 封装处理文章的路由问题
  2042. * */
  2043. function processArticles($articles, $data)
  2044. {
  2045. // 检查 $articles 是否为数组或可迭代对象
  2046. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2047. return $articles->map(function ($article) use ($data) {
  2048. $catid = $article->cat_arr_id ?? '';
  2049. $level = json_decode($catid, true);
  2050. if (!is_array($level)) {
  2051. return $article;
  2052. } else {
  2053. $level = array_map('intval', $level);
  2054. }
  2055. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2056. ->where($data)
  2057. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2058. ->pluck('aLIas_pinyin')
  2059. ->implode('/');
  2060. $article->pinyin = $pinyin ?? '';
  2061. return $article;
  2062. });
  2063. } else {
  2064. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2065. $catid = $articles->cat_arr_id ?? '';
  2066. $level = json_decode($catid, true);
  2067. if (!is_array($level)) {
  2068. return $articles;
  2069. } else {
  2070. $level = array_map('intval', $level);
  2071. }
  2072. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2073. ->where($data)
  2074. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2075. ->pluck('aLIas_pinyin')
  2076. ->implode('/');
  2077. $articles->pinyin = $pinyin ?? '';
  2078. return $articles;
  2079. }
  2080. }
  2081. // 封装处理由问题
  2082. function processJob($job, $data)
  2083. {
  2084. return $job->map(function ($job) use ($data) {
  2085. $category = $job->cat_arr_id ?? '';
  2086. $cityid = $job->city_arr_id ?? '';
  2087. $city = json_decode($cityid, true);
  2088. $pinyin = '';
  2089. $level = json_decode($category, true);
  2090. // 路由
  2091. if (!empty($level) && is_array($level)) {
  2092. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2093. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2094. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2095. ->get(['aLIas_pinyin'])
  2096. ->pluck('aLIas_pinyin')
  2097. ->implode('/');
  2098. if (empty($pinyin)) {
  2099. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2100. }
  2101. $job->pinyin = $pinyin;
  2102. }
  2103. // 取职位-城市 市??省
  2104. if (!empty($city) && is_array($city)) {
  2105. if (isset($city[1]) && !empty($city[1])) {
  2106. $city = District::where('id', $city[1])->first(['name']);
  2107. $job->city_name = $city->name ?? '';
  2108. } else if (isset($city[0]) && !empty($city[0])) {
  2109. $city = District::where('id', $city[0])->first(['name']);
  2110. $job->city_name = $city->name ?? '';
  2111. } else {
  2112. $job->city_name = '全国';
  2113. }
  2114. }
  2115. // 获取简历最后一级地区
  2116. if (isset($job->city_id) && !empty($job->city_id)) {
  2117. $city = District::where('id', $job->city_id)->first(['name']);
  2118. $job->hunt_cityname = $city->name ?? '';
  2119. }
  2120. // 组合详细地址
  2121. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2122. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2123. if (is_array($address_id) && !empty($address_id)) {
  2124. $address = District::whereIn('id', $address_id)
  2125. ->orderBy('level', 'asc')
  2126. ->get(['name'])
  2127. ->pluck('name')
  2128. ->implode('');
  2129. // $job->address_name = $address ?? '';
  2130. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2131. }
  2132. }
  2133. // 取行业
  2134. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2135. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2136. if (!empty($job->industry)) {
  2137. $query->where('hyid', $job->industry);
  2138. } else if (!empty($job->hy_id)) {
  2139. $query->where('hyid', $job->hy_id);
  2140. } else if (!empty($job->company_hy_id)) {
  2141. $query->where('hyid', $job->company_hy_id);
  2142. } else {
  2143. $query->where('hyid', $job->job_industry);
  2144. }
  2145. })->first(['hyname']);
  2146. $job->hy_name = $hy_name->hyname ?? '';
  2147. }
  2148. // 取职位类别
  2149. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2150. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2151. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2152. $job->zw_name = $zw_name->zwname ?? '';
  2153. }
  2154. // 取具体职位
  2155. 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))) {
  2156. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2157. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2158. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2159. }
  2160. // 取工作经验
  2161. if (isset($job->experience) && !empty($job->experience)) {
  2162. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2163. $job->experience_name = $experience->ename ?? '';
  2164. }
  2165. // 取学历
  2166. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2167. $education = $job->educational ?? $job->school_education;
  2168. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2169. $job->education_name = $education->ename ?? '';
  2170. }
  2171. // 语言
  2172. if (isset($job->language) && !empty($job->language)) {
  2173. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2174. $job->language_name = $language->ename ?? '';
  2175. }
  2176. // 薪资
  2177. if (isset($job->salary) && !empty($job->salary)) {
  2178. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2179. $job->salary_name = $salary->ename ?? '';
  2180. }
  2181. // 职位性质
  2182. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2183. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2184. $job->job_nature_name = $job_nature->ename ?? '';
  2185. }
  2186. // 公司规模
  2187. if (isset($job->company_size) && !empty($job->company_size)) {
  2188. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2189. $job->company_size_name = $company_size->ename ?? '';
  2190. }
  2191. // 公司性质
  2192. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2193. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2194. $job->company_nature_name = $company_nature->nature_name ?? '';
  2195. }
  2196. // $job->pinyin = $pinyin;
  2197. return $job;
  2198. });
  2199. }
  2200. /**
  2201. * 获取书籍模块
  2202. * @param array $data
  2203. * @return array
  2204. * */
  2205. public function getWebsiteBook(array $data): array
  2206. {
  2207. $input['id'] = $data['id'];
  2208. $input['website_id'] = $data['website_id'];
  2209. // 将 JSON 字符串转换为 PHP 数组
  2210. $data = json_decode($input['id'], true);
  2211. // 使用 array_map 处理每个元素
  2212. $result = array_map(function ($item) use ($input) {
  2213. // 检查parent元素是否存在且不是undefined
  2214. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2215. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2216. $website = [
  2217. 'website_id' => $input['website_id'],
  2218. ];
  2219. // 查询栏目名称
  2220. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2221. if (empty($category)) {
  2222. $parent_alias = '';
  2223. $parent_pinyin = null;
  2224. $imgBooks = [];
  2225. $textBooks = [];
  2226. } else {
  2227. $parent_alias = $category->alias ?? '';
  2228. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2229. // 查找子分类ID数组
  2230. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2231. array_push($childCategoryIds, $parentCatId);
  2232. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2233. if ($parentImgNum != 0) {
  2234. // 查询图片新闻
  2235. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2236. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2237. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2238. })
  2239. ->where('book.status', 2)
  2240. ->where('book.img_url', '!=', '')
  2241. ->leftJoin('website_category', function ($join) use ($website) {
  2242. $join->on('book.cat_id', '=', 'website_category.category_id')
  2243. ->where('website_category.website_id', '=', $website['website_id']);
  2244. })
  2245. ->select(
  2246. 'book.id',
  2247. 'book.title',
  2248. 'book.img_url',
  2249. 'book.price',
  2250. 'book.market_price',
  2251. 'book.description',
  2252. 'book.cat_id',
  2253. 'book.description',
  2254. 'book.updated_at',
  2255. 'website_category.alias as category_name',
  2256. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2257. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2258. )
  2259. ->orderBy('updated_at', 'desc')
  2260. ->limit($parentImgNum)
  2261. ->get()->all();
  2262. // 查询文字新闻
  2263. }
  2264. if ($parentTextNum != 0) {
  2265. $textBooks = [];
  2266. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2267. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2268. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2269. })
  2270. ->where('book.status', 2)
  2271. ->leftJoin('website_category', function ($join) use ($website) {
  2272. $join->on('book.cat_id', '=', 'website_category.category_id')
  2273. ->where('website_category.website_id', '=', $website['website_id']);
  2274. })
  2275. ->select(
  2276. 'book.id',
  2277. 'book.title',
  2278. 'book.img_url',
  2279. 'book.price',
  2280. 'book.market_price',
  2281. 'book.description',
  2282. 'book.cat_id',
  2283. 'book.description',
  2284. 'book.updated_at',
  2285. 'website_category.alias as category_name',
  2286. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2287. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2288. )
  2289. ->orderBy('updated_at', 'desc')
  2290. ->limit($parentTextNum)
  2291. ->get()->all();
  2292. }
  2293. }
  2294. }
  2295. $resultItem = [
  2296. 'alias' => $parent_alias ?? '',
  2297. 'category_id' => $parentCatId ?? 0,
  2298. 'pinyin' => $parent_pinyin ?? null,
  2299. 'imgnum' => $imgBooks ?? [],
  2300. 'textnum' => $textBooks ?? [],
  2301. ];
  2302. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2303. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2304. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2305. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2306. ->get()->all();
  2307. if (!empty($childCategory)) {
  2308. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2309. // 查询子栏目名称
  2310. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2311. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2312. ->first();
  2313. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2314. $childImgArticles = [];
  2315. $childTextArticles = [];
  2316. $resultItem['child'] = [];
  2317. } else {
  2318. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2319. // 查询子栏目图片新闻
  2320. $childImgArticles = Book::where('cat_id', $childCatId)
  2321. ->where('status', 2)
  2322. ->where('img_url', '!=', '')
  2323. ->leftJoin('website_category', function ($join) use ($website) {
  2324. $join->on('book.cat_id', '=', 'website_category.category_id')
  2325. ->where('website_category.website_id', '=', $website['website_id']);
  2326. })
  2327. ->select(
  2328. 'book.id',
  2329. 'book.title',
  2330. 'book.img_url',
  2331. 'book.price',
  2332. 'book.market_price',
  2333. 'book.description',
  2334. 'book.cat_id',
  2335. 'book.description',
  2336. 'book.updated_at',
  2337. DB::raw("'$child_pinyin' as pinyin")
  2338. )
  2339. ->orderBy('updated_at', 'desc')
  2340. ->limit($childImgNum)
  2341. ->get()->all();
  2342. // 查询子栏目文字新闻
  2343. $childTextArticles = Book::where('cat_id', $childCatId)
  2344. ->where('status', 2)
  2345. ->leftJoin('website_category', function ($join) use ($website) {
  2346. $join->on('book.cat_id', '=', 'website_category.category_id')
  2347. ->where('website_category.website_id', '=', $website['website_id']);
  2348. })
  2349. ->select(
  2350. 'book.id',
  2351. 'book.title',
  2352. 'book.img_url',
  2353. 'book.price',
  2354. 'book.market_price',
  2355. 'book.description',
  2356. 'book.cat_id',
  2357. 'book.description',
  2358. 'book.updated_at',
  2359. DB::raw("'$child_pinyin' as pinyin")
  2360. )
  2361. ->orderBy('updated_at', 'desc')
  2362. ->limit($childTextNum)
  2363. ->get()->all();
  2364. $resultItem['child'] = [
  2365. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2366. 'category_id' => $childCatId,
  2367. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2368. 'all_childcat' => $childCategory,
  2369. 'imgnum' => $childImgArticles,
  2370. 'textnum' => $childTextArticles,
  2371. ];
  2372. }
  2373. }
  2374. } else {
  2375. $resultItem['child'] = [];
  2376. }
  2377. return $resultItem;
  2378. }, $data);
  2379. return Result::success($result);
  2380. }
  2381. /**
  2382. * 获取书刊列表
  2383. * @param array $data
  2384. * @return array
  2385. * */
  2386. public function getWebsiteBookList(array $data): array
  2387. {
  2388. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2389. if (empty($web)) {
  2390. return Result::error("查询失败", 0);
  2391. }
  2392. $catid = $data['id'];
  2393. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2394. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2395. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2396. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2397. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2398. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2399. ->where('pid', $category['pid'])
  2400. ->select(
  2401. 'category_id',
  2402. 'alias',
  2403. 'aLIas_pinyin',
  2404. 'pid',
  2405. 'sort',
  2406. 'is_url',
  2407. 'web_url',
  2408. 'seo_title',
  2409. 'seo_keywords',
  2410. 'seo_description',
  2411. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2412. )
  2413. ->orderBy('sort')
  2414. ->get()->all();
  2415. if (empty($category)) {
  2416. return Result::error("查询失败", 0);
  2417. }
  2418. $query = Book::where('book.status', 2)
  2419. ->where('book.website_id', $data['website_id'])
  2420. ->where('book.cat_id', $catid)
  2421. ->select(
  2422. 'book.id',
  2423. 'book.title',
  2424. 'book.img_url',
  2425. 'book.description',
  2426. 'book.updated_at',
  2427. 'book.cat_id',
  2428. DB::raw("'$pinyin' as pinyin")
  2429. )
  2430. ->orderBy('book.updated_at', 'desc');
  2431. $count = $query->count();
  2432. $query = clone $query;
  2433. $Book = $query
  2434. ->limit($data['pageSize'])
  2435. ->offset(($data['page'] - 1) * $data['pageSize'])
  2436. ->get()->all();
  2437. $result = [
  2438. 'category' => $categorys,
  2439. 'books' => $Book,
  2440. 'count' => $count,
  2441. ];
  2442. // if(empty($result)){
  2443. // return Result::error("查询失败", 0);
  2444. // }
  2445. return Result::success($result);
  2446. }
  2447. /**
  2448. * 获取书刊详情
  2449. * @param array $data
  2450. * @return array
  2451. * */
  2452. public function getWebsiteBookInfo(array $data): array
  2453. {
  2454. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2455. if (empty($web)) {
  2456. return Result::error("查询失败", 0);
  2457. }
  2458. $book = Book::where('status', 2)
  2459. ->where('website_id', $data['website_id'])
  2460. ->where('id', $data['id'])
  2461. ->select(
  2462. 'book.*',
  2463. )
  2464. ->orderBy('updated_at', 'desc')
  2465. ->first();
  2466. if (empty($book)) {
  2467. return Result::error("查询失败", 0);
  2468. }
  2469. // 先查询当前分类的 pid
  2470. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2471. ->where('category_id', $book['cat_id'])
  2472. ->first(['pid', 'category_id']);
  2473. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2474. if (!empty($carpid)) {
  2475. if ($carpid->pid != 0) {
  2476. $pid = $carpid['pid'];
  2477. // $parent_pinyin = '';
  2478. } else {
  2479. $pid = $carpid['category_id'];
  2480. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2481. }
  2482. }
  2483. $categorys = $query->where('pid', $pid)
  2484. ->select(
  2485. 'category_id',
  2486. 'alias',
  2487. 'aLIas_pinyin',
  2488. 'pid',
  2489. 'sort',
  2490. 'is_url',
  2491. 'web_url',
  2492. 'category_arr_id as cat_arr_id',
  2493. )
  2494. ->orderBy('sort')
  2495. ->get();
  2496. $category = $this->processArticle($categorys, $data);
  2497. $result = [
  2498. 'category' => $category,
  2499. 'books' => $book,
  2500. ];
  2501. return Result::success($result);
  2502. }
  2503. /**
  2504. * 尝试
  2505. * @param array $data
  2506. * @return array
  2507. * */
  2508. public function test(array $data): array
  2509. {
  2510. $input['id'] = $data['id'];
  2511. $input['website_id'] = $data['website_id'];
  2512. // 将 JSON 字符串转换为 PHP 数组
  2513. $data = json_decode($input['id'], true);
  2514. $result = [];
  2515. $article = $data;
  2516. $result = array_map(function ($item) use ($input) {
  2517. $website = [
  2518. 'website_id' => $input['website_id'],
  2519. ];
  2520. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2521. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2522. $parent = [
  2523. 0 => $category['category_id'] ?? [],
  2524. 1 => $parentImgNum ?? [],
  2525. 2 => $parentTextNum ?? [],
  2526. ];
  2527. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2528. $child = [];
  2529. $resultItem = [
  2530. // 'alias' => $parent_alias ?? '',
  2531. 'category_id' => $parentCatId ?? 0,
  2532. 'pinyin' => $parentImgNum ?? null,
  2533. 'imgnum' => $parentTextNum ?? [],
  2534. // 'textnum' => $textArticles ?? [],
  2535. ];
  2536. return $parent;
  2537. }, $data);
  2538. return Result::success($result);
  2539. // });
  2540. }
  2541. /**
  2542. * 封装处理文章的路由问题
  2543. * */
  2544. function processArticle($article, $data)
  2545. {
  2546. return $article->map(function ($article) use ($data) {
  2547. $catid = $article->cat_arr_id ?? '';
  2548. $level = json_decode($catid, true);
  2549. $pinyin = '';
  2550. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2551. if (!empty($level) && is_array($level)) {
  2552. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2553. ->where('website_id', $data['website_id'])
  2554. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2555. ->get(['aLIas_pinyin'])
  2556. ->pluck('aLIas_pinyin')
  2557. ->implode('/');
  2558. } else {
  2559. $pinyin = '';
  2560. }
  2561. $article->pinyin = $pinyin;
  2562. return $article;
  2563. });
  2564. }
  2565. /**
  2566. * c端-获取招工招聘下拉选框
  2567. * @param array $data
  2568. * @return array
  2569. * */
  2570. public function getWebsiteJobSelect(array $data): array
  2571. {
  2572. $web = Website::where('id', $data['website_id'])->first();
  2573. if (empty($web)) {
  2574. return Result::error("该网站不存在", 0);
  2575. }
  2576. $hy = JobIndustry::get()->all();
  2577. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2578. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2579. $result = [
  2580. 'hy' => $hy,
  2581. 'zw' => $zw,
  2582. 'jtzw' => $jtzw,
  2583. ];
  2584. if (empty($result)) {
  2585. return Result::error("查询失败", 0);
  2586. }
  2587. return Result::success($result);
  2588. }
  2589. /**
  2590. * c端-获取招工招聘
  2591. * @param array $data
  2592. * @return array
  2593. * */
  2594. public function getWebsiteJob(array $data): array
  2595. {
  2596. $web = Website::where('id', $data['website_id'])->first();
  2597. if (empty($web)) {
  2598. return Result::error("该网站不存在", 0);
  2599. }
  2600. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2601. ->where('job_hunting.website_id', $data['website_id'])
  2602. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2603. $query->where(function ($q) use ($data) {
  2604. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2605. });
  2606. })
  2607. ->select(
  2608. 'job_hunting.id',
  2609. 'job_hunting.cat_arr_id',
  2610. 'job_hunting.job_name_get',
  2611. 'job_hunting.industry',
  2612. 'job_hunting.name',
  2613. 'job_hunting.sexy',
  2614. 'job_hunting.origin',
  2615. 'job_hunting.city_arr_id',
  2616. 'job_hunting.experience',
  2617. 'job_hunting.updated_at',
  2618. 'job_hunting.salary'
  2619. )
  2620. ->orderBy('updated_at', 'desc')
  2621. ->limit($data['job1_num'])
  2622. ->get();
  2623. $web['website_id'] = $data['website_id'];
  2624. if (empty($job_hunting)) {
  2625. $job_huntings = "未查询到相关简历信息";
  2626. } else {
  2627. $job_huntings = $this->processJob($job_hunting, $web);
  2628. }
  2629. // 0:待审核 1:已通过 2:已拒绝
  2630. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2631. ->where('job_recruiting.website_id', $data['website_id'])
  2632. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2633. $query->where(function ($q) use ($data) {
  2634. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2635. });
  2636. })
  2637. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2638. ->select(
  2639. 'job_recruiting.id',
  2640. 'job_recruiting.cat_arr_id',
  2641. 'job_recruiting.title',
  2642. 'job_recruiting.jtzw_id',
  2643. 'job_recruiting.hy_id',
  2644. 'job_recruiting.city_arr_id',
  2645. 'job_recruiting.due_data',
  2646. 'job_recruiting.updated_at',
  2647. 'job_recruiting.experience',
  2648. 'job_recruiting.educational',
  2649. 'job_recruiting.salary',
  2650. 'job_recruiting.zw_id',
  2651. 'job_company.business_name'
  2652. )
  2653. ->orderBy('updated_at', 'desc')
  2654. ->limit($data['job2_num'])
  2655. ->get();
  2656. if (empty($job_recruiting->toArray())) {
  2657. $job_recruitings = "未查询到相关职位信息";
  2658. } else {
  2659. $job_recruitings = $this->processJob($job_recruiting, $web);
  2660. }
  2661. $result = [
  2662. 'job_hunting' => $job_huntings,
  2663. 'job_recuiting' => $job_recruitings,
  2664. ];
  2665. return Result::success($result);
  2666. }
  2667. /**
  2668. * c端-获取招工招聘列表
  2669. * @param array $data
  2670. * @return array
  2671. * */
  2672. public function getWebsiteJobList(array $data): array
  2673. {
  2674. $recruit_where = [];
  2675. $hunt_where = [];
  2676. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2677. if (empty($web)) {
  2678. return Result::error("此网站不存在", 0);
  2679. }
  2680. $website_id['website_id'] = $data['website_id'];
  2681. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2682. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2683. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2684. }
  2685. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2686. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2687. }
  2688. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2689. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2690. }
  2691. $query = JobRecruiting::where('job_recruiting.status', 1)
  2692. ->where('job_recruiting.website_id', $data['website_id'])
  2693. ->where($recruit_where)
  2694. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2695. $query->where(function ($q) use ($data) {
  2696. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2697. });
  2698. })
  2699. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2700. $query->where(function ($q) use ($data) {
  2701. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2702. });
  2703. })
  2704. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2705. ->select(
  2706. 'job_recruiting.id',
  2707. 'job_recruiting.hy_id',
  2708. 'job_recruiting.title',
  2709. 'job_recruiting.zw_id',
  2710. 'job_recruiting.educational',
  2711. 'job_recruiting.jtzw_id',
  2712. 'job_recruiting.city_arr_id',
  2713. 'job_recruiting.due_data',
  2714. 'job_recruiting.experience',
  2715. 'job_recruiting.cat_arr_id',
  2716. 'job_recruiting.updated_at',
  2717. 'job_company.business_name'
  2718. )
  2719. ->orderBy('updated_at', 'desc');
  2720. $recruit_count = $query->count();
  2721. $query = clone $query;
  2722. $JobRecruiting = $query
  2723. ->offset(($data['page'] - 1) * $data['pageSize'])
  2724. ->limit($data['pageSize'])
  2725. ->get();
  2726. if (empty($JobRecruiting)) {
  2727. $JobRecruiting = "暂无相关职位信息";
  2728. } else {
  2729. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2730. }
  2731. }
  2732. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2733. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2734. array_push($hunt_where, ['job', $data['zw_id']]);
  2735. }
  2736. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2737. array_push($hunt_where, ['job_name_get', $data['jtzw_id']]);
  2738. }
  2739. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2740. array_push($hunt_where, ['industry', $data['hy_id']]);
  2741. }
  2742. $query = JobHunting::where('status', 2)
  2743. ->where('job_hunting.website_id', $data['website_id'])
  2744. ->where($hunt_where)
  2745. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2746. $query->where(function ($q) use ($data) {
  2747. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2748. });
  2749. })
  2750. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  2751. $query->where(function ($q) use ($data) {
  2752. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  2753. });
  2754. })
  2755. ->select('id', 'sexy', 'experience', 'origin', 'industry', 'name', 'job', 'job_name_get', 'city_arr_id', 'cat_arr_id', 'created_at', 'updated_at')
  2756. ->orderBy('updated_at', 'desc');
  2757. $hunt_count = $query->count();
  2758. $query = clone $query;
  2759. $JobHunting = $query
  2760. ->offset(($data['page'] - 1) * $data['pageSize'])
  2761. ->limit($data['pageSize'])
  2762. ->get();
  2763. if (empty($JobHunting)) {
  2764. $JobRecruiting = "暂无相关简历信息";
  2765. } else {
  2766. $JobHunting = $this->processJob($JobHunting, $website_id);
  2767. }
  2768. }
  2769. $result = [
  2770. 'JobRecruiting' => $JobRecruiting ?? [],
  2771. 'recruit_count' => $recruit_count ?? 0,
  2772. 'JobHunting' => $JobHunting ?? [],
  2773. 'hunt_count' => $hunt_count ?? 0,
  2774. ];
  2775. return Result::success($result);
  2776. }
  2777. /**
  2778. * c端-获取招工招聘详情
  2779. * @param array $data
  2780. * @return array
  2781. * */
  2782. public function getWebsiteJobInfo(array $data): array
  2783. {
  2784. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2785. if (empty($web)) {
  2786. return Result::error("该网站不存在", 0);
  2787. }
  2788. $webid = [
  2789. 'website_id' => $data['website_id'],
  2790. ];
  2791. // 职位相关信息
  2792. if ($data['type'] == 1) {
  2793. $query = JobRecruiting::where('status', 1)
  2794. ->where('website_id', $data['website_id'])
  2795. ->select('*');
  2796. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2797. $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();
  2798. if (!empty($company)) {
  2799. $result['company'] = $this->processJob($company, $webid);
  2800. }
  2801. $other_job = JobRecruiting::where('status', 1)
  2802. ->where('website_id', $data['website_id'])
  2803. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  2804. ->where('id', '!=', $data['id'])
  2805. ->where('user_id', '=', $job[0]['user_id'])
  2806. ->limit($data['pageSize'])
  2807. ->get();
  2808. if (!empty($other_job)) {
  2809. $result['other_job'] = $this->processJob($other_job, $webid);
  2810. }
  2811. } else {
  2812. // 简历相关信息
  2813. $job = JobHunting::where('job_hunting.status', 2)
  2814. ->where('job_hunting.website_id', $data['website_id'])
  2815. ->where('job_hunting.id', $data['id'])
  2816. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2817. ->select('job_hunting.*', 'user_name')
  2818. ->get();
  2819. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  2820. if (!empty($resume->toArray())) {
  2821. $result['resume'] = 1;
  2822. } else {
  2823. $result['resume'] = 0;
  2824. }
  2825. }
  2826. if (empty($job->toArray())) {
  2827. return Result::error("id参数错误", 0);
  2828. }
  2829. if (!empty($job[0]['job_experience'])) {
  2830. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  2831. if (!empty($job_experience)) {
  2832. // $hy = [];
  2833. foreach ($job_experience as $key => $value) {
  2834. // $id = $value['id'];
  2835. $hy[$key] = $value['job_industry'];
  2836. $zw_id[$key] = $value['job_typename'];
  2837. $jtzw_id[$key] = $value['job_name'];
  2838. }
  2839. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  2840. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  2841. // 先将关联表转换为索引数组,提高查找效率
  2842. $hyLookup = [];
  2843. foreach ($hy_table as $item) {
  2844. $hyLookup[$item['hyid']] = $item['hyname'];
  2845. }
  2846. $zwLookup = [];
  2847. foreach ($zw_table as $item) {
  2848. $zwLookup[$item['zwid']] = $item['zwname'];
  2849. }
  2850. foreach ($job_experience as $key => &$value) {
  2851. // 处理行业名称
  2852. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  2853. $value['hy_name'] = $hyLookup[$hy[$key]];
  2854. }
  2855. // 处理职位名称
  2856. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  2857. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  2858. }
  2859. // 处理具体职位名称
  2860. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  2861. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  2862. }
  2863. }
  2864. // 释放引用,防止意外修改后续代码
  2865. unset($value);
  2866. }
  2867. $result['job_experience'] = $job_experience ?? [];
  2868. }
  2869. if (!empty($job[0]['education_experience'])) {
  2870. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  2871. if (!empty($education_experience)) {
  2872. foreach ($education_experience as $key => $value) {
  2873. // $id = $value['id'];
  2874. $education[$key] = $value['school_education'];
  2875. }
  2876. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  2877. // // 先将关联表转换为索引数组,提高查找效率
  2878. $educationLookup = [];
  2879. foreach ($education_table as $item) {
  2880. $educationLookup[$item['evalue']] = $item['ename'];
  2881. }
  2882. foreach ($education_experience as $key => &$value) {
  2883. // 处理学历名称
  2884. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  2885. $value['education_name'] = $educationLookup[$education[$key]];
  2886. }
  2887. }
  2888. }
  2889. $result['education_experience'] = $job_experience ?? [];
  2890. }
  2891. $result['job'] = $this->processJob($job, $webid);
  2892. // // 返现对应的栏目
  2893. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  2894. $category = WebsiteCategory::where('website_id', $data['website_id'])
  2895. ->whereIn('category_id', $catid)
  2896. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  2897. ->orderBy('pid')->get()->all();
  2898. if (!empty($category)) {
  2899. $result['category'] = $category;
  2900. }
  2901. $result['job'] = $job;
  2902. $result['job_experience'] = $job_experience ?? [];
  2903. $result['education_experience'] = $education_experience ?? [];
  2904. if (empty($result)) {
  2905. return Result::error("参数错误", 0);
  2906. }
  2907. return Result::success($result);
  2908. }
  2909. /**
  2910. * c端-申请职位
  2911. * @param array $data
  2912. * @return array
  2913. * */
  2914. public function getWebsiteJobApply(array $data): array
  2915. {
  2916. // 首先验证网站是否存在
  2917. // return Result::success($data);
  2918. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2919. if (empty($web)) {
  2920. return Result::error("该网站不存在", 0);
  2921. }
  2922. // 验证用户是否存在且为个人会员/管理员
  2923. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2924. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2925. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  2926. return Result::error("用户不存在", 0);
  2927. }
  2928. // 去除重复元素和空元素,并保持原始顺序
  2929. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  2930. return !empty($value);
  2931. }));
  2932. // 验证职位是否存在 1:审核通过
  2933. $recruiting = JobRecruiting::where('status', 1)
  2934. ->where('website_id', $data['website_id'])
  2935. ->whereIn('id', $data['recruit_id'])
  2936. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  2937. if (empty($recruiting)) {
  2938. return Result::error("该职位不存在", 0);
  2939. }
  2940. // 简历是否存在
  2941. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  2942. if (empty($hunt_id)) {
  2943. return Result::error("该简历不存在", 0);
  2944. }
  2945. $data['hunt_id'] = $hunt_id['hunt_id'];
  2946. // // 验证是否已投递过该职位
  2947. $apply = JobApply::where('user_id', $data['user_id'])
  2948. ->where('hunt_id', $data['hunt_id'])
  2949. ->where('website_id', $data['website_id'])
  2950. ->whereIn('recruit_id', $data['recruit_id'])
  2951. ->get(['recruit_id']);
  2952. if (!empty($apply->toArray())) {
  2953. return Result::error("您已投递过该职位!");
  2954. }
  2955. $insertData = array_map(function ($recruiting) use ($data) {
  2956. return [
  2957. 'user_id' => $data['user_id'],
  2958. 'hunt_id' => $data['hunt_id'],
  2959. 'website_id' => $data['website_id'],
  2960. 'recruit_id' => $recruiting['recruit_id'],
  2961. 'receiver_id' => $recruiting['receiver_id'],
  2962. 'status' => 1,
  2963. ];
  2964. }, $recruiting);
  2965. // 批量插入数据
  2966. $result = JobApply::insert($insertData);
  2967. if (empty($result)) {
  2968. return Result::error("投递失败", 0);
  2969. }
  2970. return Result::success($result);
  2971. }
  2972. /**
  2973. * 招工招聘-沟通简历
  2974. * @param array $data
  2975. * @return array
  2976. * */
  2977. public function getWebsiteJobResume(array $data): array
  2978. {
  2979. // 首先验证网站是否存在
  2980. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2981. if (empty($web)) {
  2982. return Result::error("该网站不存在", 0);
  2983. }
  2984. // return Result::success($data);
  2985. // 验证用户是否存在且为企业会员/管理员
  2986. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2987. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2988. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2989. return Result::error("用户不存在", 0);
  2990. }
  2991. // 去除重复元素和空元素,并保持原始顺序
  2992. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  2993. return !empty($value);
  2994. }));
  2995. // 验证简历是否存在
  2996. $hunting = JobHunting::where('status', 2)
  2997. ->where('website_id', $data['website_id'])
  2998. ->whereIn('id', $data['hunt_id'])
  2999. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3000. if (empty($hunting)) {
  3001. return Result::error("该简历不存在", 0);
  3002. }
  3003. // 验证是否已沟通过该简历
  3004. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3005. ->where('recruit_id', $data['recruit_id'])
  3006. ->where('website_id', $data['website_id'])
  3007. ->whereIn('hunt_id', $data['hunt_id'])
  3008. ->get(['hunt_id']);
  3009. if (!empty($remuse->toArray())) {
  3010. return Result::error("您已沟通过该简历!");
  3011. }
  3012. // 准备要插入的数据数组
  3013. $insertData = array_map(function ($hunting) use ($data) {
  3014. return [
  3015. 'user_id' => $data['user_id'],
  3016. 'recruit_id' => $data['recruit_id'],
  3017. 'website_id' => $data['website_id'],
  3018. 'hunt_id' => $hunting['hunt_id'],
  3019. 'receiver_id' => $hunting['receiver_id'],
  3020. 'status' => 1,
  3021. ];
  3022. }, $hunting);
  3023. // 批量插入数据
  3024. $result = JobRemuse::insert($insertData);
  3025. if (empty($result)) {
  3026. return Result::error("沟通失败", 0);
  3027. }
  3028. return Result::success($result);
  3029. }
  3030. /**
  3031. * 招工招聘 -我的职位(企业会员)
  3032. * @param array $data
  3033. * @return array
  3034. */
  3035. public function getWebsiteJobRecruiting(array $data): array
  3036. {
  3037. $web = Website::where('id', $data['website_id'])->first('id');
  3038. if (empty($web)) {
  3039. return Result::error("该网站不存在", 0);
  3040. }
  3041. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3042. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3043. return Result::error("用户暂无权限!", 0);
  3044. }
  3045. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3046. $result = JobRecruiting::where('website_id', $data['website_id'])
  3047. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3048. $query->where('user_id', $user['id']);
  3049. })
  3050. ->where('status', 1)
  3051. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3052. ->orderBy('updated_at', 'desc')
  3053. ->limit($data['pageSize'])
  3054. ->get();
  3055. if (empty($result)) {
  3056. return Result::error("暂无相关职位信息", 0);
  3057. }
  3058. return Result::success($result);
  3059. }
  3060. /**
  3061. * c端 - 验证路由
  3062. * @param array $data
  3063. * @return array
  3064. */
  3065. public function checkWebsiteRoute(array $data): array
  3066. {
  3067. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3068. if (empty($web)) {
  3069. return Result::error("该网站不存在", 0);
  3070. }
  3071. // 验证栏目路由
  3072. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3073. ->where('aLIas_pinyin', $data['last_route'])
  3074. ->first();
  3075. if (empty($last_category)) {
  3076. return Result::error("该栏目不存在", 0);
  3077. }
  3078. if (isset($data['id']) && !empty($data['id'])) {
  3079. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3080. switch ($last_category['type']) {
  3081. case 1:
  3082. // 文章
  3083. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3084. $article = Article::where('status', 1)
  3085. ->where('id', $data['id'])
  3086. ->where(function ($query) use ($data) {
  3087. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3088. ->orWhereNull("ignore_ids");
  3089. })
  3090. ->first(['cat_arr_id']);
  3091. if (empty($article)) {
  3092. return Result::error("该文章不存在", 0);
  3093. }
  3094. // return Result::success($article);
  3095. break;
  3096. case 2:
  3097. // 商品
  3098. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3099. $article = Good::where('website_id', $data['website_id'])
  3100. ->where('status', 2)
  3101. ->where('id', $data['id'])
  3102. ->first(['cat_arr_id']);
  3103. if (empty($article)) {
  3104. return Result::error("该商品不存在", 0);
  3105. }
  3106. break;
  3107. case 3:
  3108. // 书刊信息
  3109. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3110. $article = Book::where('website_id', $data['website_id'])
  3111. ->where('status', 2)
  3112. ->where('id', $data['id'])
  3113. ->first(['id', 'cat_arr_id']);
  3114. if (empty($article)) {
  3115. return Result::error("该书刊不存在", 0);
  3116. }
  3117. break;
  3118. case 4:
  3119. // 招聘
  3120. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核;(只有企业会员需要审核)',
  3121. $article = JobRecruiting::where('website_id', $data['website_id'])
  3122. ->where('status', 1)
  3123. ->where('id', $data['id'])
  3124. ->first(['cat_arr_id']);
  3125. if (empty($article)) {
  3126. return Result::error("该招聘不存在", 0);
  3127. }
  3128. break;
  3129. case 5:
  3130. // 求职
  3131. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3132. $article = JobHunting::where('website_id', $data['website_id'])
  3133. ->where('status', 2)
  3134. ->where('id', $data['id'])
  3135. ->first(['cat_arr_id']);
  3136. if (empty($article)) {
  3137. return Result::error("该求职不存在", 0);
  3138. }
  3139. break;
  3140. case 6:
  3141. // 招工招聘
  3142. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3143. $article = JobRecruiting::where('website_id', $data['website_id'])
  3144. ->where('status', 1)
  3145. ->where('id', $data['id'])
  3146. ->first(['cat_arr_id']);
  3147. if (empty($article)) {
  3148. $article = JobHunting::where('website_id', $data['website_id'])
  3149. ->where('status', 2)
  3150. ->where('id', $data['id'])
  3151. ->first(['cat_arr_id']);
  3152. }
  3153. if (empty($article)) {
  3154. return Result::error("该招工招聘不存在", 0);
  3155. }
  3156. break;
  3157. default:
  3158. return Result::error("该数据不存在", 0);
  3159. break;
  3160. }
  3161. $catid = json_decode($article['cat_arr_id'], true);
  3162. if (empty($catid)) {
  3163. return Result::error("该数据不存在", 0);
  3164. }
  3165. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3166. ->orderByRaw('FIELD(category_id, ' . implode(',', $catid) . ')')
  3167. ->whereIn('category_id', $catid)
  3168. ->pluck('aLIas_pinyin')
  3169. ->implode('/');
  3170. }
  3171. if ($last_category['pid'] != 0) {
  3172. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3173. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3174. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr) . ')')
  3175. ->whereIn('category_id', $cat_arr)
  3176. ->pluck('aLIas_pinyin')
  3177. ->implode('/');
  3178. } else {
  3179. $pinyin = $last_category['aLIas_pinyin'];
  3180. }
  3181. if (empty($pinyin) || $pinyin != $data['all_route']) {
  3182. return Result::error('非法路径!');
  3183. } else {
  3184. return Result::success($pinyin);
  3185. }
  3186. }
  3187. /**
  3188. * 验证导航名称是否重复
  3189. * @return void
  3190. */
  3191. public function checkCategoryName(array $data): array
  3192. {
  3193. $result = Category::when($data, function ($query) use ($data) {
  3194. if (isset($data['name']) && $data['name']) {
  3195. $query->where("name", $data['name']);
  3196. }
  3197. if (isset($data['id']) && $data['id']) {
  3198. $query->where("id", "!=", $data['id']);
  3199. }
  3200. })->first();
  3201. if ($result) {
  3202. return Result::error("已存在");
  3203. } else {
  3204. return Result::success();
  3205. }
  3206. }
  3207. //20250226 产品列表
  3208. public function getGoodList(array $data): array
  3209. {
  3210. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3211. unset($data['type_id']);
  3212. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3213. $where = [];
  3214. if ($type_id != '10000') {
  3215. $where = [
  3216. 'good.user_id' => $user_id,
  3217. ];
  3218. }
  3219. //类型
  3220. if (isset($data['type_id']) && $data['type_id']) {
  3221. $where = [
  3222. 'type_id' => $data['type_id'],
  3223. ];
  3224. }
  3225. //名称
  3226. if (isset($data['name']) && $data['name']) {
  3227. $where = [
  3228. 'good.name' => $data['name'],
  3229. ];
  3230. }
  3231. //status
  3232. if (isset($data['status']) && $data['status'] != '') {
  3233. $where = [
  3234. 'good.status' => $data['status'],
  3235. ];
  3236. }
  3237. //status1
  3238. // if (isset($data['status1']) && $data['status1'] == 1) {
  3239. // $status1 = 1;
  3240. // }
  3241. $where1 = [];
  3242. //website_id
  3243. // if (isset($data['website_id']) && $data['website_id']) {
  3244. // $where1 = [
  3245. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3246. // ];
  3247. // }
  3248. // website_name
  3249. if (isset($data['website_name']) && $data['website_name']) {
  3250. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3251. }
  3252. // catid
  3253. if (isset($data['category_name']) && $data['category_name']) {
  3254. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3255. }
  3256. // $result = Good::where($where)
  3257. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3258. $result = Good::where($where)
  3259. ->when(!empty($where1), function ($query) use ($where1) {
  3260. return $query->where($where1);
  3261. })
  3262. //status 1待审核2已审核3已拒绝
  3263. ->when(isset($data['status1']), function ($query) {
  3264. return $query->whereIn('good.status', [1, 3]);
  3265. })
  3266. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3267. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3268. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3269. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3270. ->orderBy("updated_at", "desc")
  3271. ->limit($data['page_size'])
  3272. ->offset(($data['page'] - 1) * $data['page_size'])
  3273. ->get();
  3274. $count = Good::where($where)
  3275. ->when(!empty($where1), function ($query) use ($where1) {
  3276. return $query->where($where1);
  3277. })
  3278. //status 1待审核2已审核3已拒绝
  3279. ->when(isset($data['status1']), function ($query) {
  3280. return $query->whereIn('good.status', [1, 3]);
  3281. })
  3282. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3283. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3284. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3285. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3286. ->orderBy("updated_at", "desc")->count();
  3287. $data = [
  3288. 'rows' => $result->toArray(),
  3289. 'count' => $count,
  3290. ];
  3291. if (empty($result)) {
  3292. return Result::error("此栏目暂无相关产品", 0);
  3293. }
  3294. return Result::success($data);
  3295. }
  3296. public function getGoodInfo(array $data): array
  3297. {
  3298. $result = Good::where('id', $data['id'])->first();
  3299. if (empty($result)) {
  3300. return Result::error("此产品不存在", 0);
  3301. }
  3302. return Result::success($result);
  3303. }
  3304. public function addGood(array $data): array
  3305. {
  3306. // unset($data['city_arr_id']);
  3307. // unset($data['cat_arr_id']);
  3308. $data['city_id'] = end($data['city_arr_id']);
  3309. $data['catid'] = end($data['cat_arr_id']);
  3310. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3311. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3312. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3313. unset($data['imgUrl']);
  3314. if (isset($data['price']) && $data['price'] == '') {
  3315. $data['price'] = 0;
  3316. }
  3317. $result = Good::insert($data);
  3318. if (empty($result)) {
  3319. return Result::error("添加失败", 0);
  3320. }
  3321. return Result::success($result);
  3322. }
  3323. public function updateGood(array $data): array
  3324. {
  3325. $data['city_id'] = end($data['city_arr_id']);
  3326. $data['catid'] = end($data['cat_arr_id']);
  3327. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3328. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3329. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3330. //设置东八区
  3331. date_default_timezone_set('Asia/Shanghai');
  3332. $data['updated_at'] = date('Y-m-d H:i:s');
  3333. if (isset($data['price']) && $data['price'] == '') {
  3334. $data['price'] = 0;
  3335. }
  3336. $result = Good::where('id', $data['id'])->update($data);
  3337. if (empty($result)) {
  3338. return Result::error("更新失败", 0);
  3339. }
  3340. return Result::success($result);
  3341. }
  3342. public function delGood(array $data): array
  3343. {
  3344. $result = Good::where('id', $data['id'])->delete();
  3345. if (empty($result)) {
  3346. return Result::error("删除失败", 0);
  3347. }
  3348. return Result::success($result);
  3349. }
  3350. //20250226 产品列表
  3351. //20250306 求职信息
  3352. public function getJobHuntingList(array $data): array
  3353. {
  3354. $where = [];
  3355. if (isset($data['username']) && !empty($data['username'])) {
  3356. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3357. }
  3358. //status 1待审核2已审核3已拒绝
  3359. if (isset($data['status']) && $data['status'] != '') {
  3360. $where = [
  3361. 'job_hunting.status' => $data['status'],
  3362. ];
  3363. }
  3364. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3365. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3366. unset($data['type_id']);
  3367. if ($type_id != '10000') {
  3368. $where[] = ['job_hunting.user_id', '=', $user_id];
  3369. }
  3370. $result = JobHunting::where($where)
  3371. ->when(!empty($data['status1']), function ($query) use ($data) {
  3372. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3373. })
  3374. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3375. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3376. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3377. ->orderBy("updated_at", "desc")
  3378. ->limit($data['page_size'])
  3379. ->offset(($data['page'] - 1) * $data['page_size'])
  3380. ->get();
  3381. if (empty($result)) {
  3382. return Result::error("查询失败", 0);
  3383. }
  3384. $count = JobHunting::where($where)
  3385. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3386. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3387. ->count();
  3388. $data = [
  3389. 'rows' => $result->toArray(),
  3390. 'count' => $count,
  3391. ];
  3392. return Result::success($data);
  3393. }
  3394. public function getJobHuntingApply(array $data): array
  3395. {
  3396. var_dump($data, '-----------------test--------1-');
  3397. $where = [];
  3398. if (isset($data['username']) && !empty($data['username'])) {
  3399. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3400. }
  3401. if (isset($data['salary']) && !empty($data['salary'])) {
  3402. $where[] = [
  3403. 'job_hunting.salary',
  3404. '=',
  3405. $data['salary'],
  3406. ];
  3407. }
  3408. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3409. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3410. unset($data['type_id']);
  3411. if ($type_id != '10000') {
  3412. $where[] = ['job_apply.user_id', '=', $user_id];
  3413. }
  3414. var_dump($where, '-----------------test---------');
  3415. $result = jobApply::where($where)
  3416. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3417. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3418. // })
  3419. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3420. ->where('job_enum.egroup', '=', 'income')
  3421. ->where('job_hunting.status', 2) //已审核
  3422. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3423. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3424. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3425. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3426. //职位----是申请职位
  3427. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3428. ->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')
  3429. ->orderBy("job_hunting.updated_at", "desc")
  3430. ->limit($data['page_size'])
  3431. ->offset(($data['page'] - 1) * $data['page_size'])
  3432. ->get();
  3433. if (empty($result)) {
  3434. return Result::error("查询失败", 0);
  3435. }
  3436. $count = jobApply::where($where)
  3437. ->where('job_enum.egroup', '=', 'income')
  3438. ->where('job_hunting.status', 2) //已审核
  3439. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3440. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3441. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3442. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3443. //职位----是申请职位
  3444. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3445. ->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')
  3446. ->count();
  3447. $data = [
  3448. 'rows' => $result->toArray(),
  3449. 'count' => $count,
  3450. ];
  3451. return Result::success($data);
  3452. }
  3453. public function addJobHunting(array $data): array
  3454. {
  3455. date_default_timezone_set('Asia/Shanghai');
  3456. unset($data['company_name']);
  3457. unset($data['job_industry']);
  3458. unset($data['job_name']);
  3459. unset($data['department']);
  3460. unset($data['job_timeList']);
  3461. unset($data['job_content']);
  3462. $data['created_at'] = date('Y-m-d H:i:s');
  3463. $data['updated_at'] = date('Y-m-d H:i:s');
  3464. var_dump($data, '-----------------test---------');
  3465. $result = JobHunting::create($data);
  3466. if (empty($result)) {
  3467. return Result::error("添加失败", 0);
  3468. }
  3469. return Result::success($result);
  3470. }
  3471. public function delJobHunting(array $data): array
  3472. {
  3473. $result = JobHunting::where('id', $data['id'])->delete();
  3474. if (empty($result)) {
  3475. return Result::error("删除失败", 0);
  3476. }
  3477. return Result::success($result);
  3478. }
  3479. public function updateJobHunting(array $data): array
  3480. {
  3481. //设置东八区
  3482. date_default_timezone_set('Asia/Shanghai');
  3483. unset($data['company_name']);
  3484. unset($data['job_industry']);
  3485. unset($data['job_name']);
  3486. unset($data['department']);
  3487. unset($data['job_timeList']);
  3488. unset($data['job_content']);
  3489. unset($data['job_typename']); //不知道这是啥,
  3490. $data['created_at'] = date('Y-m-d H:i:s');
  3491. $data['updated_at'] = date('Y-m-d H:i:s');
  3492. $result = JobHunting::where('id', $data['id'])->update($data);
  3493. if (empty($result)) {
  3494. return Result::error("更新失败", 0);
  3495. }
  3496. return Result::success($result);
  3497. }
  3498. public function getJobHuntingInfo(array $data): array
  3499. {
  3500. $result = JobHunting::where('id', $data['id'])->first();
  3501. if (empty($result)) {
  3502. return Result::error("查询失败", 0);
  3503. }
  3504. return Result::success($result);
  3505. }
  3506. public function getJobHuntingData(array $data): array
  3507. {
  3508. $jobEnum = JobEnum::get();
  3509. $jobIndustry = JobIndustry::get();
  3510. $jobNature = JobNature::get();
  3511. $jobPosition = JobPosition::get();
  3512. $data = [
  3513. 'jobEnum' => $jobEnum,
  3514. 'jobIndustry' => $jobIndustry,
  3515. 'jobNature' => $jobNature,
  3516. 'jobPosition' => $jobPosition,
  3517. ];
  3518. return Result::success($data);
  3519. }
  3520. public function delJobHuntingInfo(array $data): array
  3521. {
  3522. $result = JobHunting::where('id', $data['id'])->delete();
  3523. return Result::success();
  3524. }
  3525. //20250324 通知,公告,消息
  3526. public function delNotice(array $data): array
  3527. {
  3528. $result = Notice::where('id', $data['id'])->delete();
  3529. if ($result) {
  3530. return Result::success();
  3531. } else {
  3532. return Result::error("删除失败", 0);
  3533. }
  3534. }
  3535. public function getNoticeInfo(array $data): array
  3536. {
  3537. $result = Notice::where('id', $data['id'])->first();
  3538. if (empty($result)) {
  3539. return Result::error("查询失败", 0);
  3540. }
  3541. return Result::success($result);
  3542. }
  3543. public function addNotice(array $data): array
  3544. {
  3545. date_default_timezone_set('Asia/Shanghai');
  3546. $data['created_at'] = date('Y-m-d H:i:s');
  3547. $data['updated_at'] = date('Y-m-d H:i:s');
  3548. $user_id = UserInfo::
  3549. //city_id不是null
  3550. whereNotNull('city_id')
  3551. ->whereNotNull('department_id')
  3552. ->where(function ($query) use ($data) {
  3553. $query->where(function ($subQuery) use ($data) {
  3554. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3555. });
  3556. })
  3557. ->where(function ($query) use ($data) {
  3558. $query->where(function ($subQuery) use ($data) {
  3559. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3560. });
  3561. })
  3562. ->pluck('user_id')->toArray();
  3563. $user_id = array_unique($user_id);
  3564. $chat_ids = $user_id;
  3565. $user_id = json_encode($user_id);
  3566. $data['re_user_ids'] = $user_id;
  3567. $result = Notice::insertGetId($data);
  3568. if ($result && $data['is_group'] == 1) {
  3569. //chat_group
  3570. $group_id = PublicData::uuid();
  3571. $groupData = [
  3572. 'id' => $group_id,
  3573. 'creator_id' => $data['user_id'],
  3574. 'group_name' => $data['group_name'] ?? '',
  3575. 'profile' => $data['profile'] ?? 0,
  3576. ];
  3577. var_dump($groupData, '-----------------groupData-------');
  3578. $groupResult = ChatGroups::insertGetId($groupData);
  3579. var_dump($groupResult, '-----------------groupid-------');
  3580. $groupMemberData = [
  3581. 'id' => PublicData::uuid(),
  3582. 'user_id' => $data['user_id'],
  3583. 'group_id' => $group_id,
  3584. 'leader' => 2,
  3585. ];
  3586. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  3587. //$chat_ids 去除掉$data['user_id']
  3588. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  3589. //插入群成员表
  3590. $groupMemberDataUser = [];
  3591. $chatData = [];
  3592. foreach ($chat_ids as $key => $value) {
  3593. $groupMemberDataUser[] = [
  3594. 'id' => PublicData::uuid(),
  3595. 'user_id' => $value,
  3596. 'group_id' => $group_id,
  3597. 'leader' => 1,
  3598. ];
  3599. $chatData[] = [
  3600. 'user_id' => $value,
  3601. 'msg_type' => 1,
  3602. 'receiver_id' => $group_id,
  3603. 'content' => '通过通知创建群聊',
  3604. 'group_receiver_id' => $data['user_id'],
  3605. 'action' => 'recieved',
  3606. 'created_at' => date('Y-m-d H:i:s'),
  3607. ];
  3608. }
  3609. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  3610. ChatGroupsMember::insert($groupMemberDataUser);
  3611. //插入一条管理员聊天记录
  3612. $chatData[] = [
  3613. 'user_id' => $data['user_id'],
  3614. 'msg_type' => 1,
  3615. 'receiver_id' => $group_id,
  3616. 'content' => '通过通知创建群聊',
  3617. 'group_receiver_id' => $data['user_id'],
  3618. 'action' => 'said',
  3619. 'created_at' => date('Y-m-d H:i:s'),
  3620. ];
  3621. var_dump($chatData, '-----------------chatData-------');
  3622. $chatResult = ChatRecords::insert($chatData);
  3623. //更新result的 group_id
  3624. $data['group_id'] = $group_id;
  3625. Notice::where(['id' => $result])->update($data);
  3626. }
  3627. if (empty($result)) {
  3628. return Result::error("添加失败", 0);
  3629. }
  3630. return Result::success($result);
  3631. }
  3632. public function updateNotice(array $data): array
  3633. {
  3634. date_default_timezone_set('Asia/Shanghai');
  3635. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  3636. $user_id = UserInfo::
  3637. //city_id不是null
  3638. whereNotNull('city_id')
  3639. ->whereNotNull('department_id')
  3640. ->where(function ($query) use ($data) {
  3641. $query->where(function ($subQuery) use ($data) {
  3642. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3643. });
  3644. })
  3645. ->where(function ($query) use ($data) {
  3646. $query->where(function ($subQuery) use ($data) {
  3647. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3648. });
  3649. })
  3650. ->pluck('user_id')->toArray();
  3651. $user_id = array_unique($user_id);
  3652. $user_id = json_encode($user_id);
  3653. $data['re_user_ids'] = $user_id;
  3654. $data['updated_at'] = date('Y-m-d H:i:s');
  3655. $result = Notice::where('id', $data['id'])->update($data);
  3656. return Result::success($result);
  3657. }
  3658. public function getNoticeList(array $data): array
  3659. {
  3660. $where = [];
  3661. //title
  3662. if (isset($data['title']) && !empty($data['title'])) {
  3663. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  3664. }
  3665. //level
  3666. if (isset($data['level']) && !empty($data['level'])) {
  3667. $where[] = ['notice.level', '=', $data['level']];
  3668. }
  3669. //status
  3670. if (isset($data['status']) && !empty($data['status'])) {
  3671. $where[] = ['notice.status', '=', $data['status']];
  3672. }
  3673. var_dump($data, '-----------------test---------');
  3674. if ($data['type_id'] == 10000) {
  3675. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3676. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3677. })
  3678. ->where($where)
  3679. ->orderBy('updated_at', 'desc')
  3680. ->limit($data['page_size'])
  3681. ->offset(($data['page'] - 1) * $data['page_size'])
  3682. ->get();
  3683. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3684. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3685. })
  3686. ->where($where)
  3687. ->orderBy('updated_at', 'desc')
  3688. ->count();
  3689. } else {
  3690. $result = Notice::where($where)
  3691. // ->where('user_id', $data['user_id'])
  3692. ->Where(function ($query) use ($data) {
  3693. $query->Where(function ($q) use ($data) {
  3694. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3695. ->orWhere('notice.user_id', $data['user_id']);
  3696. });
  3697. })
  3698. ->orderBy('updated_at', 'desc')
  3699. ->limit($data['page_size'])
  3700. ->offset(($data['page'] - 1) * $data['page_size'])
  3701. ->get();
  3702. $total = Notice::where($where)
  3703. // ->where('user_id', $data['user_id'])
  3704. ->Where(function ($query) use ($data) {
  3705. $query->Where(function ($q) use ($data) {
  3706. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3707. ->orWhere('notice.user_id', $data['user_id']);
  3708. });
  3709. })
  3710. ->count();
  3711. }
  3712. if (empty($result)) {
  3713. return Result::error("查询失败", 0);
  3714. }
  3715. $data = [
  3716. 'rows' => $result,
  3717. 'count' => $total,
  3718. ];
  3719. return Result::success($data);
  3720. }
  3721. public function getNoticeDetail(array $data): array
  3722. {
  3723. $result = Notice::where('id', $data['id'])->first();
  3724. if (empty($result)) {
  3725. return Result::error("查询失败", 0);
  3726. }
  3727. return Result::success($result);
  3728. }
  3729. public function deleteNotice(array $data): array
  3730. {
  3731. $notice = Notice::where('id', $data['id'])->first();
  3732. if (empty($notice)) {
  3733. return Result::error("删除失败", 0);
  3734. }
  3735. $chat_group_id = $notice->group_id;
  3736. if ($chat_group_id) {
  3737. //删除群聊
  3738. ChatGroups::where('id', $chat_group_id)->delete();
  3739. //删除群成员
  3740. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  3741. //删除群聊记录
  3742. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  3743. }
  3744. $result = Notice::where('id', $data['id'])->delete();
  3745. return Result::success($result);
  3746. }
  3747. public function getMSG(array $data): array
  3748. {
  3749. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  3750. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3751. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  3752. $result = [];
  3753. if ($type_id == 1) {
  3754. //最近的5篇已审的文章
  3755. $apply_articale = Article::where('status', 1)
  3756. ->where('admin_user_id', $user_id)
  3757. ->orderBy('updated_at', 'desc')
  3758. ->limit(5)->get();
  3759. //获取5条单聊未读聊天消息
  3760. $chat = ChatRecords::where('is_read', 0)
  3761. ->where('user_id', $user_id)
  3762. ->where('talk_type', 1)
  3763. ->orderBy('created_at', 'desc')
  3764. ->limit(5)->get();
  3765. //获取5条未读群聊信息
  3766. $chat_group = ChatRecords::where('is_read', 0)
  3767. ->where('user_id', $user_id)
  3768. ->where('talk_type', 2)
  3769. ->orderBy('created_at', 'desc')
  3770. ->limit(5)->get();
  3771. //获取5条用户的已审核商品
  3772. $good = Good::where('status', 2)
  3773. ->where('user_id', $user_id)
  3774. ->orderBy('updated_at', 'desc')
  3775. ->limit(5)->get();
  3776. //获取5条用户待审核的公告
  3777. $notice = Notice::where('status', 2)
  3778. ->where('user_id', $user_id)
  3779. ->orderBy('updated_at', 'desc')
  3780. ->limit(5)->get();
  3781. //获取5条用户的待审核投诉
  3782. $complaint = Complaint::where('status', 2)
  3783. ->where('user_id', $user_id)
  3784. ->orderBy('updated_at', 'desc')
  3785. ->limit(5)->get();
  3786. //获取5条用户的book
  3787. $book = Book::where('status', 2)
  3788. ->where('user_id', $user_id)
  3789. ->orderBy('updated_at', 'desc')
  3790. ->limit(5)->get();
  3791. //获取5条用户的求职
  3792. //获取5条用户的求职 1
  3793. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3794. ->where('job_hunting.user_id', $user_id)
  3795. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3796. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3797. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3798. ->orderBy('updated_at', 'desc')
  3799. ->limit(5)->get();
  3800. //获取5条用户的求职 2
  3801. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3802. ->where('job_recruiting.user_id', $user_id)
  3803. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3804. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3805. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3806. ->orderBy('updated_at', 'desc')
  3807. ->limit(5)->get();
  3808. //人才库 1
  3809. $job_apply = JobApply::where('job_apply.status', 1)
  3810. ->where('job_apply.receiver_id', $user_id)
  3811. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3812. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3813. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3814. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3815. ->select('job_recruiting', 'job_recruiting.', '', '')
  3816. ->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')
  3817. ->orderBy('updated_at', 'desc')
  3818. ->limit(5)->get();
  3819. // 职场机会 2
  3820. $job_resume = JobResume::where('job_resume.status', 1)
  3821. ->where('job_resume.receiver_id', $user_id)
  3822. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3823. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3824. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3825. ->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')
  3826. ->orderBy('updated_at', 'desc')
  3827. ->limit(5)->get();
  3828. $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);
  3829. $result = [
  3830. 'apply_articale' => $apply_articale,
  3831. 'chat' => $chat,
  3832. 'chat_group' => $chat_group,
  3833. 'good' => $good,
  3834. 'notice' => $notice,
  3835. 'complaint' => $complaint,
  3836. 'book' => $book,
  3837. 'job_hunting' => $job_hunting,
  3838. 'job_recruiting' => $job_recruiting,
  3839. 'job_apply' => $job_apply,
  3840. 'job_resume' => $job_resume,
  3841. 'count' => $count,
  3842. ];
  3843. } elseif ($type_id == 2) {
  3844. //最近的5篇已审的文章
  3845. $apply_articale = Article::where('status', 1)
  3846. ->where('admin_user_id', $user_id)
  3847. ->limit(5)->get();
  3848. //获取5条单聊未读聊天消息
  3849. $chat = ChatRecords::where('is_read', 0)
  3850. ->where('user_id', $user_id)
  3851. ->where('talk_type', 1)
  3852. ->orderBy('created_at', 'desc')
  3853. ->limit(5)->get();
  3854. //获取5条未读群聊信息
  3855. $chat_group = ChatRecords::where('is_read', 0)
  3856. ->where('user_id', $user_id)
  3857. ->where('talk_type', 2)
  3858. ->orderBy('created_at', 'desc')
  3859. ->limit(5)->get();
  3860. //获取5条用户的已审核商品
  3861. $good = Good::where('status', 2)
  3862. ->where('user_id', $user_id)
  3863. ->orderBy('updated_at', 'desc')
  3864. ->limit(5)->get();
  3865. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  3866. $result = [
  3867. 'apply_articale' => $apply_articale,
  3868. 'chat' => $chat,
  3869. 'chat_group' => $chat_group,
  3870. 'good' => $good,
  3871. 'count' => $count,
  3872. ];
  3873. } elseif ($type_id == 3) {
  3874. //最近的5篇已审的文章
  3875. $apply_articale = Article::where('status', 1)
  3876. ->where('admin_user_id', $user_id)
  3877. ->limit(5)->get();
  3878. //获取5条单聊未读聊天消息
  3879. $chat = ChatRecords::where('is_read', 0)
  3880. ->where('user_id', $user_id)
  3881. ->where('talk_type', 1)
  3882. ->orderBy('created_at', 'desc')
  3883. ->limit(5)->get();
  3884. //获取5条未读群聊信息
  3885. $chat_group = ChatRecords::where('is_read', 0)
  3886. ->where('user_id', $user_id)
  3887. ->where('talk_type', 2)
  3888. ->orderBy('created_at', 'desc')
  3889. ->limit(5)->get();
  3890. //获取5条用户的已审核商品
  3891. $good = Good::where('status', 2)
  3892. ->where('user_id', $user_id)
  3893. ->orderBy('updated_at', 'desc')
  3894. ->limit(5)->get();
  3895. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  3896. $result = [
  3897. 'apply_articale' => $apply_articale,
  3898. 'chat' => $chat,
  3899. 'chat_group' => $chat_group,
  3900. 'good' => $good,
  3901. 'count' => $count,
  3902. ];
  3903. } elseif ($type_id == 4) {
  3904. //最近的5篇已审的文章
  3905. $apply_articale = Article::where('status', 1)
  3906. ->where('admin_user_id', $user_id)
  3907. ->limit(5)->get();
  3908. //获取5条用户的已审核商品
  3909. $good = Good::where('status', 2)
  3910. ->where('user_id', $user_id)
  3911. ->orderBy('updated_at', 'desc')
  3912. ->limit(5)->get();
  3913. $count = count($apply_articale) + count($good);
  3914. $result = [
  3915. 'apply_articale' => $apply_articale,
  3916. 'chat' => '',
  3917. 'chat_group' => '',
  3918. 'good' => $good,
  3919. 'count' => $count,
  3920. ];
  3921. } elseif ($type_id == 10000) {
  3922. //获取未审核的5篇文章
  3923. $apply_articale = Article::where('status', 0)
  3924. ->orderBy('updated_at', 'desc')
  3925. ->limit(5)->get();
  3926. //获取5条单聊未读聊天消息
  3927. $chat = ChatRecords::where('is_read', 0)
  3928. ->where('user_id', $user_id)
  3929. ->where('talk_type', 1)
  3930. ->orderBy('created_at', 'desc')
  3931. ->limit(5)->get();
  3932. //获取5条未读群聊信息
  3933. $chat_group = ChatRecords::where('is_read', 0)
  3934. ->where('user_id', $user_id)
  3935. ->where('talk_type', 2)
  3936. ->orderBy('created_at', 'desc')
  3937. ->limit(5)->get();
  3938. //获取5条用户的已审核商品
  3939. $good = Good::where('status', 1)
  3940. // ->where('user_id', $user_id)
  3941. ->orderBy('updated_at', 'desc')
  3942. ->limit(5)->get();
  3943. //获取5条用户待审核的公告
  3944. $notice = Notice::where('status', 1)
  3945. ->orderBy('updated_at', 'desc')
  3946. ->limit(5)->get();
  3947. //获取5条用户的待审核投诉
  3948. $complaint = Complaint::where('status', 1)
  3949. ->orderBy('updated_at', 'desc')
  3950. ->limit(5)->get();
  3951. //获取5条用户的book
  3952. $book = Book::where('status', 1)
  3953. ->orderBy('updated_at', 'desc')
  3954. ->limit(5)->get();
  3955. //获取5条用户的求职 1
  3956. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3957. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3958. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3959. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3960. ->orderBy('updated_at', 'desc')
  3961. ->limit(5)->get();
  3962. //获取5条用户的求职 2
  3963. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3964. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3965. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3966. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3967. ->orderBy('updated_at', 'desc')
  3968. ->limit(5)->get();
  3969. //人才库 1
  3970. $job_apply = JobApply::where('job_apply.status', 1)
  3971. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3972. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3973. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3974. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3975. ->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')
  3976. ->orderBy('updated_at', 'desc')
  3977. ->limit(5)->get();
  3978. // 职场机会 2
  3979. $job_resume = JobResume::where('job_resume.status', 1)
  3980. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3981. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3982. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3983. ->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')
  3984. ->orderBy('updated_at', 'desc')
  3985. ->limit(5)->get();
  3986. $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);
  3987. $result = [
  3988. 'apply_articale' => $apply_articale,
  3989. 'chat' => $chat,
  3990. 'chat_group' => $chat_group,
  3991. 'good' => $good,
  3992. 'notice' => $notice,
  3993. 'complaint' => $complaint,
  3994. 'book' => $book,
  3995. 'job_hunting' => $job_hunting,
  3996. 'job_recruiting' => $job_recruiting,
  3997. 'job_apply' => $job_apply,
  3998. 'job_resume' => $job_resume,
  3999. 'count' => $count,
  4000. ];
  4001. } elseif ($type_id == 20000) {
  4002. }
  4003. var_dump($type_id, '-----------------test---------');
  4004. return Result::success($result);
  4005. }
  4006. public function getComplaintList(array $data): array
  4007. {
  4008. var_dump($data, '00000001000000000000');
  4009. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4010. unset($data['type_id']);
  4011. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4012. $where = [];
  4013. if ($type_id != 10000 && empty($data['deal_user'])) {
  4014. $where['complaint.user_id'] = $user_id;
  4015. }
  4016. if (!empty($data['title'])) {
  4017. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4018. }
  4019. if (!empty($data['department_id'])) {
  4020. $where['complaint.department_id'] = $data['department_id'];
  4021. }
  4022. if (!empty($data['deal'])) {
  4023. $where['complaint.deal'] = $data['deal'];
  4024. }
  4025. if (!empty($data['status'])) {
  4026. $where['complaint.status'] = $data['status'];
  4027. }
  4028. var_dump(!empty($data['deal_user']), '----------1');
  4029. $result = Complaint::where($where)
  4030. ->when(!empty($data['status1']), function ($query) use ($data) {
  4031. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4032. })
  4033. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4034. //json re_user_ids data[user_id]是不是在里面
  4035. $query->Where(function ($q) use ($data) {
  4036. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4037. ->where('complaint.status', 2);
  4038. });
  4039. })
  4040. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4041. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4042. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4043. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4044. ->orderBy('updated_at', 'desc')
  4045. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4046. //sql输出
  4047. if (empty($result)) {
  4048. return Result::error("暂无投诉信息", 0);
  4049. }
  4050. // 取出数据
  4051. $rows = $result->items();
  4052. $count = $result->total();
  4053. $responseData = [
  4054. 'rows' => $rows,
  4055. 'count' => $count,
  4056. ];
  4057. return Result::success($responseData);
  4058. }
  4059. public function getComplaintInfo(array $data): array
  4060. {
  4061. $result = Complaint::where('id', $data['id'])->first();
  4062. if (empty($result)) {
  4063. return Result::error("查询失败", 0);
  4064. }
  4065. return Result::success($result);
  4066. }
  4067. public function addComplaint(array $data): array
  4068. {
  4069. date_default_timezone_set('Asia/Shanghai');
  4070. $data['created_at'] = date('Y-m-d H:i:s');
  4071. $data['updated_at'] = date('Y-m-d H:i:s');
  4072. $result = Complaint::create($data);
  4073. return Result::success($result);
  4074. }
  4075. public function updateComplaint(array $data): array
  4076. {
  4077. date_default_timezone_set('Asia/Shanghai');
  4078. $data['updated_at'] = date('Y-m-d H:i:s');
  4079. $user_id = $data['user_id'] ?? 0;
  4080. $type_id = $data['type_id'] ?? 0;
  4081. unset($data['user_id']);
  4082. unset($data['type_id']);
  4083. $result = Complaint::where('id', $data['id'])->update($data);
  4084. return Result::success($result);
  4085. }
  4086. public function deleteComplaint(array $data): array
  4087. {
  4088. $result = Complaint::where('id', $data['id'])->delete();
  4089. return Result::success($result);
  4090. }
  4091. public function getComplainInfo(array $data): array
  4092. {
  4093. $result = Complaint::where('id', $data['id'])->first();
  4094. if (empty($result)) {
  4095. return Result::error("查询失败", 0);
  4096. }
  4097. return Result::success($result);
  4098. }
  4099. public function updateComplaintStatus(array $data): array
  4100. {
  4101. date_default_timezone_set('Asia/Shanghai');
  4102. $data['updated_at'] = date('Y-m-d H:i:s');
  4103. $user_id = $data['user_id'] ?? 0;
  4104. $type_id = $data['type_id'] ?? 0;
  4105. unset($data['user_id']);
  4106. unset($data['type_id']);
  4107. //处理, 写入处理人
  4108. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4109. $data['real_deal_user'] = $user_id;
  4110. }
  4111. //如果是deal 23,则判断是不是处理人
  4112. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4113. $complaintInof = Complaint::where('id', $data['id'])
  4114. ->where('real_deal_user', $user_id)
  4115. ->first();
  4116. if (empty($complaintInof)) {
  4117. return Result::error("处理人错误", 0);
  4118. }
  4119. }
  4120. $result = complaint::where('id', $data['id'])->update($data);
  4121. return Result::success($result);
  4122. }
  4123. public function updateGoodStatus(array $data): array
  4124. {
  4125. $user_id = $data['user_id'] ?? 0;
  4126. $type_id = $data['type_id'] ?? 0;
  4127. unset($data['user_id']);
  4128. unset($data['type_id']);
  4129. $result = Good::where('id', $data['id'])->update($data);
  4130. return Result::success($result);
  4131. }
  4132. public function updateJobHuntingStatus(array $data): array
  4133. {
  4134. $user_id = $data['user_id'] ?? 0;
  4135. $type_id = $data['type_id'] ?? 0;
  4136. unset($data['user_id']);
  4137. unset($data['type_id']);
  4138. $result = JobHunting::where('id', $data['id'])->update($data);
  4139. return Result::success($result);
  4140. }
  4141. public function updateNoticeStatus(array $data): array
  4142. {
  4143. $user_id = $data['user_id'] ?? 0;
  4144. $type_id = $data['type_id'] ?? 0;
  4145. unset($data['user_id']);
  4146. unset($data['type_id']);
  4147. $result = Notice::where('id', $data['id'])->update($data);
  4148. return Result::success($result);
  4149. }
  4150. public function getDUser(array $data): array
  4151. {
  4152. if (!empty($data['ids'])) {
  4153. $user = User::whereIn('id', $data['ids'])->getall();
  4154. if (empty($user)) {
  4155. return Result::error('无数据', 0);
  4156. }
  4157. return Result::success($user);
  4158. }
  4159. $where = [];
  4160. if (!empty($data['department_id'])) {
  4161. $where['department_id'] = $data['department_id'];
  4162. }
  4163. if (!empty($data['city_id'])) {
  4164. $where['city_id'] = $data['city_id'];
  4165. }
  4166. $result = User::where('type_id', 2)
  4167. ->where('status', 1)
  4168. ->where($where)
  4169. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4170. ->get();
  4171. if (empty($result)) {
  4172. return Result::error("查询失败", 0);
  4173. }
  4174. return Result::success($result);
  4175. }
  4176. //20250324 通知,公告,消息
  4177. // 20250306 -------招聘--------fr
  4178. /*
  4179. * 招聘列表
  4180. * */
  4181. public function getJobRecruitingList(array $data): array
  4182. {
  4183. $where = [];
  4184. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4185. if ($data['checkout'] == 0) {
  4186. $job_status = [0, 2];
  4187. } else {
  4188. $job_status = [1];
  4189. }
  4190. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4191. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4192. }
  4193. $user = User::where('id', $data['user_id'])->first();
  4194. if (empty($user)) {
  4195. return Result::error("用户不存在", 0);
  4196. }
  4197. // 3:企业会员
  4198. if ($user['type_id'] == 3) {
  4199. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4200. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4201. }
  4202. // 如果 $where 为空,则不添加 where 条件
  4203. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4204. return $query->where($where);
  4205. })
  4206. ->whereIn('job_recruiting.status', $job_status)
  4207. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4208. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4209. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4210. ->orderBy("updated_at", "desc")
  4211. ->offset(($data['page'] - 1) * $data['page_size'])
  4212. ->limit($data['page_size'])
  4213. ->get()
  4214. ->all();
  4215. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4216. return $query->where($where);
  4217. })
  4218. ->whereIn('job_recruiting.status', $job_status)
  4219. ->count();
  4220. if (empty($result)) {
  4221. return Result::error("暂无招聘信息", 0);
  4222. }
  4223. return Result::success($result);
  4224. }
  4225. /*
  4226. * 招聘信息添加
  4227. * */
  4228. public function addJobRecruiting(array $data): array
  4229. {
  4230. // return Result::success($data);
  4231. $user = User::where('user.id', $data['user_id'])
  4232. ->where('user.status', 1)
  4233. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4234. ->select(
  4235. 'user.type_id',
  4236. 'user.mobile',
  4237. 'user.email',
  4238. 'user_info.business_name',
  4239. 'user_info.company_hy_id',
  4240. 'user_info.company_nature',
  4241. 'user_info.company_size',
  4242. 'user_info.introduction',
  4243. 'user_info.real_name',
  4244. 'user_info.company_url',
  4245. 'user_info.address_arr_id',
  4246. 'user_info.address'
  4247. )
  4248. ->first();
  4249. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4250. return Result::error("用户不存在", 0);
  4251. }
  4252. $web = Website::where('id', $data['website_id'])->first();
  4253. if (empty($web)) {
  4254. return Result::error("网站不存在", 0);
  4255. }
  4256. // return Result::success($user);
  4257. $data['action_id'] = $data['user_id'];
  4258. $data['user_type'] = $user['type_id'];
  4259. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4260. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4261. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4262. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4263. // 公司地址 管理员必填
  4264. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4265. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4266. // 管理员-企业相关信息
  4267. $company = [
  4268. // 'user_id' => $data['user_id']?? null,
  4269. 'business_name' => $data['business_name'] ?? null,
  4270. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4271. 'company_size' => $data['company_size'] ?? null,
  4272. 'company_nature' => $data['company_nature'] ?? null,
  4273. 'introduction' => $data['introduction'] ?? null,
  4274. 'real_name' => $data['real_name'] ?? null,
  4275. 'mobile' => $data['mobile'] ?? null,
  4276. 'company_url' => $data['company_url'] ?? null,
  4277. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4278. 'address' => $data['address'] ?? null,
  4279. 'email' => $data['email'] ?? null,
  4280. ];
  4281. //去掉相关企业信息
  4282. $job = array_diff_key($data, array_flip(array_keys($company)));
  4283. Db::beginTransaction();
  4284. try {
  4285. // 先添加职位相关信息
  4286. if ($user['type_id'] == 10000) {
  4287. $job['status'] = 1;
  4288. }
  4289. $jobId = JobRecruiting::insertGetId($job);
  4290. if (empty($jobId)) {
  4291. Db::rollBack();
  4292. return Result::error("添加失败");
  4293. }
  4294. // 添加公司信息
  4295. $company['user_id'] = $data['user_id'] ?? null;
  4296. $company['job_id'] = $jobId;
  4297. $company['user_type'] = $user['type_id'] ?? null;
  4298. $company['website_id'] = $data['website_id'] ?? null;
  4299. if ($user['type_id'] == 10000) {
  4300. // 管理员添加企业信息
  4301. // return Result::success($company);
  4302. $companyId = JobCompany::insertGetId($company);
  4303. if (empty($companyId)) {
  4304. Db::rollBack();
  4305. return Result::error("添加失败");
  4306. }
  4307. } else {
  4308. // 企业会员添加企业信息
  4309. $company = [
  4310. 'user_id' => $data['user_id'] ?? null,
  4311. 'business_name' => $user['business_name'] ?? null,
  4312. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4313. 'company_size' => $user['company_size'] ?? null,
  4314. 'company_nature' => $user['company_nature'] ?? null,
  4315. 'introduction' => $user['introduction'] ?? null,
  4316. 'real_name' => $user['real_name'] ?? null,
  4317. 'mobile' => $user['mobile'] ?? null,
  4318. 'company_url' => $user['company_url'] ?? null,
  4319. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4320. 'address' => $user['address'] ?? null,
  4321. 'email' => $user['email'] ?? null,
  4322. 'website_id' => $data['website_id'] ?? null,
  4323. 'user_type' => $user['type_id'] ?? null,
  4324. 'job_id' => $jobId,
  4325. ];
  4326. $companyId = JobCompany::insertGetId($company);
  4327. if (empty($companyId)) {
  4328. Db::rollBack();
  4329. return Result::error("添加失败");
  4330. }
  4331. // return Result::success($company);
  4332. }
  4333. Db::commit();
  4334. } catch (\Exception $e) {
  4335. Db::rollBack();
  4336. return Result::error($e->getMessage(), 0);
  4337. }
  4338. $result = [
  4339. 'job_id' => $jobId,
  4340. 'company_id' => $companyId,
  4341. ];
  4342. if (empty($result)) {
  4343. return Result::error("添加失败", 0);
  4344. }
  4345. return Result::success($result);
  4346. }
  4347. /*
  4348. * 获取招聘信息详情
  4349. * */
  4350. public function getJobRecruitingInfo(array $data): array
  4351. {
  4352. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4353. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4354. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4355. ->select(
  4356. 'job_recruiting.*',
  4357. 'website.website_name as website_name',
  4358. 'job_company.business_name',
  4359. 'job_company.company_hy_id',
  4360. 'job_company.company_size',
  4361. 'job_company.company_nature',
  4362. 'job_company.introduction',
  4363. 'job_company.real_name',
  4364. 'job_company.mobile',
  4365. 'job_company.company_url',
  4366. 'job_company.address_arr_id',
  4367. 'job_company.address',
  4368. 'job_company.email'
  4369. )
  4370. ->first();
  4371. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4372. if (!empty($cityId)) {
  4373. if (isset($cityId[1]) && $cityId[1] != null) {
  4374. $city = District::where('id', $cityId[1])->first(['name']);
  4375. } else {
  4376. $city = District::where('id', $cityId[0])->first(['name']);
  4377. }
  4378. $result['city'] = $city['name'] ?? '';
  4379. }
  4380. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4381. if (is_array($addressId) && !empty($addressId)) {
  4382. $address = District::whereIn('id', $addressId)
  4383. ->orderBy('level', 'asc')
  4384. ->get(['name'])
  4385. ->pluck('name')
  4386. ->implode('');
  4387. // $job->address_name = $address ?? '';
  4388. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4389. }
  4390. if (empty($result)) {
  4391. return Result::error("招聘信息不存在", 0);
  4392. }
  4393. // return Result::success($job);
  4394. return Result::success($result);
  4395. }
  4396. /*
  4397. * 修改招聘信息
  4398. * */
  4399. public function upJobRecruiting(array $data): array
  4400. {
  4401. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4402. // return Result::success($job);
  4403. if (empty($job)) {
  4404. return Result::error("招聘信息不存在", 0);
  4405. }
  4406. $user = User::where('id', $data['user_id'])->first();
  4407. // return Result::success($user);
  4408. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4409. return Result::error("用户不存在", 0);
  4410. }
  4411. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4412. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4413. }
  4414. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4415. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4416. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4417. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4418. // 公司地址 管理员必填
  4419. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4420. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4421. // 管理员-企业相关信息
  4422. $company = [
  4423. 'business_name' => $data['business_name'] ?? null,
  4424. 'company_hy_id' => $data['hy_id'] ?? null,
  4425. 'company_size' => $data['company_size'] ?? null,
  4426. 'company_nature' => $data['company_nature'] ?? null,
  4427. 'introduction' => $data['introduction'] ?? null,
  4428. 'real_name' => $data['real_name'] ?? null,
  4429. 'mobile' => $data['mobile'] ?? null,
  4430. 'company_url' => $data['company_url'] ?? null,
  4431. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4432. 'address' => $data['address'] ?? null,
  4433. 'email' => $data['email'] ?? null,
  4434. ];
  4435. //去掉相关企业信息
  4436. $data = array_diff_key($data, array_flip(array_keys($company)));
  4437. $jobId = $data['id'];
  4438. $web = $data['website_id'];
  4439. $data['action_id'] = $data['user_id'];
  4440. unset($data['user_id']);
  4441. unset($data['user_type']);
  4442. unset($data['id']);
  4443. unset($data['website_id']);
  4444. // return Result::success($data);
  4445. Db::beginTransaction();
  4446. try {
  4447. // 管理员修改招聘信息
  4448. if ($user['type_id'] == 10000) {
  4449. $data['website_id'] = $web;
  4450. $company['website_id'] = $data['website_id'];
  4451. $data['status'] = 1;
  4452. } else {
  4453. $data['status'] = 0;
  4454. }
  4455. // Db::rollBack();
  4456. // return Result::success($company);
  4457. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4458. if (empty($result['job'])) {
  4459. Db::rollBack();
  4460. return Result::error("修改招聘信息失败");
  4461. }
  4462. // 管理员修改企业相关信息
  4463. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4464. if (empty($result['company'])) {
  4465. Db::rollBack();
  4466. return Result::error("修改企业相关信息失败");
  4467. }
  4468. Db::commit();
  4469. // return Result::success($result);
  4470. } catch (\Exception $e) {
  4471. Db::rollBack();
  4472. return Result::error($e->getMessage(), 0);
  4473. }
  4474. return Result::success($result);
  4475. }
  4476. /*
  4477. * 招聘信息删除
  4478. * */
  4479. public function delJobRecruiting(array $data): array
  4480. {
  4481. $user = User::where('id', $data['user_id'])->first();
  4482. if (empty($user)) {
  4483. return Result::error("用户不存在", 0);
  4484. }
  4485. $job = JobRecruiting::where('id', $data['id'])->first();
  4486. if (empty($job)) {
  4487. return Result::error("招聘信息不存在", 0);
  4488. }
  4489. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4490. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4491. }
  4492. Db::beginTransaction();
  4493. try {
  4494. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4495. if (empty($result['job'])) {
  4496. Db::rollBack();
  4497. return Result::error("删除招聘信息失败");
  4498. }
  4499. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4500. if (empty($result['company'])) {
  4501. Db::rollBack();
  4502. return Result::error("删除企业相关信息失败");
  4503. }
  4504. Db::commit();
  4505. } catch (\Exception $e) {
  4506. Db::rollBack();
  4507. return Result::error($e->getMessage(), 0);
  4508. }
  4509. return Result::success($result);
  4510. }
  4511. /*
  4512. * 获取公司信息
  4513. * */
  4514. public function getJobCompany(array $data): array
  4515. {
  4516. $user = User::where('user.id', $data['user_id'])
  4517. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4518. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4519. ->first();
  4520. // return Result::success($user);
  4521. if (empty($user)) {
  4522. return Result::error("用户不存在", 0);
  4523. }
  4524. if ($user['type_id'] == 3) {
  4525. $result = [
  4526. // 'id' => 0,
  4527. 'user_id' => $data['user_id'],
  4528. 'website_id' => $data['website_id'],
  4529. 'business_name' => $user['business_name'], // 企业名称
  4530. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4531. 'company_nature' => $user['company_nature'], // 公司性质
  4532. 'company_size' => $user['company_size'], // 公司规模
  4533. 'introduction' => $user['introduction'], // 公司简介
  4534. 'real_name' => $user['real_name'], // 企业联系人
  4535. 'mobile' => $user['mobile'], // 企业联系电话
  4536. 'company_url' => $user['company_url'], // 企业网址
  4537. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4538. 'address' => $user['address'], // 企业地址
  4539. 'email' => $user['email'], // 企业邮箱
  4540. ];
  4541. } else {
  4542. return Result::error("用户类型错误", 0);
  4543. }
  4544. if (empty($result)) {
  4545. return Result::error("公司信息不存在", 0);
  4546. }
  4547. return Result::success($result);
  4548. }
  4549. /*
  4550. * 修改公司信息
  4551. * */
  4552. public function upJobCompany(array $data): array
  4553. {
  4554. // return Result::success($data);
  4555. $user = User::where('user.id', $data['user_id'])
  4556. ->where('user.status', 1)
  4557. ->select('user.user_name', 'user.type_id')
  4558. ->first();
  4559. if (empty($user)) {
  4560. return Result::error("用户不存在", 0);
  4561. }
  4562. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4563. $company = [
  4564. 'business_name' => $data['business_name'], // 企业名称
  4565. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4566. 'company_nature' => $data['company_nature'], // 公司性质
  4567. 'company_size' => $data['company_size'], // 公司规模
  4568. 'introduction' => $data['introduction'], // 公司简介
  4569. // 'real_name' => $data['real_name'], // 企业联系人
  4570. 'company_url' => $data['company_url'], // 企业网址
  4571. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4572. 'address' => $data['address'], // 企业详细地址
  4573. ];
  4574. if ($user['type_id'] == 3) {
  4575. Db::beginTransaction();
  4576. try {
  4577. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  4578. 'business_name' => $data['business_name'], // 企业名称
  4579. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4580. 'company_nature' => $data['company_nature'], // 公司性质
  4581. 'company_size' => $data['company_size'], // 公司规模
  4582. 'introduction' => $data['introduction'], // 公司简介
  4583. // 'real_name' => $data['real_name'], // 企业联系人
  4584. 'company_url' => $data['company_url'], // 企业网址
  4585. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4586. 'address' => $data['address'], // 企业详细地址
  4587. ]);
  4588. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  4589. Db::commit();
  4590. } catch (\Exception $e) {
  4591. Db::rollBack();
  4592. return Result::error($e->getMessage(), 0);
  4593. }
  4594. } else {
  4595. return Result::error("用户类型错误", 0);
  4596. }
  4597. if (empty($result)) {
  4598. return Result::error("修改失败", 0);
  4599. }
  4600. return Result::success($result);
  4601. }
  4602. /*
  4603. * 获取省-市
  4604. * */
  4605. public function getJobRecruitingArea(array $data): array
  4606. {
  4607. if (isset($data['pid']) && $data['pid'] != null) {
  4608. $result = District::where('pid', $data['pid'])->get()->all();
  4609. } else {
  4610. $result = District::where('level', 1)->get()->all();
  4611. }
  4612. if (empty($result)) {
  4613. return Result::error("暂无此省市", 0);
  4614. }
  4615. return Result::success($result);
  4616. }
  4617. /*
  4618. * 获取行业分类
  4619. * */
  4620. public function getIndustry(array $data): array
  4621. {
  4622. $result = JobIndustry::get()->all();
  4623. if (empty($result)) {
  4624. return Result::error("暂无行业分类", 0);
  4625. }
  4626. return Result::success($result);
  4627. }
  4628. /*
  4629. * 获取职位
  4630. * */
  4631. public function getPositionList(array $data): array
  4632. {
  4633. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  4634. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  4635. } else {
  4636. $result = JobPosition::where('zwpid', 0)->get()->all();
  4637. }
  4638. if (empty($result)) {
  4639. return Result::error("暂无此职位", 0);
  4640. }
  4641. return Result::success($result);
  4642. }
  4643. /*
  4644. * 获取工作性质-菜单
  4645. * */
  4646. public function getJobNature(array $data): array
  4647. {
  4648. $result = JobEnum::where('egroup', 'nature')->get()->all();
  4649. if (empty($result)) {
  4650. return Result::error("暂无工作性质", 0);
  4651. }
  4652. return Result::success($result);
  4653. }
  4654. /*
  4655. * 获取工作经验-菜单
  4656. * */
  4657. public function getExperience(array $data): array
  4658. {
  4659. $result = JobEnum::where('egroup', 'years')->get()->all();
  4660. if (empty($result)) {
  4661. return Result::error("暂无工作经验", 0);
  4662. }
  4663. return Result::success($result);
  4664. }
  4665. /*
  4666. * 获取学历-菜单
  4667. * */
  4668. public function getEducation(array $data): array
  4669. {
  4670. $result = JobEnum::where('egroup', 'education')->get()->all();
  4671. if (empty($result)) {
  4672. return Result::error("暂无学历", 0);
  4673. }
  4674. return Result::success($result);
  4675. }
  4676. /*
  4677. * 获取薪资-菜单
  4678. * */
  4679. public function getSalary(array $data): array
  4680. {
  4681. $result = JobEnum::where('egroup', 'income')->get()->all();
  4682. if (empty($result)) {
  4683. return Result::error("暂无薪资", 0);
  4684. }
  4685. return Result::success($result);
  4686. }
  4687. /*
  4688. * 获取语言-菜单
  4689. * */
  4690. public function getLanguage(array $data): array
  4691. {
  4692. $result = JobEnum::where('egroup', 'language')->get()->all();
  4693. if (empty($result)) {
  4694. return Result::error("暂无语言", 0);
  4695. }
  4696. return Result::success($result);
  4697. }
  4698. /*
  4699. * 获取掌握程度-菜单
  4700. * */
  4701. public function getLevel(array $data): array
  4702. {
  4703. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  4704. if (empty($result)) {
  4705. return Result::error("暂无工作性质", 0);
  4706. }
  4707. return Result::success($result);
  4708. }
  4709. // 公司信息
  4710. /*
  4711. * 获取公司性质-菜单
  4712. * */
  4713. public function getCompanyNature(array $data): array
  4714. {
  4715. $result = JobNature::get()->all();
  4716. if (empty($result)) {
  4717. return Result::error("暂无公司性质", 0);
  4718. }
  4719. return Result::success($result);
  4720. }
  4721. /*
  4722. * 获取公司规模-菜单
  4723. * */
  4724. public function getCompanySize(array $data): array
  4725. {
  4726. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  4727. if (empty($result)) {
  4728. return Result::error("暂无公司规模", 0);
  4729. }
  4730. return Result::success($result);
  4731. }
  4732. /*
  4733. * 招聘信息审核
  4734. * */
  4735. public function checkJobRecruiting(array $data): array
  4736. {
  4737. $user = User::where('id', $data['user_id'])->first();
  4738. if (empty($user)) {
  4739. return Result::error("用户不存在", 0);
  4740. }
  4741. $job = JobRecruiting::where('id', $data['id'])->first();
  4742. if (empty($job)) {
  4743. return Result::error("招聘信息不存在", 0);
  4744. }
  4745. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  4746. if ($user['type_id'] != 10000) {
  4747. return Result::error("用户暂无权限审核此招聘信息!", 0);
  4748. }
  4749. // 驳回原因
  4750. if ($data['status'] == 2) {
  4751. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  4752. }
  4753. $data['action_id'] = $data['user_id'];
  4754. unset($data['user_id']);
  4755. $result = JobRecruiting::where('id', $data['id'])->update($data);
  4756. if (empty($result)) {
  4757. return Result::error("审核失败", 0);
  4758. }
  4759. return Result::success($result);
  4760. }
  4761. public function myApplyList(array $data): array
  4762. {
  4763. $user = User::where('id', $data['user_id'])->first();
  4764. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4765. return Result::error("用户不存在", 0);
  4766. }
  4767. // 1:个人会员 职场机会
  4768. if ($user['type_id'] == 1) {
  4769. $where['user_id'] = $user['id'];
  4770. }
  4771. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  4772. $query->where('recruit_id', $user['id']);
  4773. })
  4774. ->pluck('recruit_id');
  4775. $where = [];
  4776. if (isset($data['salary']) && $data['salary'] != null) {
  4777. $where['job_recruiting.salary'] = $data['salary'];
  4778. }
  4779. if (isset($data['experience']) && $data['experience'] != null) {
  4780. $where['job_recruiting.experience'] = $data['experience'];
  4781. }
  4782. if (isset($data['business_name']) && $data['business_name'] != null) {
  4783. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4784. }
  4785. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4786. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4787. ->where($where);
  4788. // ->count();
  4789. $count = $query->count();
  4790. $query = clone $query;
  4791. $job = $query
  4792. ->leftJoin('job_enum as income_enum', function ($join) {
  4793. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4794. ->where('income_enum.egroup', 'income');
  4795. })
  4796. ->leftJoin('job_enum as years_enum', function ($join) {
  4797. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4798. ->where('years_enum.egroup', 'years');
  4799. })
  4800. // ->where($where)
  4801. ->orderBy('job_recruiting.updated_at', 'desc')
  4802. ->select(
  4803. 'job_recruiting.id',
  4804. 'job_recruiting.title',
  4805. 'job_company.business_name',
  4806. 'income_enum.evalue as salary_evalue',
  4807. 'income_enum.ename as salary_ename',
  4808. 'years_enum.evalue as experience_evalue',
  4809. 'years_enum.ename as experience_ename',
  4810. 'job_recruiting.updated_at'
  4811. )
  4812. ->offset(($data['page'] - 1) * $data['pageSize'])
  4813. ->limit($data['pageSize'])
  4814. ->get()
  4815. ->all();
  4816. if (empty($job)) {
  4817. return Result::error("暂无招聘信息", 0);
  4818. }
  4819. $result = [
  4820. 'row' => $job,
  4821. 'count' => $count,
  4822. ];
  4823. return Result::success($result);
  4824. }
  4825. /*
  4826. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  4827. * */
  4828. public function getRecruitingList(array $data): array
  4829. {
  4830. $user = User::where('id', $data['user_id'])->first();
  4831. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4832. return Result::error("用户不存在", 0);
  4833. }
  4834. // 1:个人会员 职场机会
  4835. if ($user['type_id'] == 1) {
  4836. $where['user_id'] = $user['id'];
  4837. }
  4838. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  4839. $query->where('recruit_id', $user['id']);
  4840. })
  4841. ->pluck('recruit_id');
  4842. $where = [];
  4843. if (isset($data['salary']) && $data['salary'] != null) {
  4844. $where['job_recruiting.salary'] = $data['salary'];
  4845. }
  4846. if (isset($data['experience']) && $data['experience'] != null) {
  4847. $where['job_recruiting.experience'] = $data['experience'];
  4848. }
  4849. if (isset($data['business_name']) && $data['business_name'] != null) {
  4850. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4851. }
  4852. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4853. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4854. ->where($where);
  4855. // ->count();
  4856. $count = $query->count();
  4857. $query = clone $query;
  4858. $job = $query
  4859. ->leftJoin('job_enum as income_enum', function ($join) {
  4860. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4861. ->where('income_enum.egroup', 'income');
  4862. })
  4863. ->leftJoin('job_enum as years_enum', function ($join) {
  4864. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4865. ->where('years_enum.egroup', 'years');
  4866. })
  4867. // ->where($where)
  4868. ->orderBy('job_recruiting.updated_at', 'desc')
  4869. ->select(
  4870. 'job_recruiting.id',
  4871. 'job_recruiting.title',
  4872. 'job_company.business_name',
  4873. 'income_enum.evalue as salary_evalue',
  4874. 'income_enum.ename as salary_ename',
  4875. 'years_enum.evalue as experience_evalue',
  4876. 'years_enum.ename as experience_ename',
  4877. 'job_recruiting.updated_at'
  4878. )
  4879. ->offset(($data['page'] - 1) * $data['pageSize'])
  4880. ->limit($data['pageSize'])
  4881. ->get()
  4882. ->all();
  4883. if (empty($job)) {
  4884. return Result::error("暂无招聘信息", 0);
  4885. }
  4886. $result = [
  4887. 'row' => $job,
  4888. 'count' => $count,
  4889. ];
  4890. return Result::success($result);
  4891. }
  4892. /*
  4893. * 获取企业会员-招聘信息列表
  4894. * */
  4895. public function getRecruitingInfo(array $data): array
  4896. {
  4897. $user = User::where('id', $data['user_id'])->first();
  4898. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4899. return Result::error("用户不存在", 0);
  4900. }
  4901. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  4902. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4903. ->select(
  4904. 'job_recruiting.*',
  4905. 'job_company.business_name',
  4906. 'job_company.company_hy_id',
  4907. 'job_company.company_size',
  4908. 'job_company.company_nature',
  4909. 'job_company.introduction',
  4910. 'job_company.real_name',
  4911. 'job_company.mobile',
  4912. 'job_company.company_url',
  4913. 'job_company.address_arr_id',
  4914. 'job_company.address',
  4915. 'job_company.email'
  4916. )
  4917. ->get();
  4918. if (empty($recruiting)) {
  4919. return Result::error("暂无招聘信息", 0);
  4920. }
  4921. return Result::success($recruiting);
  4922. }
  4923. /*
  4924. * 获取企业会员-我的沟通
  4925. * */
  4926. public function getJobResumeList(array $data): array
  4927. {
  4928. $user = User::where('id', $data['user_id'])->first();
  4929. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  4930. return Result::error("用户不存在", 0);
  4931. }
  4932. $where = [];
  4933. if (isset($data['salary']) && $data['salary'] != null) {
  4934. $where['job_hunting.salary'] = $data['salary'];
  4935. }
  4936. if (isset($data['user_name']) && $data['user_name'] != null) {
  4937. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  4938. }
  4939. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  4940. $query->where('job_resume.user_id', $user['id']);
  4941. })
  4942. ->when(!empty($where), function ($query) use ($where) {
  4943. $query->where($where);
  4944. })
  4945. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  4946. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  4947. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  4948. ->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');
  4949. $count = $job->count();
  4950. if ($count == 0) {
  4951. return Result::error("暂无沟通记录", 0);
  4952. }
  4953. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  4954. ->offset(($data['page'] - 1) * $data['pageSize'])
  4955. ->limit($data['pageSize'])
  4956. ->get();
  4957. if (empty($jobs)) {
  4958. return Result::error("暂无沟通记录", 0);
  4959. }
  4960. $result['row'] = $this->processJob($jobs, '');
  4961. $result['count'] = $count;
  4962. return Result::success($result);
  4963. }
  4964. // 20250306 招聘
  4965. //20250422 书刊音像
  4966. public function addBook(array $data): array
  4967. {
  4968. // $user_id = $data['user_id'] ?? 0;
  4969. $type_id = $data['type_id'] ?? 0;
  4970. // $website_id = $data['website_id'] ?? 0;
  4971. // unset($data['user_id']);
  4972. unset($data['type_id']);
  4973. // unset($data['website_id']);
  4974. //处理数组
  4975. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  4976. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  4977. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  4978. if ($data['img_url'] == '') {
  4979. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4980. preg_match_all($reg, $data['detail'], $matches);
  4981. if (isset($matches[1][0])) {
  4982. //截取varchar240
  4983. $data['img_url'] = substr($matches[1][0], 0, 240);
  4984. }
  4985. }
  4986. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4987. //提取标题+内容中的关键词
  4988. $data['keyword'] = $data['title'];
  4989. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4990. Jieba::init(); // 初始化 jieba-php
  4991. Finalseg::init();
  4992. $segList = Jieba::cut($data['keyword']);
  4993. $segList1 = array_slice($segList, 0, 8);
  4994. $data['keyword'] = implode(',', $segList1);
  4995. }
  4996. if ($data['description'] == '') {
  4997. //提取内容中的描述
  4998. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4999. }
  5000. var_dump($data, '--');
  5001. $result = Book::insertGetId($data);
  5002. if (empty($result)) {
  5003. return Result::error("添加失败", 0);
  5004. }
  5005. return Result::success($result);
  5006. }
  5007. public function getBookList(array $data): array
  5008. {
  5009. $where = [];
  5010. if (!empty($data["title"])) {
  5011. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5012. }
  5013. if (!empty($data['website_name'])) {
  5014. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5015. }
  5016. if (!empty($data['status'])) {
  5017. $where[] = ['book.status', '=', $data['status']];
  5018. }
  5019. $user_id = $data['user_id'];
  5020. $type_id = $data['type_id'];
  5021. // $type_id = 4;
  5022. var_dump($type_id, '------1--------');
  5023. if ($type_id != 10000) {
  5024. $where[] = ['book.user_id', '=', $user_id];
  5025. }
  5026. var_dump(!empty($data['status1']), '=-===1');
  5027. $result = Book::where($where)
  5028. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5029. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5030. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5031. ->when(isset($data['status1']), function ($query) use ($data) {
  5032. $query->whereIn('book.status', [1, 3]);
  5033. })
  5034. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5035. ->orderBy("updated_at", "desc")
  5036. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5037. if (empty($result)) {
  5038. return Result::error("暂无数据", 0);
  5039. }
  5040. // 取出数据
  5041. $rows = $result->items();
  5042. $count = $result->total();
  5043. $responseData = [
  5044. 'rows' => $rows,
  5045. 'count' => $count,
  5046. ];
  5047. return Result::success($responseData);
  5048. }
  5049. public function deleteBook(array $data): array
  5050. {
  5051. $result = Book::where('id', $data['id'])->delete();
  5052. if (empty($result)) {
  5053. return Result::error("删除失败", 0);
  5054. }
  5055. return Result::success($result);
  5056. }
  5057. public function updateBook(array $data): array
  5058. {
  5059. // $user_id = $data['user_id'] ?? 0;
  5060. $type_id = $data['type_id'] ?? 0;
  5061. // $website_id = $data['website_id'] ?? 0;
  5062. unset($data['user_id']);
  5063. unset($data['type_id']);
  5064. // unset($data['website_id']);
  5065. //处理数组
  5066. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5067. if ($data['img_url'] == '') {
  5068. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5069. preg_match_all($reg, $data['detail'], $matches);
  5070. if (isset($matches[1][0])) {
  5071. //截取varchar240
  5072. $data['img_url'] = substr($matches[1][0], 0, 240);
  5073. }
  5074. }
  5075. if ($data['keyword'] == '') {
  5076. //提取标题+内容中的关键词
  5077. $data['keyword'] = $data['title'];
  5078. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5079. Jieba::init(); // 初始化 jieba-php
  5080. Finalseg::init();
  5081. $segList = Jieba::cut($data['keyword']);
  5082. $segList1 = array_slice($segList, 0, 8);
  5083. $data['keyword'] = implode(',', $segList1);
  5084. }
  5085. if ($data['description'] == '') {
  5086. //提取内容中的描述
  5087. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  5088. }
  5089. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5090. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5091. $result = Book::where("id", $data["id"])->update($data);
  5092. if (empty($result)) {
  5093. return Result::error("更新失败", 0);
  5094. }
  5095. return Result::success($result);
  5096. }
  5097. public function getBookInfo(array $data): array
  5098. {
  5099. $result = Book::where("id", $data["id"])->first();
  5100. if (empty($result)) {
  5101. return Result::error("获取失败", 0);
  5102. }
  5103. return Result::success($result);
  5104. }
  5105. public function updateBookStatus(array $data): array
  5106. {
  5107. //审核
  5108. unset($data['user_id']);
  5109. $result = Book::where("id", $data["id"])->update($data);
  5110. if (empty($result)) {
  5111. return Result::error("更新失败", 0);
  5112. }
  5113. return Result::success($result);
  5114. }
  5115. //20250422 书刊音像
  5116. }