NewsService.php 143 KB

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