NewsService.php 119 KB

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