NewsService.php 219 KB

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