NewsService.php 142 KB

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