NewsService.php 151 KB

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