NewsService.php 151 KB

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