NewsService.php 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941
  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. // return Result::success($data['website_id']);
  297. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  298. $category = array_values(array_unique($category->toArray()));
  299. $web['website_id'] = $data['website_id'];
  300. if ($category) {
  301. $where = [
  302. 'status' => 1,
  303. ];
  304. var_dump($data, 'data-----------------');
  305. // level=7 根据文章key来匹配文章
  306. if (isset($data['level']) && $data['level'] == 7) {
  307. // 根据文章id获取key
  308. // $data['id'] = 50142;
  309. if (isset($data['id']) && !empty($data['id'])) {
  310. $keyword = Article::where('id', $data['id'])->value('keyword');
  311. $keywordArray = explode(',', $keyword);
  312. $whereL7 = [];
  313. foreach ($keywordArray as $k => $v) {
  314. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  315. }
  316. // 原始查询
  317. $result['level7'] = Article::where($whereL7)
  318. ->when(!empty($data['imgnum']), function ($query) use ($data) {
  319. $query->where('article.imgurl', '!=', '')
  320. ->select('article.*')
  321. ->offset($data['placeid'])
  322. ->limit($data['imgnum']);
  323. })
  324. ->when(!empty($data['textnum']), function ($query) use ($data) {
  325. $query->select('article.*')
  326. ->offset($data['placeid'])
  327. ->limit($data['textnum']);
  328. })
  329. ->orderBy('updated_at', 'desc')
  330. ->get();
  331. $result['level7'] = $this->processArticle($result['level7'],$web);
  332. if (empty($result)) {
  333. return Result::success();
  334. }
  335. return Result::success($result);
  336. } else {
  337. return Result::error("参数错误level=7,id不能为空", 0);
  338. }
  339. }
  340. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  341. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  342. var_dump($where, 'where-----------------');
  343. // 初始化基础查询
  344. $query = Article::where($where)
  345. ->whereIn("catid", $category)
  346. ->where(function ($query) use ($data) {
  347. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  348. ->orWhereNull("ignore_ids");
  349. });
  350. // 处理 level 相关查询条件
  351. $query->when($data['level'] == 5, function ($query) {
  352. $query->inRandomOrder()
  353. ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  354. })->when($data['level'] == 4, function ($query) {
  355. $query->orderBy("article.updated_at", "desc");
  356. })->when(!empty($data['level']), function ($query) use ($data) {
  357. if ($data['level'] != 4 && $data['level'] != 5) {
  358. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  359. ->orderBy("article.updated_at", "desc");
  360. }
  361. });
  362. // 初始化结果数组
  363. $result = [];
  364. // $input = $data['website_id'];
  365. // 处理图片新闻查询
  366. if (!empty($data['imgnum'])) {
  367. // 原错误提示表明 cleanBindings 方法需要传入数组类型的参数,而实际传入了 null。
  368. // 这里克隆查询构建器,确保绑定参数为数组,避免该错误。
  369. $imgQuery = clone $query;
  370. if ($imgQuery->getBindings() === null) {
  371. $imgQuery->setBindings([]);
  372. }
  373. $result['img'] = $imgQuery->where('article.imgurl', '!=', '')
  374. ->select('article.id',
  375. 'article.title',
  376. 'article.imgurl',
  377. 'article.author',
  378. 'article.updated_at',
  379. 'article.introduce',
  380. 'article.islink',
  381. 'article.linkurl',
  382. 'article.copyfrom',
  383. 'article.cat_arr_id',
  384. 'article.catid')
  385. ->offset($data['placeid'])
  386. ->limit($data['imgnum'])
  387. ->get();
  388. $result['img'] = $this->processArticles( $result['img'], $web);
  389. }
  390. // 处理文字新闻查询
  391. if (!empty($data['textnum'])) {
  392. $textQuery = clone $query;
  393. $result['text'] = $textQuery
  394. ->select('article.id',
  395. 'article.title',
  396. 'article.imgurl',
  397. 'article.author',
  398. 'article.updated_at',
  399. 'article.introduce',
  400. 'article.islink',
  401. 'article.linkurl',
  402. 'article.copyfrom',
  403. 'article.cat_arr_id',
  404. 'article.catid')
  405. ->offset($data['placeid'])
  406. ->limit($data['textnum'])
  407. ->get();
  408. $result['text'] = $this->processArticles($result['text'], $web);
  409. }
  410. if (empty($result) || count($result) == 0) {
  411. return Result::error("暂无头条新闻");
  412. }
  413. return Result::success($result);
  414. } else {
  415. return Result::error("本网站下暂无相关栏目", 0);
  416. }
  417. }
  418. /**
  419. * 获取模块新闻
  420. * @param array $data
  421. * @return array
  422. */
  423. public function getWebsiteModelArticles(array $data): array
  424. {
  425. $catid = $data['catid'];
  426. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  427. $category = $category->toArray();
  428. if (!empty($category)) {
  429. $where = [
  430. 'status' => 1,
  431. 'catid' => $catid,
  432. ];
  433. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  434. // 1:文字新闻;2:轮播图;3:图文;
  435. // 级别:0:未分类
  436. // 3:推荐图片
  437. if ($data['level'] == 1) {
  438. $data['level'] = 0;
  439. }
  440. $result = Article::where($where)
  441. ->where(function ($query) use ($data) {
  442. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  443. ->orWhereNull("level")
  444. ->orWhereRaw("level = '[]'");
  445. })
  446. ->where(function ($query) use ($data) {
  447. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  448. ->orWhereNull("ignore_ids");
  449. })
  450. ->orderBy("updated_at", "desc")
  451. ->offset($placeid)
  452. ->limit($data['pagesize'])
  453. ->get();
  454. if (empty($result)) {
  455. return Result::error("此栏目暂无相关新闻", 0);
  456. }
  457. } else {
  458. return Result::error("此网站暂无此栏目", 0);
  459. }
  460. return Result::success($result);
  461. }
  462. /**
  463. *获取新闻列表
  464. * @param array $data
  465. * @return array
  466. */
  467. public function getWebsiteArticleList(array $data): array
  468. {
  469. // return Result::success($data);
  470. $where[] = ['status', '=', 1];
  471. if (isset($data['catid']) && !empty($data['catid'])) {
  472. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  473. array_push($where, ['catid', '=', $data['catid']]);
  474. if (empty($category)) {
  475. return Result::error("此网站暂无此栏目", 0);
  476. }
  477. }
  478. // return Result::success($where);
  479. $rep = Article::where($where)
  480. ->where(function ($query) use ($data) {
  481. $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
  482. ->orWhereNull("ignore_ids");
  483. })
  484. ->select(
  485. 'article.id',
  486. 'article.title',
  487. 'article.imgurl',
  488. 'article.author',
  489. 'article.updated_at',
  490. 'article.introduce',
  491. 'article.islink',
  492. 'article.linkurl',
  493. 'article.copyfrom',
  494. 'article.cat_arr_id',
  495. 'article.catid')
  496. ->orderBy("updated_at", "desc")
  497. ->offset(($data['page'] - 1) * $data['pageSize'])
  498. ->limit($data['pageSize'])
  499. ->get();
  500. $web['website_id'] = $data['website_id'];
  501. $rep = $this->processArticles($rep,$web);
  502. $count = Article::where($where)
  503. ->where(function ($query) use ($data) {
  504. $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
  505. ->orWhereNull("ignore_ids");
  506. })->count();
  507. $data = [
  508. 'rows' => $rep->toArray(),
  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. $query = Article::where('status', 1)
  814. ->whereIn('catid', $category)
  815. ->where(function ($query) use ($data) {
  816. $query->where(function ($subQuery) use ($data) {
  817. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  818. })->orWhereNull("ignore_ids");
  819. });
  820. // return Result::success($all_articles);
  821. if (isset($data['cityid']) && !empty($data['cityid'])) {
  822. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  823. }
  824. if (isset($data['department_id']) && !empty($data['department_id'])) {
  825. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  826. }
  827. if (isset($data['keyword']) && !empty($data['keyword'])) {
  828. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  829. }
  830. // 计算总数
  831. $count = $query->count();
  832. // 分页查询
  833. $articles = $query
  834. ->select(
  835. 'article.id',
  836. 'article.title',
  837. 'article.imgurl',
  838. 'article.author',
  839. 'article.updated_at',
  840. 'article.introduce',
  841. 'article.islink',
  842. 'article.linkurl',
  843. 'article.copyfrom',
  844. 'article.cat_arr_id',
  845. 'article.catid',
  846. 'article.department_arr_id',
  847. 'article.city_arr_id',)
  848. ->orderBy("updated_at", "desc")
  849. ->offset(($data['page'] - 1) * $data['pageSize'])
  850. ->limit($data['pageSize'])
  851. ->get();
  852. $web['website_id'] = $data['website_id'];
  853. $articles = $this->processArticles($articles,$web);
  854. if (empty($articles)) {
  855. return Result::error("没有符合条件的资讯数据");
  856. }
  857. $result = [
  858. 'rows' => $articles,
  859. 'count' => $count,
  860. ];
  861. return Result::success($result);
  862. }
  863. /**
  864. * 模块新闻加强版
  865. * @param array $data
  866. * @return array
  867. */
  868. public function getWebsiteCatidArticle(array $data): array
  869. {
  870. $where = [
  871. 'website_category.category_id' => $data['catid'],
  872. 'website_category.website_id' => $data['website_id'],
  873. ];
  874. if(isset($data['child_catnum']) && !empty($data['child_catnum'])){
  875. $child_catnum = $data['child_catnum']?? 1;
  876. $category['child'] = WebsiteCategory::where('pid',$data['catid'])->where('website_id',$data['website_id'])->select('category_id','alias')->limit($child_catnum)->get()->toArray();
  877. $childCategoryIds = array_column($category['child'], 'category_id');
  878. if(empty($childCategoryIds)){
  879. return Result::error("暂无子栏目",0);
  880. }
  881. $imgArticles = [];
  882. $textArticles = [];
  883. if(isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum']!=0){
  884. // 初始化子分类图片新闻和文字新闻数组
  885. // 查询所有子级栏目的图文新闻
  886. $imgArticles = Article::where('catid', $childCategoryIds[0])
  887. ->where(function ($query) use ($data) {
  888. $query->where(function ($subQuery) use ($data) {
  889. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
  890. })->orWhereNull("ignore_ids");
  891. })
  892. ->where('status', 1)
  893. ->where('imgurl', '!=', '')
  894. ->select('*')
  895. ->orderBy('updated_at', 'desc')
  896. ->limit($data['child_imgnum'])
  897. ->get();
  898. }
  899. if( isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum']!=0){
  900. // 查询所有子级栏目的文字新闻
  901. $textArticles = Article::where('catid', $childCategoryIds[0])
  902. ->where('status', 1)
  903. ->where(function ($query) use ($data) {
  904. $query->where(function ($subQuery) use ($data) {
  905. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
  906. })->orWhereNull("ignore_ids");
  907. })
  908. ->select('*')
  909. ->orderBy('updated_at', 'desc')
  910. ->limit($data['child_textnum'])
  911. ->get();
  912. }
  913. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  914. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  915. $child['img'] = $imgArticles? $imgArticles->where('catid', $child['category_id']) : [];
  916. $child['text'] = $textArticles? $textArticles->where('catid', $child['category_id']) : [];
  917. return $child;
  918. }, $category['child']);
  919. }
  920. // }
  921. if (isset($data['img_num']) && !empty($data['img_num'])) {
  922. $category['img'] = WebsiteCategory::where($where)
  923. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  924. ->where('article.status', 1)
  925. ->where('article.imgurl', '!=', '')
  926. ->select('article.*','website_category.category_id','website_category.alias')
  927. ->orderBy('article.updated_at', 'desc')
  928. ->limit($data['img_num'])
  929. ->get();
  930. }
  931. if (isset($data['text_num']) && !empty($data['text_num'])) {
  932. $category['text'] = WebsiteCategory::where($where)
  933. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  934. ->where('article.status', 1)
  935. ->select('article.*','website_category.category_id','website_category.alias')
  936. ->orderBy('article.updated_at', 'desc')
  937. ->limit($data['text_num'])
  938. ->get();
  939. }
  940. // $category = $category->get();
  941. if(empty($category)){
  942. return Result::error("查询失败", 0);
  943. }
  944. return Result::success($category);
  945. }
  946. /**
  947. * 模块新闻加强plus版
  948. * @param array $data
  949. * @return array
  950. */
  951. public function getWebsiteAllArticle(array $data): array
  952. {
  953. $time1 = microtime(true);
  954. $data = json_decode($data['id'], true);
  955. $wetbsite_id = $data['website_id'] ?? 2;
  956. $categorys = $this->processArticlePro($wetbsite_id);
  957. $cat_1st_arr = $categorys['cat_1st_arr'];
  958. $catiall = $categorys['catiall'];
  959. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  960. $parent_category = array_column($data, 'parent');
  961. $parent_cat = [];
  962. $child_category = array_column($data,'child');
  963. if(!empty($parent_category)){
  964. foreach($parent_category as $key => $value){
  965. $arr = array_map('intval', explode(',', $value));
  966. $parent_cat[$key] = $arr[0] ?? 0;
  967. $parent_category = $arr[0] ?? 0;
  968. $article_imgnum = $arr[1] ?? 0;
  969. $article_textnum = $arr[2] ?? 0;
  970. if($parent_category != 0){
  971. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category]);
  972. if($article_imgnum != 0){
  973. $img_article = Article::whereIn('catid', $category_arr)
  974. ->where('status',1)
  975. ->where('imgurl','!=', '')
  976. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  977. $query->from('article_ignore')
  978. ->where('website_id', $wetbsite_id);
  979. }, 'article_ignore', function ($join) {
  980. $join->on('article_ignore.article_id', '=', 'article.id');
  981. })
  982. ->where(function ($query) use ($wetbsite_id) {
  983. $query->whereNull('article_ignore.article_id')
  984. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  985. })
  986. ->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')
  987. ->orderBy('updated_at', 'desc')
  988. ->limit($article_imgnum)
  989. ->get()->all();
  990. foreach ($img_article as $k => $v) {
  991. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  992. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  993. }
  994. }else{
  995. $img_article = [];
  996. }
  997. if($article_textnum != 0){
  998. $text_article = Article::whereIn('catid', $category_arr)
  999. ->where('status',1)
  1000. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1001. $query->from('article_ignore')
  1002. ->where('website_id', $wetbsite_id);
  1003. }, 'article_ignore', function ($join) {
  1004. $join->on('article_ignore.article_id', '=', 'article.id');
  1005. })
  1006. ->where(function ($query) use ($wetbsite_id) {
  1007. $query->whereNull('article_ignore.article_id')
  1008. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1009. })
  1010. ->select('id','title','author','updated_at','introduce','islink','linkurl','copyfrom','cat_arr_id','catid')
  1011. ->orderBy('updated_at', 'desc')
  1012. ->limit($article_textnum)
  1013. ->get()->all();
  1014. foreach ($text_article as $k => $v) {
  1015. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1016. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1017. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1018. }
  1019. }else{
  1020. $text_article = [];
  1021. }
  1022. $catiall[$parent_category]['imgnum'] = $img_article;
  1023. $catiall[$parent_category]['textnum'] = $text_article;
  1024. $parent[$key] = $catiall[$parent_category];
  1025. }else{
  1026. $parent[$key] = '';
  1027. }
  1028. }
  1029. }
  1030. if(!empty($child_category)){
  1031. foreach($child_category as $key => $value){
  1032. $arr = array_map('intval', explode(',', $value));
  1033. $parent_category = $parent_cat[$key];
  1034. $child_category = $arr[0] ?? 0;
  1035. $article_imgnum = $arr[1] ?? 0;
  1036. $article_textnum = $arr[2] ?? 0;
  1037. if($child_category != 0){
  1038. $all_childcat = $cat_1st_arr[$parent_category];
  1039. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1040. // 从 $websiteInfoIndexed 中获取对应的数据
  1041. $info = $websiteInfoIndexed[$v];
  1042. // 返回一个包含所需信息的数组
  1043. return [
  1044. 'alias' => $info->alias,
  1045. 'category_id' => $info->category_id,
  1046. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1047. 'pid' => $info->pid,
  1048. 'type' => $info->type,
  1049. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1050. 'pinyin' => $info->pinyin,
  1051. ];
  1052. }, $all_childcat);
  1053. if($article_imgnum != 0){
  1054. $img_article = Article::where('catid', $child_category)
  1055. ->where('status',1)
  1056. ->where('imgurl','!=', '')
  1057. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1058. $query->from('article_ignore')
  1059. ->where('website_id', $wetbsite_id);
  1060. }, 'article_ignore', function ($join) {
  1061. $join->on('article_ignore.article_id', '=', 'article.id');
  1062. })
  1063. ->where(function ($query) use ($wetbsite_id) {
  1064. $query->whereNull('article_ignore.article_id')
  1065. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1066. })
  1067. ->select('id','title','imgurl','author','updated_at','introduce','islink','linkurl','copyfrom','cat_arr_id','catid')
  1068. ->orderBy('updated_at', 'desc')
  1069. ->limit($article_imgnum)
  1070. ->get()->all();
  1071. foreach ($img_article as $k => $v) {
  1072. // var_dump($v);
  1073. // var_dump($k);
  1074. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1075. $img_article[$k]->alias = $catiall[$v->catid]['alias'];
  1076. }
  1077. }else{
  1078. $img_article = [];
  1079. }
  1080. if($article_textnum != 0){
  1081. $text_article = Article::where('catid', $child_category)
  1082. ->where('status',1)
  1083. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1084. $query->from('article_ignore')
  1085. ->where('website_id', $wetbsite_id);
  1086. }, 'article_ignore', function ($join) {
  1087. $join->on('article_ignore.article_id', '=', 'article.id');
  1088. })
  1089. ->where(function ($query) use ($wetbsite_id) {
  1090. $query->whereNull('article_ignore.article_id')
  1091. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1092. })
  1093. ->select('id','title','author','updated_at','introduce','islink','linkurl','copyfrom','cat_arr_id','catid')
  1094. ->orderBy('updated_at', 'desc')
  1095. ->limit($article_textnum)
  1096. ->get()->all();
  1097. foreach ($text_article as $k => $v) {
  1098. // var_dump($v);
  1099. // var_dump($k);
  1100. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1101. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1102. $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1103. }
  1104. }else{
  1105. $text_article = [];
  1106. }
  1107. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1108. $catiall[$child_category]['imgnum'] = $img_article;
  1109. $catiall[$child_category]['textnum'] = $text_article;
  1110. $child[$key] = $catiall[$child_category];
  1111. // var_dump($pids);
  1112. }else{
  1113. $child[$key] = '';
  1114. }
  1115. }
  1116. }
  1117. foreach($parent as $key => $value){
  1118. $result[$key] = $value;
  1119. if(!empty($child[$key])){
  1120. // var_dump($child[$key]);
  1121. $result[$key]['child'] = $child[$key];
  1122. // $value[$key]['child'] = $child[$key];
  1123. }else{
  1124. $result[$key]['child'] = [
  1125. "alias" => null,
  1126. "category_id" => null,
  1127. "type" => null,
  1128. "pinyin" => null,
  1129. "all_childcat" => [],
  1130. "imgnum" => [],
  1131. "textnum" => []
  1132. ];
  1133. }
  1134. }
  1135. return Result::success($result);
  1136. }
  1137. /**
  1138. * 辅助方法:获取文章列表
  1139. */
  1140. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1141. {
  1142. $query = Article::where('article.status', 1)
  1143. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1144. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1145. ->where(function ($query) use ($website) {
  1146. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0 OR ignore_ids IS NULL)");
  1147. })
  1148. ->leftJoin('website_category', function($join) use ($website) {
  1149. $join->on('article.catid', '=', 'website_category.category_id')
  1150. ->where('website_category.website_id', '=', $website['website_id']);
  1151. })
  1152. ->select(
  1153. 'article.id', 'article.title', 'article.imgurl', 'article.author', 'article.updated_at',
  1154. 'article.introduce', 'article.islink', 'article.linkurl', 'article.copyfrom', 'article.cat_arr_id',
  1155. 'article.catid', 'website_category.alias as category_name'
  1156. )
  1157. ->orderBy('updated_at', 'desc')
  1158. ->limit($limit);
  1159. // 如果是图片文章,添加图片URL条件
  1160. if ($isImageArticle) {
  1161. $query->where('imgurl', '!=', '');
  1162. } else {
  1163. // 文字文章不需要imgurl字段
  1164. $query->addSelect('article.introduce');
  1165. }
  1166. $articles = $query->get();
  1167. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1168. }
  1169. /**
  1170. * 乡村网-获取特殊新闻模块
  1171. * @param array $data
  1172. * @return array
  1173. */
  1174. public function getWebsiteArticles(array $data): array
  1175. {
  1176. $input['id'] = $data['id'];
  1177. $input['website_id'] = $data['website_id'];
  1178. $data = json_decode($input['id'], true);
  1179. // 使用 array_map 处理每个元素
  1180. $result = array_map(function ($item) use ($input) {
  1181. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1182. $website = [
  1183. 'website_id' => $input['website_id']
  1184. ];
  1185. // 查询栏目名称
  1186. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  1187. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1188. if(empty($category)){
  1189. $imgArticles = [];
  1190. $textArticles = [];
  1191. // return Result::error("暂无此栏目",0);
  1192. }else{
  1193. $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1194. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin.'/' : null;
  1195. // return Result::success($website);
  1196. // 查询图片新闻
  1197. // 合并查询条件
  1198. $baseQuery = Article::where(function ($query) use ($website) {
  1199. $query->where(function ($subQuery) use ($website) {
  1200. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1201. })->orWhereNull("ignore_ids");
  1202. })
  1203. ->where('website_category.website_id', $website['website_id'])
  1204. ->where('article.status', 1)
  1205. ->leftJoin('website_category', 'website_category.category_id', 'article.catid');
  1206. // 查询文字新闻
  1207. $textArticles = clone $baseQuery;
  1208. $textArticles = $textArticles->whereIn('catid',$child_category)
  1209. ->select(
  1210. 'article.id',
  1211. 'article.title',
  1212. // 'article.imgurl',
  1213. 'article.author',
  1214. 'article.updated_at',
  1215. 'article.introduce',
  1216. 'article.islink',
  1217. 'article.linkurl',
  1218. 'article.copyfrom',
  1219. 'website_category.category_id',
  1220. 'website_category.alias',
  1221. 'website_category.aLIas_pinyin'
  1222. )
  1223. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1224. ->orderBy('article.updated_at', 'desc')
  1225. ->limit($parentTextNum)
  1226. ->get()
  1227. ->all();
  1228. if(empty($textArticles)){
  1229. $textArticles = clone $baseQuery;
  1230. $textArticles = $textArticles->where('catid',$parentCatId)
  1231. ->select(
  1232. 'article.id',
  1233. 'article.title',
  1234. // 'article.imgurl',
  1235. 'article.author',
  1236. 'article.updated_at',
  1237. 'article.introduce',
  1238. 'article.islink',
  1239. 'article.linkurl',
  1240. 'article.copyfrom',
  1241. 'website_category.category_id',
  1242. 'website_category.alias',
  1243. 'website_category.aLIas_pinyin'
  1244. )
  1245. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1246. ->orderBy('article.updated_at', 'desc')
  1247. ->limit($parentTextNum)
  1248. ->get()
  1249. ->all();
  1250. }
  1251. // 查询图片新闻
  1252. $imgArticles = clone $baseQuery;
  1253. $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid',$child_category)
  1254. ->select(
  1255. 'article.id',
  1256. 'article.title',
  1257. 'article.imgurl',
  1258. 'article.author',
  1259. 'article.updated_at',
  1260. 'article.introduce',
  1261. 'article.islink',
  1262. 'article.linkurl',
  1263. 'article.copyfrom',
  1264. 'website_category.category_id',
  1265. 'website_category.alias',
  1266. 'website_category.aLIas_pinyin'
  1267. )
  1268. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1269. ->orderBy('article.updated_at', 'desc')
  1270. ->limit($parentImgNum)
  1271. ->get()
  1272. ->all();
  1273. if(empty($imgArticles)){
  1274. $imgArticles = clone $baseQuery;
  1275. $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid',$parentCatId)
  1276. ->select(
  1277. 'article.id',
  1278. 'article.title',
  1279. 'article.imgurl',
  1280. 'article.author',
  1281. 'article.updated_at',
  1282. 'article.introduce',
  1283. 'article.islink',
  1284. 'article.linkurl',
  1285. 'article.copyfrom',
  1286. 'website_category.category_id',
  1287. 'website_category.alias',
  1288. 'website_category.aLIas_pinyin'
  1289. )
  1290. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1291. ->orderBy('article.updated_at', 'desc')
  1292. ->limit($parentImgNum)
  1293. ->get()
  1294. ->all();
  1295. }
  1296. }
  1297. $resultItem = [
  1298. 'alias' => $category ? $category->alias : null,
  1299. 'category_id' => $parentCatId,
  1300. 'pinyin' => $pinyin ? $pinyin : null,
  1301. 'imgnum' => $imgArticles ?? [],
  1302. 'textnum' => $textArticles ?? [],
  1303. ];
  1304. return $resultItem;
  1305. }, $data);
  1306. return Result::success($result);
  1307. }
  1308. // 封装处理商品的路由问题
  1309. function processGoods($goods, $data) {
  1310. return $goods->map(function ($good) use ($data) {
  1311. $catid = $good->catid ?? 0;
  1312. // $pinyin = '';
  1313. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1314. if (!empty($category->pid) && $category->pid != 0) {
  1315. $level = json_decode($category->category_arr_id);
  1316. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1317. ->whereIn('category_id', $level)
  1318. ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
  1319. ->get(['aLIas_pinyin'])
  1320. ->pluck('aLIas_pinyin')
  1321. ->implode('/');
  1322. } else {
  1323. $pinyin = $category->aLIas_pinyin ?? '';
  1324. }
  1325. if(isset($good->city_id) &&!empty($good->city_id)){
  1326. $city = District::where('id', $good->city_id)->first(['name']);
  1327. $good->city_name = $city->name ?? '';
  1328. }
  1329. // 解析imgurl JSON并取第一条数据
  1330. $imgUrls = json_decode($good->imgurl, true);
  1331. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1332. $good->pinyin = $pinyin;
  1333. return $good;
  1334. });
  1335. }
  1336. /**
  1337. * 获取商城首页-根据栏目id
  1338. * @param array $data
  1339. * @return array
  1340. * */
  1341. function getWebsiteCatidshop(array $data): array
  1342. {
  1343. $input['catid'] = $data['catid'];
  1344. $input['website_id'] = $data['website_id'];
  1345. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1346. $result = array_map(function ($item) use ($input) {
  1347. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid']!= "") {
  1348. list($catid, $goodStart,$goodNum) = explode(',', $item['catid']);
  1349. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1350. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1351. if(empty($category) || $category->type != 2){
  1352. return Result::error("暂无此栏目",0);
  1353. }else{
  1354. $website['website_id'] = $input['website_id'];
  1355. $goods = Good::where('good.status', 2)
  1356. ->where('good.website_id', $website['website_id'])
  1357. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '". intval($catid). "') = 1")
  1358. ->select('good.id', 'good.name', 'good.imgurl', 'good.description', 'good.updated_at',
  1359. 'good.catid','good.type_id','good.price','good.com','good.level','good.unit')
  1360. ->orderBy('updated_at','desc')
  1361. ->offset($goodStart)
  1362. ->limit($goodNum);
  1363. $all_goods = $goods->get();
  1364. $all_goods = $this->processGoods($all_goods, $website);
  1365. }
  1366. return $all_goods ?? [];
  1367. }
  1368. }, $data);
  1369. return Result::success($result);
  1370. }
  1371. /**
  1372. * 获取商品模块
  1373. * @param array $data
  1374. * @return array
  1375. * */
  1376. public function getWebsiteshop(array $data): array
  1377. {
  1378. $input['id'] = $data['id'];
  1379. $input['website_id'] = $data['website_id'];
  1380. $catid = $data['catid'];
  1381. $data = json_decode($input['id'] ?? '', true) ?? [];
  1382. $result['goods'] = array_map(function ($item) use ($input) {
  1383. // 检查parent元素是否存在且不是undefined
  1384. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level']!= "") {
  1385. list($Levelid, $goodStart,$goodNum) = explode(',', $item['level']);
  1386. $website = $input['website_id'];
  1387. $query = Good::where('good.status', 2)
  1388. ->where('good.website_id', $website);
  1389. switch ($Levelid) {
  1390. case 1:
  1391. case 2:
  1392. case 3:
  1393. $goods = $query->where(function($q) use ($Levelid) {
  1394. $q->whereRaw("JSON_CONTAINS(good.level, '". intval($Levelid). "') = 1")
  1395. ->orWhereRaw("JSON_CONTAINS(good.level, '\"". intval($Levelid). "\"') = 1");
  1396. });
  1397. break;
  1398. case 4:
  1399. $goods = $query;
  1400. break;
  1401. case 5:
  1402. $goods = $query->where('type_id',1);
  1403. break;
  1404. case 6:
  1405. $goods = $query->where('type_id',2);
  1406. break;
  1407. default:
  1408. return [];
  1409. }
  1410. $all_goods = $goods
  1411. ->select('good.id', 'good.name', 'good.imgurl', 'good.description',
  1412. 'good.updated_at', 'good.catid','good.type_id','good.price','good.level',
  1413. 'good.website_id')
  1414. ->orderBy('updated_at','desc')
  1415. ->offset($goodStart)
  1416. ->limit($goodNum)
  1417. ->get();
  1418. $web['website_id'] = $website;
  1419. $all_goods = $this->processGoods($all_goods, $web);
  1420. }
  1421. return $all_goods;
  1422. }, $data);
  1423. $website = $input['website_id'];
  1424. $result['article'] = Article::where(function ($query) use ($website) {
  1425. $query->where(function ($subQuery) use ($website) {
  1426. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  1427. })->orWhereNull("ignore_ids");
  1428. })
  1429. ->where('catid', $catid)
  1430. ->where('article.status', 1)
  1431. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  1432. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl','article_data.content')
  1433. ->orderBy('article.updated_at', 'desc')
  1434. ->first();
  1435. return Result::success($result);
  1436. }
  1437. /**
  1438. * 获取商品分类
  1439. * @param array $data
  1440. * @return array
  1441. * */
  1442. public function getWebsiteshopCat(array $data): array
  1443. {
  1444. $website = $data['website_id'];
  1445. $category = WebsiteCategory::where('website_id', $website)
  1446. ->whereRaw("JSON_CONTAINS(category_arr_id, '". intval($data['id']). "') = 1")
  1447. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"". intval($data['id']). "\"') = 1")
  1448. ->select('category_id', 'alias','aLIas_pinyin','pid','category_arr_id' ,'sort')
  1449. ->orderBy('sort')
  1450. ->get();
  1451. $cat = $category->map(function ($item) use ($website) {
  1452. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  1453. $pid = $item->pid?? 0;
  1454. if(!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0){
  1455. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  1456. ->where('website_id', $website)
  1457. ->orderByRaw('FIELD(category_id, '. implode(',', $cat_arr_id). ')')
  1458. ->get(['aLIas_pinyin'])
  1459. ->pluck('aLIas_pinyin')
  1460. ->implode('/');
  1461. }else{
  1462. $pinyin = $item->aLIas_pinyin ?? '';
  1463. }
  1464. $item->pinyin = $pinyin;
  1465. });
  1466. if(empty($category)){
  1467. return Result::error("栏目查询失败", 0);
  1468. }
  1469. $cat_tree = Result::buildMenuTree($category);
  1470. $web['website_id'] = $website;
  1471. $goods = Good::where('website_id', $website)
  1472. ->where('status', 2)
  1473. ->select('good.id as good_id', 'name','imgurl','description','updated_at','catid','type_id','website_id')
  1474. ->latest('updated_at')
  1475. ->offset(($data['page']-1)*$data['pageSize'])
  1476. ->limit($data['pageSize'])
  1477. ->get();
  1478. if(!empty($goods)){
  1479. if($goods->count() > 1 && !empty($goods)){
  1480. $goods = $this->processGoods($goods, $web);
  1481. }
  1482. }else{
  1483. $goods = [];
  1484. }
  1485. $result = [
  1486. 'category' => $cat_tree,
  1487. 'goods' => $goods,
  1488. ];
  1489. // $resul['goods'] = $goods;
  1490. if(empty($result)){
  1491. return Result::error("查询失败", 0);
  1492. }
  1493. return Result::success($result);
  1494. }
  1495. /*
  1496. * 获取商品列表
  1497. * @param array $data
  1498. * @return array
  1499. * */
  1500. public function getWebsiteshopList(array $data): array
  1501. {
  1502. // return Result::success($data);
  1503. $where = [
  1504. 'status' => 2,
  1505. 'website_id' => $data['website_id'],
  1506. ];
  1507. if((empty($data['catid']) ||!isset($data['catid'])) && (empty($data['keyword']) ||!isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))){
  1508. return Result::error("查询失败", 0);
  1509. }
  1510. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  1511. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid',$data['id'])->orderBy('sort')->first(['category_id']);
  1512. $data['catid'] = $category->category_id ?? 0;
  1513. }
  1514. if(isset($data['keyword']) &&!empty($data['keyword'])){
  1515. array_push($where, ['name', 'like', '%'. $data['keyword'].'%']);
  1516. }
  1517. if(isset($data['type_id']) && !empty($data['type_id'])){
  1518. array_push($where, ['type_id', $data['type_id']]);
  1519. }
  1520. $query = Good::where($where)
  1521. ->when(isset($data['catid']) &&!empty($data['catid']), function ($query) use ($data) {
  1522. $query->where(function($q) use ($data) {
  1523. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '". intval($data['catid']). "') = 1")
  1524. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"". intval($data['catid']). "\"') = 1");
  1525. });
  1526. })
  1527. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  1528. $query->where(function($q) use ($data) {
  1529. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '". intval($data['city_id']). "') = 1")
  1530. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"". intval($data['city_id']). "\"') = 1");
  1531. });
  1532. })
  1533. ->select('good.id', 'good.name', 'good.imgurl', 'good.description', 'good.updated_at', 'good.com',
  1534. 'good.catid','good.type_id','good.website_id','good.cat_arr_id','good.created_at','good.city_id')
  1535. ->latest('updated_at');
  1536. if(isset($data['ismix']) && $data['ismix'] == 1){
  1537. $result['count'] = $query->clone()->count();
  1538. $result['goods'] = $this->processGoods(
  1539. $query->clone()
  1540. ->offset(($data['page'] - 1) * $data['pageSize'])
  1541. ->limit($data['pageSize'])
  1542. ->get(),
  1543. $data
  1544. );
  1545. }else{
  1546. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  1547. // 获取 type_id 为 1 的数据
  1548. $result['type1'] = $this->processGoods(
  1549. $query->clone()
  1550. ->where('type_id', 1)
  1551. ->offset(($data['page'] - 1) * $data['pageSize'])
  1552. ->limit($data['pageSize'])
  1553. ->get(),
  1554. $data
  1555. );
  1556. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  1557. // 获取 type_id 为 2 的数据
  1558. $result['type2'] = $this->processGoods(
  1559. $query->clone()
  1560. ->where('type_id', 2)
  1561. ->offset(($data['page'] - 1) * $data['pageSize'])
  1562. ->limit($data['pageSize'])
  1563. ->get(),
  1564. $data
  1565. );
  1566. }
  1567. if(empty($result)){
  1568. return Result::error("查询失败", 0);
  1569. }
  1570. return Result::success($result);
  1571. }
  1572. /**
  1573. * 获取商品详情
  1574. * @param array $data
  1575. * @return array
  1576. * */
  1577. public function getWebsiteshopInfo(array $data): array
  1578. {
  1579. $where = [
  1580. 'good.status' => 2,
  1581. 'good.website_id' => $data['website_id'],
  1582. 'good.id' => $data['id'],
  1583. ];
  1584. $goods = Good::where($where)
  1585. ->where('good.id', $data['id'])
  1586. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  1587. ->select('good.*','website_category.alias','website_category.category_id')
  1588. ->first();
  1589. if(empty($goods)){
  1590. return Result::error("查询失败", 0);
  1591. }
  1592. $goods->imgurl = json_decode($goods->imgurl, true);
  1593. return Result::success($goods);
  1594. }
  1595. /**
  1596. * plus pro 处理文章路由问题
  1597. */
  1598. function processArticlePro($website_id){
  1599. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  1600. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  1601. // 取出category_id 对应的aLIas_pinyin
  1602. $categoryIds = array_column($categorys, 'category_id');
  1603. $categoryPIds = array_column($categorys, 'pid');
  1604. $aliasPinyins = array_column($categorys, 'aLIas_pinyin');
  1605. $cat_arr = array_combine($categoryIds, $aliasPinyins);
  1606. // return Result::success($categorys);
  1607. $catiall = [];
  1608. //一级所有子级的记录
  1609. $cat_1st_arr = [];
  1610. foreach ($categorys as $key => $value) {
  1611. if($value->pid != 0 && !in_array($value->category_id,$categoryPIds)){
  1612. $cat_1st_arr[$value->pid][] = $value->category_id;
  1613. }
  1614. // unset($cat_1st_arr[0]);
  1615. // //算出路由拼音
  1616. $category_arr_id = json_decode($value->category_arr_id);
  1617. $pinyin_str = '';
  1618. // 算出一级 并且算出子级
  1619. if ($value->pid == 0) {
  1620. $cat_1st_arr[$value->pid][] = $value->category_id;
  1621. } else {
  1622. $cat_1st_arr[$value->category_id][] = [];
  1623. // $cat_1st_arr[$value->pid][] = $value->category_id;
  1624. }
  1625. foreach ($category_arr_id as $k => $v) {
  1626. $pinyin_str .= $cat_arr[$v] . '/';
  1627. }
  1628. $pinyin_str = rtrim($pinyin_str, '/');
  1629. $catiall[$value->category_id]['alias'] = $value->alias;
  1630. $catiall[$value->category_id]['category_id'] = $value->category_id;
  1631. $catiall[$value->category_id]['type'] = $value->type;
  1632. $catiall[$value->category_id]['pinyin'] = $pinyin_str;
  1633. // $cat_id = $value->category_id;
  1634. $websiteInfoIndexed[$value->category_id]->pinyin = $pinyin_str;
  1635. }
  1636. return [
  1637. 'cat_1st_arr' => $cat_1st_arr,
  1638. 'catiall' => $catiall,
  1639. 'websiteInfoIndexed' => $websiteInfoIndexed,
  1640. ];
  1641. }
  1642. /**
  1643. * 封装处理文章的路由问题
  1644. * */
  1645. function processArticles($articles, $data) {
  1646. // 检查 $articles 是否为数组或可迭代对象
  1647. if (is_array($articles) || is_iterable($articles) &&!empty($articles)) {
  1648. return $articles->map(function ($article) use ($data) {
  1649. if(isset($article->cat_arr_id) &&!empty($article->cat_arr_id)){
  1650. $catid = $article->cat_arr_id?? '';
  1651. }
  1652. if(isset($article->category_arr_id) &&!empty($article->category_arr_id)){
  1653. $catid = $article->category_arr_id?? '';
  1654. }
  1655. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  1656. $level = json_decode($catid, true);
  1657. if (!is_array($level)) {
  1658. return $article;
  1659. } else {
  1660. $level = array_map('intval', $level);
  1661. }
  1662. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1663. ->where($data)
  1664. ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
  1665. ->pluck('aLIas_pinyin')
  1666. ->implode('/');
  1667. $article->pinyin = $pinyin ?? '';
  1668. return $article;
  1669. });
  1670. } else {
  1671. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  1672. $catid = $articles->cat_arr_id?? '';
  1673. $level = json_decode($catid, true);
  1674. if (!is_array($level)) {
  1675. return $articles;
  1676. } else {
  1677. $level = array_map('intval', $level);
  1678. }
  1679. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1680. ->where($data)
  1681. ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
  1682. ->pluck('aLIas_pinyin')
  1683. ->implode('/');
  1684. $articles->pinyin = $pinyin ?? '';
  1685. return $articles;
  1686. }
  1687. }
  1688. // 封装处理由问题
  1689. function processJob($job, $data) {
  1690. return $job->map(function ($job) use ($data) {
  1691. $category = $job->cat_arr_id?? '';
  1692. $cityid = $job->city_arr_id?? '';
  1693. $city = json_decode($cityid, true);
  1694. $pinyin = '';
  1695. $level = json_decode($category, true);
  1696. // 路由
  1697. if(!empty($level) && is_array($level)){
  1698. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1699. ->where('website_id', $data['website_id']) // 添加网站ID条件
  1700. ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
  1701. ->get(['aLIas_pinyin'])
  1702. ->pluck('aLIas_pinyin')
  1703. ->implode('/');
  1704. if(empty($pinyin)){
  1705. $pinyin = $pinyin->aLIas_pinyin?? '';
  1706. }
  1707. $job->pinyin = $pinyin;
  1708. }
  1709. // 取职位-城市 市??省
  1710. if(!empty($city) && is_array($city)){
  1711. if(isset($city[1] ) && !empty($city[1])){
  1712. $city = District::where('id', $city[1])->first(['name']);
  1713. $job->city_name = $city->name?? '';
  1714. }else if(isset($city[0] ) && !empty($city[0])){
  1715. $city = District::where('id', $city[0])->first(['name']);
  1716. $job->city_name = $city->name?? '';
  1717. }else{
  1718. $job->city_name = '全国';
  1719. }
  1720. }
  1721. // 获取简历最后一级地区
  1722. if(isset($job->city_id) &&!empty($job->city_id)){
  1723. $city = District::where('id', $job->city_id)->first(['name']);
  1724. $job->hunt_cityname = $city->name?? '';
  1725. }
  1726. // 组合详细地址
  1727. if(isset($job->address_arr_id) && !empty($job->address_arr_id)){
  1728. $address_id = json_decode($job->address_arr_id, true) ?? [];
  1729. if(is_array($address_id) && !empty($address_id)){
  1730. $address = District::whereIn('id', $address_id)
  1731. ->orderBy('level', 'asc')
  1732. ->get(['name'])
  1733. ->pluck('name')
  1734. ->implode('');
  1735. // $job->address_name = $address ?? '';
  1736. $job->address_name = ($address ?? '') . ($job->address ?? '');
  1737. }
  1738. }
  1739. // 取行业
  1740. if(!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))){
  1741. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  1742. if(!empty($job->industry)){
  1743. $query->where('hyid', $job->industry);
  1744. }else if(!empty($job->hy_id)){
  1745. $query->where('hyid', $job->hy_id);
  1746. }else if(!empty($job->company_hy_id)){
  1747. $query->where('hyid', $job->company_hy_id);
  1748. } else{
  1749. $query->where('hyid', $job->job_industry);
  1750. }
  1751. })->first(['hyname']);
  1752. $job->hy_name = $hy_name->hyname?? '';
  1753. }
  1754. // 取职位类别
  1755. if((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))){
  1756. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  1757. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  1758. $job->zw_name = $zw_name->zwname?? '';
  1759. }
  1760. // 取具体职位
  1761. 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))){
  1762. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  1763. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  1764. $job->jtzw_name = $jtzw_name->zwname?? '';
  1765. }
  1766. // 取工作经验
  1767. if(isset($job->experience) &&!empty($job->experience)){
  1768. $experience = JobEnum::where('egroup','years')->where('evalue',$job->experience)->first(['ename']);
  1769. $job->experience_name = $experience->ename?? '';
  1770. }
  1771. // 取学历
  1772. if(isset($job->educational) &&!empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  1773. $education = $job->educational ?? $job->school_education;
  1774. $education = JobEnum::where('egroup','education')->where('evalue',$education)->first(['ename']);
  1775. $job->education_name = $education->ename?? '';
  1776. }
  1777. // 语言
  1778. if(isset($job->language) &&!empty($job->language)){
  1779. $language = JobEnum::where('egroup','language')->where('evalue',$job->language)->first(['ename']);
  1780. $job->language_name = $language->ename?? '';
  1781. }
  1782. // 薪资
  1783. if(isset($job->salary) &&!empty($job->salary)){
  1784. $salary = JobEnum::where('egroup','income')->where('evalue',$job->salary)->first(['ename']);
  1785. $job->salary_name = $salary->ename?? '';
  1786. }
  1787. // 职位性质
  1788. if(isset($job->nature_id) &&!empty($job->nature_id)){
  1789. $job_nature = JobEnum::where('egroup','nature')->where('evalue',$job->nature_id)->first(['ename']);
  1790. $job->job_nature_name = $job_nature->ename?? '';
  1791. }
  1792. // 公司规模
  1793. if(isset($job->company_size) &&!empty($job->company_size)){
  1794. $company_size = JobEnum::where('egroup','cosize')->where('evalue',$job->company_size)->first(['ename']);
  1795. $job->company_size_name = $company_size->ename?? '';
  1796. }
  1797. // 公司性质
  1798. if(isset($job->company_nature) && !empty($job->company_nature)){
  1799. $company_nature = JobNature::where('id',$job->company_nature)->first(['nature_name']);
  1800. $job->company_nature_name = $company_nature->nature_name?? '';
  1801. }
  1802. // $job->pinyin = $pinyin;
  1803. return $job;
  1804. });
  1805. }
  1806. /**
  1807. * 获取书籍模块
  1808. * @param array $data
  1809. * @return array
  1810. * */
  1811. public function getWebsiteBook(array $data): array
  1812. {
  1813. $input['id'] = $data['id'];
  1814. $input['website_id'] = $data['website_id'];
  1815. // 将 JSON 字符串转换为 PHP 数组
  1816. $data = json_decode($input['id'], true);
  1817. // 使用 array_map 处理每个元素
  1818. $result = array_map(function ($item) use ($input) {
  1819. // 检查parent元素是否存在且不是undefined
  1820. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent']!= "") {
  1821. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1822. $website = [
  1823. 'website_id' => $input['website_id'],
  1824. ];
  1825. // 查询栏目名称
  1826. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  1827. if(empty($category)){
  1828. $parent_alias = '';
  1829. $parent_pinyin = null;
  1830. $imgBooks = [];
  1831. $textBooks = [];
  1832. }else{
  1833. $parent_alias = $category->alias ?? '';
  1834. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1835. // 查找子分类ID数组
  1836. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1837. array_push($childCategoryIds,$parentCatId);
  1838. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  1839. if($parentImgNum!=0){
  1840. // 查询图片新闻
  1841. $imgBooks = Book::where(function($query) use ($parentCatId) {
  1842. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  1843. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  1844. })
  1845. ->where('book.status', 2)
  1846. ->where('book.img_url', '!=', '')
  1847. ->leftJoin('website_category', function($join) use ($website) {
  1848. $join->on('book.cat_id', '=', 'website_category.category_id')
  1849. ->where('website_category.website_id', '=', $website['website_id']);
  1850. })
  1851. ->select(
  1852. 'book.id',
  1853. 'book.title',
  1854. 'book.img_url',
  1855. 'book.price',
  1856. 'book.market_price',
  1857. 'book.description',
  1858. 'book.cat_id',
  1859. 'book.description',
  1860. 'book.updated_at',
  1861. 'website_category.alias as category_name',
  1862. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  1863. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  1864. )
  1865. ->orderBy('updated_at', 'desc')
  1866. ->limit($parentImgNum)
  1867. ->get()->all();
  1868. // 查询文字新闻
  1869. }
  1870. if($parentTextNum!=0){
  1871. $textBooks = [];
  1872. $textBooks = Book::where(function($query) use ($parentCatId) {
  1873. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  1874. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  1875. })
  1876. ->where('book.status', 2)
  1877. ->leftJoin('website_category', function($join) use ($website) {
  1878. $join->on('book.cat_id', '=', 'website_category.category_id')
  1879. ->where('website_category.website_id', '=', $website['website_id']);
  1880. })
  1881. ->select(
  1882. 'book.id',
  1883. 'book.title',
  1884. 'book.img_url',
  1885. 'book.price',
  1886. 'book.market_price',
  1887. 'book.description',
  1888. 'book.cat_id',
  1889. 'book.description',
  1890. 'book.updated_at',
  1891. 'website_category.alias as category_name',
  1892. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  1893. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  1894. )
  1895. ->orderBy('updated_at', 'desc')
  1896. ->limit($parentTextNum)
  1897. ->get()->all();
  1898. }
  1899. }
  1900. }
  1901. $resultItem = [
  1902. 'alias' => $parent_alias ?? '',
  1903. 'category_id' => $parentCatId ?? 0,
  1904. 'pinyin' => $parent_pinyin ?? null,
  1905. 'imgnum' => $imgBooks ?? [],
  1906. 'textnum' => $textBooks ?? [],
  1907. ];
  1908. if(isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != ""){
  1909. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin.'/' : '';
  1910. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  1911. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1912. ->get()->all();
  1913. if (!empty($childCategory)) {
  1914. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  1915. // 查询子栏目名称
  1916. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  1917. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1918. ->first();
  1919. if(empty($childCategoryInfo) || ($childImgNum==0 && $childTextNum==0)){
  1920. $childImgArticles = [];
  1921. $childTextArticles = [];
  1922. $resultItem['child'] = [];
  1923. }else{
  1924. $child_pinyin = $childCategoryInfo->aLIas_pinyin? $childCategoryInfo->aLIas_pinyin : null;
  1925. // 查询子栏目图片新闻
  1926. $childImgArticles = Book::where('cat_id', $childCatId)
  1927. ->where('status', 2)
  1928. ->where('img_url', '!=', '')
  1929. ->leftJoin('website_category', function($join) use ($website) {
  1930. $join->on('book.cat_id', '=', 'website_category.category_id')
  1931. ->where('website_category.website_id', '=', $website['website_id']);
  1932. })
  1933. ->select(
  1934. 'book.id',
  1935. 'book.title',
  1936. 'book.img_url',
  1937. 'book.price',
  1938. 'book.market_price',
  1939. 'book.description',
  1940. 'book.cat_id',
  1941. 'book.description',
  1942. 'book.updated_at',
  1943. DB::raw("'$child_pinyin' as pinyin"))
  1944. ->orderBy('updated_at', 'desc')
  1945. ->limit($childImgNum)
  1946. ->get()->all();
  1947. // 查询子栏目文字新闻
  1948. $childTextArticles = Book::where('cat_id', $childCatId)
  1949. ->where('status', 2)
  1950. ->leftJoin('website_category', function($join) use ($website) {
  1951. $join->on('book.cat_id', '=', 'website_category.category_id')
  1952. ->where('website_category.website_id', '=', $website['website_id']);
  1953. })
  1954. ->select(
  1955. 'book.id',
  1956. 'book.title',
  1957. 'book.img_url',
  1958. 'book.price',
  1959. 'book.market_price',
  1960. 'book.description',
  1961. 'book.cat_id',
  1962. 'book.description',
  1963. 'book.updated_at',
  1964. DB::raw("'$child_pinyin' as pinyin"))
  1965. ->orderBy('updated_at', 'desc')
  1966. ->limit($childTextNum)
  1967. ->get()->all();
  1968. $resultItem['child'] = [
  1969. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  1970. 'category_id' => $childCatId,
  1971. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  1972. 'all_childcat' => $childCategory,
  1973. 'imgnum' => $childImgArticles,
  1974. 'textnum' => $childTextArticles,
  1975. ];
  1976. }
  1977. }
  1978. }else{
  1979. $resultItem['child'] = [];
  1980. }
  1981. return $resultItem;
  1982. }, $data);
  1983. return Result::success($result);
  1984. }
  1985. /**
  1986. * 获取书刊列表
  1987. * @param array $data
  1988. * @return array
  1989. * */
  1990. public function getWebsiteBookList(array $data): array
  1991. {
  1992. $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
  1993. if(empty($web)){
  1994. return Result::error("查询失败", 0);
  1995. }
  1996. $catid = $data['id'];
  1997. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id',$catid)->orderBy('sort')->first(['pid','category_id','aLias_pinyin']);
  1998. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id',$category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  1999. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2000. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2001. $pinyin =$category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '' ;
  2002. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2003. ->where('pid',$category['pid'])
  2004. ->select(
  2005. 'category_id','alias','aLIas_pinyin','pid','sort','is_url','web_url',
  2006. 'seo_title','seo_keywords','seo_description',
  2007. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2008. )
  2009. ->orderBy('sort')
  2010. ->get()->all();
  2011. if(empty($category)){
  2012. return Result::error("查询失败", 0);
  2013. }
  2014. $query = Book::where('book.status', 2)
  2015. ->where('book.website_id', $data['website_id'])
  2016. ->where('book.cat_id', $catid)
  2017. ->select(
  2018. 'book.id',
  2019. 'book.title',
  2020. 'book.img_url',
  2021. 'book.description',
  2022. 'book.updated_at',
  2023. 'book.cat_id',
  2024. DB::raw("'$pinyin' as pinyin")
  2025. )
  2026. ->orderBy('book.updated_at', 'desc');
  2027. $count = $query->count();
  2028. $query = clone $query;
  2029. $Book = $query
  2030. ->limit($data['pageSize'])
  2031. ->offset(($data['page']-1)*$data['pageSize'])
  2032. ->get()->all();
  2033. $result = [
  2034. 'category' => $categorys,
  2035. 'books' => $Book,
  2036. 'count' =>$count,
  2037. ];
  2038. // if(empty($result)){
  2039. // return Result::error("查询失败", 0);
  2040. // }
  2041. return Result::success($result);
  2042. }
  2043. /**
  2044. * 获取书刊详情
  2045. * @param array $data
  2046. * @return array
  2047. * */
  2048. public function getWebsiteBookInfo(array $data): array
  2049. {
  2050. $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
  2051. if(empty($web)){
  2052. return Result::error("查询失败", 0);
  2053. }
  2054. $book = Book::where('status', 2)
  2055. ->where('website_id', $data['website_id'])
  2056. ->where('id', $data['id'])
  2057. ->select(
  2058. 'book.*',
  2059. )
  2060. ->orderBy('updated_at', 'desc')
  2061. ->first();
  2062. if(empty($book)){
  2063. return Result::error("查询失败", 0);
  2064. }
  2065. // 先查询当前分类的 pid
  2066. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2067. ->where('category_id', $book['cat_id'])
  2068. ->first(['pid','category_id']);
  2069. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2070. if(!empty($carpid)){
  2071. if($carpid->pid!=0){
  2072. $pid = $carpid['pid'];
  2073. // $parent_pinyin = '';
  2074. }else{
  2075. $pid = $carpid['category_id'];
  2076. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2077. }
  2078. }
  2079. $categorys = $query->where('pid', $pid)
  2080. ->select('category_id','alias','aLIas_pinyin','pid','sort','is_url','web_url','category_arr_id as cat_arr_id',
  2081. )
  2082. ->orderBy('sort')
  2083. ->get();
  2084. $category = $this->processArticle($categorys, $data);
  2085. $result = [
  2086. 'category' => $category,
  2087. 'books' => $book,
  2088. ];
  2089. return Result::success($result);
  2090. }
  2091. /**
  2092. * 尝试
  2093. * @param array $data
  2094. * @return array
  2095. * */
  2096. public function test(array $data): array
  2097. {
  2098. $input['id'] = $data['id'];
  2099. $input['website_id'] = $data['website_id'];
  2100. // 将 JSON 字符串转换为 PHP 数组
  2101. $data = json_decode($input['id'], true);
  2102. $result = [];
  2103. $article = $data;
  2104. $result = array_map(function ($item) use ($input) {
  2105. $website = [
  2106. 'website_id' => $input['website_id'],
  2107. ];
  2108. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2109. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  2110. $parent = [
  2111. 0 => $category['category_id'] ?? [],
  2112. 1 => $parentImgNum?? [],
  2113. 2 => $parentTextNum?? [],
  2114. ];
  2115. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2116. $child = [];
  2117. $resultItem = [
  2118. // 'alias' => $parent_alias ?? '',
  2119. 'category_id' => $parentCatId ?? 0,
  2120. 'pinyin' => $parentImgNum ?? null,
  2121. 'imgnum' => $parentTextNum ?? [],
  2122. // 'textnum' => $textArticles ?? [],
  2123. ]; return $parent;
  2124. }, $data);
  2125. return Result::success($result);
  2126. // });
  2127. }
  2128. /**
  2129. * 封装处理文章的路由问题
  2130. * */
  2131. function processArticle($article, $data) {
  2132. return $article->map(function ($article) use ($data) {
  2133. $catid = $article->cat_arr_id?? '';
  2134. $level = json_decode($catid, true);
  2135. $pinyin = '';
  2136. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2137. if (!empty($level) && is_array($level)) {
  2138. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2139. ->where('website_id', $data['website_id'])
  2140. ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
  2141. ->get(['aLIas_pinyin'])
  2142. ->pluck('aLIas_pinyin')
  2143. ->implode('/');
  2144. } else {
  2145. $pinyin = '';
  2146. }
  2147. $article->pinyin = $pinyin;
  2148. return $article;
  2149. });
  2150. }
  2151. /**
  2152. * c端-获取招工招聘下拉选框
  2153. * @param array $data
  2154. * @return array
  2155. * */
  2156. public function getWebsiteJobSelect(array $data): array
  2157. {
  2158. $web = Website::where('id', $data['website_id'])->first();
  2159. if(empty($web)){
  2160. return Result::error("该网站不存在", 0);
  2161. }
  2162. $hy = JobIndustry::get()->all();
  2163. $zw = JobPosition::where('zwpid',0)->get()->all();
  2164. $jtzw = JobPosition::where('zwpid','!=',0)->get()->all();
  2165. $result = [
  2166. 'hy' => $hy,
  2167. 'zw' => $zw,
  2168. 'jtzw' => $jtzw,
  2169. ];
  2170. if(empty($result)){
  2171. return Result::error("查询失败", 0);
  2172. }
  2173. return Result::success($result);
  2174. }
  2175. /**
  2176. * c端-获取招工招聘
  2177. * @param array $data
  2178. * @return array
  2179. * */
  2180. public function getWebsiteJob(array $data): array
  2181. {
  2182. $web = Website::where('id', $data['website_id'])->first();
  2183. if(empty($web)){
  2184. return Result::error("该网站不存在", 0);
  2185. }
  2186. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2187. ->where('job_hunting.website_id', $data['website_id'])
  2188. ->when(isset($data['city_id']) &&!empty($data['city_id']), function ($query) use ($data) {
  2189. $query->where(function($q) use ($data) {
  2190. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '". intval($data['city_id']). "') = 1");
  2191. });
  2192. })
  2193. ->select('job_hunting.id','job_hunting.cat_arr_id','job_hunting.job_name_get','job_hunting.industry','job_hunting.name','job_hunting.sexy'
  2194. ,'job_hunting.origin','job_hunting.city_arr_id','job_hunting.experience','job_hunting.updated_at','job_hunting.salary')
  2195. ->orderBy('updated_at', 'desc')
  2196. ->limit($data['job1_num'])
  2197. ->get();
  2198. $web['website_id'] = $data['website_id'];
  2199. if(empty($job_hunting)){
  2200. $job_huntings = "未查询到相关简历信息";
  2201. }else{
  2202. $job_huntings = $this->processJob($job_hunting, $web);
  2203. }
  2204. // 0:待审核 1:已通过 2:已拒绝
  2205. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2206. ->where('job_recruiting.website_id', $data['website_id'])
  2207. ->when(isset($data['city_id']) &&!empty($data['city_id']), function ($query) use ($data) {
  2208. $query->where(function($q) use ($data) {
  2209. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '". intval($data['city_id']). "') = 1");
  2210. });
  2211. })
  2212. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2213. ->select('job_recruiting.id','job_recruiting.cat_arr_id','job_recruiting.title',
  2214. 'job_recruiting.jtzw_id','job_recruiting.hy_id','job_recruiting.city_arr_id',
  2215. 'job_recruiting.due_data','job_recruiting.updated_at','job_recruiting.experience',
  2216. 'job_recruiting.educational','job_recruiting.salary','job_recruiting.zw_id','job_company.business_name')
  2217. ->orderBy('updated_at', 'desc')
  2218. ->limit($data['job2_num'])
  2219. ->get();
  2220. if(empty($job_recruiting->toArray())){
  2221. $job_recruitings = "未查询到相关职位信息";
  2222. }else{
  2223. $job_recruitings = $this->processJob($job_recruiting, $web);
  2224. }
  2225. $result = [
  2226. 'job_hunting' => $job_huntings,
  2227. 'job_recuiting' => $job_recruitings,
  2228. ];
  2229. return Result::success($result);
  2230. }
  2231. /**
  2232. * c端-获取招工招聘列表
  2233. * @param array $data
  2234. * @return array
  2235. * */
  2236. public function getWebsiteJobList(array $data): array
  2237. {
  2238. $recruit_where = [];
  2239. $hunt_where = [];
  2240. $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
  2241. if(empty($web)){
  2242. return Result::error("此网站不存在", 0);
  2243. }
  2244. $website_id['website_id'] = $data['website_id'];
  2245. if((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])){
  2246. if(isset($data['zw_id']) && !empty($data['zw_id'])){
  2247. array_push($recruit_where, ['zw_id',$data['zw_id']]);
  2248. }
  2249. if(isset($data['jtzw_id']) &&!empty($data['jtzw_id'])){
  2250. array_push($recruit_where, ['jtzw_id',$data['jtzw_id']]);
  2251. }
  2252. if(isset($data['hy_id']) && !empty($data['hy_id'])){
  2253. array_push($recruit_where, ['hy_id',$data['hy_id']]);
  2254. }
  2255. if(isset($data['keyword']) && !empty($data['keyword'])){
  2256. array_push($recruit_where, ['title','like','%'.$data['keyword'].'%']);
  2257. }
  2258. $query = JobRecruiting::where('job_recruiting.status', 1)
  2259. ->where('job_recruiting.website_id', $data['website_id'])
  2260. ->where($recruit_where)
  2261. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2262. $query->where(function($q) use ($data) {
  2263. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '". intval($data['city_id']). "') = 1");
  2264. });
  2265. })
  2266. ->when(isset($data['catid']) &&!empty($data['catid']), function ($query) use ($data) {
  2267. $query->where(function($q) use ($data) {
  2268. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '". intval($data['catid']). "') = 1");
  2269. });
  2270. })
  2271. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2272. ->select('job_recruiting.id','job_recruiting.hy_id','job_recruiting.title','job_recruiting.zw_id','job_recruiting.educational',
  2273. 'job_recruiting.jtzw_id','job_recruiting.city_arr_id','job_recruiting.due_data','job_recruiting.experience',
  2274. 'job_recruiting.cat_arr_id','job_recruiting.updated_at','job_company.business_name')
  2275. ->orderBy('updated_at', 'desc');
  2276. $recruit_count = $query->count();
  2277. $query = clone $query;
  2278. $JobRecruiting = $query
  2279. ->offset(($data['page']-1)*$data['pageSize'])
  2280. ->limit($data['pageSize'])
  2281. ->get();
  2282. if(empty($JobRecruiting)){
  2283. $JobRecruiting = "暂无相关职位信息";
  2284. }else{
  2285. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2286. }
  2287. }
  2288. if((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])){
  2289. if(isset($data['zw_id']) && !empty($data['zw_id'])){
  2290. array_push($hunt_where, ['job',$data['zw_id']]);
  2291. }
  2292. if(isset($data['jtzw_id']) &&!empty($data['jtzw_id'])){
  2293. array_push($hunt_where, ['job_name_get',$data['jtzw_id']]);
  2294. }
  2295. if(isset($data['hy_id']) && !empty($data['hy_id'])){
  2296. array_push($hunt_where, ['industry',$data['hy_id']]);
  2297. }
  2298. $query = JobHunting::where('status', 2)
  2299. ->where('job_hunting.website_id', $data['website_id'])
  2300. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  2301. ->where($hunt_where)
  2302. ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  2303. $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  2304. })
  2305. ->when(isset($data['city_id']) &&!empty($data['city_id']), function ($query) use ($data) {
  2306. $query->where(function($q) use ($data) {
  2307. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '". intval($data['city_id']). "') = 1");
  2308. });
  2309. })
  2310. ->when(isset($data['catid_id']) &&!empty($data['catid_id']), function ($query) use ($data) {
  2311. $query->where(function($q) use ($data) {
  2312. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '". intval($data['catid_id']). "') = 1");
  2313. });
  2314. })
  2315. ->select('id','sexy','experience','origin','industry','name','job','job_name_get','city_arr_id','cat_arr_id','created_at','updated_at')
  2316. ->orderBy('updated_at', 'desc');
  2317. $hunt_count = $query->count();
  2318. $query = clone $query;
  2319. $JobHunting = $query
  2320. ->offset(($data['page']-1)*$data['pageSize'])
  2321. ->limit($data['pageSize'])
  2322. ->get();
  2323. if(empty($JobHunting)){
  2324. $JobRecruiting = "暂无相关简历信息";
  2325. }else{
  2326. $JobHunting = $this->processJob($JobHunting, $website_id);
  2327. }
  2328. }
  2329. $result = [
  2330. 'JobRecruiting' => $JobRecruiting ?? [],
  2331. 'recruit_count' =>$recruit_count ?? 0,
  2332. 'JobHunting' => $JobHunting ?? [],
  2333. 'hunt_count' =>$hunt_count ?? 0,
  2334. ];
  2335. return Result::success($result);
  2336. }
  2337. /**
  2338. * c端-获取招工招聘详情
  2339. * @param array $data
  2340. * @return array
  2341. * */
  2342. public function getWebsiteJobInfo(array $data): array
  2343. {
  2344. $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
  2345. if(empty($web)){
  2346. return Result::error("该网站不存在", 0);
  2347. }
  2348. $webid = [
  2349. 'website_id' => $data['website_id'],
  2350. ];
  2351. // 职位相关信息
  2352. if($data['type']==1){
  2353. $query = JobRecruiting::where('status', 1)
  2354. ->where('website_id', $data['website_id'])
  2355. ->select('*');
  2356. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2357. $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();
  2358. if(!empty($company)){
  2359. $result['company'] = $this->processJob($company, $webid);
  2360. }
  2361. $other_job =JobRecruiting::where('status', 1)
  2362. ->where('website_id', $data['website_id'])
  2363. ->select('title','id','updated_at','cat_arr_id','user_id')
  2364. ->where('id','!=',$data['id'])
  2365. ->where('user_id', '=', $job[0]['user_id'])
  2366. ->limit($data['pageSize'])
  2367. ->get();
  2368. if(!empty($other_job)){
  2369. $result['other_job'] = $this->processJob($other_job, $webid);
  2370. }
  2371. }else{
  2372. // 简历相关信息
  2373. $job = JobHunting::where('job_hunting.status', 2)
  2374. ->where('job_hunting.website_id', $data['website_id'])
  2375. ->where('job_hunting.id', $data['id'])
  2376. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2377. ->select('job_hunting.*','user_name')
  2378. ->get();
  2379. $resume = JobRemuse::where('hunt_id',$data['id'])->get();
  2380. if(!empty($resume->toArray())){
  2381. $result['resume'] = 1;
  2382. } else{
  2383. $result['resume'] = 0;
  2384. }
  2385. }
  2386. if(empty($job->toArray())){
  2387. return Result::error("id参数错误", 0);
  2388. }
  2389. if(!empty($job[0]['job_experience'])){
  2390. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  2391. if(!empty($job_experience)){
  2392. // $hy = [];
  2393. foreach($job_experience as $key => $value){
  2394. // $id = $value['id'];
  2395. $hy[$key] = $value['job_industry'];
  2396. $zw_id[$key] = $value['job_typename'];
  2397. $jtzw_id[$key] = $value['job_name'];
  2398. }
  2399. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid','hyname')->get();
  2400. $zw_table = JobPosition::select('zwid','zwname')->get();
  2401. // 先将关联表转换为索引数组,提高查找效率
  2402. $hyLookup = [];
  2403. foreach ($hy_table as $item) {
  2404. $hyLookup[$item['hyid']] = $item['hyname'];
  2405. }
  2406. $zwLookup = [];
  2407. foreach ($zw_table as $item) {
  2408. $zwLookup[$item['zwid']] = $item['zwname'];
  2409. }
  2410. foreach ($job_experience as $key => &$value) {
  2411. // 处理行业名称
  2412. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  2413. $value['hy_name'] = $hyLookup[$hy[$key]];
  2414. }
  2415. // 处理职位名称
  2416. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  2417. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  2418. }
  2419. // 处理具体职位名称
  2420. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  2421. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  2422. }
  2423. }
  2424. // 释放引用,防止意外修改后续代码
  2425. unset($value);
  2426. }
  2427. $result['job_experience'] = $job_experience?? [];
  2428. }
  2429. if(!empty($job[0]['education_experience'])){
  2430. $education_experience = json_decode($job[0]['education_experience'],true)?? '';
  2431. if(!empty($education_experience)){
  2432. foreach($education_experience as $key => $value){
  2433. // $id = $value['id'];
  2434. $education[$key] = $value['school_education'];
  2435. }
  2436. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue',$education)->select('evalue','ename')->get();
  2437. // // 先将关联表转换为索引数组,提高查找效率
  2438. $educationLookup = [];
  2439. foreach ($education_table as $item) {
  2440. $educationLookup[$item['evalue']] = $item['ename'];
  2441. }
  2442. foreach ($education_experience as $key => &$value) {
  2443. // 处理学历名称
  2444. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  2445. $value['education_name'] = $educationLookup[$education[$key]];
  2446. }
  2447. }
  2448. }
  2449. $result['education_experience'] = $job_experience?? [];
  2450. }
  2451. $result['job'] = $this->processJob($job, $webid);
  2452. // // 返现对应的栏目
  2453. $catid = json_decode($job[0]['cat_arr_id'],true) ?? '';
  2454. $category = WebsiteCategory::where('website_id', $data['website_id'])
  2455. ->whereIn('category_id', $catid)
  2456. ->select('category_id','alias','aLIas_pinyin','pid')
  2457. ->orderBy('pid')->get()->all();
  2458. if(!empty($category)){
  2459. $result['category'] = $category;
  2460. }
  2461. $result['job'] = $job;
  2462. $result['job_experience'] = $job_experience?? [];
  2463. $result['education_experience'] = $education_experience?? [];
  2464. if(empty($result)){
  2465. return Result::error("参数错误", 0);
  2466. }
  2467. return Result::success($result);
  2468. }
  2469. /**
  2470. * c端-申请职位
  2471. * @param array $data
  2472. * @return array
  2473. * */
  2474. public function getWebsiteJobApply(array $data): array
  2475. {
  2476. // 首先验证网站是否存在
  2477. // return Result::success($data);
  2478. $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
  2479. if(empty($web)){
  2480. return Result::error("该网站不存在", 0);
  2481. }
  2482. // 验证用户是否存在且为个人会员/管理员
  2483. $user = User::where('id', $data['user_id'])->first(['id','type_id']);
  2484. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2485. if(empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)){
  2486. return Result::error("用户不存在", 0);
  2487. }
  2488. // 去除重复元素和空元素,并保持原始顺序
  2489. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function($value) {
  2490. return !empty($value);
  2491. }));
  2492. // 验证职位是否存在 1:审核通过
  2493. $recruiting = JobRecruiting::where('status', 1)
  2494. ->where('website_id', $data['website_id'])
  2495. ->whereIn('id',$data['recruit_id'])
  2496. ->get(['id as recruit_id','user_id as receiver_id'])->all();
  2497. if(empty($recruiting)){
  2498. return Result::error("该职位不存在", 0);
  2499. }
  2500. // 简历是否存在
  2501. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status',2)->first(['id as hunt_id']);
  2502. if(empty($hunt_id)){
  2503. return Result::error("该简历不存在", 0);
  2504. }
  2505. $data['hunt_id'] = $hunt_id['hunt_id'];
  2506. // // 验证是否已投递过该职位
  2507. $apply = JobApply::where('user_id', $data['user_id'])
  2508. ->where('hunt_id', $data['hunt_id'])
  2509. ->where('website_id',$data['website_id'])
  2510. ->whereIn('recruit_id',$data['recruit_id'])
  2511. ->get(['recruit_id']);
  2512. if(!empty($apply->toArray())){
  2513. return Result::error("您已投递过该职位!");
  2514. }
  2515. $insertData = array_map(function($recruiting) use ($data) {
  2516. return [
  2517. 'user_id' => $data['user_id'],
  2518. 'hunt_id' => $data['hunt_id'],
  2519. 'website_id' => $data['website_id'],
  2520. 'recruit_id' => $recruiting['recruit_id'],
  2521. 'receiver_id' => $recruiting['receiver_id'],
  2522. 'status' => 1,
  2523. ];
  2524. }, $recruiting);
  2525. // 批量插入数据
  2526. $result = JobApply::insert($insertData);
  2527. if(empty($result)){
  2528. return Result::error("投递失败", 0);
  2529. }
  2530. return Result::success($result);
  2531. }
  2532. /**
  2533. * 招工招聘-沟通简历
  2534. * @param array $data
  2535. * @return array
  2536. * */
  2537. public function getWebsiteJobResume(array $data): array
  2538. {
  2539. // 首先验证网站是否存在
  2540. $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
  2541. if(empty($web)){
  2542. return Result::error("该网站不存在", 0);
  2543. }
  2544. // return Result::success($data);
  2545. // 验证用户是否存在且为企业会员/管理员
  2546. $user = User::where('id', $data['user_id'])->first(['id','type_id']);
  2547. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2548. if(empty($user) || ($user['type_id']!= 3 && $user['type_id']!= 10000)){
  2549. return Result::error("用户不存在", 0);
  2550. }
  2551. // 去除重复元素和空元素,并保持原始顺序
  2552. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function($value) {
  2553. return !empty($value);
  2554. }));
  2555. // 验证简历是否存在
  2556. $hunting = JobHunting::where('status', 2)
  2557. ->where('website_id', $data['website_id'])
  2558. ->whereIn('id',$data['hunt_id'])
  2559. ->get(['id as hunt_id','user_id as receiver_id'])->all();
  2560. if(empty($hunting)){
  2561. return Result::error("该简历不存在", 0);
  2562. }
  2563. // 验证是否已沟通过该简历
  2564. $remuse = JobRemuse::where('user_id', $data['user_id'])
  2565. ->where('recruit_id', $data['recruit_id'])
  2566. ->where('website_id',$data['website_id'])
  2567. ->whereIn('hunt_id',$data['hunt_id'])
  2568. ->get(['hunt_id']);
  2569. if(!empty($remuse->toArray())){
  2570. return Result::error("您已沟通过该简历!");
  2571. }
  2572. // 准备要插入的数据数组
  2573. $insertData = array_map(function($hunting) use ($data) {
  2574. return [
  2575. 'user_id' => $data['user_id'],
  2576. 'recruit_id' => $data['recruit_id'],
  2577. 'website_id' => $data['website_id'],
  2578. 'hunt_id' => $hunting['hunt_id'],
  2579. 'receiver_id' => $hunting['receiver_id'],
  2580. 'status' => 1,
  2581. ];
  2582. }, $hunting);
  2583. // 批量插入数据
  2584. $result = JobRemuse::insert($insertData);
  2585. if(empty($result)){
  2586. return Result::error("沟通失败", 0);
  2587. }
  2588. return Result::success($result);
  2589. }
  2590. /**
  2591. * 招工招聘 -我的职位(企业会员)
  2592. * @param array $data
  2593. * @return array
  2594. */
  2595. public function getWebsiteJobRecruiting(array $data): array
  2596. {
  2597. $web = Website::where('id', $data['website_id'])->first('id');
  2598. if(empty($web)){
  2599. return Result::error("该网站不存在", 0);
  2600. }
  2601. $user = User::where('id', $data['user_id'])->first(['id','type_id']);
  2602. if(empty($user) || ($user['type_id']!= 3 && $user['type_id']!= 10000)){
  2603. return Result::error("用户暂无权限!", 0);
  2604. }
  2605. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  2606. $result = JobRecruiting::where('website_id', $data['website_id'])
  2607. ->when(isset($user['type_id']) && $user['type_id']== 3, function ($query) use ($user) {
  2608. $query->where('user_id', $user['id']);
  2609. })
  2610. ->where('status', 1)
  2611. ->select('id','title','website_id','user_id','updated_at')
  2612. ->orderBy('updated_at', 'desc')
  2613. ->limit($data['pageSize'])
  2614. ->get();
  2615. if(empty($result)){
  2616. return Result::error("暂无相关职位信息", 0);
  2617. }
  2618. return Result::success($result);
  2619. }
  2620. /**
  2621. * c端 - 验证路由
  2622. * @param array $data
  2623. * @return array
  2624. */
  2625. public function checkWebsiteRoute(array $data): array
  2626. {
  2627. $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
  2628. if(empty($web)){
  2629. return Result::error("该网站不存在", 0);
  2630. }
  2631. // 验证栏目路由
  2632. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  2633. ->where('aLIas_pinyin', $data['last_route'])
  2634. ->first();
  2635. if(empty($last_category)){
  2636. return Result::error("该栏目不存在", 0);
  2637. }
  2638. if(isset($data['id']) && !empty($data['id'])){
  2639. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  2640. switch ($last_category['type']) {
  2641. case 1:
  2642. // 文章
  2643. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  2644. $article = Article::where('status', 1)
  2645. ->where('id', $data['id'])
  2646. ->where(function ($query) use ($data) {
  2647. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  2648. ->orWhereNull("ignore_ids");
  2649. })
  2650. ->first(['cat_arr_id']);
  2651. if(empty($article)){
  2652. return Result::error("该文章不存在", 0);
  2653. }
  2654. // return Result::success($article);
  2655. break;
  2656. case 2:
  2657. // 商品
  2658. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  2659. $article = Good::where('website_id', $data['website_id'])
  2660. ->where('status', 2)
  2661. ->where('id', $data['id'])
  2662. ->first(['cat_arr_id']);
  2663. if(empty($article)){
  2664. return Result::error("该商品不存在", 0);
  2665. }
  2666. break;
  2667. case 3:
  2668. // 书刊信息
  2669. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  2670. $article = Book::where('website_id', $data['website_id'])
  2671. ->where('status', 2)
  2672. ->where('id', $data['id'])
  2673. ->first(['id','cat_arr_id']);
  2674. if(empty($article)){
  2675. return Result::error("该书刊不存在", 0);
  2676. }
  2677. break;
  2678. case 4:
  2679. // 招聘
  2680. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核;(只有企业会员需要审核)',
  2681. $article = JobRecruiting::where('website_id', $data['website_id'])
  2682. ->where('status', 1)
  2683. ->where('id', $data['id'])
  2684. ->first(['cat_arr_id']);
  2685. if(empty($article)){
  2686. return Result::error("该招聘不存在", 0);
  2687. }
  2688. break;
  2689. case 5:
  2690. // 求职
  2691. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  2692. $article = JobHunting::where('website_id', $data['website_id'])
  2693. ->where('status', 2)
  2694. ->where('id', $data['id'])
  2695. ->first(['cat_arr_id']);
  2696. if(empty($article)){
  2697. return Result::error("该求职不存在", 0);
  2698. }
  2699. break;
  2700. case 6:
  2701. // 招工招聘
  2702. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  2703. $article = JobRecruiting::where('website_id', $data['website_id'])
  2704. ->where('status', 1)
  2705. ->where('id', $data['id'])
  2706. ->first(['cat_arr_id']);
  2707. if(empty($article)){
  2708. $article = JobHunting::where('website_id', $data['website_id'])
  2709. ->where('status', 2)
  2710. ->where('id', $data['id'])
  2711. ->first(['cat_arr_id']);
  2712. }
  2713. if(empty($article)){
  2714. return Result::error("该招工招聘不存在", 0);
  2715. }
  2716. break;
  2717. default:
  2718. return Result::error("该数据不存在", 0);
  2719. break;
  2720. }
  2721. $catid = json_decode($article['cat_arr_id'], true);
  2722. if(empty($catid)){
  2723. return Result::error("该数据不存在", 0);
  2724. }
  2725. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2726. ->orderByRaw('FIELD(category_id, '. implode(',', $catid). ')')
  2727. ->whereIn('category_id', $catid)
  2728. ->pluck('aLIas_pinyin')
  2729. ->implode('/');
  2730. }
  2731. if($last_category['pid']!=0){
  2732. $cat_arr = json_decode($last_category['category_arr_id'], true);
  2733. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2734. ->orderByRaw('FIELD(category_id, '. implode(',', $cat_arr). ')')
  2735. ->whereIn('category_id', $cat_arr)
  2736. ->pluck('aLIas_pinyin')
  2737. ->implode('/');
  2738. }else{
  2739. $pinyin = $last_category['aLIas_pinyin'];
  2740. }
  2741. if(empty($pinyin) || $pinyin!=$data['all_route']){
  2742. return Result::error('非法路径!');
  2743. }else{
  2744. return Result::success($pinyin);
  2745. }
  2746. }
  2747. /**
  2748. * 招工招聘 - 获取推荐职位
  2749. * @param array $data
  2750. * @return array
  2751. */
  2752. public function getWebsiteLevelJob(array $data): array
  2753. {
  2754. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  2755. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  2756. ->where('job_recruiting.status', 1)
  2757. ->where('job_level', $data['job_level'])
  2758. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2759. ->select('job_recruiting.id','job_recruiting.title','job_recruiting.cat_arr_id','job_company.business_name','job_recruiting.updated_at')
  2760. ->orderBy('job_recruiting.updated_at', 'desc')
  2761. ->limit($data['pageSize'])
  2762. ->get();
  2763. $web = ['website_id' => $data['website_id']];
  2764. if(!empty($job)){
  2765. $result = $this->processJob($job, $web);
  2766. }
  2767. if(empty($result)){
  2768. return Result::error("暂无相关职位信息", 0);
  2769. }
  2770. return Result::success($result);
  2771. }
  2772. /**
  2773. * @param array $data
  2774. * @return array
  2775. */
  2776. public function getWebsiteCompany(array $data): array
  2777. {
  2778. $where['website_id'] = $data['website_id'];
  2779. $where['status'] = 1;
  2780. if(isset($data['category_id']) && !empty($data['category_id'])){
  2781. $where['category_id'] = $data['category_id'];
  2782. }
  2783. if(isset($data['level']) && !empty($data['level'])){
  2784. $where['level'] = $data['level'];
  2785. }
  2786. // return Result::success($where);
  2787. $query = Company::where($where);
  2788. $result['img'] = $this->processArticle(
  2789. $query->clone()
  2790. ->where('imgurl','!=', '')
  2791. ->whereNotNull('imgurl')
  2792. ->select('id','imgurl','title','introduce','description','content','category_id','cat_arr_id')
  2793. ->orderBy('updated_at', 'desc')
  2794. ->limit($data['imgnum'])
  2795. ->get(),
  2796. $data
  2797. );
  2798. $result['text'] = $this->processArticle(
  2799. $query->clone()
  2800. ->select('id','title','introduce','description','content','category_id','cat_arr_id')
  2801. ->orderBy('updated_at', 'desc')
  2802. ->limit($data['textnum'])
  2803. ->get(),
  2804. $data
  2805. );
  2806. if(empty($result)){
  2807. return Result::error("暂无相关公司信息", 0);
  2808. }
  2809. return Result::success($result);
  2810. }
  2811. /**
  2812. * @param array $data
  2813. * @return array
  2814. */
  2815. public function getWebsiteCompanyList(array $data): array
  2816. {
  2817. $where['website_id'] = $data['website_id'];
  2818. $where['status'] = 1;
  2819. if(isset($data['category_id']) && !empty($data['category_id'])){
  2820. $where['category_id'] = $data['category_id'];
  2821. }
  2822. if(isset($data['keyword']) && !empty($data['keyword'])){
  2823. array_push($where, ['title', 'like', '%' . $data['keyword'] . '%']);
  2824. }
  2825. $query = Company::where($where);
  2826. $company = $this->processArticle(
  2827. $query->select('id','title','introduce','description','content','category_id','cat_arr_id')
  2828. ->orderBy('updated_at', 'desc')
  2829. ->offset(($data['page'] - 1) * $data['pageSize'])
  2830. ->limit($data['pageSize'])
  2831. ->get(),
  2832. $data
  2833. );
  2834. if(empty($company)){
  2835. return Result::error("暂无相关公司信息", 0);
  2836. }
  2837. $result = [
  2838. 'count' => $query->clone()->count(),
  2839. 'data' => $company,
  2840. ];
  2841. return Result::success($result);
  2842. }
  2843. /**
  2844. * @param array $data
  2845. * @return array
  2846. */
  2847. public function getWebsiteCompanyInfo(array $data): array
  2848. {
  2849. $company = Company::where('id', $data['id'])
  2850. ->where('status', 1)
  2851. ->where('website_id', $data['website_id'])
  2852. ->select('company.*')
  2853. ->first();
  2854. if(empty($company)){
  2855. return Result::error("暂无相关公司信息", 0);
  2856. }
  2857. return Result::success($company);
  2858. }
  2859. }