NewsService.php 126 KB

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