NewsService.php 124 KB

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