NewsService.php 126 KB

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