NewsService.php 145 KB

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