NewsService.php 132 KB

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