NewsService.php 125 KB

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