NewsService.php 211 KB

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