NewsService.php 146 KB

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