NewsService.php 195 KB

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