NewsService.php 219 KB

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