NewsService.php 145 KB

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