NewsService.php 211 KB

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