NewsService.php 136 KB

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