WebService.php 152 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\Ad;
  5. use App\Model\Category;
  6. use App\Model\AdPlace;
  7. use App\Model\Department;
  8. use App\Model\District;
  9. use App\Model\FooterCategory;
  10. use App\Model\FooterContent;
  11. use App\Model\WebsiteTemplateInfo;
  12. use App\Model\Link;
  13. use App\Model\LetterOfComplaint;
  14. use App\Model\User;
  15. use App\Model\UserInfo;
  16. use App\Model\WebsiteRole;
  17. use App\Model\WebsiteRoleUser;
  18. use App\Model\Website;
  19. use App\Model\WebsiteColumn;
  20. use App\Model\Good;
  21. use App\Model\Book;
  22. use App\Model\ChatRecords;
  23. use App\Model\ChatTopic;
  24. use App\Model\JobRecruiting;
  25. use App\Model\JobHunting;
  26. use App\Model\Notice;
  27. use App\Model\Complaint;
  28. use App\Model\Order;
  29. use App\Model\WebsiteImg;
  30. use App\Model\Company;
  31. use App\Model\Project;
  32. use App\Model\ChatTopicsReply;
  33. use App\Model\ArticleSurvey;
  34. use App\Model\JobIndustry;
  35. use App\Model\JobPosition;
  36. use App\Model\JobEnum;
  37. use App\Model\JobRemuse;
  38. use App\Model\JobCompany;
  39. use App\Model\JobNature;
  40. use App\Model\JobApply;
  41. use Hyperf\HttpServer\Contract\RequestInterface;
  42. use Hyperf\DbConnection\Db;
  43. use Hyperf\RpcServer\Annotation\RpcService;
  44. use App\Tools\Result;
  45. use Carbon\Carbon;
  46. use App\Model\WebsiteCategory;
  47. use App\Model\WebsiteGroup;
  48. use App\Model\WebsiteTemplate;
  49. use App\Model\Sector;
  50. use PhpParser\Node\Stmt\Return_;
  51. use SimpleKafkaClient\Metadata\Topic;
  52. use function PHPUnit\Framework\isNull;
  53. use Overtrue\Pinyin\Pinyin;
  54. use App\Tools\buildTree;
  55. use App\Model\WhiteRouter;
  56. use App\Model\Size;
  57. use App\Tools\PinyinHelper;
  58. use Hyperf\HttpServer\Annotation\AutoController;
  59. use Hyperf\Utils\Parallel;
  60. use Hyperf\Coroutine\Concurrent;
  61. use function Hyperf\Coroutine\batch;
  62. use Swoole\Coroutine;
  63. use App\Model\Message;
  64. use App\Model\ResearchTopic;
  65. #[RpcService(name: "WebService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  66. class WebService implements WebServiceInterface
  67. {
  68. /**
  69. * 获取栏目
  70. * @param array $data
  71. * @return array
  72. */
  73. public function getWebsiteModelCategory(array $data): array
  74. {
  75. // return Result::success($data);
  76. $website_id = [
  77. 'website_id' => $data['website_id'],
  78. ];
  79. $website_column_arr = Website::where('id', $data['website_id'])->value('website_column_arr_id');
  80. if (empty($website_column_arr)) {
  81. return Result::error("未查询到此网站所属网系!", 0);
  82. }
  83. $website_column_arr = json_decode($website_column_arr, true);
  84. // return Result::success(!in_array(3,$website_column_arr) && $data['pid'] == 0);
  85. // 初始化 $pid 数组
  86. // $pid = [];
  87. // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
  88. $pidQuery = WebsiteCategory::where($website_id)
  89. ->where('pid', '!=', 0)
  90. ->orderBy('sort')
  91. ->select('pid', 'category_id', 'alias', 'aLIas_pinyin');
  92. $pid = $pidQuery->pluck('pid');
  93. $pid = array_values(array_unique($pid->toArray()));
  94. // 构建查询语句
  95. $query = WebsiteCategory::where($website_id)
  96. ->when(!in_array(3, $website_column_arr) && $data['pid'] == 0, function ($query) use ($website_column_arr) {
  97. $query->where('is_show', 1);
  98. })
  99. ->when(in_array(3, $website_column_arr) || $data['pid'] != 0, function ($query) use ($data) {
  100. $query->where('pid', $data['pid']);
  101. })
  102. ->offset($data['placeid'])
  103. ->limit($data['num'])
  104. ->orderBy('sort')
  105. ->orderBy('updated_at', 'desc');
  106. // 如果 $pid 数组不为空,添加 CASE WHEN 条件
  107. if (!empty($pid)) {
  108. $placeholders = implode(',', array_fill(0, count($pid), '?'));
  109. $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
  110. } else {
  111. // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
  112. $query->select('website_category.*', DB::raw('0 as children_count'));
  113. }
  114. // 执行查询
  115. $placeid = $data['placeid'] - 1;
  116. $result = $query->offset($placeid)->limit($data['num'])->get();
  117. if (!empty($result)) {
  118. $pidResults = $pidQuery->get();
  119. if (isset($data['type']) && $data['type'] == 1) {
  120. $result = $result->map(function ($item) use ($pidResults) {
  121. $children = $pidResults->where('pid', $item->category_id)->map(function ($child) {
  122. if (!empty($child)) {
  123. return $child;
  124. }
  125. });
  126. // 重置索引,使 key 值从 0 开始
  127. $item->children = $children->values();
  128. return $item;
  129. });
  130. } else {
  131. $pidMap = $pidResults->keyBy('pid');
  132. $result->each(function ($record) use ($pidMap, $data) {
  133. if ($data['pid'] == 0) {
  134. $record->aLIas_pinyin = $record->path;
  135. }
  136. // $record->aLIas_pinyin = $record->path;
  137. if ($pidMap->has($record->category_id)) {
  138. $pidResult = $pidMap->get($record->category_id);
  139. $record->chilid_id = $pidResult->category_id;
  140. $record->chilid_alias = $pidResult->alias;
  141. // $record->aLIas_pinyin = $pidResult->aLIas_pinyin;
  142. }
  143. });
  144. }
  145. return Result::success($result);
  146. } else {
  147. return Result::error("本网站暂无栏目", 0);
  148. }
  149. }
  150. /**
  151. * 获取网站栏目seo
  152. * @param array $data
  153. * @return array
  154. */
  155. public function getWebsiteCategoryHead(array $data): array
  156. {
  157. if (isset($data['website_id']) && !empty($data['website_id'])) {
  158. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  159. if (empty($website)) {
  160. return Result::error("找不到网站", 0);
  161. }
  162. } else {
  163. return Result::error("参数错误", 0);
  164. }
  165. if (isset($data['catid']) && !empty($data['catid'])) {
  166. $result = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->first();
  167. }
  168. if (empty($result)) {
  169. return Result::error("暂无导航", 0);
  170. }
  171. $result['aLIas_pinyin'] = $result['path'] ?? '';
  172. $result['website_name'] = $website['website_name'] ?? '';
  173. $result['suffix'] = $website['suffix'] ?? '';
  174. return Result::success($result);
  175. }
  176. /*
  177. * 获取某个栏目
  178. * @param array $data
  179. * @return array
  180. * */
  181. public function getOneWebsiteCategory(array $data): array
  182. {
  183. if (isset($data['website_id']) && !empty($data['website_id'])) {
  184. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  185. if (empty($website)) {
  186. return Result::error("暂无该网站", 0);
  187. }
  188. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['category_id'])->first();
  189. if (empty($category)) {
  190. return Result::error("暂无此导航", 0);
  191. }
  192. $category['children_count'] = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['category_id'])->count();
  193. $parent = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->select('category_id as parent_id', 'alias as parent_name', 'aLIas_pinyin')->first();
  194. // return Result::success($parent);
  195. // $category['aLIas_pinyin'] = $category['path'] ?? '';
  196. $category['parent_id'] = $parent['parent_id'] ?? '';
  197. $category['parent_pinyin'] = $parent['aLIas_pinyin'] ?? '';
  198. $category['parent_name'] = $parent['parent_name'] ?? '';
  199. return Result::success($category);
  200. } else {
  201. return Result::error("参数错误", 0);
  202. }
  203. }
  204. /**
  205. * 路由匹配
  206. * @param array $data
  207. */
  208. public function getWebsiteRoute(array $data): array
  209. {
  210. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  211. if (empty($website)) {
  212. return Result::error("暂无该网站", 0);
  213. }
  214. if (isset($data['pinyin']) &&!empty($data['pinyin'])) {
  215. $result = WebsiteCategory::where('website_id',$data['website_id'])
  216. ->where('path',$data['pinyin'])
  217. // $result = WebsiteCategory::where('category_id', $category_id)
  218. // ->where('website_category.path', $data['pinyin'])
  219. // ->leftJoin('website_category as pc', function ($join) use ($data) {
  220. // $join->on('pc.pid', '=', 'website_category.category_id')
  221. // ->where('pc.website_id', '=', $data['website_id']);
  222. // })
  223. ->select('website_category.category_id', 'website_category.type', 'website_category.alias',)
  224. ->first();
  225. }
  226. if (isset($data['foot_pinyin']) && !empty($data['foot_pinyin'])) {
  227. $result = FooterCategory::where('website_id', $data['website_id'])->where('name_pinyin', $data['foot_pinyin'])->first(['id']);
  228. }
  229. if (!isset($result) || empty($result)) {
  230. return Result::error("暂无该导航", 0);
  231. }
  232. return Result::success($result);
  233. }
  234. /**
  235. * c端 - 验证路由
  236. * @param array $data
  237. * @return array
  238. */
  239. public function checkWebsiteRoute(array $data): array
  240. {
  241. // 测试001111111222
  242. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  243. if (empty($web)) {
  244. return Result::error("该网站不存在", 0);
  245. } elseif ($web['status'] != 1) {
  246. return Result::error("网站已经关闭", 0);
  247. }
  248. if (isset($data['other_route']) && !empty($data['other_route'])) {
  249. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  250. // 验证路由是否存在
  251. if (empty($whiteRouterInfo)) {
  252. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  253. }
  254. if (!empty($whiteRouterInfo)) {
  255. return Result::success($whiteRouterInfo->toArray());
  256. }
  257. }
  258. // 验证栏目路由
  259. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  260. ->where('path', $data['all_route'])
  261. ->get()->all();
  262. if (count($last_category) == 0) {
  263. return Result::error("该栏目不存在", 0);
  264. }
  265. if (count($last_category) > 1) {
  266. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  267. }
  268. if (count($last_category) == 1) {
  269. $last_category = $last_category[0];
  270. }
  271. // return Result::success($last_category);
  272. if (isset($data['id']) && !empty($data['id'])) {
  273. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  274. switch ($last_category['type']) {
  275. case 1:
  276. // 文章
  277. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  278. $article = Article::where('status', 1)
  279. ->where('id', $data['id'])
  280. ->where(function ($query) use ($data) {
  281. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  282. ->orWhereNull("ignore_ids");
  283. })
  284. ->first(['catid']);
  285. if (empty($article)) {
  286. return Result::error("该文章不存在", 0);
  287. }
  288. // return Result::success($article);
  289. break;
  290. case 2:
  291. // 商品
  292. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  293. $article = Good::where('website_id', $data['website_id'])
  294. ->where('status', 2)
  295. ->where('id', $data['id'])
  296. ->first(['cat_arr_id']);
  297. if (empty($article)) {
  298. return Result::error("该商品不存在", 0);
  299. }
  300. break;
  301. case 3:
  302. // 书刊信息
  303. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  304. $article = Book::where('website_id', $data['website_id'])
  305. ->where('status', 2)
  306. ->where('id', $data['id'])
  307. ->first(['id', 'cat_arr_id']);
  308. if (empty($article)) {
  309. return Result::error("该书刊不存在", 0);
  310. }
  311. break;
  312. case 4:
  313. // 招聘
  314. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  315. $article = JobRecruiting::where('website_id', $data['website_id'])
  316. ->where('status', 1)
  317. ->where('id', $data['id'])
  318. ->first(['cat_arr_id']);
  319. if (empty($article)) {
  320. return Result::error("该招聘不存在", 0);
  321. }
  322. break;
  323. case 5:
  324. // 求职
  325. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  326. $article = JobHunting::where('website_id', $data['website_id'])
  327. ->where('status', 2)
  328. ->where('id', $data['id'])
  329. ->first(['cat_arr_id']);
  330. if (empty($article)) {
  331. return Result::error("该求职不存在", 0);
  332. }
  333. break;
  334. case 6:
  335. // 企业
  336. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  337. $article = Company::
  338. // where('website_id', $data['website_id'])
  339. // ->
  340. where('status', 1)
  341. ->where('id', $data['id'])
  342. ->first(['cat_arr_id']);
  343. if (empty($article)) {
  344. return Result::error("该企业不存在", 0);
  345. }
  346. break;
  347. case 7:
  348. // 项目
  349. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  350. $article = Project::where('website_id', $data['website_id'])
  351. ->where('status', 1)
  352. ->where('id', $data['id'])
  353. ->first(['cat_arr_id']);
  354. if (empty($article)) {
  355. return Result::error("该项目不存在", 0);
  356. }
  357. break;
  358. default:
  359. return Result::error("该数据不存在", 0);
  360. break;
  361. }
  362. // return Result::success($article);
  363. // $catid =0 ;
  364. if (!isset($article['cat_arr_id'])) {
  365. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  366. } else {
  367. $catidArray = json_decode($article['cat_arr_id'], true);
  368. $catid = !empty($catidArray) ? end($catidArray) : null;
  369. }
  370. // return Result::success($catid);
  371. // // return Result::success($article['cat_arr_id']);
  372. if (empty($catid)) {
  373. return Result::error("该栏目路径不存在", 0);
  374. }
  375. $path = WebsiteCategory::where('website_id', $data['website_id'])
  376. ->where('category_id', $catid)
  377. ->first('path');
  378. }
  379. // else{
  380. // // if ($last_category['pid'] != 0) {
  381. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  382. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  383. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  384. // ->where('category_id',$catid)
  385. // ->where('path',$data['all_route'])
  386. // ->first('path');
  387. // // } else {
  388. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  389. // // }
  390. // }
  391. // return Result::success($path);
  392. if (!empty($path) && $path['path'] != $data['all_route']) {
  393. return Result::error('非法路径!');
  394. } else {
  395. return Result::success($last_category['path']);
  396. }
  397. }
  398. /**
  399. * 前端-搜索新闻列表
  400. * @param array $data
  401. * @return array
  402. */
  403. public function selectWebsiteArticle(array $data): array
  404. {
  405. $website = Website::where('id', $data['website_id'])->first();
  406. if (empty($website)) {
  407. return Result::error("网站不存在", 0);
  408. }
  409. // $website_column = $website['column'];
  410. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  411. $website_column = json_decode($website['website_column_arr_id'], true);
  412. }
  413. $website_id = $data['website_id'];
  414. $categorys = $this->processArticlePro($website_id);
  415. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  416. // return Result::success($diff_pid_categoryIds);
  417. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  418. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  419. }
  420. // return Result::success(reset($diff_pid_categoryIds) == 0);
  421. // $cat_1st_arr = $categorys['cat_1st_arr'];
  422. $catiall = $categorys['catiall'];
  423. $categoryIds = $categorys['categoryIds'];
  424. // return Result::success($categoryIds);
  425. $query = Article::where('status', 1)
  426. ->whereIn('catid', $categoryIds)
  427. ->leftJoinSub(function ($query) use ($website_id) {
  428. $query->from('article_ignore')
  429. ->where('website_id', $website_id);
  430. }, 'article_ignore', function ($join) {
  431. $join->on('article_ignore.article_id', '=', 'article.id');
  432. })
  433. ->where(function ($query) {
  434. $query->whereNull('article_ignore.article_id')
  435. ->orWhere(function ($subQuery) {
  436. $subQuery->whereNotNull('article_ignore.article_id')
  437. ->where('article_ignore.is_ignore', 0)
  438. ->where(function ($subSubQuery) {
  439. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  440. ->orWhereNull('article_ignore.c_show_time');
  441. });
  442. });
  443. });
  444. // ->get()->all();
  445. // return Result::success($query);
  446. if (isset($data['cityid']) && !empty($data['cityid'])) {
  447. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  448. }
  449. if (isset($data['department_id']) && !empty($data['department_id'])) {
  450. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  451. }
  452. if (isset($data['keyword']) && !empty($data['keyword'])) {
  453. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  454. }
  455. // 计算总数
  456. $count = $query->count();
  457. // return Result::success($count);
  458. // 分页查询
  459. $articles = $query
  460. ->select(
  461. 'article.id',
  462. 'article.title',
  463. 'article.imgurl',
  464. 'article.author',
  465. 'article.updated_at',
  466. 'article.introduce',
  467. 'article.islink',
  468. 'article.linkurl',
  469. 'article.copyfrom',
  470. 'article.cat_arr_id',
  471. 'article.catid',
  472. 'article.department_arr_id',
  473. 'article.city_arr_id',
  474. // 'article_ignore.c_show_time',
  475. // 'article_ignore.is_ignore'
  476. )
  477. ->orderBy("updated_at", "desc")
  478. ->offset(($data['page'] - 1) * $data['pageSize'])
  479. ->limit($data['pageSize'])
  480. ->get();
  481. // return Result::success($articles);
  482. foreach ($articles as $k => $v) {
  483. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  484. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  485. }
  486. if (empty($articles)) {
  487. return Result::error("没有符合条件的资讯数据");
  488. }
  489. $result = [
  490. 'rows' => $articles,
  491. 'count' => $count,
  492. ];
  493. return Result::success($result);
  494. }
  495. /**
  496. * 获取头条新闻
  497. * @param array $data
  498. * @return array
  499. */
  500. public function getWebsiteArticlett(array $data): array
  501. {
  502. $website_id = $data['website_id'];
  503. $website = Website::where('id', $data['website_id'])->first();
  504. if (empty($website)) {
  505. return Result::error("网站不存在", 0);
  506. }
  507. $categorys = $this->processArticlePro($website_id);
  508. $catiall = $categorys['catiall'];
  509. $categoryIds = $categorys['categoryIds'];
  510. $where = [
  511. 'status' => 1
  512. ];
  513. // $website_column = $website['column'];
  514. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  515. $website_column = json_decode($website['website_column_arr_id'], true);
  516. }
  517. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  518. // return Result::success($diff_pid_categoryIds);
  519. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  520. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  521. }
  522. // $website_id = $data['website_id'];
  523. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  524. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  525. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  526. switch ($data['level']) {
  527. case 1:
  528. case 2:
  529. case 3:
  530. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  531. $query = Article::where($where)
  532. ->where('level', 'like', '%' . $data['level'] . '%')
  533. ->orderBy('updated_at', 'desc');
  534. break;
  535. case 4: //最新资讯
  536. $query = Article::where($where)->orderBy('updated_at', 'desc');
  537. break;
  538. case 5: //资讯推荐
  539. $query = Article::where($where)
  540. ->where('updated_at', '>', $month);
  541. break;
  542. case 7: //资讯分类
  543. if (isset($data['id']) && !empty($data['id'])) {
  544. $keyword = Article::where('id', $data['id'])->value('keyword');
  545. $keywordArray = explode(',', $keyword);
  546. $whereL7 = [];
  547. foreach ($keywordArray as $k => $v) {
  548. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  549. }
  550. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  551. break;
  552. } else {
  553. return Result::error("请输入资讯ID", 0);
  554. break;
  555. }
  556. default:
  557. break;
  558. }
  559. // $whereL7 = [];
  560. // if(isset($data['id']) && !empty($data['id'])){
  561. // $keyword = Article::where('id', $data['id'])->value('keyword');
  562. // $keywordArray = explode(',', $keyword);
  563. // foreach ($keywordArray as $k => $v) {
  564. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  565. // }
  566. // }
  567. // $query = Article::where($where)
  568. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  569. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  570. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  571. // }
  572. // if($data['level'] == 7){
  573. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  574. // }
  575. // if($data['level'] == 4){
  576. // $query = $query->inRandomOrder()
  577. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  578. // }
  579. // if($data['level'] == 5){
  580. // $query = $query->orderBy('updated_at','desc');
  581. // }
  582. // });
  583. if ($data['textnum'] > 0) {
  584. $query = clone $query;
  585. $result['text'] = $query
  586. ->whereIn('catid', $categoryIds)
  587. ->leftJoinSub(function ($query) use ($website_id) {
  588. $query->from('article_ignore')
  589. ->where('website_id', $website_id);
  590. }, 'article_ignore', function ($join) {
  591. $join->on('article_ignore.article_id', '=', 'article.id');
  592. })
  593. ->where(function ($query) {
  594. $query->whereNull('article_ignore.article_id')
  595. ->orWhere(function ($subQuery) {
  596. $subQuery->whereNotNull('article_ignore.article_id')
  597. ->where('article_ignore.is_ignore', 0)
  598. ->where(function ($subSubQuery) {
  599. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  600. ->orWhereNull('article_ignore.c_show_time');
  601. });
  602. });
  603. })
  604. // ->where(function ($query) use ($website_id) {
  605. // $query->whereNull('article_ignore.article_id')
  606. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  607. // })
  608. ->select(
  609. 'article.id',
  610. 'article.title',
  611. 'article.author',
  612. 'article.updated_at',
  613. 'article.introduce',
  614. 'article.islink',
  615. 'article.linkurl',
  616. 'article.copyfrom',
  617. 'article.cat_arr_id',
  618. 'article.catid',
  619. 'article.level',
  620. // 'article_ignore.is_ignore',
  621. // 'article_ignore.c_show_time',
  622. )
  623. ->offset($data['placeid'])
  624. ->limit($data['textnum'])
  625. ->get()->all();
  626. foreach ($result['text'] as $k => $v) {
  627. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  628. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  629. }
  630. }
  631. if ($data['imgnum'] > 0) {
  632. $query = clone $query;
  633. if ($data['textnum'] == 0) {
  634. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  635. $query->from('article_ignore')
  636. ->where('website_id', $website_id);
  637. }, 'article_ignore', function ($join) {
  638. $join->on('article_ignore.article_id', '=', 'article.id');
  639. })
  640. ->where(function ($query) {
  641. $query->whereNull('article_ignore.article_id')
  642. ->orWhere(function ($subQuery) {
  643. $subQuery->whereNotNull('article_ignore.article_id')
  644. ->where('article_ignore.is_ignore', 0)
  645. ->where(function ($subSubQuery) {
  646. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  647. ->orWhereNull('article_ignore.c_show_time');
  648. });
  649. });
  650. });
  651. }
  652. $result['img'] = $query
  653. ->whereIn('catid', $categoryIds)
  654. ->where('article.imgurl', '!=', '')
  655. ->select(
  656. 'article.id',
  657. 'article.title',
  658. 'article.imgurl',
  659. 'article.author',
  660. 'article.updated_at',
  661. 'article.introduce',
  662. 'article.islink',
  663. 'article.linkurl',
  664. 'article.copyfrom',
  665. 'article.cat_arr_id',
  666. 'article.catid',
  667. 'article.level',
  668. // 'article_ignore.is_ignore',
  669. // 'article_ignore.c_show_time',
  670. )
  671. ->offset($data['placeid'])
  672. ->limit($data['imgnum'])
  673. ->get()->all();
  674. foreach ($result['img'] as $k => $v) {
  675. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  676. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  677. }
  678. }
  679. if (empty($result)) {
  680. return Result::error("暂无相关资讯", 0);
  681. }
  682. return Result::success($result);
  683. }
  684. /**
  685. * 模块新闻加强plus版
  686. * @param array $data
  687. * @return array
  688. */
  689. public function getWebsiteAllArticle(array $data): array
  690. {
  691. // return Result::success($data);
  692. $time1 = microtime(true);
  693. $wetbsite_id = $data['website_id'] ?? 2;
  694. $data = json_decode($data['id'], true);
  695. $website = Website::where('id', $wetbsite_id)->first();
  696. if (empty($website)) {
  697. return Result::error("网站不存在", 0);
  698. }
  699. // return Result::success($website);
  700. $website_column = $website['website_column_arr_id'] ?? '[]';
  701. $website_column = json_decode($website_column, true);
  702. $categorys = $this->processArticlePro($wetbsite_id);
  703. $cat_1st_arr = $categorys['cat_1st_arr'];
  704. $catiall = $categorys['catiall'];
  705. // return Result::success($catiall);
  706. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  707. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  708. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  709. }
  710. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  711. // return Result::success($categorys);
  712. $parent_category = array_column($data, 'parent');
  713. $parent_cat = [];
  714. $child_category = array_column($data, 'child');
  715. if (!empty($parent_category)) {
  716. foreach ($parent_category as $key => $value) {
  717. $arr = array_map('intval', explode(',', $value));
  718. $parent_cat[$key] = $arr[0] ?? 0;
  719. $parent_category = $arr[0] ?? 0;
  720. $article_imgnum = $arr[1] ?? 0;
  721. $article_textnum = $arr[2] ?? 0;
  722. if ($parent_category != 0) {
  723. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  724. // return Result::success($category_arr);
  725. if ($article_imgnum != 0) {
  726. $img_article = Article::whereIn('catid', $category_arr)
  727. ->where('status', 1)
  728. ->where('imgurl', '!=', '')
  729. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  730. $query->from('article_ignore')
  731. ->where('website_id', $wetbsite_id);
  732. }, 'article_ignore', function ($join) {
  733. $join->on('article_ignore.article_id', '=', 'article.id');
  734. })
  735. ->where(function ($query) {
  736. $query->whereNull('article_ignore.article_id')
  737. ->orWhere(function ($subQuery) {
  738. $subQuery->whereNotNull('article_ignore.article_id')
  739. ->where('article_ignore.is_ignore', 0)
  740. ->where(function ($subSubQuery) {
  741. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  742. ->orWhereNull('article_ignore.c_show_time');
  743. });
  744. });
  745. })
  746. ->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')
  747. ->orderBy('updated_at', 'desc')
  748. ->limit($article_imgnum)
  749. ->get()->all();
  750. foreach ($img_article as $k => $v) {
  751. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  752. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  753. }
  754. } else {
  755. $img_article = [];
  756. }
  757. if ($article_textnum != 0) {
  758. $text_article = Article::whereIn('catid', $category_arr)
  759. ->where('status', 1)
  760. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  761. $query->from('article_ignore')
  762. ->where('website_id', $wetbsite_id);
  763. }, 'article_ignore', function ($join) {
  764. $join->on('article_ignore.article_id', '=', 'article.id');
  765. })
  766. ->where(function ($query) {
  767. $query->whereNull('article_ignore.article_id')
  768. ->orWhere(function ($subQuery) {
  769. $subQuery->whereNotNull('article_ignore.article_id')
  770. ->where('article_ignore.is_ignore', 0)
  771. ->where(function ($subSubQuery) {
  772. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  773. ->orWhereNull('article_ignore.c_show_time');
  774. });
  775. });
  776. })
  777. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  778. ->orderBy('updated_at', 'desc')
  779. ->limit($article_textnum)
  780. ->get()->all();
  781. foreach ($text_article as $k => $v) {
  782. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  783. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  784. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  785. }
  786. } else {
  787. $text_article = [];
  788. }
  789. $catiall[$parent_category]['imgnum'] = $img_article;
  790. $catiall[$parent_category]['textnum'] = $text_article;
  791. $parent[$key] = $catiall[$parent_category];
  792. } else {
  793. $parent[$key] = '';
  794. }
  795. }
  796. }
  797. if (!empty($child_category)) {
  798. foreach ($child_category as $key => $value) {
  799. $arr = array_map('intval', explode(',', $value));
  800. $parent_category = $parent_cat[$key];
  801. $child_category = $arr[0] ?? 0;
  802. $article_imgnum = $arr[1] ?? 0;
  803. $article_textnum = $arr[2] ?? 0;
  804. if ($child_category != 0) {
  805. $all_childcat = $cat_1st_arr[$parent_category];
  806. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  807. // 从 $websiteInfoIndexed 中获取对应的数据
  808. $info = $websiteInfoIndexed[$v];
  809. // 返回一个包含所需信息的数组
  810. return [
  811. 'alias' => $info->alias,
  812. 'category_id' => $info->category_id,
  813. 'aLIas_pinyin' => $info->aLIas_pinyin,
  814. 'pid' => $info->pid,
  815. 'type' => $info->type,
  816. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  817. 'pinyin' => $info->pinyin,
  818. ];
  819. }, $all_childcat);
  820. if ($article_imgnum != 0) {
  821. $img_article = Article::where('catid', $child_category)
  822. ->where('status', 1)
  823. ->where('imgurl', '!=', '')
  824. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  825. $query->from('article_ignore')
  826. ->where('website_id', $wetbsite_id);
  827. }, 'article_ignore', function ($join) {
  828. $join->on('article_ignore.article_id', '=', 'article.id');
  829. })
  830. ->where(function ($query) {
  831. $query->whereNull('article_ignore.article_id')
  832. ->orWhere(function ($subQuery) {
  833. $subQuery->whereNotNull('article_ignore.article_id')
  834. ->where('article_ignore.is_ignore', 0)
  835. ->where(function ($subSubQuery) {
  836. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  837. ->orWhereNull('article_ignore.c_show_time');
  838. });
  839. });
  840. })
  841. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  842. ->orderBy('updated_at', 'desc')
  843. ->limit($article_imgnum)
  844. ->get()->all();
  845. foreach ($img_article as $k => $v) {
  846. // var_dump($v);
  847. // var_dump($k);
  848. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  849. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  850. }
  851. } else {
  852. $img_article = [];
  853. }
  854. if ($article_textnum != 0) {
  855. $text_article = Article::where('catid', $child_category)
  856. ->where('status', 1)
  857. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  858. $query->from('article_ignore')
  859. ->where('website_id', $wetbsite_id);
  860. }, 'article_ignore', function ($join) {
  861. $join->on('article_ignore.article_id', '=', 'article.id');
  862. })
  863. ->where(function ($query) {
  864. $query->whereNull('article_ignore.article_id')
  865. ->orWhere(function ($subQuery) {
  866. $subQuery->whereNotNull('article_ignore.article_id')
  867. ->where('article_ignore.is_ignore', 0)
  868. ->where(function ($subSubQuery) {
  869. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  870. ->orWhereNull('article_ignore.c_show_time');
  871. });
  872. });
  873. })
  874. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  875. ->orderBy('updated_at', 'desc')
  876. ->limit($article_textnum)
  877. ->get()->all();
  878. foreach ($text_article as $k => $v) {
  879. // var_dump($v);
  880. // var_dump($k);
  881. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  882. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  883. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  884. }
  885. } else {
  886. $text_article = [];
  887. }
  888. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  889. $catiall[$child_category]['imgnum'] = $img_article;
  890. $catiall[$child_category]['textnum'] = $text_article;
  891. $child[$key] = $catiall[$child_category];
  892. // var_dump($pids);
  893. } else {
  894. $child[$key] = '';
  895. }
  896. }
  897. }
  898. foreach ($parent as $key => $value) {
  899. $result[$key] = $value;
  900. if (!empty($child[$key])) {
  901. // var_dump($child[$key]);
  902. $result[$key]['child'] = $child[$key];
  903. // $value[$key]['child'] = $child[$key];
  904. } else {
  905. $result[$key]['child'] = [
  906. "alias" => null,
  907. "category_id" => null,
  908. "type" => null,
  909. "pinyin" => null,
  910. "all_childcat" => [],
  911. "imgnum" => [],
  912. "textnum" => []
  913. ];
  914. }
  915. }
  916. return Result::success($result);
  917. }
  918. /**
  919. * 乡村网-获取特殊新闻模块
  920. * @param array $data
  921. * @return array
  922. */
  923. public function getWebsiteArticles(array $data): array
  924. {
  925. $website_id = $data['website_id'];
  926. $website = Website::where('id', $website_id)->first();
  927. if (empty($website)) {
  928. return Result::error("网站不存在", 0);
  929. }
  930. // return Result::success($website);
  931. $website_column = $website['website_column_arr_id'] ?? '[]';
  932. $website_column = json_decode($website_column, true);
  933. $catids = json_decode($data['id'], true);
  934. $parent_category = array_column($catids, 'parent');
  935. if (!empty($parent_category) && is_array($parent_category)) {
  936. $categorys = $this->processArticlePro($website_id);
  937. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  938. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  939. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  940. }
  941. $catiall = $categorys['catiall'];
  942. $cat_1st_arr = $categorys['cat_1st_arr'];
  943. // return Result::success($categorys);
  944. foreach ($parent_category as $key => $value) {
  945. $arr = array_map('intval', explode(',', $value));
  946. $parent_category = $arr[0] ?? 0;
  947. $article_imgnum = $arr[1] ?? 0;
  948. $article_textnum = $arr[2] ?? 0;
  949. if ($parent_category != 0) {
  950. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  951. // return Result::success($category_arr);
  952. if ($article_imgnum != 0) {
  953. $img_article = Article::whereIn('article.catid', $category_arr)
  954. ->where('article.status', 1)
  955. ->where('article.imgurl', '!=', '')
  956. ->leftJoinSub(function ($query) use ($website_id) {
  957. $query->from('article_ignore')
  958. ->where('website_id', $website_id);
  959. }, 'article_ignore', function ($join) {
  960. $join->on('article_ignore.article_id', '=', 'article.id');
  961. })
  962. ->where(function ($query) {
  963. $query->whereNull('article_ignore.article_id')
  964. ->orWhere(function ($subQuery) {
  965. $subQuery->whereNotNull('article_ignore.article_id')
  966. ->where('article_ignore.is_ignore', 0)
  967. ->where(function ($subSubQuery) {
  968. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  969. ->orWhereNull('article_ignore.c_show_time');
  970. });
  971. });
  972. })
  973. ->select(
  974. 'article.id',
  975. 'article.title',
  976. 'article.imgurl',
  977. 'article.author',
  978. 'article.updated_at',
  979. 'article.introduce',
  980. 'article.islink',
  981. 'article.linkurl',
  982. 'article.copyfrom',
  983. 'article.cat_arr_id',
  984. 'article.catid as category_id'
  985. )
  986. ->orderBy('updated_at', 'desc')
  987. ->limit($article_imgnum)
  988. ->get()->all();
  989. foreach ($img_article as $k => $v) {
  990. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  991. // return Result::success($v);
  992. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  993. }
  994. } else {
  995. $img_article = [];
  996. }
  997. if ($article_textnum != 0) {
  998. $text_article = Article::whereIn('article.catid', $category_arr)
  999. ->where('article.status', 1)
  1000. ->leftJoinSub(function ($query) use ($website_id) {
  1001. $query->from('article_ignore')
  1002. ->where('website_id', $website_id);
  1003. }, 'article_ignore', function ($join) {
  1004. $join->on('article_ignore.article_id', '=', 'article.id');
  1005. })
  1006. ->where(function ($query) {
  1007. $query->whereNull('article_ignore.article_id')
  1008. ->orWhere(function ($subQuery) {
  1009. $subQuery->whereNotNull('article_ignore.article_id')
  1010. ->where('article_ignore.is_ignore', 0)
  1011. ->where(function ($subSubQuery) {
  1012. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1013. ->orWhereNull('article_ignore.c_show_time');
  1014. });
  1015. });
  1016. })
  1017. ->select(
  1018. 'article.id',
  1019. 'article.title',
  1020. 'article.author',
  1021. 'article.updated_at',
  1022. 'article.introduce',
  1023. 'article.islink',
  1024. 'article.linkurl',
  1025. 'article.copyfrom',
  1026. 'article.cat_arr_id',
  1027. 'article.catid as category_id'
  1028. )
  1029. ->orderBy('updated_at', 'desc')
  1030. ->limit($article_textnum)
  1031. ->get()->all();
  1032. foreach ($text_article as $k => $v) {
  1033. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1034. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1035. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1036. }
  1037. } else {
  1038. $text_article = [];
  1039. }
  1040. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  1041. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  1042. $parent[$key] = $catiall[$parent_category];
  1043. } else {
  1044. $parent[$key] = [];
  1045. }
  1046. }
  1047. }
  1048. return Result::success($parent);
  1049. }
  1050. /**
  1051. *获取新闻列表
  1052. * @param array $data
  1053. * @return array
  1054. */
  1055. public function getWebsiteArticleList(array $data): array
  1056. {
  1057. // return Result::success($data);
  1058. $where[] = ['status', '=', 1];
  1059. $website_id = $data['website_id'];
  1060. $website = Website::where('id', $data['website_id'])->first();
  1061. if (empty($website)) {
  1062. return Result::error("网站不存在", 0);
  1063. }
  1064. // $website_column = $website['column'];
  1065. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1066. $website_column = json_decode($website['website_column_arr_id'], true);
  1067. }
  1068. $categorys = $this->processArticlePro($website_id);
  1069. $cat_1st_arr = $categorys['cat_1st_arr'];
  1070. $catiall = $categorys['catiall'];
  1071. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1072. // return Result::success($diff_pid_categoryIds);
  1073. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1074. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1075. }
  1076. if (isset($data['catid']) && !empty($data['catid'])) {
  1077. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1078. if (empty($category)) {
  1079. return Result::error("此网站暂无此栏目", 0);
  1080. }
  1081. array_push($where, ['catid', '=', $data['catid']]);
  1082. }
  1083. // return Result::success($where);
  1084. $query = Article::where($where)
  1085. ->leftJoinSub(function ($query) use ($website_id) {
  1086. $query->from('article_ignore')
  1087. ->where('website_id', $website_id);
  1088. }, 'article_ignore', function ($join) {
  1089. $join->on('article_ignore.article_id', '=', 'article.id');
  1090. })
  1091. ->where(function ($query) {
  1092. $query->whereNull('article_ignore.article_id')
  1093. ->orWhere(function ($subQuery) {
  1094. $subQuery->whereNotNull('article_ignore.article_id')
  1095. ->where('article_ignore.is_ignore', 0)
  1096. ->where(function ($subSubQuery) {
  1097. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1098. ->orWhereNull('article_ignore.c_show_time');
  1099. });
  1100. });
  1101. })
  1102. ->select(
  1103. 'article.id',
  1104. 'article.title',
  1105. 'article.imgurl',
  1106. 'article.author',
  1107. 'article.updated_at',
  1108. 'article.introduce',
  1109. 'article.islink',
  1110. 'article.linkurl',
  1111. 'article.copyfrom',
  1112. 'article.cat_arr_id',
  1113. 'article.catid'
  1114. );
  1115. $count = $query->count();
  1116. $rep = $query->orderBy("updated_at", "desc")
  1117. ->offset(($data['page'] - 1) * $data['pageSize'])
  1118. ->limit($data['pageSize'])
  1119. ->get()->all();
  1120. $categorys = $this->processArticlePro($website_id);
  1121. $cat_1st_arr = $categorys['cat_1st_arr'];
  1122. $catiall = $categorys['catiall'];
  1123. // $web['website_id'] = $data['website_id'];
  1124. foreach ($rep as $k => $v) {
  1125. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1126. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1127. }
  1128. // $rep = $this->processArticles($rep,$web);
  1129. $data = [
  1130. 'rows' => $rep,
  1131. 'count' => $count,
  1132. ];
  1133. if (empty($rep)) {
  1134. return Result::error("没有信息数据");
  1135. }
  1136. return Result::success($data);
  1137. }
  1138. /**
  1139. * 前端-获取新闻详情
  1140. * @param array $data
  1141. * @return array
  1142. */
  1143. public function selectWebsiteArticleInfo(array $data): array
  1144. {
  1145. $where = [
  1146. 'article.id' => $data['id'],
  1147. 'article.status' => 1,
  1148. ];
  1149. $result = Article::where($where)
  1150. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1151. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1152. // ->where(function ($query) use ($data) {
  1153. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1154. // ->orWhereNull("ignore_ids");
  1155. // })
  1156. ->leftJoinSub(function ($query) use ($data) {
  1157. $query->from('article_ignore')
  1158. ->where('website_id', $data['website_id']);
  1159. }, 'article_ignore', function ($join) {
  1160. $join->on('article_ignore.article_id', '=', 'article.id');
  1161. })
  1162. ->where(function ($query) {
  1163. $query->whereNull('article_ignore.article_id')
  1164. ->orWhere(function ($subQuery) {
  1165. $subQuery->whereNotNull('article_ignore.article_id')
  1166. ->where('article_ignore.is_ignore', 0)
  1167. ->where(function ($subSubQuery) {
  1168. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1169. ->orWhereNull('article_ignore.c_show_time');
  1170. });
  1171. });
  1172. })
  1173. ->select(
  1174. 'article.*',
  1175. 'article_data.content',
  1176. 'article_data.article_id',
  1177. 'article_extend.website_url',
  1178. 'article_extend.email',
  1179. 'article_extend.contacts',
  1180. 'article_extend.contacts_mobile',
  1181. 'article_extend.contacts_address',
  1182. 'article_extend.zip_code',
  1183. 'article_extend.enterprise_name'
  1184. )
  1185. ->first();
  1186. if (empty($result)) {
  1187. return Result::error("暂无此新闻!", 0);
  1188. }
  1189. if (!empty($result['publiced_at'])) {
  1190. $result['updated_at'] = $result['publiced_at'];
  1191. }
  1192. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1193. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1194. ->where('website_category.website_id', $data['website_id'])
  1195. ->where(['website_category.category_id' => $result['catid']])
  1196. ->first();
  1197. if (empty($category)) {
  1198. return Result::error("查询失败", 0);
  1199. }
  1200. //手动推荐文章
  1201. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1202. if (empty($commend_ids)) {
  1203. $commendArticle = [];
  1204. } else {
  1205. //去除不存在的文章ID
  1206. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1207. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1208. ->leftJoinSub(function ($query) use ($data) {
  1209. $query->from('article_ignore')
  1210. ->where('website_id', $data['website_id']);
  1211. }, 'article_ignore', function ($join) {
  1212. $join->on('article_ignore.article_id', '=', 'article.id');
  1213. })
  1214. ->where(function ($query) {
  1215. $query->whereNull('article_ignore.article_id')
  1216. ->orWhere(function ($subQuery) {
  1217. $subQuery->whereNotNull('article_ignore.article_id')
  1218. ->where('article_ignore.is_ignore', 0)
  1219. ->where(function ($subSubQuery) {
  1220. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1221. ->orWhereNull('article_ignore.c_show_time');
  1222. });
  1223. });
  1224. })
  1225. ->where('article.status', 1)
  1226. ->where('website_category.website_id', $data['website_id'])
  1227. ->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')
  1228. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1229. // ->orderBy('article.updated_at', 'desc')
  1230. ->limit(5)
  1231. ->get();
  1232. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1233. foreach ($commendArticle as $k => $v) {
  1234. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1235. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1236. $cat_arr_id = array_unique($cat_arr_id);
  1237. // 从website_category取出alias_pinyin
  1238. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1239. ->whereIn('category_id', $cat_arr_id)
  1240. ->pluck('alias_pinyin', 'category_id')
  1241. ->toArray();
  1242. // 将cat_arr_id的json转成路径/隔开
  1243. $path_parts = [];
  1244. foreach ($cat_arr_id as $cat_id) {
  1245. if (isset($cat_arr[$cat_id])) {
  1246. $path_parts[] = $cat_arr[$cat_id];
  1247. }
  1248. }
  1249. $v->alias_pinyin = implode('/', $path_parts);
  1250. } else {
  1251. $v->alias_pinyin = '';
  1252. }
  1253. }
  1254. }
  1255. $result['category_id'] = $category['category_id'];
  1256. $result['cat_name'] = $category['alias'];
  1257. $result['website_name'] = $category['website_name'] ?? "";
  1258. $result['suffix'] = $category['suffix'] ?? "";
  1259. $result['commendArticle'] = $commendArticle;
  1260. $result['commend_ids'] = $commend_ids;
  1261. return Result::success($result);
  1262. }
  1263. /**
  1264. * plus pro 处理文章路由问题
  1265. */
  1266. function processArticlePro($website_id)
  1267. {
  1268. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  1269. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  1270. // // 取出category_id 对应的aLIas_pinyin
  1271. // $categoryIds = array_column($categorys, 'category_id');
  1272. // $categoryPIds = array_column($categorys, 'pid');
  1273. // $aliasPinyins = array_column($categorys, 'path');
  1274. // $alias = array_column($categorys, 'alias');
  1275. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  1276. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  1277. // // return Result::success($cat_arr);
  1278. // // $catiall = [];
  1279. // //一级所有子级的记录
  1280. // $cat_alias_arr = array_combine($categoryIds, $alias);
  1281. // return [
  1282. // 'cat_1st_arr' => $cat_alias_arr,
  1283. // 'catiall' => $cat_arr,
  1284. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  1285. // 'categoryIds' => $categoryIds,
  1286. // ];
  1287. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  1288. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  1289. // 取出category_id 对应的aLIas_pinyin
  1290. $categoryIds = array_column($categorys, 'category_id');
  1291. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  1292. return $pid != 0;
  1293. })));
  1294. $category_path = array_column($categorys, 'path');
  1295. $cat_arr = array_combine($categoryIds, $category_path);
  1296. // return Result::success(array_diff($categoryIds, $categoryPIds));
  1297. $catiall = [];
  1298. //一级所有子级的记录
  1299. $cat_1st_arr = [];
  1300. foreach ($categorys as $key => $value) {
  1301. // $category_arr_id = json_decode($value->category_arr_id);
  1302. // $pinyin_str = '';
  1303. // // 算出一级 并且算出子级
  1304. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  1305. $cat_1st_arr[$value->pid][] = $value->category_id;
  1306. }
  1307. // foreach ($category_arr_id as $k => $v) {
  1308. // $pinyin_str .= $cat_arr[$v] . '/';
  1309. // }
  1310. // $pinyin_str = rtrim($pinyin_str, '/');
  1311. $catiall[$value->category_id]['alias'] = $value->alias;
  1312. $catiall[$value->category_id]['category_id'] = $value->category_id;
  1313. $catiall[$value->category_id]['type'] = $value->type;
  1314. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  1315. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  1316. }
  1317. return [
  1318. 'cat_1st_arr' => $cat_1st_arr,
  1319. 'catiall' => $catiall,
  1320. 'websiteInfoIndexed' => $websiteInfoIndexed,
  1321. 'categoryIds' => $categoryIds,
  1322. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  1323. 'categoryPIds' => $categoryPIds,
  1324. ];
  1325. }
  1326. /**
  1327. * 获取网站顶部信息
  1328. * @param array $data
  1329. */
  1330. public function getWebsiteHead(array $data): array
  1331. {
  1332. $result = Website::where('id', $data['website_id'])->where('status', 1)->select('website_name', 'logo')->first();
  1333. if (empty($result)) {
  1334. return Result::error("暂无该网站", 0);
  1335. }
  1336. return Result::success($result);
  1337. }
  1338. /**
  1339. *各省市查询
  1340. * @param array $data
  1341. * @return array
  1342. */
  1343. public function selectWebArea(array $data): array
  1344. {
  1345. // return Result::success($data);
  1346. $pid = $data['pid'] ?? 0;
  1347. $result = District::leftJoin('district as district2', 'district.pid', '=', 'district2.id')
  1348. ->where('district.pid', $pid)
  1349. ->where('district.status', 1)
  1350. ->select('district.*', 'district2.name as pid_name')
  1351. ->orderBy('district.code')->get();
  1352. if (empty($result)) {
  1353. return Result::error("未查询到此地区", 0);
  1354. } else {
  1355. return Result::success($result);
  1356. }
  1357. }
  1358. /**test1
  1359. * @param array $data
  1360. * @return array
  1361. */
  1362. public function getWebsiteDistrit(array $data): array
  1363. {
  1364. $where = [];
  1365. if (isset($data['keyWord'])) {
  1366. $where = [
  1367. ['name', 'like', '%' . $data['keyWord'] . '%']
  1368. ];
  1369. }
  1370. $result = [];
  1371. if (isset($data['pageSize'])) {
  1372. $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("code", "asc")->get();
  1373. $count = District::where($where)->count();
  1374. $result = [
  1375. 'rows' => $rep,
  1376. 'count' => $count
  1377. ];
  1378. } else {
  1379. $result = District::where($data)->orderBy("code", "asc")->get();
  1380. }
  1381. return $result ? Result::success($result) : Result::error("没有查到数据");
  1382. }
  1383. /**
  1384. *
  1385. * @param array $data
  1386. * @return array
  1387. */
  1388. /**网站行政职能搜索 */
  1389. public function selectWebsiteDepartment(array $data): array
  1390. {
  1391. $depart = Department::where('pid', 0)->orderBy('id', 'asc')->get();
  1392. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1393. $departments = Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  1394. if (empty($departments)) {
  1395. $result['message'] = "未查询到与此相关职能部门";
  1396. } else {
  1397. $count = Department::where('name', 'like', "%{$data['keyword']}%")->count();
  1398. $m = [
  1399. 'department' => $depart,
  1400. 'type' => $departments,
  1401. 'count' => $count,
  1402. ];
  1403. }
  1404. $result['sele'] = $m;
  1405. return Result::success($result['sele']);
  1406. }
  1407. $result = $depart;
  1408. return Result::success($result);
  1409. }
  1410. /**
  1411. * 获取友情链接
  1412. * @param array $data
  1413. * @return array
  1414. */
  1415. public function selectWebsiteLinks(array $data): array
  1416. {
  1417. $where = [
  1418. 'website_id' => $data['website_id'],
  1419. 'status' => 1,
  1420. 'type' => $data['type'],
  1421. ];
  1422. $num = $data['num'];
  1423. $result = Link::where($where)->orderBy('sort')->limit($num)->get();
  1424. if (!empty($result)) {
  1425. return Result::success($result);
  1426. } else {
  1427. return Result::error("本网站暂无此类型友情链接", 0);
  1428. }
  1429. }
  1430. /**
  1431. * 获取网站底部导航
  1432. * @param array $data
  1433. * @return array
  1434. */
  1435. public function getWebsiteFooterCategory(array $data): array
  1436. {
  1437. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1438. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1439. if (empty($website)) {
  1440. return Result::error("找不到网站", 0);
  1441. }
  1442. } else {
  1443. return Result::error("参数错误", 0);
  1444. }
  1445. $result = FooterCategory::where('website_id', $data['website_id'])->get();
  1446. if (empty($result)) {
  1447. return Result::error("暂无底部导航", 0);
  1448. }
  1449. return Result::success($result->toArray());
  1450. }
  1451. /**
  1452. * 获取网站底部导航列表
  1453. * @param array $data
  1454. * @return array
  1455. */
  1456. public function getWebsiteFooterCategoryList(array $data): array
  1457. {
  1458. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1459. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1460. if (empty($website)) {
  1461. return Result::error("找不到网站", 0);
  1462. }
  1463. } else {
  1464. return Result::error("参数错误", 0);
  1465. }
  1466. $footercategory = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1467. // '底部导航类型 0:内容型;1:列表型;',
  1468. if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
  1469. return Result::error("底部导航id错误", 0);
  1470. } else {
  1471. $query = FooterContent::where('fcat_id', $data['fcat_id']);
  1472. if ($query->count() == 0) {
  1473. return Result::error("暂无底部导航列表", 0);
  1474. } elseif ($query->count() == 1) {
  1475. $result = $query->first();
  1476. } else {
  1477. $result = $query->get();
  1478. }
  1479. }
  1480. return Result::success($result);
  1481. }
  1482. /**
  1483. * 获取网站底部导航
  1484. * @param array $data
  1485. * @return array
  1486. */
  1487. public function getWebsiteFooterCategoryInfo(array $data): array
  1488. {
  1489. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1490. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1491. if (empty($website)) {
  1492. return Result::error("找不到网站", 0);
  1493. }
  1494. } else {
  1495. return Result::error("参数错误", 0);
  1496. }
  1497. if (isset($data['type']) && $data['type'] == 0) {
  1498. $fcatid = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1499. if (empty($fcatid)) {
  1500. return Result::error("底部导航id错误", 0);
  1501. }
  1502. $result = FooterContent::where('fcat_id', $data['fcat_id'])->first();
  1503. } else {
  1504. $result = FooterContent::where('id', $data['fcat_id'])->first();
  1505. }
  1506. if (empty($result)) {
  1507. return Result::error("暂无底部导航内容", 0);
  1508. }
  1509. return Result::success($result);
  1510. }
  1511. /**
  1512. * 获取网站底部基础信息
  1513. * @param array $data
  1514. * @return array
  1515. */
  1516. public function getWebsiteFootInfo(array $data): array
  1517. {
  1518. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1519. $website_head = Website::where('id', $data['website_id'])
  1520. ->where('status', 1)
  1521. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')
  1522. ->first();
  1523. if (empty($website_head)) {
  1524. return Result::error("找不到网站", 0);
  1525. }
  1526. } else {
  1527. return Result::error("参数错误", 0);
  1528. }
  1529. $website_head = Website::where('id', $data['website_id'])
  1530. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')->first();
  1531. $website_foot = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1532. if (empty($website_foot)) {
  1533. return Result::error("暂无底部基础信息", 0);
  1534. }
  1535. $website_head['website_url'] = $website_head['website_url'] ? json_decode($website_head['website_url']) : [];
  1536. $result = [
  1537. 'website_foot' => $website_foot,
  1538. 'website_head' => $website_head,
  1539. ];
  1540. return Result::success($result);
  1541. }
  1542. /**
  1543. * 获取网站栏目信息
  1544. * @param array $data
  1545. */
  1546. public function getWebsiteFootAll(array $data): array
  1547. {
  1548. if(!isset($data['is_diyweb']) || empty($data['is_diyweb'])){
  1549. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1550. }else{
  1551. $website = Website::where('id',$data['website_id'])->first();
  1552. }
  1553. if (empty($website)) {
  1554. return Result::error("暂无该网站", 0);
  1555. }
  1556. // 1:图片 2:文字 3:底部
  1557. $result['foot_cate'] = FooterCategory::where('website_id', $data['website_id'])->get()->all();
  1558. $result['link_img'] = Link::where('website_id', $data['website_id'])->where('type', 1)->where('status', 1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all();
  1559. $result['link_text'] = Link::where('website_id', $data['website_id'])->where('type', 2)->where('status', 1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
  1560. $result['link_foot'] = Link::where('website_id', $data['website_id'])->where('type', 3)->where('status', 1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
  1561. $result['foot_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1562. if (empty($result)) {
  1563. return Result::error("暂无此网站信息", 0);
  1564. }
  1565. return Result::success($result);
  1566. }
  1567. /**
  1568. * 获取网站栏目信息
  1569. * @param array $data
  1570. */
  1571. public function getWebsiteAllinfo(array $data): array
  1572. {
  1573. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1574. if (empty($website)) {
  1575. return Result::error("暂无该网站", 0);
  1576. }
  1577. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1578. $website_head = Website::where('id', $data['website_id'])
  1579. ->where('status', 1)
  1580. ->select(
  1581. 'id',
  1582. 'website_name',
  1583. 'logo',
  1584. 'title',
  1585. 'keywords',
  1586. 'description',
  1587. 'suffix',
  1588. 'website_url',
  1589. 'ad_key',
  1590. 'api_url',
  1591. 'login_url',
  1592. 'weblog_url'
  1593. )
  1594. ->first();
  1595. if (empty($website_head)) {
  1596. return Result::error("找不到网站", 0);
  1597. }
  1598. } else {
  1599. return Result::error("参数错误", 0);
  1600. }
  1601. $website_foot['foot_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1602. if (empty($website_foot)) {
  1603. return Result::error("暂无底部基础信息", 0);
  1604. }
  1605. $website_head['website_url'] = $website_head['website_url'] ? json_decode($website_head['website_url']) : [];
  1606. $result['website_head'] = $website_head;
  1607. $result['website_foot'] = $website_foot;
  1608. // return Result::success($result);
  1609. // 1:图片 2:文字 3:底部
  1610. $result['website_foot']['foot_cate'] = FooterCategory::where('website_id', $data['website_id'])->get()->all();
  1611. $result['website_foot']['link_img'] = Link::where('website_id', $data['website_id'])->where('type', 1)->where('status', 1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all();
  1612. $result['website_foot']['link_text'] = Link::where('website_id', $data['website_id'])->where('type', 2)->where('status', 1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
  1613. $result['website_foot']['link_foot'] = Link::where('website_id', $data['website_id'])->where('type', 3)->where('status', 1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
  1614. if (empty($result)) {
  1615. return Result::error("暂无此网站信息", 0);
  1616. }
  1617. return Result::success($result);
  1618. }
  1619. /**
  1620. * 查询网站的广告
  1621. * @param array $data
  1622. * @return array
  1623. */
  1624. public function getWebsiteAdvertisement(array $data): array
  1625. {
  1626. $where = [
  1627. 'ad_place.status' => 1,
  1628. ];
  1629. if (isset($data['ad_tag']) && !empty($data['ad_tag'])) {
  1630. $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
  1631. $where[] = ['ad_place.ad_tag', 'like', '%' . $data['ad_tag'] . '%'];
  1632. // return Result::success($where);
  1633. $result = AdPlace::where($where)
  1634. ->leftJoin("ad", function ($join) use ($now) {
  1635. $join->on("ad.pid", "=", "ad_place.id")
  1636. ->where('ad.status', 1)
  1637. ->where('ad.fromtime', '<=', $now)
  1638. ->where('ad.totime', '>=', $now);
  1639. })
  1640. ->select(
  1641. 'ad_place.name as place_name',
  1642. 'ad_place.thumb',
  1643. 'ad_place.ad_tag',
  1644. 'ad_place.introduce',
  1645. 'ad.name as ad_name',
  1646. 'ad.image_src',
  1647. 'ad.image_url',
  1648. 'ad.image_alt',
  1649. 'ad_place.ad_url'
  1650. )
  1651. ->get()->all();
  1652. } else {
  1653. $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
  1654. // return Result::success($where);
  1655. $result = AdPlace::where($where)
  1656. ->where('ad_place.website_id', $data['website_id'])
  1657. ->leftJoin("ad", function ($join) use ($now) {
  1658. $join->on("ad.pid", "=", "ad_place.id")
  1659. ->where('ad.status', 1)
  1660. ->where('ad.fromtime', '<=', $now)
  1661. ->where('ad.totime', '>=', $now);
  1662. })
  1663. ->select(
  1664. 'ad_place.name as place_name',
  1665. 'ad_place.thumb',
  1666. 'ad_place.ad_tag',
  1667. 'ad_place.introduce',
  1668. 'ad.name as ad_name',
  1669. 'ad.image_src',
  1670. 'ad.image_url',
  1671. 'ad.image_alt',
  1672. 'ad_place.ad_url',
  1673. )
  1674. ->get()->all();
  1675. // return Result::error("请选择广告位!",0);
  1676. }
  1677. if (empty($result)) {
  1678. return Result::error("此广告位不存在!", 0);
  1679. }
  1680. return Result::success($result);
  1681. }
  1682. /**
  1683. * 前端-获取网站调查问卷
  1684. * @param array $data
  1685. * @return array
  1686. */
  1687. public function getWebsiteSurvey(array $data): array
  1688. {
  1689. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1690. $website = Website::where('id', $data['website_id'])->first();
  1691. if (empty($website)) {
  1692. return Result::error("暂无此网站", 0);
  1693. }
  1694. }
  1695. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1696. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1697. if (empty($article)) {
  1698. return Result::error("暂无此文章", 0);
  1699. }
  1700. // return Result::error($data,0);
  1701. $where['art_id'] = $data['art_id'];
  1702. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1703. } else {
  1704. $survey = Article::where(function ($query) {
  1705. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1706. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1707. })
  1708. ->where('status', 1)
  1709. ->where('is_survey', 1)
  1710. ->select('survey_id')
  1711. ->orderBy('updated_at', 'desc')
  1712. ->first();
  1713. if (empty($survey)) {
  1714. return Result::error("暂无调查问卷", 0);
  1715. }
  1716. $where['sur_id'] = $survey['survey_id'];
  1717. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1718. }
  1719. // return Result::success($where);
  1720. $result = ArticleSurvey::where($where)
  1721. ->where(function ($query) {
  1722. $query->where('is_other', 0)
  1723. ->orWhere(function ($subQuery) {
  1724. $subQuery->where('is_other', 1)
  1725. ->where('other_id', 0);
  1726. });
  1727. })
  1728. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1729. ->select('article_survey.*', 'article.survey_type')
  1730. ->get()->all();
  1731. if (empty($result)) {
  1732. return Result::error("此文章暂无调查问卷", 0);
  1733. }
  1734. return Result::success($result);
  1735. }
  1736. /**
  1737. * 前端-添加网站调查问卷选项
  1738. * @param array $data
  1739. * @return array
  1740. */
  1741. public function addWebsiteSurveyOption(array $data): array
  1742. {
  1743. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1744. $website = Website::where('id', $data['website_id'])->first();
  1745. if (empty($website)) {
  1746. return Result::error("暂无此网站", 0);
  1747. }
  1748. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1749. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1750. if (empty($survey)) {
  1751. return Result::error("此调查问卷不可添加选项", 0);
  1752. }
  1753. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1754. $choice = [
  1755. 'art_id' => $survey['art_id'],
  1756. 'website_id' => $data['website_id'],
  1757. 'survey_name' => $survey['survey_name'],
  1758. 'choice_name' => $data['choice_name'],
  1759. 'sur_id' => $survey['sur_id'],
  1760. 'is_other' => 1,
  1761. 'other_id' => $survey['id'],
  1762. ];
  1763. $result = ArticleSurvey::insertGetId($choice);
  1764. if (empty($result)) {
  1765. return Result::error("添加失败", 0);
  1766. }
  1767. return Result::success($result);
  1768. }
  1769. }
  1770. return Result::error("添加失败", 0);
  1771. }
  1772. return Result::error("添加失败", 0);
  1773. }
  1774. /**
  1775. * 前端-调查问卷投票
  1776. * @param array $data
  1777. * @return array
  1778. */
  1779. public function addWebsiteSurveyVote(array $data): array
  1780. {
  1781. // return Result::success($data);
  1782. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1783. $website = Website::where('id', $data['website_id'])->first();
  1784. if (empty($website)) {
  1785. return Result::error("暂无此网站", 0);
  1786. }
  1787. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1788. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1789. // return Result::success($survey);
  1790. if (empty($is_survey)) {
  1791. return Result::error("此调查问卷不存在", 0);
  1792. }
  1793. // return Result::success($survey);
  1794. // 调查问卷类型
  1795. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1796. //多选 若是json型则转化成数组类型
  1797. if (strpos($data['choice_id'], '[') === 0) {
  1798. $data['choice_id'] = json_decode($data['choice_id'], true);
  1799. } else {
  1800. // 单选 也转换成数组
  1801. $data['choice_id'] = [$data['choice_id']];
  1802. }
  1803. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1804. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1805. // ->where('website_id',$data['website_id'])
  1806. ->where('is_other', 1)
  1807. ->where('other_id', 0)
  1808. ->first();
  1809. if (!empty($other)) {
  1810. return Result::error("请选择已有的选项!", 0);
  1811. }
  1812. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1813. // ->where('website_id',$data['website_id'])
  1814. ->where('is_other', 1)
  1815. ->where('other_id', '!=', 0)
  1816. ->first();
  1817. // return Result::success($choice['other']);
  1818. $choice_id = $data['choice_id'];
  1819. if (!empty($choice['other'])) {
  1820. // array_push($data['choice_id'],$choice['other']['other_id']);
  1821. if (!empty($choice_id)) {
  1822. $key = array_search($choice['other']['id'], $choice_id);
  1823. if ($key !== false) {
  1824. unset($choice_id[$key]);
  1825. $choice_id = array_values($choice_id);
  1826. }
  1827. array_push($choice_id, $choice['other']['other_id']);
  1828. } else {
  1829. $choice_id[0] = $choice['other']['other_id'];
  1830. }
  1831. array_push($data['choice_id'], $choice['other']['other_id']);
  1832. }
  1833. // return Result::success($data);
  1834. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1835. // ->where('website_id',$data['website_id'])
  1836. ->increment('results', 1);
  1837. if (empty($choice)) {
  1838. return Result::error("请选择已有的选项!", 0);
  1839. }
  1840. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1841. // ->where('website_id',$data['website_id'])
  1842. ->where('other_id', 0)
  1843. ->get();
  1844. $survey['choice'] = $choice_id;
  1845. return Result::success($survey);
  1846. }
  1847. return Result::error("参数必填!");
  1848. }
  1849. return Result::error("此调查问卷不存在", 0);
  1850. }
  1851. return Result::error("参数必填!");
  1852. }
  1853. /**
  1854. * 获取商城首页-根据栏目id
  1855. * @param array $data
  1856. * @return array
  1857. * */
  1858. function getWebsiteCatidshop(array $data): array
  1859. {
  1860. $input['catid'] = $data['catid'];
  1861. $input['website_id'] = $data['website_id'];
  1862. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1863. $result = array_map(function ($item) use ($input) {
  1864. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1865. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1866. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1867. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1868. if (empty($category) || $category->type != 2) {
  1869. return Result::error("暂无此栏目", 0);
  1870. } else {
  1871. $website['website_id'] = $input['website_id'];
  1872. $goods = Good::where('good.status', 2)
  1873. ->where('good.website_id', $website['website_id'])
  1874. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1875. ->select(
  1876. 'good.id',
  1877. 'good.name',
  1878. 'good.imgurl',
  1879. 'good.description',
  1880. 'good.updated_at',
  1881. 'good.catid',
  1882. 'good.type_id',
  1883. 'good.price',
  1884. 'good.com',
  1885. 'good.level',
  1886. 'good.unit'
  1887. )
  1888. ->orderBy('updated_at', 'desc')
  1889. ->offset($goodStart)
  1890. ->limit($goodNum);
  1891. $all_goods = $goods->get();
  1892. $all_goods = $this->processGoods($all_goods, $website);
  1893. }
  1894. return $all_goods ?? [];
  1895. }
  1896. }, $data);
  1897. return Result::success($result);
  1898. }
  1899. /**
  1900. * 获取商品模块
  1901. * @param array $data
  1902. * @return array
  1903. * */
  1904. public function getWebsiteshop(array $data): array
  1905. {
  1906. $input['id'] = $data['id'];
  1907. $input['website_id'] = $data['website_id'];
  1908. $catid = $data['catid'];
  1909. $data = json_decode($input['id'] ?? '', true) ?? [];
  1910. $result['goods'] = array_map(function ($item) use ($input) {
  1911. // 检查parent元素是否存在且不是undefined
  1912. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  1913. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  1914. $website = $input['website_id'];
  1915. $query = Good::where('good.status', 2)
  1916. ->where('good.website_id', $website);
  1917. switch ($Levelid) {
  1918. case 1:
  1919. case 2:
  1920. case 3:
  1921. $goods = $query->where(function ($q) use ($Levelid) {
  1922. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  1923. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  1924. });
  1925. break;
  1926. case 4:
  1927. $goods = $query;
  1928. break;
  1929. case 5:
  1930. $goods = $query->where('type_id', 1);
  1931. break;
  1932. case 6:
  1933. $goods = $query->where('type_id', 2);
  1934. break;
  1935. default:
  1936. return [];
  1937. }
  1938. $all_goods = $goods
  1939. ->select(
  1940. 'good.id',
  1941. 'good.name',
  1942. 'good.imgurl',
  1943. 'good.description',
  1944. 'good.updated_at',
  1945. 'good.catid',
  1946. 'good.type_id',
  1947. 'good.price',
  1948. 'good.level',
  1949. 'good.website_id'
  1950. )
  1951. ->orderBy('updated_at', 'desc')
  1952. ->offset($goodStart)
  1953. ->limit($goodNum)
  1954. ->get();
  1955. $web['website_id'] = $website;
  1956. $all_goods = $this->processGoods($all_goods, $web);
  1957. }
  1958. return $all_goods;
  1959. }, $data);
  1960. $website = $input['website_id'];
  1961. $result['article'] = Article::where(function ($query) use ($website) {
  1962. $query->where(function ($subQuery) use ($website) {
  1963. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  1964. })->orWhereNull("ignore_ids");
  1965. })
  1966. ->where('catid', $catid)
  1967. ->where('article.status', 1)
  1968. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  1969. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  1970. ->orderBy('article.updated_at', 'desc')
  1971. ->first();
  1972. return Result::success($result);
  1973. }
  1974. /**
  1975. * 获取商品分类
  1976. * @param array $data
  1977. * @return array
  1978. * */
  1979. public function getWebsiteshopCat(array $data): array
  1980. {
  1981. $website = $data['website_id'];
  1982. $category = WebsiteCategory::where('website_id', $website)
  1983. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  1984. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  1985. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  1986. ->orderBy('sort')
  1987. ->get();
  1988. $cat = $category->map(function ($item) use ($website) {
  1989. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  1990. $pid = $item->pid ?? 0;
  1991. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  1992. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  1993. ->where('website_id', $website)
  1994. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  1995. ->get(['aLIas_pinyin'])
  1996. ->pluck('aLIas_pinyin')
  1997. ->implode('/');
  1998. } else {
  1999. $pinyin = $item->aLIas_pinyin ?? '';
  2000. }
  2001. $item->pinyin = $pinyin;
  2002. });
  2003. if (empty($category)) {
  2004. return Result::error("栏目查询失败", 0);
  2005. }
  2006. $cat_tree = Result::buildMenuTree($category);
  2007. $web['website_id'] = $website;
  2008. $goods = Good::where('website_id', $website)
  2009. ->where('status', 2)
  2010. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2011. ->latest('updated_at')
  2012. ->offset(($data['page'] - 1) * $data['pageSize'])
  2013. ->limit($data['pageSize'])
  2014. ->get();
  2015. if (!empty($goods)) {
  2016. if ($goods->count() > 1 && !empty($goods)) {
  2017. $goods = $this->processGoods($goods, $web);
  2018. }
  2019. } else {
  2020. $goods = [];
  2021. }
  2022. $result = [
  2023. 'category' => $cat_tree,
  2024. 'goods' => $goods,
  2025. ];
  2026. // $resul['goods'] = $goods;
  2027. if (empty($result)) {
  2028. return Result::error("查询失败", 0);
  2029. }
  2030. return Result::success($result);
  2031. }
  2032. /*
  2033. * 获取商品列表
  2034. * @param array $data
  2035. * @return array
  2036. * */
  2037. public function getWebsiteshopList(array $data): array
  2038. {
  2039. // return Result::success($data);
  2040. $where = [
  2041. 'status' => 2,
  2042. 'website_id' => $data['website_id'],
  2043. ];
  2044. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2045. // return Result::error("查询失败", 0);
  2046. // }
  2047. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2048. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2049. $data['catid'] = $category->category_id ?? 0;
  2050. }
  2051. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2052. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2053. }
  2054. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2055. array_push($where, ['type_id', $data['type_id']]);
  2056. }
  2057. $query = Good::where($where)
  2058. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2059. $query->where(function ($q) use ($data) {
  2060. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2061. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2062. });
  2063. })
  2064. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2065. $query->where(function ($q) use ($data) {
  2066. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2067. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2068. });
  2069. })
  2070. ->select(
  2071. 'good.id',
  2072. 'good.name',
  2073. 'good.imgurl',
  2074. 'good.description',
  2075. 'good.updated_at',
  2076. 'good.com',
  2077. 'good.catid',
  2078. 'good.type_id',
  2079. 'good.website_id',
  2080. 'good.cat_arr_id',
  2081. 'good.created_at',
  2082. 'good.city_id'
  2083. )
  2084. ->latest('updated_at');
  2085. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2086. $result['count'] = $query->clone()->count();
  2087. $result['goods'] = $this->processGoods(
  2088. $query->clone()
  2089. ->offset(($data['page'] - 1) * $data['pageSize'])
  2090. ->limit($data['pageSize'])
  2091. ->get(),
  2092. $data
  2093. );
  2094. } else {
  2095. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2096. // 获取 type_id 为 1 的数据
  2097. $result['type1'] = $this->processGoods(
  2098. $query->clone()
  2099. ->where('type_id', 1)
  2100. ->offset(($data['page'] - 1) * $data['pageSize'])
  2101. ->limit($data['pageSize'])
  2102. ->get(),
  2103. $data
  2104. );
  2105. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2106. // 获取 type_id 为 2 的数据
  2107. $result['type2'] = $this->processGoods(
  2108. $query->clone()
  2109. ->where('type_id', 2)
  2110. ->offset(($data['page'] - 1) * $data['pageSize'])
  2111. ->limit($data['pageSize'])
  2112. ->get(),
  2113. $data
  2114. );
  2115. }
  2116. if (empty($result)) {
  2117. return Result::error("查询失败", 0);
  2118. }
  2119. return Result::success($result);
  2120. }
  2121. /**
  2122. * 获取商品详情
  2123. * @param array $data
  2124. * @return array
  2125. * */
  2126. public function getWebsiteshopInfo(array $data): array
  2127. {
  2128. $where = [
  2129. 'good.status' => 2,
  2130. 'good.website_id' => $data['website_id'],
  2131. 'good.id' => $data['id'],
  2132. ];
  2133. $goods = Good::where($where)
  2134. ->where('good.id', $data['id'])
  2135. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2136. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2137. ->first();
  2138. if (empty($goods)) {
  2139. return Result::error("查询失败", 0);
  2140. }
  2141. $goods->imgurl = json_decode($goods->imgurl, true);
  2142. return Result::success($goods);
  2143. }
  2144. // 封装处理商品的路由问题
  2145. function processGoods($goods, $data)
  2146. {
  2147. return $goods->map(function ($good) use ($data) {
  2148. $catid = $good->catid ?? 0;
  2149. // $pinyin = '';
  2150. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2151. if (!empty($category->pid) && $category->pid != 0) {
  2152. $level = json_decode($category->category_arr_id, true);
  2153. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2154. ->whereIn('category_id', $level)
  2155. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2156. ->get(['aLIas_pinyin'])
  2157. ->pluck('aLIas_pinyin')
  2158. ->implode('/');
  2159. } else {
  2160. $pinyin = $category->aLIas_pinyin ?? '';
  2161. }
  2162. if (isset($good->city_id) && !empty($good->city_id)) {
  2163. $city = District::where('id', $good->city_id)->first(['name']);
  2164. $good->city_name = $city->name ?? '';
  2165. }
  2166. // 解析imgurl JSON并取第一条数据
  2167. $imgUrls = json_decode($good->imgurl, true);
  2168. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2169. $good->pinyin = $pinyin;
  2170. return $good;
  2171. });
  2172. }
  2173. /**
  2174. * c端-获取招工招聘下拉选框
  2175. * @param array $data
  2176. * @return array
  2177. * */
  2178. public function getWebsiteJobSelect(array $data): array
  2179. {
  2180. $web = Website::where('id', $data['website_id'])->first();
  2181. if (empty($web)) {
  2182. return Result::error("该网站不存在", 0);
  2183. }
  2184. $hy = JobIndustry::get()->all();
  2185. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2186. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2187. $result = [
  2188. 'hy' => $hy,
  2189. 'zw' => $zw,
  2190. 'jtzw' => $jtzw,
  2191. ];
  2192. if (empty($result)) {
  2193. return Result::error("查询失败", 0);
  2194. }
  2195. return Result::success($result);
  2196. }
  2197. /**
  2198. * c端-获取招工招聘
  2199. * @param array $data
  2200. * @return array
  2201. * */
  2202. public function getWebsiteJob(array $data): array
  2203. {
  2204. $web = Website::where('id', $data['website_id'])->first();
  2205. if (empty($web)) {
  2206. return Result::error("该网站不存在", 0);
  2207. }
  2208. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2209. ->where('job_hunting.website_id', $data['website_id'])
  2210. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2211. $query->where(function ($q) use ($data) {
  2212. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2213. });
  2214. })
  2215. ->select(
  2216. 'job_hunting.id',
  2217. 'job_hunting.catid',
  2218. 'job_hunting.cat_arr_id',
  2219. 'job_hunting.job_name_get',
  2220. 'job_hunting.industry',
  2221. 'job_hunting.name',
  2222. 'job_hunting.sexy',
  2223. 'job_hunting.origin',
  2224. 'job_hunting.city_arr_id',
  2225. 'job_hunting.experience',
  2226. 'job_hunting.updated_at',
  2227. 'job_hunting.salary',
  2228. 'job_hunting.skillList',
  2229. 'job_hunting.slelf_evaluation',
  2230. )
  2231. ->orderBy('updated_at', 'desc')
  2232. ->limit($data['job1_num'])
  2233. ->get();
  2234. $web['website_id'] = $data['website_id'];
  2235. if (empty($job_hunting)) {
  2236. $job_huntings = "未查询到相关简历信息";
  2237. } else {
  2238. $job_huntings = $this->processJob($job_hunting, $web);
  2239. }
  2240. // 0:待审核 1:已通过 2:已拒绝
  2241. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2242. ->where('job_recruiting.website_id', $data['website_id'])
  2243. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2244. $query->where(function ($q) use ($data) {
  2245. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2246. });
  2247. })
  2248. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2249. ->select(
  2250. 'job_recruiting.id',
  2251. 'job_recruiting.catid',
  2252. 'job_recruiting.cat_arr_id',
  2253. 'job_recruiting.title',
  2254. 'job_recruiting.jtzw_id',
  2255. 'job_recruiting.hy_id',
  2256. 'job_recruiting.city_arr_id',
  2257. 'job_recruiting.due_data',
  2258. 'job_recruiting.updated_at',
  2259. 'job_recruiting.experience',
  2260. 'job_recruiting.educational',
  2261. 'job_recruiting.salary',
  2262. 'job_recruiting.zw_id',
  2263. 'job_company.business_name',
  2264. 'job_recruiting.keyword',
  2265. 'job_recruiting.description',
  2266. )
  2267. ->orderBy('updated_at', 'desc')
  2268. ->limit($data['job2_num'])
  2269. ->get();
  2270. if (empty($job_recruiting->toArray())) {
  2271. $job_recruitings = "未查询到相关职位信息";
  2272. } else {
  2273. $job_recruitings = $this->processJob($job_recruiting, $web);
  2274. }
  2275. $result = [
  2276. 'job_hunting' => $job_huntings,
  2277. 'job_recuiting' => $job_recruitings,
  2278. ];
  2279. return Result::success($result);
  2280. }
  2281. /**
  2282. * c端-获取招工招聘列表
  2283. * @param array $data
  2284. * @return array
  2285. * */
  2286. public function getWebsiteJobList(array $data): array
  2287. {
  2288. $recruit_where = [];
  2289. $hunt_where = [];
  2290. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2291. if (empty($web)) {
  2292. return Result::error("此网站不存在", 0);
  2293. }
  2294. $website_id['website_id'] = $data['website_id'];
  2295. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2296. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2297. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2298. }
  2299. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2300. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2301. }
  2302. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2303. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2304. }
  2305. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2306. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  2307. }
  2308. $query = JobRecruiting::where('job_recruiting.status', 1)
  2309. ->where('job_recruiting.website_id', $data['website_id'])
  2310. ->where($recruit_where)
  2311. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2312. $query->where(function ($q) use ($data) {
  2313. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2314. });
  2315. })
  2316. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2317. $query->where(function ($q) use ($data) {
  2318. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2319. });
  2320. })
  2321. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2322. ->select(
  2323. 'job_recruiting.id',
  2324. 'job_recruiting.catid',
  2325. 'job_recruiting.hy_id',
  2326. 'job_recruiting.title',
  2327. 'job_recruiting.zw_id',
  2328. 'job_recruiting.educational',
  2329. 'job_recruiting.jtzw_id',
  2330. 'job_recruiting.city_arr_id',
  2331. 'job_recruiting.due_data',
  2332. 'job_recruiting.experience',
  2333. 'job_recruiting.cat_arr_id',
  2334. 'job_recruiting.updated_at',
  2335. 'job_company.business_name',
  2336. 'job_recruiting.keyword',
  2337. 'job_recruiting.description',
  2338. )
  2339. ->orderBy('job_recruiting.updated_at', 'desc');
  2340. $recruit_count = $query->count();
  2341. $query = clone $query;
  2342. $JobRecruiting = $query
  2343. ->offset(($data['page'] - 1) * $data['pageSize'])
  2344. ->limit($data['pageSize'])
  2345. ->get();
  2346. if (empty($JobRecruiting)) {
  2347. $JobRecruiting = "暂无相关职位信息";
  2348. } else {
  2349. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2350. }
  2351. }
  2352. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2353. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2354. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  2355. }
  2356. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2357. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  2358. }
  2359. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2360. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  2361. }
  2362. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2363. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  2364. }
  2365. $query = JobHunting::where('job_hunting.status', 2)
  2366. ->where('job_hunting.website_id', $data['website_id'])
  2367. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  2368. ->where($hunt_where)
  2369. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  2370. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  2371. // })
  2372. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2373. $query->where(function ($q) use ($data) {
  2374. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2375. });
  2376. })
  2377. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  2378. $query->where(function ($q) use ($data) {
  2379. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  2380. });
  2381. })
  2382. ->select(
  2383. 'job_hunting.id',
  2384. 'job_hunting.catid',
  2385. 'job_hunting.sexy',
  2386. 'job_hunting.experience',
  2387. 'job_hunting.origin',
  2388. 'job_hunting.industry',
  2389. 'job_hunting.name',
  2390. 'job_hunting.job',
  2391. 'job_hunting.job_name_get',
  2392. 'job_hunting.city_arr_id',
  2393. 'job_hunting.cat_arr_id',
  2394. 'job_hunting.created_at',
  2395. 'job_hunting.updated_at',
  2396. 'job_position.zwname as job_name',
  2397. 'job_hunting.skillList',
  2398. 'job_hunting.slelf_evaluation',
  2399. )
  2400. ->orderBy('job_hunting.updated_at', 'desc');
  2401. $hunt_count = $query->count();
  2402. $query = clone $query;
  2403. $JobHunting = $query
  2404. ->offset(($data['page'] - 1) * $data['pageSize'])
  2405. ->limit($data['pageSize'])
  2406. ->get();
  2407. if (empty($JobHunting)) {
  2408. $JobRecruiting = "暂无相关简历信息";
  2409. } else {
  2410. $JobHunting = $this->processJob($JobHunting, $website_id);
  2411. }
  2412. }
  2413. $result = [
  2414. 'JobRecruiting' => $JobRecruiting ?? [],
  2415. 'recruit_count' => $recruit_count ?? 0,
  2416. 'JobHunting' => $JobHunting ?? [],
  2417. 'hunt_count' => $hunt_count ?? 0,
  2418. ];
  2419. return Result::success($result);
  2420. }
  2421. /**
  2422. * c端-获取招工招聘详情
  2423. * @param array $data
  2424. * @return array
  2425. * */
  2426. public function getWebsiteJobInfo(array $data): array
  2427. {
  2428. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2429. if (empty($web)) {
  2430. return Result::error("该网站不存在", 0);
  2431. }
  2432. $webid = [
  2433. 'website_id' => $data['website_id'],
  2434. ];
  2435. // 职位相关信息
  2436. if ($data['type'] == 1) {
  2437. $query = JobRecruiting::where('status', 1)
  2438. ->where('website_id', $data['website_id'])
  2439. ->select('*');
  2440. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2441. $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();
  2442. if (!empty($company)) {
  2443. $result['company'] = $this->processJob($company, $webid);
  2444. }
  2445. $other_job = JobRecruiting::where('status', 1)
  2446. ->where('website_id', $data['website_id'])
  2447. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  2448. ->where('id', '!=', $data['id'])
  2449. ->where('user_id', '=', $job[0]['user_id'])
  2450. ->limit($data['pageSize'])
  2451. ->get();
  2452. if (!empty($other_job)) {
  2453. $result['other_job'] = $this->processJob($other_job, $webid);
  2454. }
  2455. } else {
  2456. // 简历相关信息
  2457. $job = JobHunting::where('job_hunting.status', 2)
  2458. ->where('job_hunting.website_id', $data['website_id'])
  2459. ->where('job_hunting.id', $data['id'])
  2460. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2461. ->select('job_hunting.*', 'user_name')
  2462. ->get();
  2463. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  2464. if (!empty($resume->toArray())) {
  2465. $result['resume'] = 1;
  2466. } else {
  2467. $result['resume'] = 0;
  2468. }
  2469. }
  2470. if (empty($job->toArray())) {
  2471. return Result::error("id参数错误", 0);
  2472. }
  2473. if (!empty($job[0]['job_experience'])) {
  2474. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  2475. if (!empty($job_experience)) {
  2476. // $hy = [];
  2477. foreach ($job_experience as $key => $value) {
  2478. // $id = $value['id'];
  2479. $hy[$key] = $value['job_industry'];
  2480. $zw_id[$key] = $value['job_typename'];
  2481. $jtzw_id[$key] = $value['job_name'];
  2482. }
  2483. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  2484. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  2485. // 先将关联表转换为索引数组,提高查找效率
  2486. $hyLookup = [];
  2487. foreach ($hy_table as $item) {
  2488. $hyLookup[$item['hyid']] = $item['hyname'];
  2489. }
  2490. $zwLookup = [];
  2491. foreach ($zw_table as $item) {
  2492. $zwLookup[$item['zwid']] = $item['zwname'];
  2493. }
  2494. foreach ($job_experience as $key => &$value) {
  2495. // 处理行业名称
  2496. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  2497. $value['hy_name'] = $hyLookup[$hy[$key]];
  2498. }
  2499. // 处理职位名称
  2500. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  2501. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  2502. }
  2503. // 处理具体职位名称
  2504. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  2505. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  2506. }
  2507. }
  2508. // 释放引用,防止意外修改后续代码
  2509. unset($value);
  2510. }
  2511. $result['job_experience'] = $job_experience ?? [];
  2512. }
  2513. if (!empty($job[0]['education_experience'])) {
  2514. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  2515. if (!empty($education_experience)) {
  2516. foreach ($education_experience as $key => $value) {
  2517. // $id = $value['id'];
  2518. $education[$key] = $value['school_education'];
  2519. }
  2520. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  2521. // // 先将关联表转换为索引数组,提高查找效率
  2522. $educationLookup = [];
  2523. foreach ($education_table as $item) {
  2524. $educationLookup[$item['evalue']] = $item['ename'];
  2525. }
  2526. foreach ($education_experience as $key => &$value) {
  2527. // 处理学历名称
  2528. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  2529. $value['education_name'] = $educationLookup[$education[$key]];
  2530. }
  2531. }
  2532. }
  2533. $result['education_experience'] = $job_experience ?? [];
  2534. }
  2535. $result['job'] = $this->processJob($job, $webid);
  2536. // // 返现对应的栏目
  2537. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  2538. $category = WebsiteCategory::where('website_id', $data['website_id'])
  2539. ->whereIn('category_id', $catid)
  2540. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  2541. ->orderBy('pid')->get()->all();
  2542. if (!empty($category)) {
  2543. $result['category'] = $category;
  2544. }
  2545. $result['job'] = $job;
  2546. $result['job_experience'] = $job_experience ?? [];
  2547. $result['education_experience'] = $education_experience ?? [];
  2548. if (empty($result)) {
  2549. return Result::error("参数错误", 0);
  2550. }
  2551. return Result::success($result);
  2552. }
  2553. /**
  2554. * c端-申请职位
  2555. * @param array $data
  2556. * @return array
  2557. * */
  2558. public function getWebsiteJobApply(array $data): array
  2559. {
  2560. // 首先验证网站是否存在
  2561. // return Result::success($data);
  2562. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2563. if (empty($web)) {
  2564. return Result::error("该网站不存在", 0);
  2565. }
  2566. // 验证用户是否存在且为个人会员/管理员
  2567. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2568. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2569. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  2570. return Result::error("用户不存在", 0);
  2571. }
  2572. // 去除重复元素和空元素,并保持原始顺序
  2573. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  2574. return !empty($value);
  2575. }));
  2576. // 验证职位是否存在 1:审核通过
  2577. $recruiting = JobRecruiting::where('status', 1)
  2578. ->where('website_id', $data['website_id'])
  2579. ->whereIn('id', $data['recruit_id'])
  2580. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  2581. if (empty($recruiting)) {
  2582. return Result::error("该职位不存在", 0);
  2583. }
  2584. // 简历是否存在
  2585. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  2586. if (empty($hunt_id)) {
  2587. return Result::error("该简历不存在", 0);
  2588. }
  2589. $data['hunt_id'] = $hunt_id['hunt_id'];
  2590. // // 验证是否已投递过该职位
  2591. $apply = JobApply::where('user_id', $data['user_id'])
  2592. ->where('hunt_id', $data['hunt_id'])
  2593. ->where('website_id', $data['website_id'])
  2594. ->whereIn('recruit_id', $data['recruit_id'])
  2595. ->get(['recruit_id']);
  2596. if (!empty($apply->toArray())) {
  2597. return Result::error("您已投递过该职位!");
  2598. }
  2599. $insertData = array_map(function ($recruiting) use ($data) {
  2600. return [
  2601. 'user_id' => $data['user_id'],
  2602. 'hunt_id' => $data['hunt_id'],
  2603. 'website_id' => $data['website_id'],
  2604. 'recruit_id' => $recruiting['recruit_id'],
  2605. 'receiver_id' => $recruiting['receiver_id'],
  2606. 'status' => 1,
  2607. ];
  2608. }, $recruiting);
  2609. // 批量插入数据
  2610. $result = JobApply::insert($insertData);
  2611. if (empty($result)) {
  2612. return Result::error("投递失败", 0);
  2613. }
  2614. return Result::success($result);
  2615. }
  2616. /**
  2617. * 招工招聘-沟通简历
  2618. * @param array $data
  2619. * @return array
  2620. * */
  2621. public function getWebsiteJobResume(array $data): array
  2622. {
  2623. // 首先验证网站是否存在
  2624. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2625. if (empty($web)) {
  2626. return Result::error("该网站不存在", 0);
  2627. }
  2628. // return Result::success($data);
  2629. // 验证用户是否存在且为企业会员/管理员
  2630. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2631. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2632. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2633. return Result::error("用户不存在", 0);
  2634. }
  2635. // 去除重复元素和空元素,并保持原始顺序
  2636. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  2637. return !empty($value);
  2638. }));
  2639. // 验证简历是否存在
  2640. $hunting = JobHunting::where('status', 2)
  2641. ->where('website_id', $data['website_id'])
  2642. ->whereIn('id', $data['hunt_id'])
  2643. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  2644. if (empty($hunting)) {
  2645. return Result::error("该简历不存在", 0);
  2646. }
  2647. // 验证是否已沟通过该简历
  2648. $remuse = JobRemuse::where('user_id', $data['user_id'])
  2649. ->where('recruit_id', $data['recruit_id'])
  2650. ->where('website_id', $data['website_id'])
  2651. ->whereIn('hunt_id', $data['hunt_id'])
  2652. ->get(['hunt_id']);
  2653. if (!empty($remuse->toArray())) {
  2654. return Result::error("您已沟通过该简历!");
  2655. }
  2656. // 准备要插入的数据数组
  2657. $insertData = array_map(function ($hunting) use ($data) {
  2658. return [
  2659. 'user_id' => $data['user_id'],
  2660. 'recruit_id' => $data['recruit_id'],
  2661. 'website_id' => $data['website_id'],
  2662. 'hunt_id' => $hunting['hunt_id'],
  2663. 'receiver_id' => $hunting['receiver_id'],
  2664. 'status' => 1,
  2665. ];
  2666. }, $hunting);
  2667. // 批量插入数据
  2668. $result = JobRemuse::insert($insertData);
  2669. if (empty($result)) {
  2670. return Result::error("沟通失败", 0);
  2671. }
  2672. return Result::success($result);
  2673. }
  2674. /**
  2675. * 招工招聘 -我的职位(企业会员)
  2676. * @param array $data
  2677. * @return array
  2678. */
  2679. public function getWebsiteJobRecruiting(array $data): array
  2680. {
  2681. $web = Website::where('id', $data['website_id'])->first('id');
  2682. if (empty($web)) {
  2683. return Result::error("该网站不存在", 0);
  2684. }
  2685. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2686. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2687. return Result::error("用户暂无权限!", 0);
  2688. }
  2689. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  2690. $result = JobRecruiting::where('website_id', $data['website_id'])
  2691. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  2692. $query->where('user_id', $user['id']);
  2693. })
  2694. ->where('status', 1)
  2695. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  2696. ->orderBy('updated_at', 'desc')
  2697. ->limit($data['pageSize'])
  2698. ->get();
  2699. if (empty($result)) {
  2700. return Result::error("暂无相关职位信息", 0);
  2701. }
  2702. return Result::success($result);
  2703. }
  2704. /*
  2705. * 获取职位
  2706. * */
  2707. public function getPositionList(array $data): array
  2708. {
  2709. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  2710. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  2711. } else {
  2712. $result = JobPosition::where('zwpid', 0)->get()->all();
  2713. }
  2714. if (empty($result)) {
  2715. return Result::error("暂无此职位", 0);
  2716. }
  2717. return Result::success($result);
  2718. }
  2719. /**
  2720. * 招工招聘 - 获取推荐职位
  2721. * @param array $data
  2722. * @return array
  2723. */
  2724. public function getWebsiteLevelJob(array $data): array
  2725. {
  2726. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  2727. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  2728. ->where('job_recruiting.status', 1)
  2729. ->where('job_level', $data['job_level'])
  2730. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2731. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  2732. ->orderBy('job_recruiting.updated_at', 'desc')
  2733. ->limit($data['pageSize'])
  2734. ->get();
  2735. $web = ['website_id' => $data['website_id']];
  2736. if (!empty($job)) {
  2737. $result = $this->processJob($job, $web);
  2738. }
  2739. if (empty($result)) {
  2740. return Result::error("暂无相关职位信息", 0);
  2741. }
  2742. return Result::success($result);
  2743. }
  2744. /**
  2745. * 招工招聘 - 根据栏目获取职位
  2746. * @param array $data
  2747. * @return array
  2748. */
  2749. public function getWebsiteCategoryJob(array $data): array
  2750. {
  2751. $categorys = json_decode($data['id'], true);
  2752. if (!empty($categorys)) {
  2753. $category_arr = $this->processArticlePro($data['website_id']);
  2754. $cat_1st_arr = $category_arr['cat_1st_arr'];
  2755. $catiall = $category_arr['catiall'];
  2756. foreach ($categorys as $key => $val) {
  2757. if (isset($val['id']) && !empty($val['id'])) {
  2758. $catid = explode(',', $val['id'])[0] ?? null;
  2759. $type = explode(',', $val['id'])[1] ?? null;
  2760. $textnum = explode(',', $val['id'])[2] ?? null;
  2761. }
  2762. // 4:招聘;5:求职;
  2763. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  2764. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  2765. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  2766. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2767. ->where('job_recruiting.status', 1)
  2768. ->where('job_recruiting.website_id', $data['website_id'])
  2769. ->select(
  2770. 'job_recruiting.id',
  2771. 'job_recruiting.title',
  2772. 'job_company.business_name',
  2773. 'job_recruiting.updated_at',
  2774. 'job_recruiting.cat_arr_id',
  2775. 'job_recruiting.keyword',
  2776. 'job_recruiting.description'
  2777. )
  2778. ->orderBy('job_recruiting.updated_at', 'desc')
  2779. ->limit($textnum)
  2780. ->get()->all();
  2781. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  2782. // 状态 审核状态,1待审核2已审核3已拒绝
  2783. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  2784. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  2785. ->where('job_hunting.status', 2)
  2786. ->where('job_hunting.website_id', $data['website_id'])
  2787. ->select(
  2788. 'job_hunting.id',
  2789. 'job_hunting.name',
  2790. 'job_hunting.cat_arr_id',
  2791. 'job_position.zwname as job_name',
  2792. 'job_hunting.updated_at',
  2793. // 'job_hunting.keyword',
  2794. 'job_hunting.slelf_evaluation'
  2795. )
  2796. ->orderBy('updated_at', 'desc')
  2797. ->limit($textnum)
  2798. ->get()->all();
  2799. } else {
  2800. $job = [];
  2801. }
  2802. // var_dump($catid.'222uuuuuuu'.$key);
  2803. if (!empty($job)) {
  2804. foreach ($job as $k => $value) {
  2805. if (isset($value->cat_arr_id)) {
  2806. $catArr = json_decode($value->cat_arr_id, true);
  2807. $catId = end($catArr);
  2808. } else {
  2809. continue;
  2810. }
  2811. if (isset($catiall[$catId])) {
  2812. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  2813. }
  2814. }
  2815. }
  2816. // var_dump($catid.'xxxxx'.$key);
  2817. $result[$key] = $job ?? [];
  2818. }
  2819. }
  2820. if (empty($result)) {
  2821. return Result::error("暂无相关分类信息", 0);
  2822. }
  2823. return Result::success($result);
  2824. }
  2825. // 封装处理由问题
  2826. function processJob($job, $data)
  2827. {
  2828. return $job->map(function ($job) use ($data) {
  2829. $category = $job->cat_arr_id ?? '';
  2830. $cityid = $job->city_arr_id ?? '';
  2831. $city = json_decode($cityid, true);
  2832. $pinyin = '';
  2833. $level = json_decode($category, true);
  2834. // 路由
  2835. if (!empty($level) && is_array($level)) {
  2836. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2837. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2838. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2839. ->get(['aLIas_pinyin'])
  2840. ->pluck('aLIas_pinyin')
  2841. ->implode('/');
  2842. if (empty($pinyin)) {
  2843. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2844. }
  2845. $job->pinyin = $pinyin;
  2846. }
  2847. // 取职位-城市 市??省
  2848. if (!empty($city) && is_array($city)) {
  2849. if (isset($city[1]) && !empty($city[1])) {
  2850. $city = District::where('id', $city[1])->first(['name']);
  2851. $job->city_name = $city->name ?? '';
  2852. } else if (isset($city[0]) && !empty($city[0])) {
  2853. $city = District::where('id', $city[0])->first(['name']);
  2854. $job->city_name = $city->name ?? '';
  2855. } else {
  2856. $job->city_name = '全国';
  2857. }
  2858. }
  2859. // 获取简历最后一级地区
  2860. if (isset($job->city_id) && !empty($job->city_id)) {
  2861. $city = District::where('id', $job->city_id)->first(['name']);
  2862. $job->hunt_cityname = $city->name ?? '';
  2863. }
  2864. // 组合详细地址
  2865. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2866. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2867. if (is_array($address_id) && !empty($address_id)) {
  2868. $address = District::whereIn('id', $address_id)
  2869. ->orderBy('level', 'asc')
  2870. ->get(['name'])
  2871. ->pluck('name')
  2872. ->implode('');
  2873. // $job->address_name = $address ?? '';
  2874. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2875. }
  2876. }
  2877. // 取行业
  2878. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2879. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2880. if (!empty($job->industry)) {
  2881. $query->where('hyid', $job->industry);
  2882. } else if (!empty($job->hy_id)) {
  2883. $query->where('hyid', $job->hy_id);
  2884. } else if (!empty($job->company_hy_id)) {
  2885. $query->where('hyid', $job->company_hy_id);
  2886. } else {
  2887. $query->where('hyid', $job->job_industry);
  2888. }
  2889. })->first(['hyname']);
  2890. $job->hy_name = $hy_name->hyname ?? '';
  2891. }
  2892. // 取职位类别
  2893. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2894. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2895. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2896. $job->zw_name = $zw_name->zwname ?? '';
  2897. }
  2898. // 取具体职位
  2899. 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))) {
  2900. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2901. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2902. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2903. }
  2904. // 取工作经验
  2905. if (isset($job->experience) && !empty($job->experience)) {
  2906. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2907. $job->experience_name = $experience->ename ?? '';
  2908. }
  2909. // 取学历
  2910. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2911. $education = $job->educational ?? $job->school_education;
  2912. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2913. $job->education_name = $education->ename ?? '';
  2914. }
  2915. // 语言
  2916. if (isset($job->language) && !empty($job->language)) {
  2917. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2918. $job->language_name = $language->ename ?? '';
  2919. }
  2920. // 薪资
  2921. if (isset($job->salary) && !empty($job->salary)) {
  2922. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2923. $job->salary_name = $salary->ename ?? '';
  2924. }
  2925. // 职位性质
  2926. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2927. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2928. $job->job_nature_name = $job_nature->ename ?? '';
  2929. }
  2930. // 公司规模
  2931. if (isset($job->company_size) && !empty($job->company_size)) {
  2932. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2933. $job->company_size_name = $company_size->ename ?? '';
  2934. }
  2935. // 公司性质
  2936. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2937. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2938. $job->company_nature_name = $company_nature->nature_name ?? '';
  2939. }
  2940. // $job->pinyin = $pinyin;
  2941. return $job;
  2942. });
  2943. }
  2944. /**
  2945. * 获取书籍模块
  2946. * @param array $data
  2947. * @return array
  2948. * */
  2949. public function getWebsiteBook(array $data): array
  2950. {
  2951. $input['id'] = $data['id'];
  2952. $input['website_id'] = $data['website_id'];
  2953. // 将 JSON 字符串转换为 PHP 数组
  2954. $data = json_decode($input['id'], true);
  2955. // 使用 array_map 处理每个元素
  2956. $result = array_map(function ($item) use ($input) {
  2957. // 检查parent元素是否存在且不是undefined
  2958. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2959. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2960. $website = [
  2961. 'website_id' => $input['website_id'],
  2962. ];
  2963. // 查询栏目名称
  2964. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2965. if (empty($category)) {
  2966. $parent_alias = '';
  2967. $parent_pinyin = null;
  2968. $imgBooks = [];
  2969. $textBooks = [];
  2970. } else {
  2971. $parent_alias = $category->alias ?? '';
  2972. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2973. // 查找子分类ID数组
  2974. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2975. array_push($childCategoryIds, $parentCatId);
  2976. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2977. if ($parentImgNum != 0) {
  2978. // 查询图片新闻
  2979. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2980. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2981. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2982. })
  2983. ->where('book.status', 2)
  2984. ->where('book.img_url', '!=', '')
  2985. ->where('book.website_id', $website['website_id'])
  2986. ->leftJoin('website_category', function ($join) use ($website) {
  2987. $join->on('book.cat_id', '=', 'website_category.category_id')
  2988. ->where('website_category.website_id', '=', $website['website_id']);
  2989. })
  2990. ->select(
  2991. 'book.id',
  2992. 'book.title',
  2993. 'book.img_url',
  2994. 'book.price',
  2995. 'book.market_price',
  2996. 'book.description',
  2997. 'book.cat_id',
  2998. 'book.description',
  2999. 'book.updated_at',
  3000. 'website_category.alias as category_name',
  3001. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3002. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3003. )
  3004. ->orderBy('updated_at', 'desc')
  3005. ->limit($parentImgNum)
  3006. ->get()->all();
  3007. // 查询文字新闻
  3008. }
  3009. if ($parentTextNum != 0) {
  3010. $textBooks = [];
  3011. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3012. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3013. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3014. })
  3015. ->where('book.status', 2)
  3016. ->where('book.website_id', $website['website_id'])
  3017. ->leftJoin('website_category', function ($join) use ($website) {
  3018. $join->on('book.cat_id', '=', 'website_category.category_id')
  3019. ->where('website_category.website_id', '=', $website['website_id']);
  3020. })
  3021. ->select(
  3022. 'book.id',
  3023. 'book.title',
  3024. 'book.img_url',
  3025. 'book.price',
  3026. 'book.market_price',
  3027. 'book.description',
  3028. 'book.cat_id',
  3029. 'book.description',
  3030. 'book.updated_at',
  3031. 'website_category.alias as category_name',
  3032. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3033. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3034. )
  3035. ->orderBy('updated_at', 'desc')
  3036. ->limit($parentTextNum)
  3037. ->get()->all();
  3038. }
  3039. }
  3040. }
  3041. $resultItem = [
  3042. 'alias' => $parent_alias ?? '',
  3043. 'category_id' => $parentCatId ?? 0,
  3044. 'pinyin' => $parent_pinyin ?? null,
  3045. 'imgnum' => $imgBooks ?? [],
  3046. 'textnum' => $textBooks ?? [],
  3047. ];
  3048. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3049. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3050. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3051. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3052. ->get()->all();
  3053. if (!empty($childCategory)) {
  3054. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3055. // 查询子栏目名称
  3056. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3057. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3058. ->first();
  3059. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3060. $childImgArticles = [];
  3061. $childTextArticles = [];
  3062. $resultItem['child'] = [];
  3063. } else {
  3064. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3065. // 查询子栏目图片新闻
  3066. $childImgArticles = Book::where('cat_id', $childCatId)
  3067. ->where('status', 2)
  3068. ->where('img_url', '!=', '')
  3069. ->where('book.website_id', $website['website_id'])
  3070. ->leftJoin('website_category', function ($join) use ($website) {
  3071. $join->on('book.cat_id', '=', 'website_category.category_id')
  3072. ->where('website_category.website_id', '=', $website['website_id']);
  3073. })
  3074. ->select(
  3075. 'book.id',
  3076. 'book.title',
  3077. 'book.img_url',
  3078. 'book.price',
  3079. 'book.market_price',
  3080. 'book.description',
  3081. 'book.cat_id',
  3082. 'book.description',
  3083. 'book.updated_at',
  3084. DB::raw("'$child_pinyin' as pinyin")
  3085. )
  3086. ->orderBy('updated_at', 'desc')
  3087. ->limit($childImgNum)
  3088. ->get()->all();
  3089. // 查询子栏目文字新闻
  3090. $childTextArticles = Book::where('cat_id', $childCatId)
  3091. ->where('status', 2)
  3092. ->where('book.website_id', $website['website_id'])
  3093. ->leftJoin('website_category', function ($join) use ($website) {
  3094. $join->on('book.cat_id', '=', 'website_category.category_id')
  3095. ->where('website_category.website_id', '=', $website['website_id']);
  3096. })
  3097. ->select(
  3098. 'book.id',
  3099. 'book.title',
  3100. 'book.img_url',
  3101. 'book.price',
  3102. 'book.market_price',
  3103. 'book.description',
  3104. 'book.cat_id',
  3105. 'book.description',
  3106. 'book.updated_at',
  3107. DB::raw("'$child_pinyin' as pinyin")
  3108. )
  3109. ->orderBy('updated_at', 'desc')
  3110. ->limit($childTextNum)
  3111. ->get()->all();
  3112. $resultItem['child'] = [
  3113. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3114. 'category_id' => $childCatId,
  3115. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3116. 'all_childcat' => $childCategory,
  3117. 'imgnum' => $childImgArticles,
  3118. 'textnum' => $childTextArticles,
  3119. ];
  3120. }
  3121. }
  3122. } else {
  3123. $resultItem['child'] = [];
  3124. }
  3125. return $resultItem;
  3126. }, $data);
  3127. return Result::success($result);
  3128. }
  3129. /**
  3130. * 获取书刊列表
  3131. * @param array $data
  3132. * @return array
  3133. * */
  3134. public function getWebsiteBookList(array $data): array
  3135. {
  3136. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3137. if (empty($web)) {
  3138. return Result::error("查询失败", 0);
  3139. }
  3140. $catid = $data['id'];
  3141. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3142. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3143. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3144. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3145. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3146. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3147. ->where('pid', $category['pid'])
  3148. ->select(
  3149. 'category_id',
  3150. 'alias',
  3151. 'aLIas_pinyin',
  3152. 'pid',
  3153. 'sort',
  3154. 'is_url',
  3155. 'web_url',
  3156. 'seo_title',
  3157. 'seo_keywords',
  3158. 'seo_description',
  3159. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3160. )
  3161. ->orderBy('sort')
  3162. ->get()->all();
  3163. if (empty($category)) {
  3164. return Result::error("查询失败", 0);
  3165. }
  3166. $query = Book::where('book.status', 2)
  3167. ->where('book.website_id', $data['website_id'])
  3168. ->where('book.cat_id', $catid)
  3169. ->select(
  3170. 'book.id',
  3171. 'book.title',
  3172. 'book.img_url',
  3173. 'book.description',
  3174. 'book.updated_at',
  3175. 'book.cat_id',
  3176. DB::raw("'$pinyin' as pinyin")
  3177. )
  3178. ->orderBy('book.updated_at', 'desc');
  3179. $count = $query->count();
  3180. $query = clone $query;
  3181. $Book = $query
  3182. ->limit($data['pageSize'])
  3183. ->offset(($data['page'] - 1) * $data['pageSize'])
  3184. ->get()->all();
  3185. $result = [
  3186. 'category' => $categorys,
  3187. 'books' => $Book,
  3188. 'count' => $count,
  3189. ];
  3190. // if(empty($result)){
  3191. // return Result::error("查询失败", 0);
  3192. // }
  3193. return Result::success($result);
  3194. }
  3195. /**
  3196. * 获取书刊详情
  3197. * @param array $data
  3198. * @return array
  3199. * */
  3200. public function getWebsiteBookInfo(array $data): array
  3201. {
  3202. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3203. if (empty($web)) {
  3204. return Result::error("查询失败", 0);
  3205. }
  3206. $book = Book::where('status', 2)
  3207. ->where('website_id', $data['website_id'])
  3208. ->where('id', $data['id'])
  3209. ->select(
  3210. 'book.*',
  3211. )
  3212. ->orderBy('updated_at', 'desc')
  3213. ->first();
  3214. if (empty($book)) {
  3215. return Result::error("查询失败", 0);
  3216. }
  3217. // 先查询当前分类的 pid
  3218. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3219. ->where('category_id', $book['cat_id'])
  3220. ->first(['pid', 'category_id']);
  3221. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3222. if (!empty($carpid)) {
  3223. if ($carpid->pid != 0) {
  3224. $pid = $carpid['pid'];
  3225. // $parent_pinyin = '';
  3226. } else {
  3227. $pid = $carpid['category_id'];
  3228. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3229. }
  3230. }
  3231. $categorys = $query->where('pid', $pid)
  3232. ->select(
  3233. 'category_id',
  3234. 'alias',
  3235. 'aLIas_pinyin',
  3236. 'pid',
  3237. 'sort',
  3238. 'is_url',
  3239. 'web_url',
  3240. 'category_arr_id as cat_arr_id',
  3241. )
  3242. ->orderBy('sort')
  3243. ->get();
  3244. $category = $this->processArticle($categorys, $data);
  3245. $result = [
  3246. 'category' => $category,
  3247. 'books' => $book,
  3248. ];
  3249. return Result::success($result);
  3250. }
  3251. /**
  3252. * 封装处理文章的路由问题
  3253. * */
  3254. function processArticle($article, $data)
  3255. {
  3256. return $article->map(function ($article) use ($data) {
  3257. $catid = $article->cat_arr_id ?? '';
  3258. $level = json_decode($catid, true);
  3259. $pinyin = '';
  3260. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3261. if (!empty($level) && is_array($level)) {
  3262. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3263. ->where('website_id', $data['website_id'])
  3264. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3265. ->get(['aLIas_pinyin'])
  3266. ->pluck('aLIas_pinyin')
  3267. ->implode('/');
  3268. } else {
  3269. $pinyin = '';
  3270. }
  3271. $article->pinyin = $pinyin;
  3272. return $article;
  3273. });
  3274. }
  3275. /**
  3276. * @param array $data
  3277. * @return array
  3278. */
  3279. public function getWebsiteCompany(array $data): array
  3280. {
  3281. $categorys = json_decode($data['id'], true);
  3282. $category_arr = $this->processArticlePro($data['website_id']);
  3283. $cat_1st_arr = $category_arr['cat_1st_arr'];
  3284. $catiall = $category_arr['catiall'];
  3285. $categoryIds = $category_arr['categoryIds'];
  3286. // return Result::success($category_arr);
  3287. foreach ($categorys as $key => $value) {
  3288. if (array_key_exists('level', $value)) {
  3289. $parts = explode(',', $value['level']);
  3290. $level = $parts[0] ?? null;
  3291. $imgnum = $parts[1] ?? null;
  3292. $textnum = $parts[2] ?? null;
  3293. if (!empty($textnum) && $textnum > 0) {
  3294. $text_num = Company::where('level', $level)
  3295. ->whereIn('category_id', $categoryIds)
  3296. ->where('status', 1)
  3297. ->select(
  3298. 'company.id',
  3299. 'company.title',
  3300. 'company.description',
  3301. 'company.updated_at',
  3302. 'company.category_id',
  3303. 'company.cat_arr_id'
  3304. )
  3305. ->orderBy('updated_at', 'desc')
  3306. ->limit($textnum)
  3307. ->get()->all();
  3308. }
  3309. if (!empty($imgnum) && $imgnum > 0) {
  3310. $img_num = Company::where('level', $level)
  3311. ->whereIn('category_id', $categoryIds)
  3312. ->where('status', 1)
  3313. ->where('imgurl', '!=', '')
  3314. ->whereNotNull('imgurl')
  3315. ->select(
  3316. 'company.id',
  3317. 'company.title',
  3318. 'company.description',
  3319. 'company.updated_at',
  3320. 'company.imgurl as imgs',
  3321. 'company.category_id',
  3322. 'company.cat_arr_id'
  3323. )
  3324. ->orderBy('updated_at', 'desc')
  3325. ->limit($imgnum)
  3326. ->get()->all();
  3327. }
  3328. }
  3329. if (array_key_exists('id', $value)) {
  3330. $parts = explode(',', $value['id']);
  3331. $category_id = $parts[0] ?? null;
  3332. $imgnum = $parts[1] ?? null;
  3333. $textnum = $parts[2] ?? null;
  3334. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  3335. if (!empty($textnum) && $textnum > 0) {
  3336. $text_num = Company::whereIn('category_id', $category_arr)
  3337. // ->where('website_id', $data['website_id'])
  3338. ->where('status', 1)
  3339. ->select(
  3340. 'company.id',
  3341. 'company.title',
  3342. 'company.description',
  3343. 'company.updated_at',
  3344. 'company.category_id',
  3345. 'company.cat_arr_id'
  3346. )
  3347. ->orderBy('updated_at', 'desc')
  3348. ->limit($textnum)
  3349. ->get()->all();
  3350. }
  3351. if (!empty($imgnum) && $imgnum > 0) {
  3352. $img_num = Company::whereIn('category_id', $category_arr)
  3353. // ->where('website_id', $data['website_id'])
  3354. ->where('status', 1)
  3355. ->where('imgurl', '!=', '')
  3356. ->whereNotNull('imgurl')
  3357. ->select(
  3358. 'company.id',
  3359. 'company.title',
  3360. 'company.description',
  3361. 'company.updated_at',
  3362. 'company.imgurl as imgs',
  3363. 'company.category_id',
  3364. 'company.cat_arr_id'
  3365. )
  3366. ->orderBy('updated_at', 'desc')
  3367. ->limit($imgnum)
  3368. ->get()->all();
  3369. }
  3370. }
  3371. if (!empty($text_num)) {
  3372. foreach ($text_num as $k => $v) {
  3373. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  3374. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  3375. }
  3376. }
  3377. if (!empty($img_num)) {
  3378. foreach ($img_num as $k => $v) {
  3379. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  3380. $imgurl = json_decode($v['imgs'], true);
  3381. if (!empty($imgurl)) {
  3382. $img_num[$k]->imgurl = $imgurl[0];
  3383. }
  3384. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  3385. }
  3386. }
  3387. $company[$key]['img_num'] = $img_num ?? [];
  3388. $company[$key]['text_num'] = $text_num ?? [];
  3389. }
  3390. if (empty($company)) {
  3391. return Result::error("暂无相关企业信息", 0);
  3392. }
  3393. return Result::success($company);
  3394. }
  3395. /**
  3396. * @param array $data
  3397. * @return array
  3398. */
  3399. public function getWebsiteCompanyList(array $data): array
  3400. {
  3401. $where['website_id'] = $data['website_id'];
  3402. $where['status'] = 1;
  3403. $categoryIds = [];
  3404. if (isset($data['category_id']) && !empty($data['category_id'])) {
  3405. $category_id = $data['category_id'];
  3406. }
  3407. $category_arr = $this->processArticlePro($data['website_id']);
  3408. $categoryIds = $category_arr['categoryIds'];
  3409. // return Result::success($cat_1st_arr);
  3410. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  3411. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  3412. })
  3413. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  3414. $query->whereIn('category_id', $categoryIds);
  3415. })
  3416. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  3417. $query->where('category_id', $category_id);
  3418. })
  3419. ->where('status',1)
  3420. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  3421. ->orderBy('updated_at', 'desc')
  3422. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  3423. if (empty($company)) {
  3424. return Result::error("暂无相关公司信息", 0);
  3425. }
  3426. $result = [
  3427. 'count' => $company->total(),
  3428. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  3429. ];
  3430. return Result::success($result);
  3431. }
  3432. public function getWebsiteCompanyInfo(array $data): array
  3433. {
  3434. $company = Company::where('id', $data['id'])
  3435. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  3436. ->where('status', 1)
  3437. // ->where('website_id', $data['website_id'])
  3438. ->select('company.*', 'job_industry.hyname as hy_name')
  3439. ->first();
  3440. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  3441. $jobnature_id = $company['jobnature_id'] ?? null;
  3442. if ($jobnature_id !== null) {
  3443. switch ($jobnature_id) {
  3444. case 0:
  3445. $company->jobnature_name = '市场监督';
  3446. break;
  3447. case 1:
  3448. $company->jobnature_name = '信访纪检';
  3449. break;
  3450. case 2:
  3451. $company->jobnature_name = '公检法司';
  3452. break;
  3453. case 3:
  3454. $company->jobnature_name = '高关注机构';
  3455. break;
  3456. default:
  3457. $company->jobnature_name = '';
  3458. break;
  3459. }
  3460. } else {
  3461. $company->jobnature_name = '';
  3462. }
  3463. $city_arr = $company->city_arr_id;
  3464. if (!empty($city_arr)) {
  3465. $city_arr = json_decode($city_arr, true);
  3466. $cityNames = District::whereIn('id', $city_arr)
  3467. ->pluck('name')
  3468. ->implode('-');
  3469. $company->city_name = $cityNames;
  3470. } else {
  3471. $company->city_name = '';
  3472. }
  3473. if (empty($company)) {
  3474. return Result::error("暂无相关公司信息", 0);
  3475. }
  3476. return Result::success($company);
  3477. }
  3478. /**
  3479. * @param array $data
  3480. * @return array
  3481. */
  3482. public function getWebsiteProject(array $data): array
  3483. {
  3484. $categorys = json_decode($data['id'], true);
  3485. if (!empty($categorys)) {
  3486. $category_arr = $this->processArticlePro($data['website_id']);
  3487. $cat_1st_arr = $category_arr['cat_1st_arr'];
  3488. $catiall = $category_arr['catiall'];
  3489. // return Result::success($catiall);
  3490. foreach ($categorys as $key => $val) {
  3491. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  3492. $level = explode(',', $val['level'])[0];
  3493. $imgnum = explode(',', $val['level'])[1] ?? null;
  3494. $textnum = explode(',', $val['level'])[2] ?? null;
  3495. if ($level == 1) {
  3496. if (!empty($textnum) && $textnum > 0) {
  3497. $text_num = Project::where('level', $level)
  3498. ->where('website_id', $data['website_id'])
  3499. ->where('status', 1)
  3500. ->select(
  3501. 'project.id',
  3502. 'project.title',
  3503. 'project.description',
  3504. 'project.updated_at',
  3505. 'project.category_id',
  3506. 'project.cat_arr_id'
  3507. )
  3508. ->orderBy('updated_at', 'desc')
  3509. ->limit($textnum)
  3510. ->get()->all();
  3511. }
  3512. if (!empty($imgnum) && $imgnum > 0) {
  3513. $img_num = Project::where('level', $level)
  3514. ->where('website_id', $data['website_id'])
  3515. ->where('status', 1)
  3516. ->where('imgurl', '!=', '')
  3517. ->whereNotNull('imgurl')
  3518. ->select(
  3519. 'project.id',
  3520. 'project.title',
  3521. 'project.description',
  3522. 'project.updated_at',
  3523. 'project.imgurl as imgs',
  3524. 'project.category_id',
  3525. 'project.cat_arr_id'
  3526. )
  3527. ->orderBy('updated_at', 'desc')
  3528. ->limit($imgnum)
  3529. ->get()->all();
  3530. }
  3531. } else {
  3532. if (!empty($textnum) && $textnum > 0) {
  3533. $text_num = Project::where('website_id', $data['website_id'])
  3534. ->where('status', 1)
  3535. ->select(
  3536. 'project.id',
  3537. 'project.title',
  3538. 'project.description',
  3539. 'project.updated_at',
  3540. 'project.category_id',
  3541. 'project.cat_arr_id',
  3542. 'project.website_id',
  3543. 'project.updated_at',
  3544. 'project.created_at'
  3545. )
  3546. ->orderBy('updated_at', 'desc')
  3547. ->limit($textnum)
  3548. ->get()->all();
  3549. }
  3550. if (!empty($imgnum) && $imgnum > 0) {
  3551. $img_num = Project::where('website_id', $data['website_id'])
  3552. ->where('status', 1)
  3553. ->where('imgurl', '!=', '')
  3554. ->whereNotNull('imgurl')
  3555. ->select(
  3556. 'project.id',
  3557. 'project.title',
  3558. 'project.description',
  3559. 'project.updated_at',
  3560. 'project.imgurl as imgs',
  3561. 'project.category_id',
  3562. 'project.cat_arr_id'
  3563. )
  3564. ->orderBy('updated_at', 'desc')
  3565. ->limit($imgnum)
  3566. ->get()->all();
  3567. }
  3568. }
  3569. }
  3570. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  3571. $category_ids = explode(',', $val['id'])[0];
  3572. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  3573. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  3574. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  3575. if (!empty($cat_textnum) && $cat_textnum > 0) {
  3576. $text_num = Project::whereIn('category_id', $category_arr)
  3577. ->where('website_id', $data['website_id'])
  3578. ->where('status', 1)
  3579. ->select(
  3580. 'project.id',
  3581. 'project.title',
  3582. 'project.description',
  3583. 'project.updated_at',
  3584. 'project.category_id',
  3585. 'project.cat_arr_id'
  3586. )
  3587. ->orderBy('updated_at', 'desc')
  3588. ->limit($cat_textnum)
  3589. ->get()->all();
  3590. }
  3591. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  3592. $img_num = Project::whereIn('category_id', $category_arr)
  3593. ->where('website_id', $data['website_id'])
  3594. ->where('status', 1)
  3595. ->where('imgurl', '!=', '')
  3596. ->whereNotNull('imgurl')
  3597. ->select(
  3598. 'project.id',
  3599. 'project.title',
  3600. 'project.description',
  3601. 'project.updated_at',
  3602. 'project.imgurl as imgs',
  3603. 'project.category_id',
  3604. 'project.cat_arr_id'
  3605. )
  3606. ->orderBy('updated_at', 'desc')
  3607. ->limit($cat_imgnum)
  3608. ->get()->all();
  3609. }
  3610. }
  3611. if (!empty($img_num)) {
  3612. foreach ($img_num as $k => $v) {
  3613. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  3614. $imgurl = json_decode($v['imgs'], true);
  3615. if (!empty($imgurl)) {
  3616. $img_num[$k]->imgurl = $imgurl[0];
  3617. }
  3618. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  3619. }
  3620. }
  3621. if (!empty($text_num)) {
  3622. foreach ($text_num as $k => $v) {
  3623. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  3624. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  3625. }
  3626. }
  3627. $project[$key]['img_num'] = $img_num ?? [];
  3628. $project[$key]['text_num'] = $text_num ?? [];
  3629. }
  3630. }
  3631. if (empty($project)) {
  3632. return Result::error("暂无相关项目信息", 0);
  3633. }
  3634. return Result::success($project);
  3635. }
  3636. /**
  3637. * @param array $data
  3638. * @return array
  3639. */
  3640. public function getWebsiteProjectInfo(array $data): array
  3641. {
  3642. $project = Project::where('id', $data['id'])
  3643. ->where('status', 1)
  3644. ->where('website_id', $data['website_id'])
  3645. ->select('project.*')
  3646. ->first();
  3647. if (empty($project)) {
  3648. return Result::error("暂无相关项目信息", 0);
  3649. }
  3650. return Result::success($project);
  3651. }
  3652. /**
  3653. * @param array $data
  3654. * @return array
  3655. */
  3656. public function getWebsiteProjectList(array $data): array
  3657. {
  3658. $where = [];
  3659. if (isset($data['category_id']) && !empty($data['category_id'])) {
  3660. $where['category_id'] = $data['category_id'];
  3661. }
  3662. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3663. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  3664. }
  3665. $query = Project::where($where)
  3666. ->where('status', 1)
  3667. ->where('website_id', $data['website_id'])
  3668. ->select(
  3669. 'project.id',
  3670. 'project.title',
  3671. 'project.description',
  3672. 'project.imgurl as imgs',
  3673. 'project.category_id',
  3674. 'project.cat_arr_id'
  3675. )
  3676. ->orderBy('updated_at', 'desc');
  3677. $count = $query->count();
  3678. $project = $query->clone()
  3679. ->offset(($data['page'] - 1) * $data['pageSize'])
  3680. ->limit($data['pageSize'])
  3681. ->get()->all();
  3682. if (empty($project)) {
  3683. return Result::error("暂无相关项目信息", 0);
  3684. }
  3685. $categorys = $this->processArticlePro($data['website_id']);
  3686. $catiall = $categorys['catiall'];
  3687. foreach ($project as $key => $val) {
  3688. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  3689. if (!empty($val['imgs'])) {
  3690. $imgurl = json_decode($val['imgs'], true);
  3691. if (!empty($imgurl)) {
  3692. $project[$key]->imgurl = $imgurl[0];
  3693. }
  3694. } else {
  3695. $project[$key]->imgurl = '';
  3696. }
  3697. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  3698. }
  3699. $result = [
  3700. 'rows' => $project,
  3701. 'count' => $count,
  3702. ];
  3703. return Result::success($result);
  3704. }
  3705. /**
  3706. * @param array $data
  3707. * @return array
  3708. */
  3709. public function getWebsiteMessage(array $data): array
  3710. {
  3711. $web = Website::where('id',$data['website_id'])->first();
  3712. if (empty($web)) {
  3713. return Result::error("暂无相关网站信息", 0);
  3714. }
  3715. $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
  3716. $message = Message::whereIn('message.column_id', $column_arr)
  3717. ->where('message.status', 1)
  3718. ->leftJoin('user', 'message.user_id', '=', 'user.id')
  3719. ->select('message.title', 'message.content','message.reply',
  3720. 'message.updated_at','user.nickname')
  3721. ->orderBy('message.updated_at', 'desc')
  3722. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  3723. if (empty($message->items())) {
  3724. return Result::error("暂无相关消息信息", 0);
  3725. }
  3726. $result = [
  3727. 'data' => $message->items(),
  3728. 'count' => $message->total(),
  3729. ];
  3730. return Result::success($result);
  3731. }
  3732. /**
  3733. * @param array $data
  3734. * @return array
  3735. */
  3736. /**
  3737. * 获取省份城市列表
  3738. * @param array $data
  3739. * @return array
  3740. */
  3741. public function getWebsiteProvinceCity(array $data): array
  3742. {
  3743. $province_city = District::whereIn('level', [1,2])
  3744. ->select('id', 'name', 'pid', 'abbreviation')
  3745. ->get()->all();
  3746. if (empty($province_city)) {
  3747. return Result::error("暂无相关省份城市信息", 0);
  3748. }
  3749. $result = Result::buildCityTree($province_city);
  3750. return Result::success($result);
  3751. }
  3752. /**
  3753. * @param array $data
  3754. * @return array
  3755. */
  3756. public function getWebsiteResearchTopic(array $data): array
  3757. {
  3758. $web = Website::where('id',$data['website_id'])->first();
  3759. if (empty($web)) {
  3760. return Result::error("暂无相关网站信息", 0);
  3761. }
  3762. $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
  3763. $where['level'] = 1;
  3764. if (isset($data['province_id']) && !empty($data['province_id'])) {
  3765. $where['province_id'] = $data['province_id'];
  3766. }
  3767. if (isset($data['city_id']) && !empty($data['city_id'])) {
  3768. $where['city_id'] = $data['city_id'];
  3769. }
  3770. if (isset($data['county_id']) && !empty($data['county_id'])) {
  3771. $where['county_id'] = $data['county_id'];
  3772. }
  3773. if(isset($data['title']) && !empty($data['title'])){
  3774. array_push($where,['title','like','%'.$data['title'].'%']);
  3775. }
  3776. $research_topic = ResearchTopic::whereIn('column_id', $column_arr)
  3777. ->where($where)
  3778. ->select('id', 'title', 'keyword', 'description','province_id','city_id','county_id')
  3779. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  3780. if (empty($research_topic->items())) {
  3781. return Result::error("暂无相关研究主题信息", 0);
  3782. }
  3783. $result = [
  3784. 'rows' => $research_topic->items(),
  3785. 'count' => $research_topic->total(),
  3786. ];
  3787. return Result::success($result);
  3788. }
  3789. }