NewsService.php 120 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768
  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\Website;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\Good;
  9. use Hyperf\DbConnection\Db;
  10. use Hyperf\RpcServer\Annotation\RpcService;
  11. use App\Tools\Result;
  12. use App\Model\ArticleSurvey;
  13. use App\Model\District;
  14. use App\Tools\buildMenuTree;
  15. use App\Model\Book;
  16. use App\Model\JobHunting;
  17. use App\Model\JobRecruiting;
  18. use App\Model\JobPosition;
  19. use App\Model\JobIndustry;
  20. use App\Model\JobEnum;
  21. use App\Model\JobCompany;
  22. use App\Model\JobNature;
  23. use App\Model\User;
  24. use App\Model\JobApply;
  25. use App\Model\JobRemuse;
  26. use Hyperf\Redis\Redis;
  27. use Hyperf\Di\Annotation\Inject;
  28. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  29. class NewsService implements NewsServiceInterface
  30. {
  31. #[Inject]
  32. protected Redis $redis;
  33. /**
  34. * 获取导航池列表
  35. * @param array $data
  36. * @return array
  37. */
  38. public function getCategoryList(array $data): array
  39. {
  40. $where = [];
  41. if(isset($data['name']) && $data['name']){
  42. array_push($where, ['category.name','like','%'.$data['name'].'%']);
  43. }
  44. if(isset($data['department_id']) && $data['department_id']){
  45. array_push($where, ['category.department_id','=',$data['department_id']]);
  46. }
  47. if(isset($data['city_id']) && $data['city_id']){
  48. array_push($where, ['category.city_id','=',$data['city_id']]);
  49. }
  50. $rep = Category::where($where)
  51. ->leftJoin('district','category.city_id','district.id')
  52. ->leftJoin('department','category.department_id','department.id')
  53. ->select("category.*","district.name as city_name","department.name as department_name")
  54. ->limit($data['pageSize'])->orderBy("category.sort","desc")->orderByDesc('category.updated_at')->offset(($data['page']-1)*$data['pageSize'])->get();
  55. $count = Category::where($where)->count();
  56. $data = [
  57. 'rows'=>$rep->toArray(),
  58. 'count'=>$count
  59. ];
  60. if(empty($rep->toArray())){
  61. return Result::error("没有导航池数据");
  62. }
  63. return Result::success($data);
  64. }
  65. /**
  66. * @param array $data
  67. * @return array
  68. */
  69. public function categoryList(array $data): array
  70. {
  71. $where[] = [
  72. 'pid','=',$data['pid']
  73. ];
  74. if(isset($data['name'])){
  75. array_push($where, ['category.name','like','%'.$data['name'].'%']);
  76. }
  77. var_dump($where);
  78. $result = Category::where($where)->select('category.*','category.id as category_id')->get();
  79. if(empty($result)){
  80. return Result::error("没有栏目数据");
  81. }
  82. return Result::success($result);
  83. }
  84. /**
  85. * @param array $data
  86. * @return array
  87. */
  88. public function addCategory(array $data): array
  89. {
  90. $id = Category::insertGetId($data);
  91. if(empty($id)){
  92. return Result::error("添加失败");
  93. }
  94. return Result::success(['id'=>$id]);
  95. }
  96. /**
  97. * @param array $data
  98. * @return array
  99. */
  100. public function delCategory(array $data): array
  101. {
  102. $categoryList = Category::where(['pid'=>$data['id']])->get();
  103. var_dump("分类列表:",$data,$categoryList);
  104. if($categoryList->toArray()){
  105. return Result::error("分类下面有子分类不能删除");
  106. }
  107. $articleList = Article::where(['catid'=>$data['id']])->get();
  108. var_dump("文章列表:",$articleList);
  109. if($articleList->toArray()){
  110. return Result::error("分类下面有资讯不能删除");
  111. }
  112. $result = Category::where($data)->delete();
  113. if(!$result){
  114. return Result::error("删除失败");
  115. }
  116. return Result::success($result);
  117. }
  118. /**
  119. * @param array $data
  120. * @return array
  121. */
  122. public function updateCategory(array $data): array
  123. {
  124. $where = [
  125. 'id'=>$data['id']
  126. ];
  127. $result = Category::where($where)->update($data);
  128. if($result){
  129. return Result::success($result);
  130. }else{
  131. return Result::error("更新失败");
  132. }
  133. }
  134. /**
  135. * 获取导航池信息
  136. * @param array $data
  137. * @return array
  138. */
  139. public function getCategoryInfo(array $data): array
  140. {
  141. $where = [
  142. 'id'=>$data['id']
  143. ];
  144. $result = Category::where($where)->first();
  145. if($result){
  146. return Result::success($result);
  147. }else{
  148. return Result::error("更新失败");
  149. }
  150. }
  151. /**
  152. * @param array $data
  153. * @return array
  154. */
  155. public function getArticleList(array $data): array
  156. {
  157. $where= [];
  158. if(isset($data['title']) && $data['title']){
  159. array_push($where,['article.title','like','%'.$data['title'].'%']);
  160. }
  161. if(isset($data['category_name']) && $data['category_name']){
  162. array_push($where,['category.name','like','%'.$data['category_name'].'%']);
  163. }
  164. if(isset($data['author']) && $data['author']){
  165. array_push($where,['article.author','=',$data['author']]);
  166. }
  167. if(isset($data['islink']) && $data['islink']!==""){
  168. array_push($where,['article.islink','=',$data['islink']]);
  169. }
  170. if(isset($data['status']) && $data['status']!==""){
  171. array_push($where,['article.status','=',$data['status']]);
  172. }
  173. $rep = Article::where($where)
  174. ->whereNotIn('article.status',[404])
  175. ->leftJoin('category','article.catid','category.id')
  176. ->select("article.*","category.name as category_name")
  177. ->orderBy("article.id","desc")
  178. ->limit($data['pageSize'])
  179. ->offset(($data['page']-1)*$data['pageSize'])->get();
  180. $count = Article::where($where)->whereNotIn('article.status',[404])
  181. ->leftJoin('category','article.catid','category.id')->count();
  182. $data = [
  183. 'rows'=>$rep->toArray(),
  184. 'count'=>$count
  185. ];
  186. if(empty($rep)){
  187. return Result::error("没有信息数据");
  188. }
  189. return Result::success($data);
  190. }
  191. /**
  192. * @param array $data
  193. * @return array
  194. */
  195. public function addArticle(array $data): array
  196. {
  197. Db::beginTransaction();
  198. try{
  199. $articleData = $data;
  200. unset($articleData['content']);
  201. $id = Article::insertGetId($articleData);
  202. $articleDataContent = [
  203. 'article_id'=>$id,
  204. 'content'=>$data['content']
  205. ];
  206. ArticleData::insertGetId($articleDataContent);
  207. Db::commit();
  208. } catch(\Throwable $ex){
  209. Db::rollBack();
  210. var_dump($ex->getMessage());
  211. return Result::error("创建失败",0);
  212. }
  213. return Result::success(['id'=>$id]);
  214. }
  215. /**
  216. * @param array $data
  217. * @return array
  218. */
  219. public function delArticle(array $data): array
  220. {
  221. $result = Article::where($data)->update(['status'=>404]);
  222. if(!$result){
  223. return Result::error("删除失败");
  224. }
  225. return Result::success($result);
  226. }
  227. /**
  228. * @param array $data
  229. * @return array
  230. */
  231. public function updateArticle(array $data): array
  232. {
  233. Db::beginTransaction();
  234. try{
  235. $data['cat_arr_id'] = isset($data['cat_arr_id'])?json_encode($data['cat_arr_id']):'';
  236. $data['tag'] = isset($data['tag'])?json_encode($data['tag']):'';
  237. $articleData = $data;
  238. unset($articleData['content']);
  239. unset($articleData['status_name']);
  240. unset($articleData['name']);
  241. unset($articleData['content']);
  242. unset($articleData['pid_arr']);
  243. unset($articleData['pid']);
  244. $id = Article::where(['id'=>$data['id']])->update($articleData);
  245. $articleDataContent = [
  246. 'content'=>$data['content']
  247. ];
  248. ArticleData::where(['article_id'=>$data['id']])->update($articleDataContent);
  249. } catch(\Throwable $ex){
  250. Db::rollBack();
  251. var_dump($ex->getMessage());
  252. return Result::error("更新失败",0);
  253. }
  254. return Result::success([]);
  255. }
  256. /**
  257. * 更新资讯状态
  258. * @param array $data
  259. * @return array
  260. */
  261. public function upArticleStatus(array $data):array
  262. {
  263. $result = Article::where(['id'=>$data['id']])->update($data);
  264. if($result){
  265. return Result::success();
  266. }else{
  267. return Result::error("更新状态失败",0);
  268. }
  269. }
  270. /**
  271. * 获取新闻详情
  272. * @param array $data
  273. * @return array
  274. */
  275. public function getArticleInfo(array $data): array
  276. {
  277. $where = [
  278. 'article.id'=>$data['id'],
  279. // 'article.status'=>1
  280. ];
  281. $result = Article::where($where)->leftJoin("article_data","article.id","article_data.article_id")->first();
  282. if(empty($result)){
  283. return Result::error("查询失败",0);
  284. }
  285. return Result::success($result);
  286. }
  287. /**
  288. * 获取头条新闻
  289. * @param array $data
  290. * @return array
  291. */
  292. public function getWebsiteArticlett(array $data): array
  293. {
  294. // return Result::success($data['website_id']);
  295. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  296. $category = array_values(array_unique($category->toArray()));
  297. $web['website_id'] = $data['website_id'];
  298. if ($category) {
  299. $where = [
  300. 'status' => 1,
  301. ];
  302. var_dump($data, 'data-----------------');
  303. // level=7 根据文章key来匹配文章
  304. if (isset($data['level']) && $data['level'] == 7) {
  305. // 根据文章id获取key
  306. // $data['id'] = 50142;
  307. if (isset($data['id']) && !empty($data['id'])) {
  308. $keyword = Article::where('id', $data['id'])->value('keyword');
  309. $keywordArray = explode(',', $keyword);
  310. $whereL7 = [];
  311. foreach ($keywordArray as $k => $v) {
  312. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  313. }
  314. // 原始查询
  315. $result['level7'] = Article::where($whereL7)
  316. ->when(!empty($data['imgnum']), function ($query) use ($data) {
  317. $query->where('article.imgurl', '!=', '')
  318. ->select('article.*')
  319. ->offset($data['placeid'])
  320. ->limit($data['imgnum']);
  321. })
  322. ->when(!empty($data['textnum']), function ($query) use ($data) {
  323. $query->select('article.*')
  324. ->offset($data['placeid'])
  325. ->limit($data['textnum']);
  326. })
  327. ->orderBy('updated_at', 'desc')
  328. ->get();
  329. $result['level7'] = $this->processArticle($result['level7'],$web);
  330. if (empty($result)) {
  331. return Result::success();
  332. }
  333. return Result::success($result);
  334. } else {
  335. return Result::error("参数错误level=7,id不能为空", 0);
  336. }
  337. }
  338. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  339. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  340. var_dump($where, 'where-----------------');
  341. // 初始化基础查询
  342. $query = Article::where($where)
  343. ->whereIn("catid", $category)
  344. ->where(function ($query) use ($data) {
  345. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  346. ->orWhereNull("ignore_ids");
  347. });
  348. // 处理 level 相关查询条件
  349. $query->when($data['level'] == 5, function ($query) {
  350. $query->inRandomOrder()
  351. ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  352. })->when($data['level'] == 4, function ($query) {
  353. $query->orderBy("article.updated_at", "desc");
  354. })->when(!empty($data['level']), function ($query) use ($data) {
  355. if ($data['level'] != 4 && $data['level'] != 5) {
  356. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  357. ->orderBy("article.updated_at", "desc");
  358. }
  359. });
  360. // 初始化结果数组
  361. $result = [];
  362. // $input = $data['website_id'];
  363. // 处理图片新闻查询
  364. if (!empty($data['imgnum'])) {
  365. // 原错误提示表明 cleanBindings 方法需要传入数组类型的参数,而实际传入了 null。
  366. // 这里克隆查询构建器,确保绑定参数为数组,避免该错误。
  367. $imgQuery = clone $query;
  368. if ($imgQuery->getBindings() === null) {
  369. $imgQuery->setBindings([]);
  370. }
  371. $result['img'] = $imgQuery->where('article.imgurl', '!=', '')
  372. ->select('article.id',
  373. 'article.title',
  374. 'article.imgurl',
  375. 'article.author',
  376. 'article.updated_at',
  377. 'article.introduce',
  378. 'article.islink',
  379. 'article.linkurl',
  380. 'article.copyfrom',
  381. 'article.cat_arr_id',
  382. 'article.catid')
  383. ->offset($data['placeid'])
  384. ->limit($data['imgnum'])
  385. ->get();
  386. $result['img'] = $this->processArticles( $result['img'], $web);
  387. }
  388. // 处理文字新闻查询
  389. if (!empty($data['textnum'])) {
  390. $textQuery = clone $query;
  391. $result['text'] = $textQuery
  392. ->select('article.id',
  393. 'article.title',
  394. 'article.imgurl',
  395. 'article.author',
  396. 'article.updated_at',
  397. 'article.introduce',
  398. 'article.islink',
  399. 'article.linkurl',
  400. 'article.copyfrom',
  401. 'article.cat_arr_id',
  402. 'article.catid')
  403. ->offset($data['placeid'])
  404. ->limit($data['textnum'])
  405. ->get();
  406. $result['text'] = $this->processArticles($result['text'], $web);
  407. }
  408. if (empty($result) || count($result) == 0) {
  409. return Result::error("暂无头条新闻");
  410. }
  411. return Result::success($result);
  412. } else {
  413. return Result::error("本网站下暂无相关栏目", 0);
  414. }
  415. }
  416. /**
  417. * 获取模块新闻
  418. * @param array $data
  419. * @return array
  420. */
  421. public function getWebsiteModelArticles(array $data): array
  422. {
  423. $catid = $data['catid'];
  424. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  425. $category = $category->toArray();
  426. if (!empty($category)) {
  427. $where = [
  428. 'status' => 1,
  429. 'catid' => $catid,
  430. ];
  431. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  432. // 1:文字新闻;2:轮播图;3:图文;
  433. // 级别:0:未分类
  434. // 3:推荐图片
  435. if ($data['level'] == 1) {
  436. $data['level'] = 0;
  437. }
  438. $result = Article::where($where)
  439. ->where(function ($query) use ($data) {
  440. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  441. ->orWhereNull("level")
  442. ->orWhereRaw("level = '[]'");
  443. })
  444. ->where(function ($query) use ($data) {
  445. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  446. ->orWhereNull("ignore_ids");
  447. })
  448. ->orderBy("updated_at", "desc")
  449. ->offset($placeid)
  450. ->limit($data['pagesize'])
  451. ->get();
  452. if (empty($result)) {
  453. return Result::error("此栏目暂无相关新闻", 0);
  454. }
  455. } else {
  456. return Result::error("此网站暂无此栏目", 0);
  457. }
  458. return Result::success($result);
  459. }
  460. /**
  461. *获取新闻列表
  462. * @param array $data
  463. * @return array
  464. */
  465. public function getWebsiteArticleList(array $data): array
  466. {
  467. // return Result::success($data);
  468. $where[] = ['status', '=', 1];
  469. if (isset($data['catid']) && !empty($data['catid'])) {
  470. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  471. array_push($where, ['catid', '=', $data['catid']]);
  472. if (empty($category)) {
  473. return Result::error("此网站暂无此栏目", 0);
  474. }
  475. }
  476. // return Result::success($where);
  477. $rep = Article::where($where)
  478. ->where(function ($query) use ($data) {
  479. $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
  480. ->orWhereNull("ignore_ids");
  481. })
  482. ->select(
  483. 'article.id',
  484. 'article.title',
  485. 'article.imgurl',
  486. 'article.author',
  487. 'article.updated_at',
  488. 'article.introduce',
  489. 'article.islink',
  490. 'article.linkurl',
  491. 'article.copyfrom',
  492. 'article.cat_arr_id',
  493. 'article.catid')
  494. ->orderBy("updated_at", "desc")
  495. ->offset(($data['page'] - 1) * $data['pageSize'])
  496. ->limit($data['pageSize'])
  497. ->get();
  498. $web['website_id'] = $data['website_id'];
  499. $rep = $this->processArticles($rep,$web);
  500. $count = Article::where($where)
  501. ->where(function ($query) use ($data) {
  502. $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
  503. ->orWhereNull("ignore_ids");
  504. })->count();
  505. $data = [
  506. 'rows' => $rep->toArray(),
  507. 'count' => $count,
  508. ];
  509. if (empty($rep)) {
  510. return Result::error("没有信息数据");
  511. }
  512. return Result::success($data);
  513. }
  514. /**
  515. * 前端-获取新闻详情
  516. * @param array $data
  517. * @return array
  518. */
  519. public function selectWebsiteArticleInfo(array $data): array
  520. {
  521. $where = [
  522. 'article.id'=>$data['id'],
  523. 'article.status'=>1
  524. ];
  525. $result = Article::where($where)->leftJoin("article_data","article.id","article_data.article_id")
  526. ->where(function ($query) use ($data) {
  527. $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
  528. ->orWhereNull("ignore_ids");
  529. })
  530. ->first();
  531. if(empty($result)){
  532. return Result::error("暂无此新闻!",0);
  533. }
  534. $category = WebsiteCategory::where('website_id',$data['website_id'])->where(['category_id'=>$result['catid']])->first();
  535. if(empty($category)){
  536. return Result::error("查询失败",0);
  537. }
  538. $result['category_id'] = $category['category_id'];
  539. $result['cat_name'] = $category['alias'];
  540. return Result::success($result);
  541. }
  542. /**
  543. * 前端-获取网站调查问卷
  544. * @param array $data
  545. * @return array
  546. */
  547. public function getWebsiteSurvey(array $data): array
  548. {
  549. if(isset($data['website_id']) && !empty($data['website_id'])){
  550. $website = Website::where('id',$data['website_id'])->first();
  551. if(empty($website)){
  552. return Result::error("暂无此网站",0);
  553. }
  554. }
  555. if(isset($data['art_id']) && !empty($data['art_id'])){
  556. $article = Article::where('id',$data['art_id'])->where('status',1)->first();
  557. if(empty($article)){
  558. return Result::error("暂无此文章",0);
  559. }
  560. // return Result::error($data,0);
  561. $where['art_id'] = $data['art_id'];
  562. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  563. }else{
  564. $survey = Article::where(function ($query) {
  565. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  566. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  567. })
  568. ->where('status',1)
  569. ->where('is_survey',1)
  570. ->select('survey_id')
  571. ->orderBy('updated_at','desc')
  572. ->first();
  573. if(empty($survey)){
  574. return Result::error("暂无调查问卷",0);
  575. }
  576. $where['sur_id'] = $survey['survey_id'];
  577. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  578. }
  579. // return Result::success($where);
  580. $result = ArticleSurvey::where($where)
  581. ->where(function ($query) {
  582. $query->where('is_other', 0)
  583. ->orWhere(function ($subQuery) {
  584. $subQuery->where('is_other', 1)
  585. ->where('other_id', 0);
  586. });
  587. })
  588. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  589. ->select('article_survey.*', 'article.survey_type')
  590. ->get()->all();
  591. if(empty($result)){
  592. return Result::error("此文章暂无调查问卷",0);
  593. }
  594. return Result::success($result);
  595. }
  596. /**
  597. * 前端-添加网站调查问卷选项
  598. * @param array $data
  599. * @return array
  600. */
  601. public function addWebsiteSurveyOption(array $data): array
  602. {
  603. if(isset($data['website_id']) && !empty($data['website_id'])){
  604. $website = Website::where('id',$data['website_id'])->first();
  605. if(empty($website)){
  606. return Result::error("暂无此网站",0);
  607. }
  608. if(isset($data['sur_id']) && !empty($data['sur_id'])){
  609. $survey = ArticleSurvey::where('sur_id',$data['sur_id'])->where('is_other',1)->where('other_id',0)->first();
  610. if(empty($survey)){
  611. return Result::error("此调查问卷不可添加选项",0);
  612. }
  613. if(isset($data['choice_name']) &&!empty($data['choice_name'])){
  614. $choice = [
  615. 'art_id'=>$survey['art_id'],
  616. 'website_id'=>$data['website_id'],
  617. 'survey_name'=>$survey['survey_name'],
  618. 'choice_name'=>$data['choice_name'],
  619. 'sur_id'=>$survey['sur_id'],
  620. 'is_other'=>1,
  621. 'other_id'=>$survey['id'],
  622. ];
  623. $result = ArticleSurvey::insertGetId($choice);
  624. if(empty($result)){
  625. return Result::error("添加失败",0);
  626. }
  627. return Result::success($result);
  628. }
  629. }
  630. return Result::error("添加失败",0);
  631. }
  632. return Result::error("添加失败",0);
  633. }
  634. /**
  635. * 前端-调查问卷投票
  636. * @param array $data
  637. * @return array
  638. */
  639. public function addWebsiteSurveyVote(array $data): array
  640. {
  641. // return Result::success($data);
  642. if(isset($data['website_id']) && !empty($data['website_id'])){
  643. $website = Website::where('id',$data['website_id'])->first();
  644. if(empty($website)){
  645. return Result::error("暂无此网站",0);
  646. }
  647. if(isset($data['sur_id']) && !empty($data['sur_id'])){
  648. $is_survey = ArticleSurvey::where('sur_id',$data['sur_id'])->first();
  649. // return Result::success($survey);
  650. if(empty($is_survey)){
  651. return Result::error("此调查问卷不存在",0);
  652. }
  653. // return Result::success($survey);
  654. // 调查问卷类型
  655. if(isset($data['choice_id']) &&!empty($data['choice_id'])){
  656. //多选 若是json型则转化成数组类型
  657. if (strpos($data['choice_id'], '[') === 0) {
  658. $data['choice_id'] = json_decode($data['choice_id'], true);
  659. } else {
  660. // 单选 也转换成数组
  661. $data['choice_id'] = [$data['choice_id']];
  662. }
  663. $data['choice_id'] = array_map('intval', $data['choice_id']);
  664. $other = ArticleSurvey::whereIn('id',$data['choice_id'])
  665. // ->where('website_id',$data['website_id'])
  666. ->where('is_other',1)
  667. ->where('other_id',0)
  668. ->first();
  669. if(!empty($other)){
  670. return Result::error("请选择已有的选项!",0);
  671. }
  672. $choice['other'] = ArticleSurvey::whereIn('id',$data['choice_id'])
  673. // ->where('website_id',$data['website_id'])
  674. ->where('is_other',1)
  675. ->where('other_id','!=',0)
  676. ->first();
  677. // return Result::success($choice['other']);
  678. $choice_id = $data['choice_id'];
  679. if(!empty($choice['other'])){
  680. // array_push($data['choice_id'],$choice['other']['other_id']);
  681. if(!empty($choice_id)){
  682. $key = array_search($choice['other']['id'], $choice_id);
  683. if ($key!== false) {
  684. unset($choice_id[$key]);
  685. $choice_id = array_values($choice_id);
  686. }
  687. array_push($choice_id,$choice['other']['other_id']);
  688. }else{
  689. $choice_id[0] = $choice['other']['other_id'];
  690. }
  691. array_push($data['choice_id'],$choice['other']['other_id']);
  692. }
  693. // return Result::success($data);
  694. $choice = ArticleSurvey::whereIn('id',$data['choice_id'])
  695. // ->where('website_id',$data['website_id'])
  696. ->increment('results', 1);
  697. if(empty($choice)){
  698. return Result::error("请选择已有的选项!",0);
  699. }
  700. $survey['data'] = ArticleSurvey::where('sur_id',$data['sur_id'])
  701. // ->where('website_id',$data['website_id'])
  702. ->where('other_id', 0)
  703. ->get();
  704. $survey['choice'] = $choice_id;
  705. return Result::success($survey);
  706. }
  707. return Result::error("参数必填!");
  708. }
  709. return Result::error("此调查问卷不存在",0);
  710. }
  711. return Result::error("参数必填!");
  712. }
  713. /**
  714. * 后端-获取网站调查问卷列表
  715. * @param array $data
  716. * @return array
  717. */
  718. public function getSurveyList(array $data): array
  719. {
  720. $where = [];
  721. if(isset($data['survey_name']) &&!empty($data['survey_name'])){
  722. array_push($where,['survey_name','like','%'.$data['survey_name'].'%']);
  723. }
  724. if(isset($data['survey_type']) && $data['survey_type'] != null){
  725. array_push($where,['survey_type','=',$data['survey_type']]);
  726. }
  727. if(isset($data['is_survey']) && $data['is_survey'] != null){
  728. array_push($where,['is_survey','=',$data['is_survey']]);
  729. }
  730. // return Result::success($where);
  731. if (!empty($where)) {
  732. $query = Article::where($where)->where(function ($q) {
  733. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  734. });
  735. } else {
  736. $query = Article::where(function ($q) {
  737. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  738. });
  739. }
  740. $count = $query->count();
  741. $survey = $query->orderByDesc('id')
  742. ->limit($data['pageSize'])
  743. ->offset(($data['page']-1)*$data['pageSize'])
  744. ->get();
  745. if(empty($survey->toArray())){
  746. return Result::error("暂无调查问卷!",0);
  747. }
  748. $result = [
  749. 'rows'=>$survey,
  750. 'count'=>$count
  751. ];
  752. return Result::success($result);
  753. }
  754. /**
  755. * 后端-获取网站调查问卷详情
  756. * @param array $data
  757. * @return array
  758. */
  759. public function getSurveyInfo(array $data): array
  760. {
  761. if(isset($data['sur_id']) &&!empty($data['sur_id'])){
  762. $where = [ 'sur_id'=>$data['sur_id']];
  763. $choose = ArticleSurvey::where($where)->where('is_other',0)
  764. ->leftJoin('article','article_survey.art_id','article.id')
  765. ->select('article_survey.*','article.survey_type')
  766. ->get()->all();
  767. if(empty($choose)){
  768. return Result::error("此调查问卷不存在",0);
  769. }
  770. $resultsArray = array_column($choose, 'results');
  771. $total = array_sum($resultsArray);
  772. $other = ArticleSurvey::where($where)->where('is_other',1)->where('other_id',0)->first();
  773. $others = ArticleSurvey::where($where)->where('is_other',1)->where('other_id','!=',0)->orderByDesc('created_at')->get()->all();
  774. // $total = 0;
  775. if(!empty($other)){
  776. $total = $total + $other['results'];
  777. $other['choice_name'] ='(其他)';
  778. if(!empty($others)){
  779. $other['hasChildren'] = true;
  780. // array_push($other,['hasChildren','=',true]);
  781. $other['children'] = $others;
  782. $other_choices = [$other->toArray()];
  783. $mer_choice = array_merge($choose,$other_choices);
  784. $value_choice = array_values($mer_choice);
  785. }
  786. else{
  787. // return Result::error('1111');
  788. $other_choices = [$other->toArray()];
  789. $other_choices = array_merge($choose,$other_choices);
  790. $value_choice = array_values($other_choices);
  791. // return Result::success($result);
  792. }
  793. }else{
  794. $value_choice = $choose;
  795. }
  796. $result = [
  797. 'choose'=>$value_choice,
  798. 'total'=>$total
  799. ];
  800. }
  801. return Result::success($result);
  802. }
  803. /**
  804. * 前端-搜索新闻列表
  805. * @param array $data
  806. * @return array
  807. */
  808. public function selectWebsiteArticle(array $data): array
  809. {
  810. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  811. $query = Article::where('status', 1)
  812. ->whereIn('catid', $category)
  813. ->where(function ($query) use ($data) {
  814. $query->where(function ($subQuery) use ($data) {
  815. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  816. })->orWhereNull("ignore_ids");
  817. });
  818. // return Result::success($all_articles);
  819. if (isset($data['cityid']) && !empty($data['cityid'])) {
  820. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  821. }
  822. if (isset($data['department_id']) && !empty($data['department_id'])) {
  823. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  824. }
  825. if (isset($data['keyword']) && !empty($data['keyword'])) {
  826. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  827. }
  828. // 计算总数
  829. $count = $query->count();
  830. // 分页查询
  831. $articles = $query
  832. ->select(
  833. 'article.id',
  834. 'article.title',
  835. 'article.imgurl',
  836. 'article.author',
  837. 'article.updated_at',
  838. 'article.introduce',
  839. 'article.islink',
  840. 'article.linkurl',
  841. 'article.copyfrom',
  842. 'article.cat_arr_id',
  843. 'article.catid',
  844. 'article.department_arr_id',
  845. 'article.city_arr_id',)
  846. ->orderBy("updated_at", "desc")
  847. ->offset(($data['page'] - 1) * $data['pageSize'])
  848. ->limit($data['pageSize'])
  849. ->get();
  850. $web['website_id'] = $data['website_id'];
  851. $articles = $this->processArticles($articles,$web);
  852. if (empty($articles)) {
  853. return Result::error("没有符合条件的资讯数据");
  854. }
  855. $result = [
  856. 'rows' => $articles,
  857. 'count' => $count,
  858. ];
  859. return Result::success($result);
  860. }
  861. /**
  862. * 模块新闻加强版
  863. * @param array $data
  864. * @return array
  865. */
  866. public function getWebsiteCatidArticle(array $data): array
  867. {
  868. $where = [
  869. 'website_category.category_id' => $data['catid'],
  870. 'website_category.website_id' => $data['website_id'],
  871. ];
  872. if(isset($data['child_catnum']) && !empty($data['child_catnum'])){
  873. $child_catnum = $data['child_catnum']?? 1;
  874. $category['child'] = WebsiteCategory::where('pid',$data['catid'])->where('website_id',$data['website_id'])->select('category_id','alias')->limit($child_catnum)->get()->toArray();
  875. $childCategoryIds = array_column($category['child'], 'category_id');
  876. if(empty($childCategoryIds)){
  877. return Result::error("暂无子栏目",0);
  878. }
  879. $imgArticles = [];
  880. $textArticles = [];
  881. if(isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum']!=0){
  882. // 初始化子分类图片新闻和文字新闻数组
  883. // 查询所有子级栏目的图文新闻
  884. $imgArticles = Article::where('catid', $childCategoryIds[0])
  885. ->where(function ($query) use ($data) {
  886. $query->where(function ($subQuery) use ($data) {
  887. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
  888. })->orWhereNull("ignore_ids");
  889. })
  890. ->where('status', 1)
  891. ->where('imgurl', '!=', '')
  892. ->select('*')
  893. ->orderBy('updated_at', 'desc')
  894. ->limit($data['child_imgnum'])
  895. ->get();
  896. }
  897. if( isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum']!=0){
  898. // 查询所有子级栏目的文字新闻
  899. $textArticles = Article::where('catid', $childCategoryIds[0])
  900. ->where('status', 1)
  901. ->where(function ($query) use ($data) {
  902. $query->where(function ($subQuery) use ($data) {
  903. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
  904. })->orWhereNull("ignore_ids");
  905. })
  906. ->select('*')
  907. ->orderBy('updated_at', 'desc')
  908. ->limit($data['child_textnum'])
  909. ->get();
  910. }
  911. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  912. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  913. $child['img'] = $imgArticles? $imgArticles->where('catid', $child['category_id']) : [];
  914. $child['text'] = $textArticles? $textArticles->where('catid', $child['category_id']) : [];
  915. return $child;
  916. }, $category['child']);
  917. }
  918. // }
  919. if (isset($data['img_num']) && !empty($data['img_num'])) {
  920. $category['img'] = WebsiteCategory::where($where)
  921. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  922. ->where('article.status', 1)
  923. ->where('article.imgurl', '!=', '')
  924. ->select('article.*','website_category.category_id','website_category.alias')
  925. ->orderBy('article.updated_at', 'desc')
  926. ->limit($data['img_num'])
  927. ->get();
  928. }
  929. if (isset($data['text_num']) && !empty($data['text_num'])) {
  930. $category['text'] = WebsiteCategory::where($where)
  931. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  932. ->where('article.status', 1)
  933. ->select('article.*','website_category.category_id','website_category.alias')
  934. ->orderBy('article.updated_at', 'desc')
  935. ->limit($data['text_num'])
  936. ->get();
  937. }
  938. // $category = $category->get();
  939. if(empty($category)){
  940. return Result::error("查询失败", 0);
  941. }
  942. return Result::success($category);
  943. }
  944. /**
  945. * 模块新闻加强plus版
  946. * @param array $data
  947. * @return array
  948. */
  949. public function getWebsiteAllArticle(array $data): array
  950. {
  951. // 修正传入的字符串,将单引号替换为双引号
  952. $input['id'] = $data['id'];
  953. $input['website_id'] = $data['website_id'];
  954. // 将 JSON 字符串转换为 PHP 数组
  955. $data = json_decode($input['id'], true);
  956. // 使用 array_map 处理每个元素
  957. $result = array_map(function ($item) use ($input) {
  958. // 检查parent元素是否存在且不是undefined
  959. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent']!= "" ) {
  960. $count = explode(',', $item['parent']);
  961. if(count($count)!=3){
  962. return Result::error("参数错误",0);
  963. }
  964. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  965. $website = [
  966. 'website_id' => $input['website_id'],
  967. ];
  968. // 查询栏目名称
  969. $categroy = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin','type']);
  970. // 查询图片新闻
  971. if(isset($parentImgNum) && $parentImgNum!=0 && !empty($categroy)){
  972. $imgArticles = Article::where('article.status', 1)
  973. ->where(function($query) use ($parentCatId) {
  974. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  975. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  976. })
  977. ->where(function ($query) use ($website) {
  978. $query->where(function ($subQuery) use ($website) {
  979. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 1")
  980. ->orWhereNull("ignore_ids");
  981. });
  982. })
  983. ->where('imgurl', '!=', '')
  984. ->leftJoin('website_category', function($join) use ($website) {
  985. $join->on('article.catid', '=', 'website_category.category_id')
  986. ->where('website_category.website_id', '=', $website['website_id']);
  987. })
  988. ->select(
  989. 'article.id','article.title','article.imgurl','article.author','article.updated_at',
  990. 'article.introduce','article.islink','article.linkurl','article.copyfrom','article.cat_arr_id',
  991. 'article.catid','website_category.alias as category_name',
  992. )
  993. ->orderBy('updated_at', 'desc')
  994. ->limit($parentImgNum)
  995. ->get();
  996. //调取封装路由的方法,处理新闻路由
  997. if(!empty($imgArticles)){
  998. $imgArticles = $this->processArticles($imgArticles , $website);
  999. }
  1000. }
  1001. // 查询文字新闻
  1002. if(isset($parentTextNum) && $parentTextNum!=0 && !empty($categroy)){
  1003. $textArticles = [];
  1004. $textArticles = Article::where('article.status', 1)
  1005. ->where(function($query) use ($parentCatId) {
  1006. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  1007. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  1008. })
  1009. ->where(function ($query) use ($website) {
  1010. $query->where(function ($subQuery) use ($website) {
  1011. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 1")
  1012. ->orWhereNull("ignore_ids");
  1013. });
  1014. })
  1015. ->leftJoin('website_category', function($join) use ($website) {
  1016. $join->on('article.catid', '=', 'website_category.category_id')
  1017. ->where('website_category.website_id', '=', $website['website_id']);
  1018. })
  1019. ->select(
  1020. 'article.id','article.title','article.author','article.updated_at','article.cat_arr_id',
  1021. 'article.introduce','article.islink','article.linkurl','article.copyfrom',
  1022. 'article.catid','website_category.alias as category_name',
  1023. )
  1024. ->orderBy('updated_at', 'desc')
  1025. ->limit($parentTextNum)
  1026. ->get();
  1027. if(!empty($textArticles)){
  1028. $textArticles = $this->processArticles($textArticles , $website);
  1029. }
  1030. }
  1031. }
  1032. $resultItem = [
  1033. 'alias' => $categroy ? $categroy->alias : null,
  1034. 'category_id' => $categroy ? $categroy->category_id : null,
  1035. 'pinyin' => $categroy ? $categroy->aLIas_pinyin : null,
  1036. 'imgnum' => $imgArticles ?? [],
  1037. 'textnum' => $textArticles ?? [],
  1038. ];
  1039. if(isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != ""){
  1040. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  1041. $childCategory = WebsiteCategory::where($website)
  1042. ->where("category_id", $childCatId)
  1043. ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($parentCatId)."') = 1")
  1044. ->first(['alias', 'category_id','aLIas_pinyin','pid','type','category_arr_id as cat_arr_id']);
  1045. if (!empty($childCategory)) {
  1046. $childCategory = $this->processArticles($childCategory, $website);
  1047. // 查询此层级的所有子栏目
  1048. $all_childcat = WebsiteCategory::where($website)
  1049. ->where("pid", $childCategory['pid'])
  1050. ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($parentCatId)."') = 1")
  1051. ->get(['alias', 'category_id','aLIas_pinyin','pid','type','category_arr_id as cat_arr_id']);
  1052. $all_childcat = $this->processArticles($all_childcat, $website);
  1053. // 查询子栏目图片新闻
  1054. if( isset($childImgNum) && $childImgNum!=0 ){
  1055. $childImgArticles = Article::where('catid', $childCatId)
  1056. ->where('status', 1)
  1057. ->where(function ($query) use ($website) {
  1058. $query->where(function ($subQuery) use ($website) {
  1059. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 1");
  1060. })->orWhereNull("ignore_ids");
  1061. })
  1062. ->select(
  1063. 'article.id',
  1064. 'article.title',
  1065. 'article.imgurl',
  1066. 'article.author',
  1067. 'article.updated_at',
  1068. 'article.introduce',
  1069. 'article.islink',
  1070. 'article.linkurl',
  1071. 'article.catid',
  1072. 'article.cat_arr_id',
  1073. 'article.copyfrom',)
  1074. ->where('imgurl', '!=', '')
  1075. ->orderBy('updated_at', 'desc')
  1076. ->limit($childImgNum)
  1077. ->get();
  1078. $childImgArticles = $this->processArticles($childImgArticles, $website);
  1079. }
  1080. // 查询子栏目文字新闻
  1081. if( isset($childTextNum) && $childTextNum!=0 ){
  1082. $childTextArticles = Article::where('catid', $childCatId)
  1083. ->where('status', 1)
  1084. ->where(function ($query) use ($website) {
  1085. $query->where(function ($subQuery) use ($website) {
  1086. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 1");
  1087. })->orWhereNull("ignore_ids");
  1088. })
  1089. ->select(
  1090. 'article.id',
  1091. 'article.title',
  1092. 'article.author',
  1093. 'article.updated_at',
  1094. 'article.introduce',
  1095. 'article.islink',
  1096. 'article.linkurl',
  1097. 'article.catid',
  1098. 'article.cat_arr_id',
  1099. 'article.copyfrom',)
  1100. ->orderBy('updated_at', 'desc')
  1101. ->limit($childTextNum)
  1102. ->get();
  1103. $childTextArticles = $this->processArticles($childTextArticles, $website);
  1104. }
  1105. }
  1106. $resultItem['child'] = [
  1107. 'alias' => $childCategory ? $childCategory->alias : null,
  1108. 'category_id' => $childCategory ? $childCategory->category_id : null,
  1109. 'type' => $childCategory ? $childCategory->type : null,
  1110. 'pinyin' => $childCategory ? $childCategory->pinyin : null,
  1111. 'all_childcat' => $all_childcat ?? [],
  1112. 'imgnum' => $childImgArticles ?? [],
  1113. 'textnum' => $childTextArticles ?? [],
  1114. ];
  1115. }else{
  1116. $resultItem['child'] = [];
  1117. }
  1118. return $resultItem;
  1119. }, $data);
  1120. return Result::success($result);
  1121. // return Result::success($data);
  1122. }
  1123. /**
  1124. * 辅助方法:获取文章列表
  1125. */
  1126. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1127. {
  1128. $query = Article::where('article.status', 1)
  1129. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1130. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1131. ->where(function ($query) use ($website) {
  1132. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0 OR ignore_ids IS NULL)");
  1133. })
  1134. ->leftJoin('website_category', function($join) use ($website) {
  1135. $join->on('article.catid', '=', 'website_category.category_id')
  1136. ->where('website_category.website_id', '=', $website['website_id']);
  1137. })
  1138. ->select(
  1139. 'article.id', 'article.title', 'article.imgurl', 'article.author', 'article.updated_at',
  1140. 'article.introduce', 'article.islink', 'article.linkurl', 'article.copyfrom', 'article.cat_arr_id',
  1141. 'article.catid', 'website_category.alias as category_name'
  1142. )
  1143. ->orderBy('updated_at', 'desc')
  1144. ->limit($limit);
  1145. // 如果是图片文章,添加图片URL条件
  1146. if ($isImageArticle) {
  1147. $query->where('imgurl', '!=', '');
  1148. } else {
  1149. // 文字文章不需要imgurl字段
  1150. $query->addSelect('article.introduce');
  1151. }
  1152. $articles = $query->get();
  1153. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1154. }
  1155. /**
  1156. * 乡村网-获取特殊新闻模块
  1157. * @param array $data
  1158. * @return array
  1159. */
  1160. public function getWebsiteArticles(array $data): array
  1161. {
  1162. $input['id'] = $data['id'];
  1163. $input['website_id'] = $data['website_id'];
  1164. $data = json_decode($input['id'], true);
  1165. // 使用 array_map 处理每个元素
  1166. $result = array_map(function ($item) use ($input) {
  1167. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1168. $website = [
  1169. 'website_id' => $input['website_id']
  1170. ];
  1171. // 查询栏目名称
  1172. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  1173. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1174. if(empty($category)){
  1175. $imgArticles = [];
  1176. $textArticles = [];
  1177. // return Result::error("暂无此栏目",0);
  1178. }else{
  1179. $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1180. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin.'/' : null;
  1181. // return Result::success($website);
  1182. // 查询图片新闻
  1183. // 合并查询条件
  1184. $baseQuery = Article::where(function ($query) use ($website) {
  1185. $query->where(function ($subQuery) use ($website) {
  1186. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1187. })->orWhereNull("ignore_ids");
  1188. })
  1189. ->where('website_category.website_id', $website['website_id'])
  1190. ->where('article.status', 1)
  1191. ->leftJoin('website_category', 'website_category.category_id', 'article.catid');
  1192. // 查询文字新闻
  1193. $textArticles = clone $baseQuery;
  1194. $textArticles = $textArticles->whereIn('catid',$child_category)
  1195. ->select(
  1196. 'article.id',
  1197. 'article.title',
  1198. // 'article.imgurl',
  1199. 'article.author',
  1200. 'article.updated_at',
  1201. 'article.introduce',
  1202. 'article.islink',
  1203. 'article.linkurl',
  1204. 'article.copyfrom',
  1205. 'website_category.category_id',
  1206. 'website_category.alias',
  1207. 'website_category.aLIas_pinyin'
  1208. )
  1209. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1210. ->orderBy('article.updated_at', 'desc')
  1211. ->limit($parentTextNum)
  1212. ->get()
  1213. ->all();
  1214. if(empty($textArticles)){
  1215. $textArticles = clone $baseQuery;
  1216. $textArticles = $textArticles->where('catid',$parentCatId)
  1217. ->select(
  1218. 'article.id',
  1219. 'article.title',
  1220. // 'article.imgurl',
  1221. 'article.author',
  1222. 'article.updated_at',
  1223. 'article.introduce',
  1224. 'article.islink',
  1225. 'article.linkurl',
  1226. 'article.copyfrom',
  1227. 'website_category.category_id',
  1228. 'website_category.alias',
  1229. 'website_category.aLIas_pinyin'
  1230. )
  1231. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1232. ->orderBy('article.updated_at', 'desc')
  1233. ->limit($parentTextNum)
  1234. ->get()
  1235. ->all();
  1236. }
  1237. // 查询图片新闻
  1238. $imgArticles = clone $baseQuery;
  1239. $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid',$child_category)
  1240. ->select(
  1241. 'article.id',
  1242. 'article.title',
  1243. 'article.imgurl',
  1244. 'article.author',
  1245. 'article.updated_at',
  1246. 'article.introduce',
  1247. 'article.islink',
  1248. 'article.linkurl',
  1249. 'article.copyfrom',
  1250. 'website_category.category_id',
  1251. 'website_category.alias',
  1252. 'website_category.aLIas_pinyin'
  1253. )
  1254. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1255. ->orderBy('article.updated_at', 'desc')
  1256. ->limit($parentImgNum)
  1257. ->get()
  1258. ->all();
  1259. if(empty($imgArticles)){
  1260. $imgArticles = clone $baseQuery;
  1261. $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid',$parentCatId)
  1262. ->select(
  1263. 'article.id',
  1264. 'article.title',
  1265. 'article.imgurl',
  1266. 'article.author',
  1267. 'article.updated_at',
  1268. 'article.introduce',
  1269. 'article.islink',
  1270. 'article.linkurl',
  1271. 'article.copyfrom',
  1272. 'website_category.category_id',
  1273. 'website_category.alias',
  1274. 'website_category.aLIas_pinyin'
  1275. )
  1276. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1277. ->orderBy('article.updated_at', 'desc')
  1278. ->limit($parentImgNum)
  1279. ->get()
  1280. ->all();
  1281. }
  1282. }
  1283. $resultItem = [
  1284. 'alias' => $category ? $category->alias : null,
  1285. 'category_id' => $parentCatId,
  1286. 'pinyin' => $pinyin ? $pinyin : null,
  1287. 'imgnum' => $imgArticles ?? [],
  1288. 'textnum' => $textArticles ?? [],
  1289. ];
  1290. return $resultItem;
  1291. }, $data);
  1292. return Result::success($result);
  1293. }
  1294. // 封装处理商品的路由问题
  1295. function processGoods($goods, $data) {
  1296. return $goods->map(function ($good) use ($data) {
  1297. $catid = $good->catid ?? 0;
  1298. // $pinyin = '';
  1299. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1300. if (!empty($category->pid) && $category->pid != 0) {
  1301. $level = json_decode($category->category_arr_id);
  1302. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1303. ->whereIn('category_id', $level)
  1304. ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
  1305. ->get(['aLIas_pinyin'])
  1306. ->pluck('aLIas_pinyin')
  1307. ->implode('/');
  1308. } else {
  1309. $pinyin = $category->aLIas_pinyin ?? '';
  1310. }
  1311. if(isset($good->city_id) &&!empty($good->city_id)){
  1312. $city = District::where('id', $good->city_id)->first(['name']);
  1313. $good->city_name = $city->name ?? '';
  1314. }
  1315. // 解析imgurl JSON并取第一条数据
  1316. $imgUrls = json_decode($good->imgurl, true);
  1317. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1318. $good->pinyin = $pinyin;
  1319. return $good;
  1320. });
  1321. }
  1322. /**
  1323. * 获取商城首页-根据栏目id
  1324. * @param array $data
  1325. * @return array
  1326. * */
  1327. function getWebsiteCatidshop(array $data): array
  1328. {
  1329. $input['catid'] = $data['catid'];
  1330. $input['website_id'] = $data['website_id'];
  1331. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1332. $result = array_map(function ($item) use ($input) {
  1333. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid']!= "") {
  1334. list($catid, $goodStart,$goodNum) = explode(',', $item['catid']);
  1335. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1336. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1337. if(empty($category) || $category->type != 2){
  1338. return Result::error("暂无此栏目",0);
  1339. }else{
  1340. $website['website_id'] = $input['website_id'];
  1341. $goods = Good::where('good.status', 2)
  1342. ->where('good.website_id', $website['website_id'])
  1343. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '". intval($catid). "') = 1")
  1344. ->select('good.id', 'good.name', 'good.imgurl', 'good.description', 'good.updated_at',
  1345. 'good.catid','good.type_id','good.price','good.com','good.level','good.unit')
  1346. ->orderBy('updated_at','desc')
  1347. ->offset($goodStart)
  1348. ->limit($goodNum);
  1349. $all_goods = $goods->get();
  1350. $all_goods = $this->processGoods($all_goods, $website);
  1351. }
  1352. return $all_goods ?? [];
  1353. }
  1354. }, $data);
  1355. return Result::success($result);
  1356. }
  1357. /**
  1358. * 获取商品模块
  1359. * @param array $data
  1360. * @return array
  1361. * */
  1362. public function getWebsiteshop(array $data): array
  1363. {
  1364. $input['id'] = $data['id'];
  1365. $input['website_id'] = $data['website_id'];
  1366. $catid = $data['catid'];
  1367. $data = json_decode($input['id'] ?? '', true) ?? [];
  1368. $result['goods'] = array_map(function ($item) use ($input) {
  1369. // 检查parent元素是否存在且不是undefined
  1370. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level']!= "") {
  1371. list($Levelid, $goodStart,$goodNum) = explode(',', $item['level']);
  1372. $website = $input['website_id'];
  1373. $query = Good::where('good.status', 2)
  1374. ->where('good.website_id', $website);
  1375. switch ($Levelid) {
  1376. case 1:
  1377. case 2:
  1378. case 3:
  1379. $goods = $query->where(function($q) use ($Levelid) {
  1380. $q->whereRaw("JSON_CONTAINS(good.level, '". intval($Levelid). "') = 1")
  1381. ->orWhereRaw("JSON_CONTAINS(good.level, '\"". intval($Levelid). "\"') = 1");
  1382. });
  1383. break;
  1384. case 4:
  1385. $goods = $query;
  1386. break;
  1387. case 5:
  1388. $goods = $query->where('type_id',1);
  1389. break;
  1390. case 6:
  1391. $goods = $query->where('type_id',2);
  1392. break;
  1393. default:
  1394. return [];
  1395. }
  1396. $all_goods = $goods
  1397. ->select('good.id', 'good.name', 'good.imgurl', 'good.description',
  1398. 'good.updated_at', 'good.catid','good.type_id','good.price','good.level',
  1399. 'good.website_id')
  1400. ->orderBy('updated_at','desc')
  1401. ->offset($goodStart)
  1402. ->limit($goodNum)
  1403. ->get();
  1404. $web['website_id'] = $website;
  1405. $all_goods = $this->processGoods($all_goods, $web);
  1406. }
  1407. return $all_goods;
  1408. }, $data);
  1409. $website = $input['website_id'];
  1410. $result['article'] = Article::where(function ($query) use ($website) {
  1411. $query->where(function ($subQuery) use ($website) {
  1412. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  1413. })->orWhereNull("ignore_ids");
  1414. })
  1415. ->where('catid', $catid)
  1416. ->where('article.status', 1)
  1417. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  1418. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl','article_data.content')
  1419. ->orderBy('article.updated_at', 'desc')
  1420. ->first();
  1421. return Result::success($result);
  1422. }
  1423. /**
  1424. * 获取商品分类
  1425. * @param array $data
  1426. * @return array
  1427. * */
  1428. public function getWebsiteshopCat(array $data): array
  1429. {
  1430. $website = $data['website_id'];
  1431. $category = WebsiteCategory::where('website_id', $website)
  1432. ->whereRaw("JSON_CONTAINS(category_arr_id, '". intval($data['id']). "') = 1")
  1433. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"". intval($data['id']). "\"') = 1")
  1434. ->select('category_id', 'alias','aLIas_pinyin','pid','category_arr_id' ,'sort')
  1435. ->orderBy('sort')
  1436. ->get();
  1437. $cat = $category->map(function ($item) use ($website) {
  1438. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  1439. $pid = $item->pid?? 0;
  1440. if(!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0){
  1441. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  1442. ->where('website_id', $website)
  1443. ->orderByRaw('FIELD(category_id, '. implode(',', $cat_arr_id). ')')
  1444. ->get(['aLIas_pinyin'])
  1445. ->pluck('aLIas_pinyin')
  1446. ->implode('/');
  1447. }else{
  1448. $pinyin = $item->aLIas_pinyin ?? '';
  1449. }
  1450. $item->pinyin = $pinyin;
  1451. });
  1452. if(empty($category)){
  1453. return Result::error("栏目查询失败", 0);
  1454. }
  1455. $cat_tree = Result::buildMenuTree($category);
  1456. $web['website_id'] = $website;
  1457. $goods = Good::where('website_id', $website)
  1458. ->where('status', 2)
  1459. ->select('good.id as good_id', 'name','imgurl','description','updated_at','catid','type_id','website_id')
  1460. ->latest('updated_at')
  1461. ->offset(($data['page']-1)*$data['pageSize'])
  1462. ->limit($data['pageSize'])
  1463. ->get();
  1464. if(!empty($goods)){
  1465. if($goods->count() > 1 && !empty($goods)){
  1466. $goods = $this->processGoods($goods, $web);
  1467. }
  1468. }else{
  1469. $goods = [];
  1470. }
  1471. $result = [
  1472. 'category' => $cat_tree,
  1473. 'goods' => $goods,
  1474. ];
  1475. // $resul['goods'] = $goods;
  1476. if(empty($result)){
  1477. return Result::error("查询失败", 0);
  1478. }
  1479. return Result::success($result);
  1480. }
  1481. /*
  1482. * 获取商品列表
  1483. * @param array $data
  1484. * @return array
  1485. * */
  1486. public function getWebsiteshopList(array $data): array
  1487. {
  1488. // return Result::success($data);
  1489. $where = [
  1490. 'status' => 2,
  1491. 'website_id' => $data['website_id'],
  1492. ];
  1493. if((empty($data['catid']) ||!isset($data['catid'])) && (empty($data['keyword']) ||!isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))){
  1494. return Result::error("查询失败", 0);
  1495. }
  1496. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  1497. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid',$data['id'])->orderBy('sort')->first(['category_id']);
  1498. $data['catid'] = $category->category_id ?? 0;
  1499. }
  1500. if(isset($data['keyword']) &&!empty($data['keyword'])){
  1501. array_push($where, ['name', 'like', '%'. $data['keyword'].'%']);
  1502. }
  1503. if(isset($data['type_id']) && !empty($data['type_id'])){
  1504. array_push($where, ['type_id', $data['type_id']]);
  1505. }
  1506. $query = Good::where($where)
  1507. ->when(isset($data['catid']) &&!empty($data['catid']), function ($query) use ($data) {
  1508. $query->where(function($q) use ($data) {
  1509. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '". intval($data['catid']). "') = 1")
  1510. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"". intval($data['catid']). "\"') = 1");
  1511. });
  1512. })
  1513. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  1514. $query->where(function($q) use ($data) {
  1515. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '". intval($data['city_id']). "') = 1")
  1516. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"". intval($data['city_id']). "\"') = 1");
  1517. });
  1518. })
  1519. ->select('good.id', 'good.name', 'good.imgurl', 'good.description', 'good.updated_at', 'good.com',
  1520. 'good.catid','good.type_id','good.website_id','good.cat_arr_id','good.created_at','good.city_id')
  1521. ->latest('updated_at');
  1522. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  1523. // 获取 type_id 为 1 的数据
  1524. $result['type1'] = $this->processGoods(
  1525. $query->clone()
  1526. ->where('type_id', 1)
  1527. ->offset(($data['page'] - 1) * $data['pageSize'])
  1528. ->limit($data['pageSize'])
  1529. ->get(),
  1530. $data
  1531. );
  1532. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  1533. // 获取 type_id 为 2 的数据
  1534. $result['type2'] = $this->processGoods(
  1535. $query->clone()
  1536. ->where('type_id', 2)
  1537. ->offset(($data['page'] - 1) * $data['pageSize'])
  1538. ->limit($data['pageSize'])
  1539. ->get(),
  1540. $data
  1541. );
  1542. if(empty($result)){
  1543. return Result::error("查询失败", 0);
  1544. }
  1545. return Result::success($result);
  1546. }
  1547. /**
  1548. * 获取商品详情
  1549. * @param array $data
  1550. * @return array
  1551. * */
  1552. public function getWebsiteshopInfo(array $data): array
  1553. {
  1554. $where = [
  1555. 'good.status' => 2,
  1556. 'good.website_id' => $data['website_id'],
  1557. 'good.id' => $data['id'],
  1558. ];
  1559. $goods = Good::where($where)
  1560. ->where('good.id', $data['id'])
  1561. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  1562. ->select('good.*','website_category.alias','website_category.category_id')
  1563. ->first();
  1564. if(empty($goods)){
  1565. return Result::error("查询失败", 0);
  1566. }
  1567. $goods->imgurl = json_decode($goods->imgurl, true);
  1568. return Result::success($goods);
  1569. }
  1570. /**
  1571. * 封装处理文章的路由问题
  1572. * */
  1573. function processArticles($articles, $data) {
  1574. // 检查 $articles 是否为数组或可迭代对象
  1575. if (is_array($articles) || is_iterable($articles) &&!empty($articles)) {
  1576. return $articles->map(function ($article) use ($data) {
  1577. if(isset($article->cat_arr_id) &&!empty($article->cat_arr_id)){
  1578. $catid = $article->cat_arr_id?? '';
  1579. }
  1580. if(isset($article->category_arr_id) &&!empty($article->category_arr_id)){
  1581. $catid = $article->category_arr_id?? '';
  1582. }
  1583. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  1584. $level = json_decode($catid, true);
  1585. if (!is_array($level)) {
  1586. return $article;
  1587. } else {
  1588. $level = array_map('intval', $level);
  1589. }
  1590. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1591. ->where($data)
  1592. ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
  1593. ->pluck('aLIas_pinyin')
  1594. ->implode('/');
  1595. $article->pinyin = $pinyin ?? '';
  1596. return $article;
  1597. });
  1598. } else {
  1599. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  1600. $catid = $articles->cat_arr_id?? '';
  1601. $level = json_decode($catid, true);
  1602. if (!is_array($level)) {
  1603. return $articles;
  1604. } else {
  1605. $level = array_map('intval', $level);
  1606. }
  1607. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1608. ->where($data)
  1609. ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
  1610. ->pluck('aLIas_pinyin')
  1611. ->implode('/');
  1612. $articles->pinyin = $pinyin ?? '';
  1613. return $articles;
  1614. }
  1615. }
  1616. // 封装处理由问题
  1617. function processJob($job, $data) {
  1618. return $job->map(function ($job) use ($data) {
  1619. $category = $job->cat_arr_id?? '';
  1620. $cityid = $job->city_arr_id?? '';
  1621. $city = json_decode($cityid, true);
  1622. $pinyin = '';
  1623. $level = json_decode($category, true);
  1624. // 路由
  1625. if(!empty($level) && is_array($level)){
  1626. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1627. ->where('website_id', $data['website_id']) // 添加网站ID条件
  1628. ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
  1629. ->get(['aLIas_pinyin'])
  1630. ->pluck('aLIas_pinyin')
  1631. ->implode('/');
  1632. if(empty($pinyin)){
  1633. $pinyin = $pinyin->aLIas_pinyin?? '';
  1634. }
  1635. $job->pinyin = $pinyin;
  1636. }
  1637. // 取职位-城市 市??省
  1638. if(!empty($city) && is_array($city)){
  1639. if(isset($city[1] ) && !empty($city[1])){
  1640. $city = District::where('id', $city[1])->first(['name']);
  1641. $job->city_name = $city->name?? '';
  1642. }else if(isset($city[0] ) && !empty($city[0])){
  1643. $city = District::where('id', $city[0])->first(['name']);
  1644. $job->city_name = $city->name?? '';
  1645. }else{
  1646. $job->city_name = '全国';
  1647. }
  1648. }
  1649. // 获取简历最后一级地区
  1650. if(isset($job->city_id) &&!empty($job->city_id)){
  1651. $city = District::where('id', $job->city_id)->first(['name']);
  1652. $job->hunt_cityname = $city->name?? '';
  1653. }
  1654. // 组合详细地址
  1655. if(isset($job->address_arr_id) && !empty($job->address_arr_id)){
  1656. $address_id = json_decode($job->address_arr_id, true) ?? [];
  1657. if(is_array($address_id) && !empty($address_id)){
  1658. $address = District::whereIn('id', $address_id)
  1659. ->orderBy('level', 'asc')
  1660. ->get(['name'])
  1661. ->pluck('name')
  1662. ->implode('');
  1663. // $job->address_name = $address ?? '';
  1664. $job->address_name = ($address ?? '') . ($job->address ?? '');
  1665. }
  1666. }
  1667. // 取行业
  1668. if(!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))){
  1669. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  1670. if(!empty($job->industry)){
  1671. $query->where('hyid', $job->industry);
  1672. }else if(!empty($job->hy_id)){
  1673. $query->where('hyid', $job->hy_id);
  1674. }else if(!empty($job->company_hy_id)){
  1675. $query->where('hyid', $job->company_hy_id);
  1676. } else{
  1677. $query->where('hyid', $job->job_industry);
  1678. }
  1679. })->first(['hyname']);
  1680. $job->hy_name = $hy_name->hyname?? '';
  1681. }
  1682. // 取职位类别
  1683. if((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))){
  1684. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  1685. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  1686. $job->zw_name = $zw_name->zwname?? '';
  1687. }
  1688. // 取具体职位
  1689. if((isset($job->jtzw_id) &&!empty($job->jtzw_id)) || (isset($job->job_name_get) && !empty($job->job_name_get)) || (isset($job->job_name) && !empty($job->job_name))){
  1690. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  1691. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  1692. $job->jtzw_name = $jtzw_name->zwname?? '';
  1693. }
  1694. // 取工作经验
  1695. if(isset($job->experience) &&!empty($job->experience)){
  1696. $experience = JobEnum::where('egroup','years')->where('evalue',$job->experience)->first(['ename']);
  1697. $job->experience_name = $experience->ename?? '';
  1698. }
  1699. // 取学历
  1700. if(isset($job->educational) &&!empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  1701. $education = $job->educational ?? $job->school_education;
  1702. $education = JobEnum::where('egroup','education')->where('evalue',$education)->first(['ename']);
  1703. $job->education_name = $education->ename?? '';
  1704. }
  1705. // 语言
  1706. if(isset($job->language) &&!empty($job->language)){
  1707. $language = JobEnum::where('egroup','language')->where('evalue',$job->language)->first(['ename']);
  1708. $job->language_name = $language->ename?? '';
  1709. }
  1710. // 薪资
  1711. if(isset($job->salary) &&!empty($job->salary)){
  1712. $salary = JobEnum::where('egroup','income')->where('evalue',$job->salary)->first(['ename']);
  1713. $job->salary_name = $salary->ename?? '';
  1714. }
  1715. // 职位性质
  1716. if(isset($job->nature_id) &&!empty($job->nature_id)){
  1717. $job_nature = JobEnum::where('egroup','nature')->where('evalue',$job->nature_id)->first(['ename']);
  1718. $job->job_nature_name = $job_nature->ename?? '';
  1719. }
  1720. // 公司规模
  1721. if(isset($job->company_size) &&!empty($job->company_size)){
  1722. $company_size = JobEnum::where('egroup','cosize')->where('evalue',$job->company_size)->first(['ename']);
  1723. $job->company_size_name = $company_size->ename?? '';
  1724. }
  1725. // 公司性质
  1726. if(isset($job->company_nature) && !empty($job->company_nature)){
  1727. $company_nature = JobNature::where('id',$job->company_nature)->first(['nature_name']);
  1728. $job->company_nature_name = $company_nature->nature_name?? '';
  1729. }
  1730. // $job->pinyin = $pinyin;
  1731. return $job;
  1732. });
  1733. }
  1734. /**
  1735. * 获取书籍模块
  1736. * @param array $data
  1737. * @return array
  1738. * */
  1739. public function getWebsiteBook(array $data): array
  1740. {
  1741. $input['id'] = $data['id'];
  1742. $input['website_id'] = $data['website_id'];
  1743. // 将 JSON 字符串转换为 PHP 数组
  1744. $data = json_decode($input['id'], true);
  1745. // 使用 array_map 处理每个元素
  1746. $result = array_map(function ($item) use ($input) {
  1747. // 检查parent元素是否存在且不是undefined
  1748. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent']!= "") {
  1749. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1750. $website = [
  1751. 'website_id' => $input['website_id'],
  1752. ];
  1753. // 查询栏目名称
  1754. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  1755. if(empty($category)){
  1756. $parent_alias = '';
  1757. $parent_pinyin = null;
  1758. $imgBooks = [];
  1759. $textBooks = [];
  1760. }else{
  1761. $parent_alias = $category->alias ?? '';
  1762. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1763. // 查找子分类ID数组
  1764. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1765. array_push($childCategoryIds,$parentCatId);
  1766. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  1767. if($parentImgNum!=0){
  1768. // 查询图片新闻
  1769. $imgBooks = Book::where(function($query) use ($parentCatId) {
  1770. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  1771. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  1772. })
  1773. ->where('book.status', 2)
  1774. ->where('book.img_url', '!=', '')
  1775. ->leftJoin('website_category', function($join) use ($website) {
  1776. $join->on('book.cat_id', '=', 'website_category.category_id')
  1777. ->where('website_category.website_id', '=', $website['website_id']);
  1778. })
  1779. ->select(
  1780. 'book.id',
  1781. 'book.title',
  1782. 'book.img_url',
  1783. 'book.price',
  1784. 'book.market_price',
  1785. 'book.description',
  1786. 'book.cat_id',
  1787. 'book.description',
  1788. 'book.updated_at',
  1789. 'website_category.alias as category_name',
  1790. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  1791. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  1792. )
  1793. ->orderBy('updated_at', 'desc')
  1794. ->limit($parentImgNum)
  1795. ->get()->all();
  1796. // 查询文字新闻
  1797. }
  1798. if($parentTextNum!=0){
  1799. $textBooks = [];
  1800. $textBooks = Book::where(function($query) use ($parentCatId) {
  1801. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  1802. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  1803. })
  1804. ->where('book.status', 2)
  1805. ->leftJoin('website_category', function($join) use ($website) {
  1806. $join->on('book.cat_id', '=', 'website_category.category_id')
  1807. ->where('website_category.website_id', '=', $website['website_id']);
  1808. })
  1809. ->select(
  1810. 'book.id',
  1811. 'book.title',
  1812. 'book.img_url',
  1813. 'book.price',
  1814. 'book.market_price',
  1815. 'book.description',
  1816. 'book.cat_id',
  1817. 'book.description',
  1818. 'book.updated_at',
  1819. 'website_category.alias as category_name',
  1820. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  1821. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  1822. )
  1823. ->orderBy('updated_at', 'desc')
  1824. ->limit($parentTextNum)
  1825. ->get()->all();
  1826. }
  1827. }
  1828. }
  1829. $resultItem = [
  1830. 'alias' => $parent_alias ?? '',
  1831. 'category_id' => $parentCatId ?? 0,
  1832. 'pinyin' => $parent_pinyin ?? null,
  1833. 'imgnum' => $imgBooks ?? [],
  1834. 'textnum' => $textBooks ?? [],
  1835. ];
  1836. if(isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != ""){
  1837. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin.'/' : '';
  1838. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  1839. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1840. ->get()->all();
  1841. if (!empty($childCategory)) {
  1842. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  1843. // 查询子栏目名称
  1844. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  1845. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1846. ->first();
  1847. if(empty($childCategoryInfo) || ($childImgNum==0 && $childTextNum==0)){
  1848. $childImgArticles = [];
  1849. $childTextArticles = [];
  1850. $resultItem['child'] = [];
  1851. }else{
  1852. $child_pinyin = $childCategoryInfo->aLIas_pinyin? $childCategoryInfo->aLIas_pinyin : null;
  1853. // 查询子栏目图片新闻
  1854. $childImgArticles = Book::where('cat_id', $childCatId)
  1855. ->where('status', 2)
  1856. ->where('img_url', '!=', '')
  1857. ->leftJoin('website_category', function($join) use ($website) {
  1858. $join->on('book.cat_id', '=', 'website_category.category_id')
  1859. ->where('website_category.website_id', '=', $website['website_id']);
  1860. })
  1861. ->select(
  1862. 'book.id',
  1863. 'book.title',
  1864. 'book.img_url',
  1865. 'book.price',
  1866. 'book.market_price',
  1867. 'book.description',
  1868. 'book.cat_id',
  1869. 'book.description',
  1870. 'book.updated_at',
  1871. DB::raw("'$child_pinyin' as pinyin"))
  1872. ->orderBy('updated_at', 'desc')
  1873. ->limit($childImgNum)
  1874. ->get()->all();
  1875. // 查询子栏目文字新闻
  1876. $childTextArticles = Book::where('cat_id', $childCatId)
  1877. ->where('status', 2)
  1878. ->leftJoin('website_category', function($join) use ($website) {
  1879. $join->on('book.cat_id', '=', 'website_category.category_id')
  1880. ->where('website_category.website_id', '=', $website['website_id']);
  1881. })
  1882. ->select(
  1883. 'book.id',
  1884. 'book.title',
  1885. 'book.img_url',
  1886. 'book.price',
  1887. 'book.market_price',
  1888. 'book.description',
  1889. 'book.cat_id',
  1890. 'book.description',
  1891. 'book.updated_at',
  1892. DB::raw("'$child_pinyin' as pinyin"))
  1893. ->orderBy('updated_at', 'desc')
  1894. ->limit($childTextNum)
  1895. ->get()->all();
  1896. $resultItem['child'] = [
  1897. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  1898. 'category_id' => $childCatId,
  1899. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  1900. 'all_childcat' => $childCategory,
  1901. 'imgnum' => $childImgArticles,
  1902. 'textnum' => $childTextArticles,
  1903. ];
  1904. }
  1905. }
  1906. }else{
  1907. $resultItem['child'] = [];
  1908. }
  1909. return $resultItem;
  1910. }, $data);
  1911. return Result::success($result);
  1912. }
  1913. /**
  1914. * 获取书刊列表
  1915. * @param array $data
  1916. * @return array
  1917. * */
  1918. public function getWebsiteBookList(array $data): array
  1919. {
  1920. $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
  1921. if(empty($web)){
  1922. return Result::error("查询失败", 0);
  1923. }
  1924. $catid = $data['id'];
  1925. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id',$catid)->orderBy('sort')->first(['pid','category_id','aLias_pinyin']);
  1926. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id',$category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  1927. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  1928. $category_pinyin = $category ? $category->aLias_pinyin : '';
  1929. $pinyin =$category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '' ;
  1930. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  1931. ->where('pid',$category['pid'])
  1932. ->select(
  1933. 'category_id','alias','aLIas_pinyin','pid','sort','is_url','web_url',
  1934. 'seo_title','seo_keywords','seo_description',
  1935. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  1936. )
  1937. ->orderBy('sort')
  1938. ->get()->all();
  1939. if(empty($category)){
  1940. return Result::error("查询失败", 0);
  1941. }
  1942. $query = Book::where('book.status', 2)
  1943. ->where('book.website_id', $data['website_id'])
  1944. ->where('book.cat_id', $catid)
  1945. ->select(
  1946. 'book.id',
  1947. 'book.title',
  1948. 'book.img_url',
  1949. 'book.description',
  1950. 'book.updated_at',
  1951. 'book.cat_id',
  1952. DB::raw("'$pinyin' as pinyin")
  1953. )
  1954. ->orderBy('book.updated_at', 'desc');
  1955. $count = $query->count();
  1956. $query = clone $query;
  1957. $Book = $query
  1958. ->limit($data['pageSize'])
  1959. ->offset(($data['page']-1)*$data['pageSize'])
  1960. ->get()->all();
  1961. $result = [
  1962. 'category' => $categorys,
  1963. 'books' => $Book,
  1964. 'count' =>$count,
  1965. ];
  1966. // if(empty($result)){
  1967. // return Result::error("查询失败", 0);
  1968. // }
  1969. return Result::success($result);
  1970. }
  1971. /**
  1972. * 获取书刊详情
  1973. * @param array $data
  1974. * @return array
  1975. * */
  1976. public function getWebsiteBookInfo(array $data): array
  1977. {
  1978. $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
  1979. if(empty($web)){
  1980. return Result::error("查询失败", 0);
  1981. }
  1982. $book = Book::where('status', 2)
  1983. ->where('website_id', $data['website_id'])
  1984. ->where('id', $data['id'])
  1985. ->select(
  1986. 'book.*',
  1987. )
  1988. ->orderBy('updated_at', 'desc')
  1989. ->first();
  1990. if(empty($book)){
  1991. return Result::error("查询失败", 0);
  1992. }
  1993. // 先查询当前分类的 pid
  1994. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  1995. ->where('category_id', $book['cat_id'])
  1996. ->first(['pid','category_id']);
  1997. $query = WebsiteCategory::where('website_id', $data['website_id']);
  1998. if(!empty($carpid)){
  1999. if($carpid->pid!=0){
  2000. $pid = $carpid['pid'];
  2001. // $parent_pinyin = '';
  2002. }else{
  2003. $pid = $carpid['category_id'];
  2004. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2005. }
  2006. }
  2007. $categorys = $query->where('pid', $pid)
  2008. ->select('category_id','alias','aLIas_pinyin','pid','sort','is_url','web_url','category_arr_id as cat_arr_id',
  2009. )
  2010. ->orderBy('sort')
  2011. ->get();
  2012. $category = $this->processArticle($categorys, $data);
  2013. $result = [
  2014. 'category' => $category,
  2015. 'books' => $book,
  2016. ];
  2017. return Result::success($result);
  2018. }
  2019. /**
  2020. * 尝试
  2021. * @param array $data
  2022. * @return array
  2023. * */
  2024. public function test(array $data): array
  2025. {
  2026. $input['id'] = $data['id'];
  2027. $input['website_id'] = $data['website_id'];
  2028. // 将 JSON 字符串转换为 PHP 数组
  2029. $data = json_decode($input['id'], true);
  2030. $result = [];
  2031. $article = $data;
  2032. $result = array_map(function ($item) use ($input) {
  2033. $website = [
  2034. 'website_id' => $input['website_id'],
  2035. ];
  2036. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2037. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  2038. $parent = [
  2039. 0 => $category['category_id'] ?? [],
  2040. 1 => $parentImgNum?? [],
  2041. 2 => $parentTextNum?? [],
  2042. ];
  2043. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2044. $child = [];
  2045. $resultItem = [
  2046. // 'alias' => $parent_alias ?? '',
  2047. 'category_id' => $parentCatId ?? 0,
  2048. 'pinyin' => $parentImgNum ?? null,
  2049. 'imgnum' => $parentTextNum ?? [],
  2050. // 'textnum' => $textArticles ?? [],
  2051. ]; return $parent;
  2052. }, $data);
  2053. return Result::success($result);
  2054. // });
  2055. }
  2056. /**
  2057. * 封装处理文章的路由问题
  2058. * */
  2059. function processArticle($article, $data) {
  2060. return $article->map(function ($article) use ($data) {
  2061. $catid = $article->cat_arr_id?? '';
  2062. $level = json_decode($catid, true);
  2063. $pinyin = '';
  2064. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2065. if (!empty($level) && is_array($level)) {
  2066. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2067. ->where('website_id', $data['website_id'])
  2068. ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
  2069. ->get(['aLIas_pinyin'])
  2070. ->pluck('aLIas_pinyin')
  2071. ->implode('/');
  2072. } else {
  2073. $pinyin = '';
  2074. }
  2075. $article->pinyin = $pinyin;
  2076. return $article;
  2077. });
  2078. }
  2079. /**
  2080. * c端-获取招工招聘下拉选框
  2081. * @param array $data
  2082. * @return array
  2083. * */
  2084. public function getWebsiteJobSelect(array $data): array
  2085. {
  2086. $web = Website::where('id', $data['website_id'])->first();
  2087. if(empty($web)){
  2088. return Result::error("该网站不存在", 0);
  2089. }
  2090. $hy = JobIndustry::get()->all();
  2091. $zw = JobPosition::where('zwpid',0)->get()->all();
  2092. $jtzw = JobPosition::where('zwpid','!=',0)->get()->all();
  2093. $result = [
  2094. 'hy' => $hy,
  2095. 'zw' => $zw,
  2096. 'jtzw' => $jtzw,
  2097. ];
  2098. if(empty($result)){
  2099. return Result::error("查询失败", 0);
  2100. }
  2101. return Result::success($result);
  2102. }
  2103. /**
  2104. * c端-获取招工招聘
  2105. * @param array $data
  2106. * @return array
  2107. * */
  2108. public function getWebsiteJob(array $data): array
  2109. {
  2110. $web = Website::where('id', $data['website_id'])->first();
  2111. if(empty($web)){
  2112. return Result::error("该网站不存在", 0);
  2113. }
  2114. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2115. ->where('job_hunting.website_id', $data['website_id'])
  2116. ->when(isset($data['city_id']) &&!empty($data['city_id']), function ($query) use ($data) {
  2117. $query->where(function($q) use ($data) {
  2118. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '". intval($data['city_id']). "') = 1");
  2119. });
  2120. })
  2121. ->select('job_hunting.id','job_hunting.cat_arr_id','job_hunting.job_name_get','job_hunting.industry','job_hunting.name','job_hunting.sexy'
  2122. ,'job_hunting.origin','job_hunting.city_arr_id','job_hunting.experience','job_hunting.updated_at','job_hunting.salary')
  2123. ->orderBy('updated_at', 'desc')
  2124. ->limit($data['job1_num'])
  2125. ->get();
  2126. $web['website_id'] = $data['website_id'];
  2127. if(empty($job_hunting)){
  2128. $job_huntings = "未查询到相关简历信息";
  2129. }else{
  2130. $job_huntings = $this->processJob($job_hunting, $web);
  2131. }
  2132. // 0:待审核 1:已通过 2:已拒绝
  2133. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2134. ->where('job_recruiting.website_id', $data['website_id'])
  2135. ->when(isset($data['city_id']) &&!empty($data['city_id']), function ($query) use ($data) {
  2136. $query->where(function($q) use ($data) {
  2137. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '". intval($data['city_id']). "') = 1");
  2138. });
  2139. })
  2140. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2141. ->select('job_recruiting.id','job_recruiting.cat_arr_id','job_recruiting.title',
  2142. 'job_recruiting.jtzw_id','job_recruiting.hy_id','job_recruiting.city_arr_id',
  2143. 'job_recruiting.due_data','job_recruiting.updated_at','job_recruiting.experience',
  2144. 'job_recruiting.educational','job_recruiting.salary','job_recruiting.zw_id','job_company.business_name')
  2145. ->orderBy('updated_at', 'desc')
  2146. ->limit($data['job2_num'])
  2147. ->get();
  2148. if(empty($job_recruiting->toArray())){
  2149. $job_recruitings = "未查询到相关职位信息";
  2150. }else{
  2151. $job_recruitings = $this->processJob($job_recruiting, $web);
  2152. }
  2153. $result = [
  2154. 'job_hunting' => $job_huntings,
  2155. 'job_recuiting' => $job_recruitings,
  2156. ];
  2157. return Result::success($result);
  2158. }
  2159. /**
  2160. * c端-获取招工招聘列表
  2161. * @param array $data
  2162. * @return array
  2163. * */
  2164. public function getWebsiteJobList(array $data): array
  2165. {
  2166. $recruit_where = [];
  2167. $hunt_where = [];
  2168. $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
  2169. if(empty($web)){
  2170. return Result::error("此网站不存在", 0);
  2171. }
  2172. $website_id['website_id'] = $data['website_id'];
  2173. if((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])){
  2174. if(isset($data['zw_id']) && !empty($data['zw_id'])){
  2175. array_push($recruit_where, ['zw_id',$data['zw_id']]);
  2176. }
  2177. if(isset($data['jtzw_id']) &&!empty($data['jtzw_id'])){
  2178. array_push($recruit_where, ['jtzw_id',$data['jtzw_id']]);
  2179. }
  2180. if(isset($data['hy_id']) && !empty($data['hy_id'])){
  2181. array_push($recruit_where, ['hy_id',$data['hy_id']]);
  2182. }
  2183. $query = JobRecruiting::where('job_recruiting.status', 1)
  2184. ->where('job_recruiting.website_id', $data['website_id'])
  2185. ->where($recruit_where)
  2186. ->when(isset($data['city_id']) &&!empty($data['city_id']), function ($query) use ($data) {
  2187. $query->where(function($q) use ($data) {
  2188. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '". intval($data['city_id']). "') = 1");
  2189. });
  2190. })
  2191. ->when(isset($data['catid']) &&!empty($data['catid']), function ($query) use ($data) {
  2192. $query->where(function($q) use ($data) {
  2193. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '". intval($data['catid']). "') = 1");
  2194. });
  2195. })
  2196. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2197. ->select('job_recruiting.id','job_recruiting.hy_id','job_recruiting.title','job_recruiting.zw_id','job_recruiting.educational',
  2198. 'job_recruiting.jtzw_id','job_recruiting.city_arr_id','job_recruiting.due_data','job_recruiting.experience',
  2199. 'job_recruiting.cat_arr_id','job_recruiting.updated_at','job_company.business_name')
  2200. ->orderBy('updated_at', 'desc');
  2201. $recruit_count = $query->count();
  2202. $query = clone $query;
  2203. $JobRecruiting = $query
  2204. ->offset(($data['page']-1)*$data['pageSize'])
  2205. ->limit($data['pageSize'])
  2206. ->get();
  2207. if(empty($JobRecruiting)){
  2208. $JobRecruiting = "暂无相关职位信息";
  2209. }else{
  2210. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2211. }
  2212. }
  2213. if((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])){
  2214. if(isset($data['zw_id']) && !empty($data['zw_id'])){
  2215. array_push($hunt_where, ['job',$data['zw_id']]);
  2216. }
  2217. if(isset($data['jtzw_id']) &&!empty($data['jtzw_id'])){
  2218. array_push($hunt_where, ['job_name_get',$data['jtzw_id']]);
  2219. }
  2220. if(isset($data['hy_id']) && !empty($data['hy_id'])){
  2221. array_push($hunt_where, ['industry',$data['hy_id']]);
  2222. }
  2223. $query = JobHunting::where('status', 2)
  2224. ->where('job_hunting.website_id', $data['website_id'])
  2225. ->where($hunt_where)
  2226. ->when(isset($data['city_id']) &&!empty($data['city_id']), function ($query) use ($data) {
  2227. $query->where(function($q) use ($data) {
  2228. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '". intval($data['city_id']). "') = 1");
  2229. });
  2230. })
  2231. ->when(isset($data['catid_id']) &&!empty($data['catid_id']), function ($query) use ($data) {
  2232. $query->where(function($q) use ($data) {
  2233. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '". intval($data['catid_id']). "') = 1");
  2234. });
  2235. })
  2236. ->select('id','sexy','experience','origin','industry','name','job','job_name_get','city_arr_id','cat_arr_id','created_at','updated_at')
  2237. ->orderBy('updated_at', 'desc');
  2238. $hunt_count = $query->count();
  2239. $query = clone $query;
  2240. $JobHunting = $query
  2241. ->offset(($data['page']-1)*$data['pageSize'])
  2242. ->limit($data['pageSize'])
  2243. ->get();
  2244. if(empty($JobHunting)){
  2245. $JobRecruiting = "暂无相关简历信息";
  2246. }else{
  2247. $JobHunting = $this->processJob($JobHunting, $website_id);
  2248. }
  2249. }
  2250. $result = [
  2251. 'JobRecruiting' => $JobRecruiting ?? [],
  2252. 'recruit_count' =>$recruit_count ?? 0,
  2253. 'JobHunting' => $JobHunting ?? [],
  2254. 'hunt_count' =>$hunt_count ?? 0,
  2255. ];
  2256. return Result::success($result);
  2257. }
  2258. /**
  2259. * c端-获取招工招聘详情
  2260. * @param array $data
  2261. * @return array
  2262. * */
  2263. public function getWebsiteJobInfo(array $data): array
  2264. {
  2265. $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
  2266. if(empty($web)){
  2267. return Result::error("该网站不存在", 0);
  2268. }
  2269. $webid = [
  2270. 'website_id' => $data['website_id'],
  2271. ];
  2272. // 职位相关信息
  2273. if($data['type']==1){
  2274. $query = JobRecruiting::where('status', 1)
  2275. ->where('website_id', $data['website_id'])
  2276. ->select('*');
  2277. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2278. $company = JobCompany::where('job_id', $data['id'])->select('id','business_name','company_hy_id','company_size','company_nature','address_arr_id','address','job_company.email')->get();
  2279. if(!empty($company)){
  2280. $result['company'] = $this->processJob($company, $webid);
  2281. }
  2282. $other_job =JobRecruiting::where('status', 1)
  2283. ->where('website_id', $data['website_id'])
  2284. ->select('title','id','updated_at','cat_arr_id','user_id')
  2285. ->where('id','!=',$data['id'])
  2286. ->where('user_id', '=', $job[0]['user_id'])
  2287. ->limit($data['pageSize'])
  2288. ->get();
  2289. if(!empty($other_job)){
  2290. $result['other_job'] = $this->processJob($other_job, $webid);
  2291. }
  2292. }else{
  2293. // 简历相关信息
  2294. $job = JobHunting::where('job_hunting.status', 2)
  2295. ->where('job_hunting.website_id', $data['website_id'])
  2296. ->where('job_hunting.id', $data['id'])
  2297. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2298. ->select('job_hunting.*','user_name')
  2299. ->get();
  2300. $resume = JobRemuse::where('hunt_id',$data['id'])->get();
  2301. if(!empty($resume->toArray())){
  2302. $result['resume'] = 1;
  2303. } else{
  2304. $result['resume'] = 0;
  2305. }
  2306. }
  2307. if(empty($job->toArray())){
  2308. return Result::error("id参数错误", 0);
  2309. }
  2310. if(!empty($job[0]['job_experience'])){
  2311. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  2312. if(!empty($job_experience)){
  2313. // $hy = [];
  2314. foreach($job_experience as $key => $value){
  2315. // $id = $value['id'];
  2316. $hy[$key] = $value['job_industry'];
  2317. $zw_id[$key] = $value['job_typename'];
  2318. $jtzw_id[$key] = $value['job_name'];
  2319. }
  2320. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid','hyname')->get();
  2321. $zw_table = JobPosition::select('zwid','zwname')->get();
  2322. // 先将关联表转换为索引数组,提高查找效率
  2323. $hyLookup = [];
  2324. foreach ($hy_table as $item) {
  2325. $hyLookup[$item['hyid']] = $item['hyname'];
  2326. }
  2327. $zwLookup = [];
  2328. foreach ($zw_table as $item) {
  2329. $zwLookup[$item['zwid']] = $item['zwname'];
  2330. }
  2331. foreach ($job_experience as $key => &$value) {
  2332. // 处理行业名称
  2333. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  2334. $value['hy_name'] = $hyLookup[$hy[$key]];
  2335. }
  2336. // 处理职位名称
  2337. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  2338. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  2339. }
  2340. // 处理具体职位名称
  2341. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  2342. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  2343. }
  2344. }
  2345. // 释放引用,防止意外修改后续代码
  2346. unset($value);
  2347. }
  2348. $result['job_experience'] = $job_experience?? [];
  2349. }
  2350. if(!empty($job[0]['education_experience'])){
  2351. $education_experience = json_decode($job[0]['education_experience'],true)?? '';
  2352. if(!empty($education_experience)){
  2353. foreach($education_experience as $key => $value){
  2354. // $id = $value['id'];
  2355. $education[$key] = $value['school_education'];
  2356. }
  2357. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue',$education)->select('evalue','ename')->get();
  2358. // // 先将关联表转换为索引数组,提高查找效率
  2359. $educationLookup = [];
  2360. foreach ($education_table as $item) {
  2361. $educationLookup[$item['evalue']] = $item['ename'];
  2362. }
  2363. foreach ($education_experience as $key => &$value) {
  2364. // 处理学历名称
  2365. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  2366. $value['education_name'] = $educationLookup[$education[$key]];
  2367. }
  2368. }
  2369. }
  2370. $result['education_experience'] = $job_experience?? [];
  2371. }
  2372. $result['job'] = $this->processJob($job, $webid);
  2373. // // 返现对应的栏目
  2374. $catid = json_decode($job[0]['cat_arr_id'],true) ?? '';
  2375. $category = WebsiteCategory::where('website_id', $data['website_id'])
  2376. ->whereIn('category_id', $catid)
  2377. ->select('category_id','alias','aLIas_pinyin','pid')
  2378. ->orderBy('pid')->get()->all();
  2379. if(!empty($category)){
  2380. $result['category'] = $category;
  2381. }
  2382. $result['job'] = $job;
  2383. $result['job_experience'] = $job_experience?? [];
  2384. $result['education_experience'] = $education_experience?? [];
  2385. if(empty($result)){
  2386. return Result::error("参数错误", 0);
  2387. }
  2388. return Result::success($result);
  2389. }
  2390. /**
  2391. * c端-申请职位
  2392. * @param array $data
  2393. * @return array
  2394. * */
  2395. public function getWebsiteJobApply(array $data): array
  2396. {
  2397. // 首先验证网站是否存在
  2398. // return Result::success($data);
  2399. $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
  2400. if(empty($web)){
  2401. return Result::error("该网站不存在", 0);
  2402. }
  2403. // 验证用户是否存在且为个人会员/管理员
  2404. $user = User::where('id', $data['user_id'])->first(['id','type_id']);
  2405. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2406. if(empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)){
  2407. return Result::error("用户不存在", 0);
  2408. }
  2409. // 去除重复元素和空元素,并保持原始顺序
  2410. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function($value) {
  2411. return !empty($value);
  2412. }));
  2413. // 验证职位是否存在 1:审核通过
  2414. $recruiting = JobRecruiting::where('status', 1)
  2415. ->where('website_id', $data['website_id'])
  2416. ->whereIn('id',$data['recruit_id'])
  2417. ->get(['id as recruit_id','user_id as receiver_id'])->all();
  2418. if(empty($recruiting)){
  2419. return Result::error("该职位不存在", 0);
  2420. }
  2421. // 简历是否存在
  2422. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status',2)->first(['id as hunt_id']);
  2423. if(empty($hunt_id)){
  2424. return Result::error("该简历不存在", 0);
  2425. }
  2426. $data['hunt_id'] = $hunt_id['hunt_id'];
  2427. // // 验证是否已投递过该职位
  2428. $apply = JobApply::where('user_id', $data['user_id'])
  2429. ->where('hunt_id', $data['hunt_id'])
  2430. ->where('website_id',$data['website_id'])
  2431. ->whereIn('recruit_id',$data['recruit_id'])
  2432. ->get(['recruit_id']);
  2433. if(!empty($apply->toArray())){
  2434. return Result::error("您已投递过该职位!");
  2435. }
  2436. $insertData = array_map(function($recruiting) use ($data) {
  2437. return [
  2438. 'user_id' => $data['user_id'],
  2439. 'hunt_id' => $data['hunt_id'],
  2440. 'website_id' => $data['website_id'],
  2441. 'recruit_id' => $recruiting['recruit_id'],
  2442. 'receiver_id' => $recruiting['receiver_id'],
  2443. 'status' => 1,
  2444. ];
  2445. }, $recruiting);
  2446. // 批量插入数据
  2447. $result = JobApply::insert($insertData);
  2448. if(empty($result)){
  2449. return Result::error("投递失败", 0);
  2450. }
  2451. return Result::success($result);
  2452. }
  2453. /**
  2454. * 招工招聘-沟通简历
  2455. * @param array $data
  2456. * @return array
  2457. * */
  2458. public function getWebsiteJobResume(array $data): array
  2459. {
  2460. // 首先验证网站是否存在
  2461. $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
  2462. if(empty($web)){
  2463. return Result::error("该网站不存在", 0);
  2464. }
  2465. // return Result::success($data);
  2466. // 验证用户是否存在且为企业会员/管理员
  2467. $user = User::where('id', $data['user_id'])->first(['id','type_id']);
  2468. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2469. if(empty($user) || ($user['type_id']!= 3 && $user['type_id']!= 10000)){
  2470. return Result::error("用户不存在", 0);
  2471. }
  2472. // 去除重复元素和空元素,并保持原始顺序
  2473. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function($value) {
  2474. return !empty($value);
  2475. }));
  2476. // 验证简历是否存在
  2477. $hunting = JobHunting::where('status', 2)
  2478. ->where('website_id', $data['website_id'])
  2479. ->whereIn('id',$data['hunt_id'])
  2480. ->get(['id as hunt_id','user_id as receiver_id'])->all();
  2481. if(empty($hunting)){
  2482. return Result::error("该简历不存在", 0);
  2483. }
  2484. // 验证是否已沟通过该简历
  2485. $remuse = JobRemuse::where('user_id', $data['user_id'])
  2486. ->where('recruit_id', $data['recruit_id'])
  2487. ->where('website_id',$data['website_id'])
  2488. ->whereIn('hunt_id',$data['hunt_id'])
  2489. ->get(['hunt_id']);
  2490. if(!empty($remuse->toArray())){
  2491. return Result::error("您已沟通过该简历!");
  2492. }
  2493. // 准备要插入的数据数组
  2494. $insertData = array_map(function($hunting) use ($data) {
  2495. return [
  2496. 'user_id' => $data['user_id'],
  2497. 'recruit_id' => $data['recruit_id'],
  2498. 'website_id' => $data['website_id'],
  2499. 'hunt_id' => $hunting['hunt_id'],
  2500. 'receiver_id' => $hunting['receiver_id'],
  2501. 'status' => 1,
  2502. ];
  2503. }, $hunting);
  2504. // 批量插入数据
  2505. $result = JobRemuse::insert($insertData);
  2506. if(empty($result)){
  2507. return Result::error("沟通失败", 0);
  2508. }
  2509. return Result::success($result);
  2510. }
  2511. /**
  2512. * 招工招聘 -我的职位(企业会员)
  2513. * @param array $data
  2514. * @return array
  2515. */
  2516. public function getWebsiteJobRecruiting(array $data): array
  2517. {
  2518. $web = Website::where('id', $data['website_id'])->first('id');
  2519. if(empty($web)){
  2520. return Result::error("该网站不存在", 0);
  2521. }
  2522. $user = User::where('id', $data['user_id'])->first(['id','type_id']);
  2523. if(empty($user) || ($user['type_id']!= 3 && $user['type_id']!= 10000)){
  2524. return Result::error("用户暂无权限!", 0);
  2525. }
  2526. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  2527. $result = JobRecruiting::where('website_id', $data['website_id'])
  2528. ->when(isset($user['type_id']) && $user['type_id']== 3, function ($query) use ($user) {
  2529. $query->where('user_id', $user['id']);
  2530. })
  2531. ->where('status', 1)
  2532. ->select('id','title','website_id','user_id','updated_at')
  2533. ->orderBy('updated_at', 'desc')
  2534. ->limit($data['pageSize'])
  2535. ->get();
  2536. if(empty($result)){
  2537. return Result::error("暂无相关职位信息", 0);
  2538. }
  2539. return Result::success($result);
  2540. }
  2541. /**
  2542. * c端 - 验证路由
  2543. * @param array $data
  2544. * @return array
  2545. */
  2546. public function checkWebsiteRoute(array $data): array
  2547. {
  2548. $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
  2549. if(empty($web)){
  2550. return Result::error("该网站不存在", 0);
  2551. }
  2552. // 验证栏目路由
  2553. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  2554. ->where('aLIas_pinyin', $data['last_route'])
  2555. ->first();
  2556. if(empty($last_category)){
  2557. return Result::error("该栏目不存在", 0);
  2558. }
  2559. if(isset($data['id']) && !empty($data['id'])){
  2560. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  2561. switch ($last_category['type']) {
  2562. case 1:
  2563. // 文章
  2564. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  2565. $article = Article::where('status', 1)
  2566. ->where('id', $data['id'])
  2567. ->where(function ($query) use ($data) {
  2568. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  2569. ->orWhereNull("ignore_ids");
  2570. })
  2571. ->first(['cat_arr_id']);
  2572. if(empty($article)){
  2573. return Result::error("该文章不存在", 0);
  2574. }
  2575. // return Result::success($article);
  2576. break;
  2577. case 2:
  2578. // 商品
  2579. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  2580. $article = Good::where('website_id', $data['website_id'])
  2581. ->where('status', 2)
  2582. ->where('id', $data['id'])
  2583. ->first(['cat_arr_id']);
  2584. if(empty($article)){
  2585. return Result::error("该商品不存在", 0);
  2586. }
  2587. break;
  2588. case 3:
  2589. // 书刊信息
  2590. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  2591. $article = Book::where('website_id', $data['website_id'])
  2592. ->where('status', 2)
  2593. ->where('id', $data['id'])
  2594. ->first(['id','cat_arr_id']);
  2595. if(empty($article)){
  2596. return Result::error("该书刊不存在", 0);
  2597. }
  2598. break;
  2599. case 4:
  2600. // 招聘
  2601. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核;(只有企业会员需要审核)',
  2602. $article = JobRecruiting::where('website_id', $data['website_id'])
  2603. ->where('status', 1)
  2604. ->where('id', $data['id'])
  2605. ->first(['cat_arr_id']);
  2606. if(empty($article)){
  2607. return Result::error("该招聘不存在", 0);
  2608. }
  2609. break;
  2610. case 5:
  2611. // 求职
  2612. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  2613. $article = JobHunting::where('website_id', $data['website_id'])
  2614. ->where('status', 2)
  2615. ->where('id', $data['id'])
  2616. ->first(['cat_arr_id']);
  2617. if(empty($article)){
  2618. return Result::error("该求职不存在", 0);
  2619. }
  2620. break;
  2621. case 6:
  2622. // 招工招聘
  2623. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  2624. $article = JobRecruiting::where('website_id', $data['website_id'])
  2625. ->where('status', 1)
  2626. ->where('id', $data['id'])
  2627. ->first(['cat_arr_id']);
  2628. if(empty($article)){
  2629. $article = JobHunting::where('website_id', $data['website_id'])
  2630. ->where('status', 2)
  2631. ->where('id', $data['id'])
  2632. ->first(['cat_arr_id']);
  2633. }
  2634. if(empty($article)){
  2635. return Result::error("该招工招聘不存在", 0);
  2636. }
  2637. break;
  2638. default:
  2639. return Result::error("该数据不存在", 0);
  2640. break;
  2641. }
  2642. $catid = json_decode($article['cat_arr_id'], true);
  2643. if(empty($catid)){
  2644. return Result::error("该数据不存在", 0);
  2645. }
  2646. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2647. ->orderByRaw('FIELD(category_id, '. implode(',', $catid). ')')
  2648. ->whereIn('category_id', $catid)
  2649. ->pluck('aLIas_pinyin')
  2650. ->implode('/');
  2651. }
  2652. if($last_category['pid']!=0){
  2653. $cat_arr = json_decode($last_category['category_arr_id'], true);
  2654. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2655. ->orderByRaw('FIELD(category_id, '. implode(',', $cat_arr). ')')
  2656. ->whereIn('category_id', $cat_arr)
  2657. ->pluck('aLIas_pinyin')
  2658. ->implode('/');
  2659. }else{
  2660. $pinyin = $last_category['aLIas_pinyin'];
  2661. }
  2662. if(empty($pinyin) || $pinyin!=$data['all_route']){
  2663. return Result::error('非法路径!');
  2664. }else{
  2665. return Result::success($pinyin);
  2666. }
  2667. }
  2668. /**
  2669. * 招工招聘 - 获取推荐职位
  2670. * @param array $data
  2671. * @return array
  2672. */
  2673. public function getWebsiteLevelJob(array $data): array
  2674. {
  2675. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  2676. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  2677. ->where('job_recruiting.status', 1)
  2678. ->where('job_level', $data['job_level'])
  2679. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2680. ->select('job_recruiting.id','job_recruiting.title','job_recruiting.cat_arr_id','job_company.business_name','job_recruiting.updated_at')
  2681. ->orderBy('job_recruiting.updated_at', 'desc')
  2682. ->limit($data['pageSize'])
  2683. ->get();
  2684. $web = ['website_id' => $data['website_id']];
  2685. if(!empty($job)){
  2686. $result = $this->processJob($job, $web);
  2687. }
  2688. if(empty($result)){
  2689. return Result::error("暂无相关职位信息", 0);
  2690. }
  2691. return Result::success($result);
  2692. }
  2693. }