NewsService.php 151 KB

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