NewsService.php 114 KB

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