NewsService.php 136 KB

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