NewsService.php 121 KB

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