NewsService.php 125 KB

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