NewsService.php 141 KB

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