| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861 |
- <?php
- namespace App\JsonRpc;
- use App\Model\Article;
- use App\Model\Ad;
- use App\Model\Category;
- use App\Model\AdPlace;
- use App\Model\Department;
- use App\Model\District;
- use App\Model\FooterCategory;
- use App\Model\FooterContent;
- use App\Model\WebsiteTemplateInfo;
- use App\Model\Link;
- use App\Model\LetterOfComplaint;
- use App\Model\User;
- use App\Model\UserInfo;
- use App\Model\WebsiteRole;
- use App\Model\WebsiteRoleUser;
- use App\Model\Website;
- use App\Model\WebsiteColumn;
- use App\Model\Good;
- use App\Model\Book;
- use App\Model\ChatRecords;
- use App\Model\ChatTopic;
- use App\Model\JobRecruiting;
- use App\Model\JobHunting;
- use App\Model\Notice;
- use App\Model\Complaint;
- use App\Model\Order;
- use App\Model\WebsiteImg;
- use App\Model\Company;
- use App\Model\Project;
- use App\Model\ChatTopicsReply;
- use App\Model\ArticleSurvey;
- use App\Model\JobIndustry;
- use App\Model\JobPosition;
- use App\Model\JobEnum;
- use App\Model\JobRemuse;
- use App\Model\JobCompany;
- use App\Model\JobNature;
- use App\Model\JobApply;
- use Hyperf\HttpServer\Contract\RequestInterface;
- use Hyperf\DbConnection\Db;
- use Hyperf\RpcServer\Annotation\RpcService;
- use App\Tools\Result;
- use Carbon\Carbon;
- use App\Model\WebsiteCategory;
- use App\Model\WebsiteGroup;
- use App\Model\WebsiteTemplate;
- use App\Model\Sector;
- use PhpParser\Node\Stmt\Return_;
- use SimpleKafkaClient\Metadata\Topic;
- use function PHPUnit\Framework\isNull;
- use Overtrue\Pinyin\Pinyin;
- use App\Tools\buildTree;
- use App\Model\WhiteRouter;
- use App\Model\Size;
- use App\Tools\PinyinHelper;
- use Hyperf\HttpServer\Annotation\AutoController;
- use Hyperf\Utils\Parallel;
- use Hyperf\Coroutine\Concurrent;
- use function Hyperf\Coroutine\batch;
- use Swoole\Coroutine;
- use App\Model\Message;
- use App\Model\ResearchTopic;
- #[RpcService(name: "WebService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
- class WebService implements WebServiceInterface
- {
- /**
- * 获取栏目
- * @param array $data
- * @return array
- */
- public function getWebsiteModelCategory(array $data): array
- {
- // return Result::success($data);
- $website_id = [
- 'website_id' => $data['website_id'],
- ];
- $website_column_arr = Website::where('id', $data['website_id'])->value('website_column_arr_id');
- if (empty($website_column_arr)) {
- return Result::error("未查询到此网站所属网系!", 0);
- }
- $website_column_arr = json_decode($website_column_arr, true);
- // return Result::success(!in_array(3,$website_column_arr) && $data['pid'] == 0);
- // 初始化 $pid 数组
- // $pid = [];
- // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
- $pidQuery = WebsiteCategory::where($website_id)
- ->where('pid', '!=', 0)
- ->orderBy('sort')
- ->select('pid', 'category_id', 'alias', 'aLIas_pinyin');
- $pid = $pidQuery->pluck('pid');
- $pid = array_values(array_unique($pid->toArray()));
- // 构建查询语句
- $query = WebsiteCategory::where($website_id)
- ->when(!in_array(3, $website_column_arr) && $data['pid'] == 0, function ($query) use ($website_column_arr) {
- $query->where('is_show', 1);
- })
- ->when(in_array(3, $website_column_arr) || $data['pid'] != 0, function ($query) use ($data) {
- $query->where('pid', $data['pid']);
- })
- ->offset($data['placeid'])
- ->limit($data['num'])
- ->orderBy('sort')
- ->orderBy('updated_at', 'desc');
- // 如果 $pid 数组不为空,添加 CASE WHEN 条件
- if (!empty($pid)) {
- $placeholders = implode(',', array_fill(0, count($pid), '?'));
- $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
- } else {
- // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
- $query->select('website_category.*', DB::raw('0 as children_count'));
- }
- // 执行查询
- $placeid = $data['placeid'] - 1;
- $result = $query->offset($placeid)->limit($data['num'])->get();
- if (!empty($result)) {
- $pidResults = $pidQuery->get();
- if (isset($data['type']) && $data['type'] == 1) {
- $result = $result->map(function ($item) use ($pidResults) {
- $children = $pidResults->where('pid', $item->category_id)->map(function ($child) {
- if (!empty($child)) {
- return $child;
- }
- });
- // 重置索引,使 key 值从 0 开始
- $item->children = $children->values();
- return $item;
- });
- } else {
- $pidMap = $pidResults->keyBy('pid');
- $result->each(function ($record) use ($pidMap, $data) {
- if ($data['pid'] == 0) {
- $record->aLIas_pinyin = $record->path;
- }
- // $record->aLIas_pinyin = $record->path;
- if ($pidMap->has($record->category_id)) {
- $pidResult = $pidMap->get($record->category_id);
- $record->chilid_id = $pidResult->category_id;
- $record->chilid_alias = $pidResult->alias;
- // $record->aLIas_pinyin = $pidResult->aLIas_pinyin;
- }
- });
- }
- return Result::success($result);
- } else {
- return Result::error("本网站暂无栏目", 0);
- }
- }
- /**
- * 获取网站栏目seo
- * @param array $data
- * @return array
- */
- public function getWebsiteCategoryHead(array $data): array
- {
- if (isset($data['website_id']) && !empty($data['website_id'])) {
- $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
- if (empty($website)) {
- return Result::error("找不到网站", 0);
- }
- } else {
- return Result::error("参数错误", 0);
- }
- if (isset($data['catid']) && !empty($data['catid'])) {
- $result = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->first();
- }
- if (empty($result)) {
- return Result::error("暂无导航", 0);
- }
- $result['aLIas_pinyin'] = $result['path'] ?? '';
- $result['website_name'] = $website['website_name'] ?? '';
- $result['suffix'] = $website['suffix'] ?? '';
- return Result::success($result);
- }
- /*
- * 获取某个栏目
- * @param array $data
- * @return array
- * */
- public function getOneWebsiteCategory(array $data): array
- {
- if (isset($data['website_id']) && !empty($data['website_id'])) {
- $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
- if (empty($website)) {
- return Result::error("暂无该网站", 0);
- }
- $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['category_id'])->first();
- if (empty($category)) {
- return Result::error("暂无此导航", 0);
- }
- $category['children_count'] = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['category_id'])->count();
- $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();
- // return Result::success($parent);
- // $category['aLIas_pinyin'] = $category['path'] ?? '';
- $category['parent_id'] = $parent['parent_id'] ?? '';
- $category['parent_pinyin'] = $parent['aLIas_pinyin'] ?? '';
- $category['parent_name'] = $parent['parent_name'] ?? '';
- return Result::success($category);
- } else {
- return Result::error("参数错误", 0);
- }
- }
- /**
- * 路由匹配
- * @param array $data
- */
- public function getWebsiteRoute(array $data): array
- {
- $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
- if (empty($website)) {
- return Result::error("暂无该网站", 0);
- }
- if (isset($data['pinyin']) &&!empty($data['pinyin'])) {
- $result = WebsiteCategory::where('website_id',$data['website_id'])
- ->where('path',$data['pinyin'])
- // $result = WebsiteCategory::where('category_id', $category_id)
- // ->where('website_category.path', $data['pinyin'])
- // ->leftJoin('website_category as pc', function ($join) use ($data) {
- // $join->on('pc.pid', '=', 'website_category.category_id')
- // ->where('pc.website_id', '=', $data['website_id']);
- // })
- ->select('website_category.category_id', 'website_category.type', 'website_category.alias',)
- ->first();
- }
- if (isset($data['foot_pinyin']) && !empty($data['foot_pinyin'])) {
- $result = FooterCategory::where('website_id', $data['website_id'])->where('name_pinyin', $data['foot_pinyin'])->first(['id']);
- }
- if (!isset($result) || empty($result)) {
- return Result::error("暂无该导航", 0);
- }
- return Result::success($result);
- }
- /**
- * c端 - 验证路由
- * @param array $data
- * @return array
- */
- public function checkWebsiteRoute(array $data): array
- {
- // 测试001111111222
- $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
- if (empty($web)) {
- return Result::error("该网站不存在", 0);
- } elseif ($web['status'] != 1) {
- return Result::error("网站已经关闭", 0);
- }
- if (isset($data['other_route']) && !empty($data['other_route'])) {
- $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
- // 验证路由是否存在
- if (empty($whiteRouterInfo)) {
- $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
- }
- if (!empty($whiteRouterInfo)) {
- return Result::success($whiteRouterInfo->toArray());
- }
- }
- // 验证栏目路由
- $last_category = WebsiteCategory::where('website_id', $data['website_id'])
- ->where('path', $data['all_route'])
- ->get()->all();
- if (count($last_category) == 0) {
- return Result::error("该栏目不存在", 0);
- }
- if (count($last_category) > 1) {
- return Result::error("该栏目路由存在多个,路由验证失败!", 0);
- }
- if (count($last_category) == 1) {
- $last_category = $last_category[0];
- }
- // return Result::success($last_category);
- if (isset($data['id']) && !empty($data['id'])) {
- // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
- switch ($last_category['type']) {
- case 1:
- // 文章
- // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
- $article = Article::where('status', 1)
- ->where('id', $data['id'])
- ->where(function ($query) use ($data) {
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
- ->orWhereNull("ignore_ids");
- })
- ->first(['catid']);
- if (empty($article)) {
- return Result::error("该文章不存在", 0);
- }
- // return Result::success($article);
- break;
- case 2:
- // 商品
- // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
- $article = Good::where('website_id', $data['website_id'])
- ->where('status', 2)
- ->where('id', $data['id'])
- ->first(['cat_arr_id']);
- if (empty($article)) {
- return Result::error("该商品不存在", 0);
- }
- break;
- case 3:
- // 书刊信息
- // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
- $article = Book::where('website_id', $data['website_id'])
- ->where('status', 2)
- ->where('id', $data['id'])
- ->first(['id', 'cat_arr_id']);
- if (empty($article)) {
- return Result::error("该书刊不存在", 0);
- }
- break;
- case 4:
- // 招聘
- // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
- $article = JobRecruiting::where('website_id', $data['website_id'])
- ->where('status', 1)
- ->where('id', $data['id'])
- ->first(['cat_arr_id']);
- if (empty($article)) {
- return Result::error("该招聘不存在", 0);
- }
- break;
- case 5:
- // 求职
- // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
- $article = JobHunting::where('website_id', $data['website_id'])
- ->where('status', 2)
- ->where('id', $data['id'])
- ->first(['cat_arr_id']);
- if (empty($article)) {
- return Result::error("该求职不存在", 0);
- }
- break;
- case 6:
- // 企业
- // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
- $article = Company::
- // where('website_id', $data['website_id'])
- // ->
- where('status', 1)
- ->where('id', $data['id'])
- ->first(['cat_arr_id']);
- if (empty($article)) {
- return Result::error("该企业不存在", 0);
- }
- break;
- case 7:
- // 项目
- // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
- $article = Project::where('website_id', $data['website_id'])
- ->where('status', 1)
- ->where('id', $data['id'])
- ->first(['cat_arr_id']);
- if (empty($article)) {
- return Result::error("该项目不存在", 0);
- }
- break;
- default:
- return Result::error("该数据不存在", 0);
- break;
- }
- // return Result::success($article);
- // $catid =0 ;
- if (!isset($article['cat_arr_id'])) {
- $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
- } else {
- $catidArray = json_decode($article['cat_arr_id'], true);
- $catid = !empty($catidArray) ? end($catidArray) : null;
- }
- // return Result::success($catid);
- // // return Result::success($article['cat_arr_id']);
- if (empty($catid)) {
- return Result::error("该栏目路径不存在", 0);
- }
- $path = WebsiteCategory::where('website_id', $data['website_id'])
- ->where('category_id', $catid)
- ->first('path');
- }
- // else{
- // // if ($last_category['pid'] != 0) {
- // $cat_arr = json_decode($last_category['category_arr_id'], true);
- // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
- // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
- // ->where('category_id',$catid)
- // ->where('path',$data['all_route'])
- // ->first('path');
- // // } else {
- // // $pinyin[0] = $last_category['aLIas_pinyin'];
- // // }
- // }
- // return Result::success($path);
- if (!empty($path) && $path['path'] != $data['all_route']) {
- return Result::error('非法路径!');
- } else {
- return Result::success($last_category['path']);
- }
- }
- /**
- * 前端-搜索新闻列表
- * @param array $data
- * @return array
- */
- public function selectWebsiteArticle(array $data): array
- {
- $website = Website::where('id', $data['website_id'])->first();
- if (empty($website)) {
- return Result::error("网站不存在", 0);
- }
- // $website_column = $website['column'];
- if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
- $website_column = json_decode($website['website_column_arr_id'], true);
- }
- $website_id = $data['website_id'];
- $categorys = $this->processArticlePro($website_id);
- $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
- // return Result::success($diff_pid_categoryIds);
- if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
- return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
- }
- // return Result::success(reset($diff_pid_categoryIds) == 0);
- // $cat_1st_arr = $categorys['cat_1st_arr'];
- $catiall = $categorys['catiall'];
- $categoryIds = $categorys['categoryIds'];
- // return Result::success($categoryIds);
- $query = Article::where('status', 1)
- ->whereIn('catid', $categoryIds)
- ->leftJoinSub(function ($query) use ($website_id) {
- $query->from('article_ignore')
- ->where('website_id', $website_id);
- }, 'article_ignore', function ($join) {
- $join->on('article_ignore.article_id', '=', 'article.id');
- })
- ->where(function ($query) {
- $query->whereNull('article_ignore.article_id')
- ->orWhere(function ($subQuery) {
- $subQuery->whereNotNull('article_ignore.article_id')
- ->where('article_ignore.is_ignore', 0)
- ->where(function ($subSubQuery) {
- $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
- ->orWhereNull('article_ignore.c_show_time');
- });
- });
- });
- // ->get()->all();
- // return Result::success($query);
- if (isset($data['cityid']) && !empty($data['cityid'])) {
- $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
- }
- if (isset($data['department_id']) && !empty($data['department_id'])) {
- $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
- }
- if (isset($data['keyword']) && !empty($data['keyword'])) {
- $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
- }
- // 计算总数
- $count = $query->count();
- // return Result::success($count);
- // 分页查询
- $articles = $query
- ->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',
- 'article.department_arr_id',
- 'article.city_arr_id',
- // 'article_ignore.c_show_time',
- // 'article_ignore.is_ignore'
- )
- ->orderBy("updated_at", "desc")
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get();
- // return Result::success($articles);
- foreach ($articles as $k => $v) {
- $articles[$k]->category_name = $catiall[$v->catid]['alias'];
- $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
- }
- if (empty($articles)) {
- return Result::error("没有符合条件的资讯数据");
- }
- $result = [
- 'rows' => $articles,
- 'count' => $count,
- ];
- return Result::success($result);
- }
- /**
- * 获取头条新闻
- * @param array $data
- * @return array
- */
- public function getWebsiteArticlett(array $data): array
- {
- $website_id = $data['website_id'];
- $website = Website::where('id', $data['website_id'])->first();
- if (empty($website)) {
- return Result::error("网站不存在", 0);
- }
- $categorys = $this->processArticlePro($website_id);
- $catiall = $categorys['catiall'];
- $categoryIds = $categorys['categoryIds'];
- $where = [
- 'status' => 1
- ];
- // $website_column = $website['column'];
- if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
- $website_column = json_decode($website['website_column_arr_id'], true);
- }
- $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
- // return Result::success($diff_pid_categoryIds);
- if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
- return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
- }
- // $website_id = $data['website_id'];
- $month = date("Y-m-d H:i:s", strtotime("-30 day"));
- //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
- // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
- switch ($data['level']) {
- case 1:
- case 2:
- case 3:
- case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
- $query = Article::where($where)
- ->where('level', 'like', '%' . $data['level'] . '%')
- ->orderBy('updated_at', 'desc');
- break;
- case 4: //最新资讯
- $query = Article::where($where)->orderBy('updated_at', 'desc');
- break;
- case 5: //资讯推荐
- $query = Article::where($where)
- ->where('updated_at', '>', $month);
- break;
- case 7: //资讯分类
- if (isset($data['id']) && !empty($data['id'])) {
- $keyword = Article::where('id', $data['id'])->value('keyword');
- $keywordArray = explode(',', $keyword);
- $whereL7 = [];
- foreach ($keywordArray as $k => $v) {
- $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
- }
- $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
- break;
- } else {
- return Result::error("请输入资讯ID", 0);
- break;
- }
- default:
- break;
- }
- // $whereL7 = [];
- // if(isset($data['id']) && !empty($data['id'])){
- // $keyword = Article::where('id', $data['id'])->value('keyword');
- // $keywordArray = explode(',', $keyword);
- // foreach ($keywordArray as $k => $v) {
- // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
- // }
- // }
- // $query = Article::where($where)
- // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
- // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
- // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
- // }
- // if($data['level'] == 7){
- // $query = $query->where($whereL7)->orderBy('updated_at','desc');
- // }
- // if($data['level'] == 4){
- // $query = $query->inRandomOrder()
- // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
- // }
- // if($data['level'] == 5){
- // $query = $query->orderBy('updated_at','desc');
- // }
- // });
- if ($data['textnum'] > 0) {
- $query = clone $query;
- $result['text'] = $query
- ->whereIn('catid', $categoryIds)
- ->leftJoinSub(function ($query) use ($website_id) {
- $query->from('article_ignore')
- ->where('website_id', $website_id);
- }, 'article_ignore', function ($join) {
- $join->on('article_ignore.article_id', '=', 'article.id');
- })
- ->where(function ($query) {
- $query->whereNull('article_ignore.article_id')
- ->orWhere(function ($subQuery) {
- $subQuery->whereNotNull('article_ignore.article_id')
- ->where('article_ignore.is_ignore', 0)
- ->where(function ($subSubQuery) {
- $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
- ->orWhereNull('article_ignore.c_show_time');
- });
- });
- })
- // ->where(function ($query) use ($website_id) {
- // $query->whereNull('article_ignore.article_id')
- // ->orWhere('article_ignore.website_id', '!=', $website_id);
- // })
- ->select(
- 'article.id',
- 'article.title',
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- 'article.cat_arr_id',
- 'article.catid',
- 'article.level',
- // 'article_ignore.is_ignore',
- // 'article_ignore.c_show_time',
- )
- ->offset($data['placeid'])
- ->limit($data['textnum'])
- ->get()->all();
- foreach ($result['text'] as $k => $v) {
- $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
- $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
- }
- }
- if ($data['imgnum'] > 0) {
- $query = clone $query;
- if ($data['textnum'] == 0) {
- $query = $query->leftJoinSub(function ($query) use ($website_id) {
- $query->from('article_ignore')
- ->where('website_id', $website_id);
- }, 'article_ignore', function ($join) {
- $join->on('article_ignore.article_id', '=', 'article.id');
- })
- ->where(function ($query) {
- $query->whereNull('article_ignore.article_id')
- ->orWhere(function ($subQuery) {
- $subQuery->whereNotNull('article_ignore.article_id')
- ->where('article_ignore.is_ignore', 0)
- ->where(function ($subSubQuery) {
- $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
- ->orWhereNull('article_ignore.c_show_time');
- });
- });
- });
- }
- $result['img'] = $query
- ->whereIn('catid', $categoryIds)
- ->where('article.imgurl', '!=', '')
- ->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',
- 'article.level',
- // 'article_ignore.is_ignore',
- // 'article_ignore.c_show_time',
- )
- ->offset($data['placeid'])
- ->limit($data['imgnum'])
- ->get()->all();
- foreach ($result['img'] as $k => $v) {
- $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
- $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
- }
- }
- if (empty($result)) {
- return Result::error("暂无相关资讯", 0);
- }
- return Result::success($result);
- }
- /**
- * 模块新闻加强plus版
- * @param array $data
- * @return array
- */
- public function getWebsiteAllArticle(array $data): array
- {
- // return Result::success($data);
- $time1 = microtime(true);
- $wetbsite_id = $data['website_id'] ?? 2;
- $data = json_decode($data['id'], true);
- $website = Website::where('id', $wetbsite_id)->first();
- if (empty($website)) {
- return Result::error("网站不存在", 0);
- }
- // return Result::success($website);
- $website_column = $website['website_column_arr_id'] ?? '[]';
- $website_column = json_decode($website_column, true);
- $categorys = $this->processArticlePro($wetbsite_id);
- $cat_1st_arr = $categorys['cat_1st_arr'];
- $catiall = $categorys['catiall'];
- // return Result::success($catiall);
- $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
- if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
- return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
- }
- $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
- // return Result::success($categorys);
- $parent_category = array_column($data, 'parent');
- $parent_cat = [];
- $child_category = array_column($data, 'child');
- if (!empty($parent_category)) {
- foreach ($parent_category as $key => $value) {
- $arr = array_map('intval', explode(',', $value));
- $parent_cat[$key] = $arr[0] ?? 0;
- $parent_category = $arr[0] ?? 0;
- $article_imgnum = $arr[1] ?? 0;
- $article_textnum = $arr[2] ?? 0;
- if ($parent_category != 0) {
- $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
- // return Result::success($category_arr);
- if ($article_imgnum != 0) {
- $img_article = Article::whereIn('catid', $category_arr)
- ->where('status', 1)
- ->where('imgurl', '!=', '')
- ->leftJoinSub(function ($query) use ($wetbsite_id) {
- $query->from('article_ignore')
- ->where('website_id', $wetbsite_id);
- }, 'article_ignore', function ($join) {
- $join->on('article_ignore.article_id', '=', 'article.id');
- })
- ->where(function ($query) {
- $query->whereNull('article_ignore.article_id')
- ->orWhere(function ($subQuery) {
- $subQuery->whereNotNull('article_ignore.article_id')
- ->where('article_ignore.is_ignore', 0)
- ->where(function ($subSubQuery) {
- $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
- ->orWhereNull('article_ignore.c_show_time');
- });
- });
- })
- ->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')
- ->orderBy('updated_at', 'desc')
- ->limit($article_imgnum)
- ->get()->all();
- foreach ($img_article as $k => $v) {
- $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
- $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
- }
- } else {
- $img_article = [];
- }
- if ($article_textnum != 0) {
- $text_article = Article::whereIn('catid', $category_arr)
- ->where('status', 1)
- ->leftJoinSub(function ($query) use ($wetbsite_id) {
- $query->from('article_ignore')
- ->where('website_id', $wetbsite_id);
- }, 'article_ignore', function ($join) {
- $join->on('article_ignore.article_id', '=', 'article.id');
- })
- ->where(function ($query) {
- $query->whereNull('article_ignore.article_id')
- ->orWhere(function ($subQuery) {
- $subQuery->whereNotNull('article_ignore.article_id')
- ->where('article_ignore.is_ignore', 0)
- ->where(function ($subSubQuery) {
- $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
- ->orWhereNull('article_ignore.c_show_time');
- });
- });
- })
- ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
- ->orderBy('updated_at', 'desc')
- ->limit($article_textnum)
- ->get()->all();
- foreach ($text_article as $k => $v) {
- $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
- $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
- // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
- }
- } else {
- $text_article = [];
- }
- $catiall[$parent_category]['imgnum'] = $img_article;
- $catiall[$parent_category]['textnum'] = $text_article;
- $parent[$key] = $catiall[$parent_category];
- } else {
- $parent[$key] = '';
- }
- }
- }
- if (!empty($child_category)) {
- foreach ($child_category as $key => $value) {
- $arr = array_map('intval', explode(',', $value));
- $parent_category = $parent_cat[$key];
- $child_category = $arr[0] ?? 0;
- $article_imgnum = $arr[1] ?? 0;
- $article_textnum = $arr[2] ?? 0;
- if ($child_category != 0) {
- $all_childcat = $cat_1st_arr[$parent_category];
- $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
- // 从 $websiteInfoIndexed 中获取对应的数据
- $info = $websiteInfoIndexed[$v];
- // 返回一个包含所需信息的数组
- return [
- 'alias' => $info->alias,
- 'category_id' => $info->category_id,
- 'aLIas_pinyin' => $info->aLIas_pinyin,
- 'pid' => $info->pid,
- 'type' => $info->type,
- 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
- 'pinyin' => $info->pinyin,
- ];
- }, $all_childcat);
- if ($article_imgnum != 0) {
- $img_article = Article::where('catid', $child_category)
- ->where('status', 1)
- ->where('imgurl', '!=', '')
- ->leftJoinSub(function ($query) use ($wetbsite_id) {
- $query->from('article_ignore')
- ->where('website_id', $wetbsite_id);
- }, 'article_ignore', function ($join) {
- $join->on('article_ignore.article_id', '=', 'article.id');
- })
- ->where(function ($query) {
- $query->whereNull('article_ignore.article_id')
- ->orWhere(function ($subQuery) {
- $subQuery->whereNotNull('article_ignore.article_id')
- ->where('article_ignore.is_ignore', 0)
- ->where(function ($subSubQuery) {
- $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
- ->orWhereNull('article_ignore.c_show_time');
- });
- });
- })
- ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
- ->orderBy('updated_at', 'desc')
- ->limit($article_imgnum)
- ->get()->all();
- foreach ($img_article as $k => $v) {
- // var_dump($v);
- // var_dump($k);
- $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
- $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
- }
- } else {
- $img_article = [];
- }
- if ($article_textnum != 0) {
- $text_article = Article::where('catid', $child_category)
- ->where('status', 1)
- ->leftJoinSub(function ($query) use ($wetbsite_id) {
- $query->from('article_ignore')
- ->where('website_id', $wetbsite_id);
- }, 'article_ignore', function ($join) {
- $join->on('article_ignore.article_id', '=', 'article.id');
- })
- ->where(function ($query) {
- $query->whereNull('article_ignore.article_id')
- ->orWhere(function ($subQuery) {
- $subQuery->whereNotNull('article_ignore.article_id')
- ->where('article_ignore.is_ignore', 0)
- ->where(function ($subSubQuery) {
- $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
- ->orWhereNull('article_ignore.c_show_time');
- });
- });
- })
- ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
- ->orderBy('updated_at', 'desc')
- ->limit($article_textnum)
- ->get()->all();
- foreach ($text_article as $k => $v) {
- // var_dump($v);
- // var_dump($k);
- $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
- // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
- $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
- }
- } else {
- $text_article = [];
- }
- $catiall[$child_category]['all_childcat'] = $processedChildCat;
- $catiall[$child_category]['imgnum'] = $img_article;
- $catiall[$child_category]['textnum'] = $text_article;
- $child[$key] = $catiall[$child_category];
- // var_dump($pids);
- } else {
- $child[$key] = '';
- }
- }
- }
- foreach ($parent as $key => $value) {
- $result[$key] = $value;
- if (!empty($child[$key])) {
- // var_dump($child[$key]);
- $result[$key]['child'] = $child[$key];
- // $value[$key]['child'] = $child[$key];
- } else {
- $result[$key]['child'] = [
- "alias" => null,
- "category_id" => null,
- "type" => null,
- "pinyin" => null,
- "all_childcat" => [],
- "imgnum" => [],
- "textnum" => []
- ];
- }
- }
- return Result::success($result);
- }
- /**
- * 乡村网-获取特殊新闻模块
- * @param array $data
- * @return array
- */
- public function getWebsiteArticles(array $data): array
- {
- $website_id = $data['website_id'];
- $website = Website::where('id', $website_id)->first();
- if (empty($website)) {
- return Result::error("网站不存在", 0);
- }
- // return Result::success($website);
- $website_column = $website['website_column_arr_id'] ?? '[]';
- $website_column = json_decode($website_column, true);
- $catids = json_decode($data['id'], true);
- $parent_category = array_column($catids, 'parent');
- if (!empty($parent_category) && is_array($parent_category)) {
- $categorys = $this->processArticlePro($website_id);
- $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
- if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
- return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
- }
- $catiall = $categorys['catiall'];
- $cat_1st_arr = $categorys['cat_1st_arr'];
- // return Result::success($categorys);
- foreach ($parent_category as $key => $value) {
- $arr = array_map('intval', explode(',', $value));
- $parent_category = $arr[0] ?? 0;
- $article_imgnum = $arr[1] ?? 0;
- $article_textnum = $arr[2] ?? 0;
- if ($parent_category != 0) {
- $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
- // return Result::success($category_arr);
- if ($article_imgnum != 0) {
- $img_article = Article::whereIn('article.catid', $category_arr)
- ->where('article.status', 1)
- ->where('article.imgurl', '!=', '')
- ->leftJoinSub(function ($query) use ($website_id) {
- $query->from('article_ignore')
- ->where('website_id', $website_id);
- }, 'article_ignore', function ($join) {
- $join->on('article_ignore.article_id', '=', 'article.id');
- })
- ->where(function ($query) {
- $query->whereNull('article_ignore.article_id')
- ->orWhere(function ($subQuery) {
- $subQuery->whereNotNull('article_ignore.article_id')
- ->where('article_ignore.is_ignore', 0)
- ->where(function ($subSubQuery) {
- $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
- ->orWhereNull('article_ignore.c_show_time');
- });
- });
- })
- ->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 as category_id'
- )
- ->orderBy('updated_at', 'desc')
- ->limit($article_imgnum)
- ->get()->all();
- foreach ($img_article as $k => $v) {
- $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
- // return Result::success($v);
- $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
- }
- } else {
- $img_article = [];
- }
- if ($article_textnum != 0) {
- $text_article = Article::whereIn('article.catid', $category_arr)
- ->where('article.status', 1)
- ->leftJoinSub(function ($query) use ($website_id) {
- $query->from('article_ignore')
- ->where('website_id', $website_id);
- }, 'article_ignore', function ($join) {
- $join->on('article_ignore.article_id', '=', 'article.id');
- })
- ->where(function ($query) {
- $query->whereNull('article_ignore.article_id')
- ->orWhere(function ($subQuery) {
- $subQuery->whereNotNull('article_ignore.article_id')
- ->where('article_ignore.is_ignore', 0)
- ->where(function ($subSubQuery) {
- $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
- ->orWhereNull('article_ignore.c_show_time');
- });
- });
- })
- ->select(
- 'article.id',
- 'article.title',
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- 'article.cat_arr_id',
- 'article.catid as category_id'
- )
- ->orderBy('updated_at', 'desc')
- ->limit($article_textnum)
- ->get()->all();
- foreach ($text_article as $k => $v) {
- $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
- $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
- // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
- }
- } else {
- $text_article = [];
- }
- $catiall[$parent_category]['imgnum'] = $img_article ?? [];
- $catiall[$parent_category]['textnum'] = $text_article ?? [];
- $parent[$key] = $catiall[$parent_category];
- } else {
- $parent[$key] = [];
- }
- }
- }
- return Result::success($parent);
- }
- /**
- *获取新闻列表
- * @param array $data
- * @return array
- */
- public function getWebsiteArticleList(array $data): array
- {
- // return Result::success($data);
- $where[] = ['status', '=', 1];
- $website_id = $data['website_id'];
- $website = Website::where('id', $data['website_id'])->first();
- if (empty($website)) {
- return Result::error("网站不存在", 0);
- }
- // $website_column = $website['column'];
- if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
- $website_column = json_decode($website['website_column_arr_id'], true);
- }
- $categorys = $this->processArticlePro($website_id);
- $cat_1st_arr = $categorys['cat_1st_arr'];
- $catiall = $categorys['catiall'];
- $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
- // return Result::success($diff_pid_categoryIds);
- if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
- return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
- }
- if (isset($data['catid']) && !empty($data['catid'])) {
- $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
- if (empty($category)) {
- return Result::error("此网站暂无此栏目", 0);
- }
- array_push($where, ['catid', '=', $data['catid']]);
- }
- // return Result::success($where);
- $query = Article::where($where)
- ->leftJoinSub(function ($query) use ($website_id) {
- $query->from('article_ignore')
- ->where('website_id', $website_id);
- }, 'article_ignore', function ($join) {
- $join->on('article_ignore.article_id', '=', 'article.id');
- })
- ->where(function ($query) {
- $query->whereNull('article_ignore.article_id')
- ->orWhere(function ($subQuery) {
- $subQuery->whereNotNull('article_ignore.article_id')
- ->where('article_ignore.is_ignore', 0)
- ->where(function ($subSubQuery) {
- $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
- ->orWhereNull('article_ignore.c_show_time');
- });
- });
- })
- ->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'
- );
- $count = $query->count();
- $rep = $query->orderBy("updated_at", "desc")
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get()->all();
- $categorys = $this->processArticlePro($website_id);
- $cat_1st_arr = $categorys['cat_1st_arr'];
- $catiall = $categorys['catiall'];
- // $web['website_id'] = $data['website_id'];
- foreach ($rep as $k => $v) {
- $rep[$k]->category_name = $catiall[$v->catid]['alias'];
- $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
- }
- // $rep = $this->processArticles($rep,$web);
- $data = [
- 'rows' => $rep,
- 'count' => $count,
- ];
- if (empty($rep)) {
- return Result::error("没有信息数据");
- }
- return Result::success($data);
- }
- /**
- * 前端-获取新闻详情
- * @param array $data
- * @return array
- */
- public function selectWebsiteArticleInfo(array $data): array
- {
- $where = [
- 'article.id' => $data['id'],
- 'article.status' => 1,
- ];
- $result = Article::where($where)
- ->leftJoin("article_data", "article.id", "article_data.article_id")
- ->leftJoin("article_extend", "article_extend.article_id", "article.id")
- // ->where(function ($query) use ($data) {
- // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
- // ->orWhereNull("ignore_ids");
- // })
- ->leftJoinSub(function ($query) use ($data) {
- $query->from('article_ignore')
- ->where('website_id', $data['website_id']);
- }, 'article_ignore', function ($join) {
- $join->on('article_ignore.article_id', '=', 'article.id');
- })
- ->where(function ($query) {
- $query->whereNull('article_ignore.article_id')
- ->orWhere(function ($subQuery) {
- $subQuery->whereNotNull('article_ignore.article_id')
- ->where('article_ignore.is_ignore', 0)
- ->where(function ($subSubQuery) {
- $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
- ->orWhereNull('article_ignore.c_show_time');
- });
- });
- })
- ->select(
- 'article.*',
- 'article_data.content',
- 'article_data.article_id',
- 'article_extend.website_url',
- 'article_extend.email',
- 'article_extend.contacts',
- 'article_extend.contacts_mobile',
- 'article_extend.contacts_address',
- 'article_extend.zip_code',
- 'article_extend.enterprise_name'
- )
- ->first();
- if (empty($result)) {
- return Result::error("暂无此新闻!", 0);
- }
- if (!empty($result['publiced_at'])) {
- $result['updated_at'] = $result['publiced_at'];
- }
- $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
- ->select('website_category.*', 'website.website_name', 'website.suffix')
- ->where('website_category.website_id', $data['website_id'])
- ->where(['website_category.category_id' => $result['catid']])
- ->first();
- if (empty($category)) {
- return Result::error("查询失败", 0);
- }
- //手动推荐文章
- $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
- if (empty($commend_ids)) {
- $commendArticle = [];
- } else {
- //去除不存在的文章ID
- $commendArticle = Article::whereIn('article.id', $commend_ids)
- ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
- ->leftJoinSub(function ($query) use ($data) {
- $query->from('article_ignore')
- ->where('website_id', $data['website_id']);
- }, 'article_ignore', function ($join) {
- $join->on('article_ignore.article_id', '=', 'article.id');
- })
- ->where(function ($query) {
- $query->whereNull('article_ignore.article_id')
- ->orWhere(function ($subQuery) {
- $subQuery->whereNotNull('article_ignore.article_id')
- ->where('article_ignore.is_ignore', 0)
- ->where(function ($subSubQuery) {
- $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
- ->orWhereNull('article_ignore.c_show_time');
- });
- });
- })
- ->where('article.status', 1)
- ->where('website_category.website_id', $data['website_id'])
- ->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')
- ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
- // ->orderBy('article.updated_at', 'desc')
- ->limit(5)
- ->get();
- //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
- foreach ($commendArticle as $k => $v) {
- $cat_arr_id = json_decode($v->cat_arr_id, true);
- if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
- $cat_arr_id = array_unique($cat_arr_id);
- // 从website_category取出alias_pinyin
- $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
- ->whereIn('category_id', $cat_arr_id)
- ->pluck('alias_pinyin', 'category_id')
- ->toArray();
- // 将cat_arr_id的json转成路径/隔开
- $path_parts = [];
- foreach ($cat_arr_id as $cat_id) {
- if (isset($cat_arr[$cat_id])) {
- $path_parts[] = $cat_arr[$cat_id];
- }
- }
- $v->alias_pinyin = implode('/', $path_parts);
- } else {
- $v->alias_pinyin = '';
- }
- }
- }
- $result['category_id'] = $category['category_id'];
- $result['cat_name'] = $category['alias'];
- $result['website_name'] = $category['website_name'] ?? "";
- $result['suffix'] = $category['suffix'] ?? "";
- $result['commendArticle'] = $commendArticle;
- $result['commend_ids'] = $commend_ids;
- return Result::success($result);
- }
- /**
- * plus pro 处理文章路由问题
- */
- function processArticlePro($website_id)
- {
- // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
- // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
- // // 取出category_id 对应的aLIas_pinyin
- // $categoryIds = array_column($categorys, 'category_id');
- // $categoryPIds = array_column($categorys, 'pid');
- // $aliasPinyins = array_column($categorys, 'path');
- // $alias = array_column($categorys, 'alias');
- // $cat_arr = array_combine($categoryIds, $aliasPinyins);
- // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
- // // return Result::success($cat_arr);
- // // $catiall = [];
- // //一级所有子级的记录
- // $cat_alias_arr = array_combine($categoryIds, $alias);
- // return [
- // 'cat_1st_arr' => $cat_alias_arr,
- // 'catiall' => $cat_arr,
- // // 'websiteInfoIndexed' => $websiteInfoIndexed,
- // 'categoryIds' => $categoryIds,
- // ];
- $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
- $websiteInfoIndexed = array_column($categorys, null, 'category_id');
- // 取出category_id 对应的aLIas_pinyin
- $categoryIds = array_column($categorys, 'category_id');
- $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
- return $pid != 0;
- })));
- $category_path = array_column($categorys, 'path');
- $cat_arr = array_combine($categoryIds, $category_path);
- // return Result::success(array_diff($categoryIds, $categoryPIds));
- $catiall = [];
- //一级所有子级的记录
- $cat_1st_arr = [];
- foreach ($categorys as $key => $value) {
- // $category_arr_id = json_decode($value->category_arr_id);
- // $pinyin_str = '';
- // // 算出一级 并且算出子级
- if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
- $cat_1st_arr[$value->pid][] = $value->category_id;
- }
- // foreach ($category_arr_id as $k => $v) {
- // $pinyin_str .= $cat_arr[$v] . '/';
- // }
- // $pinyin_str = rtrim($pinyin_str, '/');
- $catiall[$value->category_id]['alias'] = $value->alias;
- $catiall[$value->category_id]['category_id'] = $value->category_id;
- $catiall[$value->category_id]['type'] = $value->type;
- $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
- $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
- }
- return [
- 'cat_1st_arr' => $cat_1st_arr,
- 'catiall' => $catiall,
- 'websiteInfoIndexed' => $websiteInfoIndexed,
- 'categoryIds' => $categoryIds,
- 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
- 'categoryPIds' => $categoryPIds,
- ];
- }
- /**
- * 获取网站顶部信息
- * @param array $data
- */
- public function getWebsiteHead(array $data): array
- {
- $result = Website::where('id', $data['website_id'])->where('status', 1)->select('website_name', 'logo')->first();
- if (empty($result)) {
- return Result::error("暂无该网站", 0);
- }
- return Result::success($result);
- }
- /**
- *各省市查询
- * @param array $data
- * @return array
- */
- public function selectWebArea(array $data): array
- {
- // return Result::success($data);
- $pid = $data['pid'] ?? 0;
- $result = District::leftJoin('district as district2', 'district.pid', '=', 'district2.id')
- ->where('district.pid', $pid)
- ->where('district.status', 1)
- ->select('district.*', 'district2.name as pid_name')
- ->orderBy('district.code')->get();
- if (empty($result)) {
- return Result::error("未查询到此地区", 0);
- } else {
- return Result::success($result);
- }
- }
- /**test1
- * @param array $data
- * @return array
- */
- public function getWebsiteDistrit(array $data): array
- {
- $where = [];
- if (isset($data['keyWord'])) {
- $where = [
- ['name', 'like', '%' . $data['keyWord'] . '%']
- ];
- }
- $result = [];
- if (isset($data['pageSize'])) {
- $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("code", "asc")->get();
- $count = District::where($where)->count();
- $result = [
- 'rows' => $rep,
- 'count' => $count
- ];
- } else {
- $result = District::where($data)->orderBy("code", "asc")->get();
- }
- return $result ? Result::success($result) : Result::error("没有查到数据");
- }
- /**
- *
- * @param array $data
- * @return array
- */
- /**网站行政职能搜索 */
- public function selectWebsiteDepartment(array $data): array
- {
- $depart = Department::where('pid', 0)->orderBy('id', 'asc')->get();
- if (isset($data['keyword']) && !empty($data['keyword'])) {
- $departments = Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
- if (empty($departments)) {
- $result['message'] = "未查询到与此相关职能部门";
- } else {
- $count = Department::where('name', 'like', "%{$data['keyword']}%")->count();
- $m = [
- 'department' => $depart,
- 'type' => $departments,
- 'count' => $count,
- ];
- }
- $result['sele'] = $m;
- return Result::success($result['sele']);
- }
- $result = $depart;
- return Result::success($result);
- }
- /**
- * 获取友情链接
- * @param array $data
- * @return array
- */
- public function selectWebsiteLinks(array $data): array
- {
- $where = [
- 'website_id' => $data['website_id'],
- 'status' => 1,
- 'type' => $data['type'],
- ];
- $num = $data['num'];
- $result = Link::where($where)->orderBy('sort')->limit($num)->get();
- if (!empty($result)) {
- return Result::success($result);
- } else {
- return Result::error("本网站暂无此类型友情链接", 0);
- }
- }
- /**
- * 获取网站底部导航
- * @param array $data
- * @return array
- */
- public function getWebsiteFooterCategory(array $data): array
- {
- if (isset($data['website_id']) && !empty($data['website_id'])) {
- $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
- if (empty($website)) {
- return Result::error("找不到网站", 0);
- }
- } else {
- return Result::error("参数错误", 0);
- }
- $result = FooterCategory::where('website_id', $data['website_id'])->get();
- if (empty($result)) {
- return Result::error("暂无底部导航", 0);
- }
- return Result::success($result->toArray());
- }
- /**
- * 获取网站底部导航列表
- * @param array $data
- * @return array
- */
- public function getWebsiteFooterCategoryList(array $data): array
- {
- if (isset($data['website_id']) && !empty($data['website_id'])) {
- $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
- if (empty($website)) {
- return Result::error("找不到网站", 0);
- }
- } else {
- return Result::error("参数错误", 0);
- }
- $footercategory = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
- // '底部导航类型 0:内容型;1:列表型;',
- if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
- return Result::error("底部导航id错误", 0);
- } else {
- $query = FooterContent::where('fcat_id', $data['fcat_id']);
- if ($query->count() == 0) {
- return Result::error("暂无底部导航列表", 0);
- } elseif ($query->count() == 1) {
- $result = $query->first();
- } else {
- $result = $query->get();
- }
- }
- return Result::success($result);
- }
- /**
- * 获取网站底部导航
- * @param array $data
- * @return array
- */
- public function getWebsiteFooterCategoryInfo(array $data): array
- {
- if (isset($data['website_id']) && !empty($data['website_id'])) {
- $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
- if (empty($website)) {
- return Result::error("找不到网站", 0);
- }
- } else {
- return Result::error("参数错误", 0);
- }
- if (isset($data['type']) && $data['type'] == 0) {
- $fcatid = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
- if (empty($fcatid)) {
- return Result::error("底部导航id错误", 0);
- }
- $result = FooterContent::where('fcat_id', $data['fcat_id'])->first();
- } else {
- $result = FooterContent::where('id', $data['fcat_id'])->first();
- }
- if (empty($result)) {
- return Result::error("暂无底部导航内容", 0);
- }
- return Result::success($result);
- }
- /**
- * 获取网站底部基础信息
- * @param array $data
- * @return array
- */
- public function getWebsiteFootInfo(array $data): array
- {
- if (isset($data['website_id']) && !empty($data['website_id'])) {
- $website_head = Website::where('id', $data['website_id'])
- ->where('status', 1)
- ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')
- ->first();
- if (empty($website_head)) {
- return Result::error("找不到网站", 0);
- }
- } else {
- return Result::error("参数错误", 0);
- }
- $website_head = Website::where('id', $data['website_id'])
- ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')->first();
- $website_foot = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
- if (empty($website_foot)) {
- return Result::error("暂无底部基础信息", 0);
- }
- $website_head['website_url'] = $website_head['website_url'] ? json_decode($website_head['website_url']) : [];
- $result = [
- 'website_foot' => $website_foot,
- 'website_head' => $website_head,
- ];
- return Result::success($result);
- }
- /**
- * 获取网站栏目信息
- * @param array $data
- */
- public function getWebsiteFootAll(array $data): array
- {
- if(!isset($data['is_diyweb']) || empty($data['is_diyweb'])){
- $website = Website::where('id',$data['website_id'])->where('status',1)->first();
- }else{
- $website = Website::where('id',$data['website_id'])->first();
- }
- if (empty($website)) {
- return Result::error("暂无该网站", 0);
- }
- // 1:图片 2:文字 3:底部
- $result['foot_cate'] = FooterCategory::where('website_id', $data['website_id'])->get()->all();
- $result['link_img'] = Link::where('website_id', $data['website_id'])->where('type', 1)->where('status', 1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all();
- $result['link_text'] = Link::where('website_id', $data['website_id'])->where('type', 2)->where('status', 1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
- $result['link_foot'] = Link::where('website_id', $data['website_id'])->where('type', 3)->where('status', 1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
- $result['foot_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
- if (empty($result)) {
- return Result::error("暂无此网站信息", 0);
- }
- return Result::success($result);
- }
- /**
- * 获取网站栏目信息
- * @param array $data
- */
- public function getWebsiteAllinfo(array $data): array
- {
- $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
- if (empty($website)) {
- return Result::error("暂无该网站", 0);
- }
- if (isset($data['website_id']) && !empty($data['website_id'])) {
- $website_head = Website::where('id', $data['website_id'])
- ->where('status', 1)
- ->select(
- 'id',
- 'website_name',
- 'logo',
- 'title',
- 'keywords',
- 'description',
- 'suffix',
- 'website_url',
- 'ad_key',
- 'api_url',
- 'login_url',
- 'weblog_url'
- )
- ->first();
- if (empty($website_head)) {
- return Result::error("找不到网站", 0);
- }
- } else {
- return Result::error("参数错误", 0);
- }
- $website_foot['foot_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
- if (empty($website_foot)) {
- return Result::error("暂无底部基础信息", 0);
- }
- $website_head['website_url'] = $website_head['website_url'] ? json_decode($website_head['website_url']) : [];
- $result['website_head'] = $website_head;
- $result['website_foot'] = $website_foot;
- // return Result::success($result);
- // 1:图片 2:文字 3:底部
- $result['website_foot']['foot_cate'] = FooterCategory::where('website_id', $data['website_id'])->get()->all();
- $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();
- $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();
- $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();
- if (empty($result)) {
- return Result::error("暂无此网站信息", 0);
- }
- return Result::success($result);
- }
- /**
- * 查询网站的广告
- * @param array $data
- * @return array
- */
- public function getWebsiteAdvertisement(array $data): array
- {
- $where = [
- 'ad_place.status' => 1,
- ];
- if (isset($data['ad_tag']) && !empty($data['ad_tag'])) {
- $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
- $where[] = ['ad_place.ad_tag', 'like', '%' . $data['ad_tag'] . '%'];
- // return Result::success($where);
- $result = AdPlace::where($where)
- ->leftJoin("ad", function ($join) use ($now) {
- $join->on("ad.pid", "=", "ad_place.id")
- ->where('ad.status', 1)
- ->where('ad.fromtime', '<=', $now)
- ->where('ad.totime', '>=', $now);
- })
- ->select(
- 'ad_place.name as place_name',
- 'ad_place.thumb',
- 'ad_place.ad_tag',
- 'ad_place.introduce',
- 'ad.name as ad_name',
- 'ad.image_src',
- 'ad.image_url',
- 'ad.image_alt',
- 'ad_place.ad_url'
- )
- ->get()->all();
- } else {
- $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
- // return Result::success($where);
- $result = AdPlace::where($where)
- ->where('ad_place.website_id', $data['website_id'])
- ->leftJoin("ad", function ($join) use ($now) {
- $join->on("ad.pid", "=", "ad_place.id")
- ->where('ad.status', 1)
- ->where('ad.fromtime', '<=', $now)
- ->where('ad.totime', '>=', $now);
- })
- ->select(
- 'ad_place.name as place_name',
- 'ad_place.thumb',
- 'ad_place.ad_tag',
- 'ad_place.introduce',
- 'ad.name as ad_name',
- 'ad.image_src',
- 'ad.image_url',
- 'ad.image_alt',
- 'ad_place.ad_url',
- )
- ->get()->all();
- // return Result::error("请选择广告位!",0);
- }
- if (empty($result)) {
- return Result::error("此广告位不存在!", 0);
- }
- return Result::success($result);
- }
- /**
- * 前端-获取网站调查问卷
- * @param array $data
- * @return array
- */
- public function getWebsiteSurvey(array $data): array
- {
- if (isset($data['website_id']) && !empty($data['website_id'])) {
- $website = Website::where('id', $data['website_id'])->first();
- if (empty($website)) {
- return Result::error("暂无此网站", 0);
- }
- }
- if (isset($data['art_id']) && !empty($data['art_id'])) {
- $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
- if (empty($article)) {
- return Result::error("暂无此文章", 0);
- }
- // return Result::error($data,0);
- $where['art_id'] = $data['art_id'];
- // $query = ArticleSurvey::where('art_id',$data['art_id']);
- } else {
- $survey = Article::where(function ($query) {
- $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
- ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
- })
- ->where('status', 1)
- ->where('is_survey', 1)
- ->select('survey_id')
- ->orderBy('updated_at', 'desc')
- ->first();
- if (empty($survey)) {
- return Result::error("暂无调查问卷", 0);
- }
- $where['sur_id'] = $survey['survey_id'];
- // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
- }
- // return Result::success($where);
- $result = ArticleSurvey::where($where)
- ->where(function ($query) {
- $query->where('is_other', 0)
- ->orWhere(function ($subQuery) {
- $subQuery->where('is_other', 1)
- ->where('other_id', 0);
- });
- })
- ->leftJoin('article', 'article_survey.art_id', 'article.id')
- ->select('article_survey.*', 'article.survey_type')
- ->get()->all();
- if (empty($result)) {
- return Result::error("此文章暂无调查问卷", 0);
- }
- return Result::success($result);
- }
- /**
- * 前端-添加网站调查问卷选项
- * @param array $data
- * @return array
- */
- public function addWebsiteSurveyOption(array $data): array
- {
- if (isset($data['website_id']) && !empty($data['website_id'])) {
- $website = Website::where('id', $data['website_id'])->first();
- if (empty($website)) {
- return Result::error("暂无此网站", 0);
- }
- if (isset($data['sur_id']) && !empty($data['sur_id'])) {
- $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
- if (empty($survey)) {
- return Result::error("此调查问卷不可添加选项", 0);
- }
- if (isset($data['choice_name']) && !empty($data['choice_name'])) {
- $choice = [
- 'art_id' => $survey['art_id'],
- 'website_id' => $data['website_id'],
- 'survey_name' => $survey['survey_name'],
- 'choice_name' => $data['choice_name'],
- 'sur_id' => $survey['sur_id'],
- 'is_other' => 1,
- 'other_id' => $survey['id'],
- ];
- $result = ArticleSurvey::insertGetId($choice);
- if (empty($result)) {
- return Result::error("添加失败", 0);
- }
- return Result::success($result);
- }
- }
- return Result::error("添加失败", 0);
- }
- return Result::error("添加失败", 0);
- }
- /**
- * 前端-调查问卷投票
- * @param array $data
- * @return array
- */
- public function addWebsiteSurveyVote(array $data): array
- {
- // return Result::success($data);
- if (isset($data['website_id']) && !empty($data['website_id'])) {
- $website = Website::where('id', $data['website_id'])->first();
- if (empty($website)) {
- return Result::error("暂无此网站", 0);
- }
- if (isset($data['sur_id']) && !empty($data['sur_id'])) {
- $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
- // return Result::success($survey);
- if (empty($is_survey)) {
- return Result::error("此调查问卷不存在", 0);
- }
- // return Result::success($survey);
- // 调查问卷类型
- if (isset($data['choice_id']) && !empty($data['choice_id'])) {
- //多选 若是json型则转化成数组类型
- if (strpos($data['choice_id'], '[') === 0) {
- $data['choice_id'] = json_decode($data['choice_id'], true);
- } else {
- // 单选 也转换成数组
- $data['choice_id'] = [$data['choice_id']];
- }
- $data['choice_id'] = array_map('intval', $data['choice_id']);
- $other = ArticleSurvey::whereIn('id', $data['choice_id'])
- // ->where('website_id',$data['website_id'])
- ->where('is_other', 1)
- ->where('other_id', 0)
- ->first();
- if (!empty($other)) {
- return Result::error("请选择已有的选项!", 0);
- }
- $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
- // ->where('website_id',$data['website_id'])
- ->where('is_other', 1)
- ->where('other_id', '!=', 0)
- ->first();
- // return Result::success($choice['other']);
- $choice_id = $data['choice_id'];
- if (!empty($choice['other'])) {
- // array_push($data['choice_id'],$choice['other']['other_id']);
- if (!empty($choice_id)) {
- $key = array_search($choice['other']['id'], $choice_id);
- if ($key !== false) {
- unset($choice_id[$key]);
- $choice_id = array_values($choice_id);
- }
- array_push($choice_id, $choice['other']['other_id']);
- } else {
- $choice_id[0] = $choice['other']['other_id'];
- }
- array_push($data['choice_id'], $choice['other']['other_id']);
- }
- // return Result::success($data);
- $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
- // ->where('website_id',$data['website_id'])
- ->increment('results', 1);
- if (empty($choice)) {
- return Result::error("请选择已有的选项!", 0);
- }
- $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
- // ->where('website_id',$data['website_id'])
- ->where('other_id', 0)
- ->get();
- $survey['choice'] = $choice_id;
- return Result::success($survey);
- }
- return Result::error("参数必填!");
- }
- return Result::error("此调查问卷不存在", 0);
- }
- return Result::error("参数必填!");
- }
- /**
- * 获取商城首页-根据栏目id
- * @param array $data
- * @return array
- * */
- function getWebsiteCatidshop(array $data): array
- {
- $input['catid'] = $data['catid'];
- $input['website_id'] = $data['website_id'];
- $data = json_decode($input['catid'] ?? '', true) ?? [];
- $result = array_map(function ($item) use ($input) {
- if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
- list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
- $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
- // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
- if (empty($category) || $category->type != 2) {
- return Result::error("暂无此栏目", 0);
- } else {
- $website['website_id'] = $input['website_id'];
- $goods = Good::where('good.status', 2)
- ->where('good.website_id', $website['website_id'])
- ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
- ->select(
- 'good.id',
- 'good.name',
- 'good.imgurl',
- 'good.description',
- 'good.updated_at',
- 'good.catid',
- 'good.type_id',
- 'good.price',
- 'good.com',
- 'good.level',
- 'good.unit'
- )
- ->orderBy('updated_at', 'desc')
- ->offset($goodStart)
- ->limit($goodNum);
- $all_goods = $goods->get();
- $all_goods = $this->processGoods($all_goods, $website);
- }
- return $all_goods ?? [];
- }
- }, $data);
- return Result::success($result);
- }
- /**
- * 获取商品模块
- * @param array $data
- * @return array
- * */
- public function getWebsiteshop(array $data): array
- {
- $input['id'] = $data['id'];
- $input['website_id'] = $data['website_id'];
- $catid = $data['catid'];
- $data = json_decode($input['id'] ?? '', true) ?? [];
- $result['goods'] = array_map(function ($item) use ($input) {
- // 检查parent元素是否存在且不是undefined
- if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
- list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
- $website = $input['website_id'];
- $query = Good::where('good.status', 2)
- ->where('good.website_id', $website);
- switch ($Levelid) {
- case 1:
- case 2:
- case 3:
- $goods = $query->where(function ($q) use ($Levelid) {
- $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
- ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
- });
- break;
- case 4:
- $goods = $query;
- break;
- case 5:
- $goods = $query->where('type_id', 1);
- break;
- case 6:
- $goods = $query->where('type_id', 2);
- break;
- default:
- return [];
- }
- $all_goods = $goods
- ->select(
- 'good.id',
- 'good.name',
- 'good.imgurl',
- 'good.description',
- 'good.updated_at',
- 'good.catid',
- 'good.type_id',
- 'good.price',
- 'good.level',
- 'good.website_id'
- )
- ->orderBy('updated_at', 'desc')
- ->offset($goodStart)
- ->limit($goodNum)
- ->get();
- $web['website_id'] = $website;
- $all_goods = $this->processGoods($all_goods, $web);
- }
- return $all_goods;
- }, $data);
- $website = $input['website_id'];
- $result['article'] = Article::where(function ($query) use ($website) {
- $query->where(function ($subQuery) use ($website) {
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
- })->orWhereNull("ignore_ids");
- })
- ->where('catid', $catid)
- ->where('article.status', 1)
- ->leftJoin('article_data', 'article_data.article_id', 'article.id')
- ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
- ->orderBy('article.updated_at', 'desc')
- ->first();
- return Result::success($result);
- }
- /**
- * 获取商品分类
- * @param array $data
- * @return array
- * */
- public function getWebsiteshopCat(array $data): array
- {
- $website = $data['website_id'];
- $category = WebsiteCategory::where('website_id', $website)
- ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
- ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
- ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
- ->orderBy('sort')
- ->get();
- $cat = $category->map(function ($item) use ($website) {
- $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
- $pid = $item->pid ?? 0;
- if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
- $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
- ->where('website_id', $website)
- ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
- ->get(['aLIas_pinyin'])
- ->pluck('aLIas_pinyin')
- ->implode('/');
- } else {
- $pinyin = $item->aLIas_pinyin ?? '';
- }
- $item->pinyin = $pinyin;
- });
- if (empty($category)) {
- return Result::error("栏目查询失败", 0);
- }
- $cat_tree = Result::buildMenuTree($category);
- $web['website_id'] = $website;
- $goods = Good::where('website_id', $website)
- ->where('status', 2)
- ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
- ->latest('updated_at')
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get();
- if (!empty($goods)) {
- if ($goods->count() > 1 && !empty($goods)) {
- $goods = $this->processGoods($goods, $web);
- }
- } else {
- $goods = [];
- }
- $result = [
- 'category' => $cat_tree,
- 'goods' => $goods,
- ];
- // $resul['goods'] = $goods;
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取商品列表
- * @param array $data
- * @return array
- * */
- public function getWebsiteshopList(array $data): array
- {
- // return Result::success($data);
- $where = [
- 'status' => 2,
- 'website_id' => $data['website_id'],
- ];
- // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
- // return Result::error("查询失败", 0);
- // }
- if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
- $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
- $data['catid'] = $category->category_id ?? 0;
- }
- if (isset($data['keyword']) && !empty($data['keyword'])) {
- array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
- }
- if (isset($data['type_id']) && !empty($data['type_id'])) {
- array_push($where, ['type_id', $data['type_id']]);
- }
- $query = Good::where($where)
- ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
- $query->where(function ($q) use ($data) {
- $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
- ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
- });
- })
- ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
- $query->where(function ($q) use ($data) {
- $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
- ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
- });
- })
- ->select(
- 'good.id',
- 'good.name',
- 'good.imgurl',
- 'good.description',
- 'good.updated_at',
- 'good.com',
- 'good.catid',
- 'good.type_id',
- 'good.website_id',
- 'good.cat_arr_id',
- 'good.created_at',
- 'good.city_id'
- )
- ->latest('updated_at');
- if (isset($data['ismix']) && $data['ismix'] == 1) {
- $result['count'] = $query->clone()->count();
- $result['goods'] = $this->processGoods(
- $query->clone()
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get(),
- $data
- );
- } else {
- $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
- // 获取 type_id 为 1 的数据
- $result['type1'] = $this->processGoods(
- $query->clone()
- ->where('type_id', 1)
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get(),
- $data
- );
- $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
- // 获取 type_id 为 2 的数据
- $result['type2'] = $this->processGoods(
- $query->clone()
- ->where('type_id', 2)
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get(),
- $data
- );
- }
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- return Result::success($result);
- }
- /**
- * 获取商品详情
- * @param array $data
- * @return array
- * */
- public function getWebsiteshopInfo(array $data): array
- {
- $where = [
- 'good.status' => 2,
- 'good.website_id' => $data['website_id'],
- 'good.id' => $data['id'],
- ];
- $goods = Good::where($where)
- ->where('good.id', $data['id'])
- ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
- ->select('good.*', 'website_category.alias', 'website_category.category_id')
- ->first();
- if (empty($goods)) {
- return Result::error("查询失败", 0);
- }
- $goods->imgurl = json_decode($goods->imgurl, true);
- return Result::success($goods);
- }
- // 封装处理商品的路由问题
- function processGoods($goods, $data)
- {
- return $goods->map(function ($good) use ($data) {
- $catid = $good->catid ?? 0;
- // $pinyin = '';
- $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
- if (!empty($category->pid) && $category->pid != 0) {
- $level = json_decode($category->category_arr_id, true);
- $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
- ->whereIn('category_id', $level)
- ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
- ->get(['aLIas_pinyin'])
- ->pluck('aLIas_pinyin')
- ->implode('/');
- } else {
- $pinyin = $category->aLIas_pinyin ?? '';
- }
- if (isset($good->city_id) && !empty($good->city_id)) {
- $city = District::where('id', $good->city_id)->first(['name']);
- $good->city_name = $city->name ?? '';
- }
- // 解析imgurl JSON并取第一条数据
- $imgUrls = json_decode($good->imgurl, true);
- $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
- $good->pinyin = $pinyin;
- return $good;
- });
- }
- /**
- * c端-获取招工招聘下拉选框
- * @param array $data
- * @return array
- * */
- public function getWebsiteJobSelect(array $data): array
- {
- $web = Website::where('id', $data['website_id'])->first();
- if (empty($web)) {
- return Result::error("该网站不存在", 0);
- }
- $hy = JobIndustry::get()->all();
- $zw = JobPosition::where('zwpid', 0)->get()->all();
- $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
- $result = [
- 'hy' => $hy,
- 'zw' => $zw,
- 'jtzw' => $jtzw,
- ];
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- return Result::success($result);
- }
- /**
- * c端-获取招工招聘
- * @param array $data
- * @return array
- * */
- public function getWebsiteJob(array $data): array
- {
- $web = Website::where('id', $data['website_id'])->first();
- if (empty($web)) {
- return Result::error("该网站不存在", 0);
- }
- $job_hunting = JobHunting::where('job_hunting.status', 2)
- ->where('job_hunting.website_id', $data['website_id'])
- ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
- $query->where(function ($q) use ($data) {
- $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
- });
- })
- ->select(
- 'job_hunting.id',
- 'job_hunting.catid',
- 'job_hunting.cat_arr_id',
- 'job_hunting.job_name_get',
- 'job_hunting.industry',
- 'job_hunting.name',
- 'job_hunting.sexy',
- 'job_hunting.origin',
- 'job_hunting.city_arr_id',
- 'job_hunting.experience',
- 'job_hunting.updated_at',
- 'job_hunting.salary',
- 'job_hunting.skillList',
- 'job_hunting.slelf_evaluation',
- )
- ->orderBy('updated_at', 'desc')
- ->limit($data['job1_num'])
- ->get();
- $web['website_id'] = $data['website_id'];
- if (empty($job_hunting)) {
- $job_huntings = "未查询到相关简历信息";
- } else {
- $job_huntings = $this->processJob($job_hunting, $web);
- }
- // 0:待审核 1:已通过 2:已拒绝
- $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
- ->where('job_recruiting.website_id', $data['website_id'])
- ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
- $query->where(function ($q) use ($data) {
- $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
- });
- })
- ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
- ->select(
- 'job_recruiting.id',
- 'job_recruiting.catid',
- 'job_recruiting.cat_arr_id',
- 'job_recruiting.title',
- 'job_recruiting.jtzw_id',
- 'job_recruiting.hy_id',
- 'job_recruiting.city_arr_id',
- 'job_recruiting.due_data',
- 'job_recruiting.updated_at',
- 'job_recruiting.experience',
- 'job_recruiting.educational',
- 'job_recruiting.salary',
- 'job_recruiting.zw_id',
- 'job_company.business_name',
- 'job_recruiting.keyword',
- 'job_recruiting.description',
- )
- ->orderBy('updated_at', 'desc')
- ->limit($data['job2_num'])
- ->get();
- if (empty($job_recruiting->toArray())) {
- $job_recruitings = "未查询到相关职位信息";
- } else {
- $job_recruitings = $this->processJob($job_recruiting, $web);
- }
- $result = [
- 'job_hunting' => $job_huntings,
- 'job_recuiting' => $job_recruitings,
- ];
- return Result::success($result);
- }
- /**
- * c端-获取招工招聘列表
- * @param array $data
- * @return array
- * */
- public function getWebsiteJobList(array $data): array
- {
- $recruit_where = [];
- $hunt_where = [];
- $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
- if (empty($web)) {
- return Result::error("此网站不存在", 0);
- }
- $website_id['website_id'] = $data['website_id'];
- if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
- if (isset($data['zw_id']) && !empty($data['zw_id'])) {
- array_push($recruit_where, ['zw_id', $data['zw_id']]);
- }
- if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
- array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
- }
- if (isset($data['hy_id']) && !empty($data['hy_id'])) {
- array_push($recruit_where, ['hy_id', $data['hy_id']]);
- }
- if (isset($data['keyword']) && !empty($data['keyword'])) {
- array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
- }
- $query = JobRecruiting::where('job_recruiting.status', 1)
- ->where('job_recruiting.website_id', $data['website_id'])
- ->where($recruit_where)
- ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
- $query->where(function ($q) use ($data) {
- $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
- });
- })
- ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
- $query->where(function ($q) use ($data) {
- $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
- });
- })
- ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
- ->select(
- 'job_recruiting.id',
- 'job_recruiting.catid',
- 'job_recruiting.hy_id',
- 'job_recruiting.title',
- 'job_recruiting.zw_id',
- 'job_recruiting.educational',
- 'job_recruiting.jtzw_id',
- 'job_recruiting.city_arr_id',
- 'job_recruiting.due_data',
- 'job_recruiting.experience',
- 'job_recruiting.cat_arr_id',
- 'job_recruiting.updated_at',
- 'job_company.business_name',
- 'job_recruiting.keyword',
- 'job_recruiting.description',
- )
- ->orderBy('job_recruiting.updated_at', 'desc');
- $recruit_count = $query->count();
- $query = clone $query;
- $JobRecruiting = $query
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get();
- if (empty($JobRecruiting)) {
- $JobRecruiting = "暂无相关职位信息";
- } else {
- $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
- }
- }
- if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
- if (isset($data['zw_id']) && !empty($data['zw_id'])) {
- array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
- }
- if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
- array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
- }
- if (isset($data['hy_id']) && !empty($data['hy_id'])) {
- array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
- }
- if (isset($data['keyword']) && !empty($data['keyword'])) {
- array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
- }
- $query = JobHunting::where('job_hunting.status', 2)
- ->where('job_hunting.website_id', $data['website_id'])
- ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
- ->where($hunt_where)
- // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
- // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
- // })
- ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
- $query->where(function ($q) use ($data) {
- $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
- });
- })
- ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
- $query->where(function ($q) use ($data) {
- $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
- });
- })
- ->select(
- 'job_hunting.id',
- 'job_hunting.catid',
- 'job_hunting.sexy',
- 'job_hunting.experience',
- 'job_hunting.origin',
- 'job_hunting.industry',
- 'job_hunting.name',
- 'job_hunting.job',
- 'job_hunting.job_name_get',
- 'job_hunting.city_arr_id',
- 'job_hunting.cat_arr_id',
- 'job_hunting.created_at',
- 'job_hunting.updated_at',
- 'job_position.zwname as job_name',
- 'job_hunting.skillList',
- 'job_hunting.slelf_evaluation',
- )
- ->orderBy('job_hunting.updated_at', 'desc');
- $hunt_count = $query->count();
- $query = clone $query;
- $JobHunting = $query
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get();
- if (empty($JobHunting)) {
- $JobRecruiting = "暂无相关简历信息";
- } else {
- $JobHunting = $this->processJob($JobHunting, $website_id);
- }
- }
- $result = [
- 'JobRecruiting' => $JobRecruiting ?? [],
- 'recruit_count' => $recruit_count ?? 0,
- 'JobHunting' => $JobHunting ?? [],
- 'hunt_count' => $hunt_count ?? 0,
- ];
- return Result::success($result);
- }
- /**
- * c端-获取招工招聘详情
- * @param array $data
- * @return array
- * */
- public function getWebsiteJobInfo(array $data): array
- {
- $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
- if (empty($web)) {
- return Result::error("该网站不存在", 0);
- }
- $webid = [
- 'website_id' => $data['website_id'],
- ];
- // 职位相关信息
- if ($data['type'] == 1) {
- $query = JobRecruiting::where('status', 1)
- ->where('website_id', $data['website_id'])
- ->select('*');
- $job = $query->where('job_recruiting.id', $data['id'])->get();
- $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();
- if (!empty($company)) {
- $result['company'] = $this->processJob($company, $webid);
- }
- $other_job = JobRecruiting::where('status', 1)
- ->where('website_id', $data['website_id'])
- ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
- ->where('id', '!=', $data['id'])
- ->where('user_id', '=', $job[0]['user_id'])
- ->limit($data['pageSize'])
- ->get();
- if (!empty($other_job)) {
- $result['other_job'] = $this->processJob($other_job, $webid);
- }
- } else {
- // 简历相关信息
- $job = JobHunting::where('job_hunting.status', 2)
- ->where('job_hunting.website_id', $data['website_id'])
- ->where('job_hunting.id', $data['id'])
- ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
- ->select('job_hunting.*', 'user_name')
- ->get();
- $resume = JobRemuse::where('hunt_id', $data['id'])->get();
- if (!empty($resume->toArray())) {
- $result['resume'] = 1;
- } else {
- $result['resume'] = 0;
- }
- }
- if (empty($job->toArray())) {
- return Result::error("id参数错误", 0);
- }
- if (!empty($job[0]['job_experience'])) {
- $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
- if (!empty($job_experience)) {
- // $hy = [];
- foreach ($job_experience as $key => $value) {
- // $id = $value['id'];
- $hy[$key] = $value['job_industry'];
- $zw_id[$key] = $value['job_typename'];
- $jtzw_id[$key] = $value['job_name'];
- }
- $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
- $zw_table = JobPosition::select('zwid', 'zwname')->get();
- // 先将关联表转换为索引数组,提高查找效率
- $hyLookup = [];
- foreach ($hy_table as $item) {
- $hyLookup[$item['hyid']] = $item['hyname'];
- }
- $zwLookup = [];
- foreach ($zw_table as $item) {
- $zwLookup[$item['zwid']] = $item['zwname'];
- }
- foreach ($job_experience as $key => &$value) {
- // 处理行业名称
- if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
- $value['hy_name'] = $hyLookup[$hy[$key]];
- }
- // 处理职位名称
- if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
- $value['zw_name'] = $zwLookup[$zw_id[$key]];
- }
- // 处理具体职位名称
- if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
- $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
- }
- }
- // 释放引用,防止意外修改后续代码
- unset($value);
- }
- $result['job_experience'] = $job_experience ?? [];
- }
- if (!empty($job[0]['education_experience'])) {
- $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
- if (!empty($education_experience)) {
- foreach ($education_experience as $key => $value) {
- // $id = $value['id'];
- $education[$key] = $value['school_education'];
- }
- $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
- // // 先将关联表转换为索引数组,提高查找效率
- $educationLookup = [];
- foreach ($education_table as $item) {
- $educationLookup[$item['evalue']] = $item['ename'];
- }
- foreach ($education_experience as $key => &$value) {
- // 处理学历名称
- if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
- $value['education_name'] = $educationLookup[$education[$key]];
- }
- }
- }
- $result['education_experience'] = $job_experience ?? [];
- }
- $result['job'] = $this->processJob($job, $webid);
- // // 返现对应的栏目
- $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
- $category = WebsiteCategory::where('website_id', $data['website_id'])
- ->whereIn('category_id', $catid)
- ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
- ->orderBy('pid')->get()->all();
- if (!empty($category)) {
- $result['category'] = $category;
- }
- $result['job'] = $job;
- $result['job_experience'] = $job_experience ?? [];
- $result['education_experience'] = $education_experience ?? [];
- if (empty($result)) {
- return Result::error("参数错误", 0);
- }
- return Result::success($result);
- }
- /**
- * c端-申请职位
- * @param array $data
- * @return array
- * */
- public function getWebsiteJobApply(array $data): array
- {
- // 首先验证网站是否存在
- // return Result::success($data);
- $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
- if (empty($web)) {
- return Result::error("该网站不存在", 0);
- }
- // 验证用户是否存在且为个人会员/管理员
- $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
- // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
- if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
- return Result::error("用户不存在", 0);
- }
- // 去除重复元素和空元素,并保持原始顺序
- $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
- return !empty($value);
- }));
- // 验证职位是否存在 1:审核通过
- $recruiting = JobRecruiting::where('status', 1)
- ->where('website_id', $data['website_id'])
- ->whereIn('id', $data['recruit_id'])
- ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
- if (empty($recruiting)) {
- return Result::error("该职位不存在", 0);
- }
- // 简历是否存在
- $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
- if (empty($hunt_id)) {
- return Result::error("该简历不存在", 0);
- }
- $data['hunt_id'] = $hunt_id['hunt_id'];
- // // 验证是否已投递过该职位
- $apply = JobApply::where('user_id', $data['user_id'])
- ->where('hunt_id', $data['hunt_id'])
- ->where('website_id', $data['website_id'])
- ->whereIn('recruit_id', $data['recruit_id'])
- ->get(['recruit_id']);
- if (!empty($apply->toArray())) {
- return Result::error("您已投递过该职位!");
- }
- $insertData = array_map(function ($recruiting) use ($data) {
- return [
- 'user_id' => $data['user_id'],
- 'hunt_id' => $data['hunt_id'],
- 'website_id' => $data['website_id'],
- 'recruit_id' => $recruiting['recruit_id'],
- 'receiver_id' => $recruiting['receiver_id'],
- 'status' => 1,
- ];
- }, $recruiting);
- // 批量插入数据
- $result = JobApply::insert($insertData);
- if (empty($result)) {
- return Result::error("投递失败", 0);
- }
- return Result::success($result);
- }
- /**
- * 招工招聘-沟通简历
- * @param array $data
- * @return array
- * */
- public function getWebsiteJobResume(array $data): array
- {
- // 首先验证网站是否存在
- $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
- if (empty($web)) {
- return Result::error("该网站不存在", 0);
- }
- // return Result::success($data);
- // 验证用户是否存在且为企业会员/管理员
- $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
- // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
- if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
- return Result::error("用户不存在", 0);
- }
- // 去除重复元素和空元素,并保持原始顺序
- $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
- return !empty($value);
- }));
- // 验证简历是否存在
- $hunting = JobHunting::where('status', 2)
- ->where('website_id', $data['website_id'])
- ->whereIn('id', $data['hunt_id'])
- ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
- if (empty($hunting)) {
- return Result::error("该简历不存在", 0);
- }
- // 验证是否已沟通过该简历
- $remuse = JobRemuse::where('user_id', $data['user_id'])
- ->where('recruit_id', $data['recruit_id'])
- ->where('website_id', $data['website_id'])
- ->whereIn('hunt_id', $data['hunt_id'])
- ->get(['hunt_id']);
- if (!empty($remuse->toArray())) {
- return Result::error("您已沟通过该简历!");
- }
- // 准备要插入的数据数组
- $insertData = array_map(function ($hunting) use ($data) {
- return [
- 'user_id' => $data['user_id'],
- 'recruit_id' => $data['recruit_id'],
- 'website_id' => $data['website_id'],
- 'hunt_id' => $hunting['hunt_id'],
- 'receiver_id' => $hunting['receiver_id'],
- 'status' => 1,
- ];
- }, $hunting);
- // 批量插入数据
- $result = JobRemuse::insert($insertData);
- if (empty($result)) {
- return Result::error("沟通失败", 0);
- }
- return Result::success($result);
- }
- /**
- * 招工招聘 -我的职位(企业会员)
- * @param array $data
- * @return array
- */
- public function getWebsiteJobRecruiting(array $data): array
- {
- $web = Website::where('id', $data['website_id'])->first('id');
- if (empty($web)) {
- return Result::error("该网站不存在", 0);
- }
- $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
- if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
- return Result::error("用户暂无权限!", 0);
- }
- // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
- $result = JobRecruiting::where('website_id', $data['website_id'])
- ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
- $query->where('user_id', $user['id']);
- })
- ->where('status', 1)
- ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
- ->orderBy('updated_at', 'desc')
- ->limit($data['pageSize'])
- ->get();
- if (empty($result)) {
- return Result::error("暂无相关职位信息", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取职位
- * */
- public function getPositionList(array $data): array
- {
- if (isset($data['zwpid']) && $data['zwpid'] != null) {
- $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
- } else {
- $result = JobPosition::where('zwpid', 0)->get()->all();
- }
- if (empty($result)) {
- return Result::error("暂无此职位", 0);
- }
- return Result::success($result);
- }
- /**
- * 招工招聘 - 获取推荐职位
- * @param array $data
- * @return array
- */
- public function getWebsiteLevelJob(array $data): array
- {
- // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
- $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
- ->where('job_recruiting.status', 1)
- ->where('job_level', $data['job_level'])
- ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
- ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
- ->orderBy('job_recruiting.updated_at', 'desc')
- ->limit($data['pageSize'])
- ->get();
- $web = ['website_id' => $data['website_id']];
- if (!empty($job)) {
- $result = $this->processJob($job, $web);
- }
- if (empty($result)) {
- return Result::error("暂无相关职位信息", 0);
- }
- return Result::success($result);
- }
- /**
- * 招工招聘 - 根据栏目获取职位
- * @param array $data
- * @return array
- */
- public function getWebsiteCategoryJob(array $data): array
- {
- $categorys = json_decode($data['id'], true);
- if (!empty($categorys)) {
- $category_arr = $this->processArticlePro($data['website_id']);
- $cat_1st_arr = $category_arr['cat_1st_arr'];
- $catiall = $category_arr['catiall'];
- foreach ($categorys as $key => $val) {
- if (isset($val['id']) && !empty($val['id'])) {
- $catid = explode(',', $val['id'])[0] ?? null;
- $type = explode(',', $val['id'])[1] ?? null;
- $textnum = explode(',', $val['id'])[2] ?? null;
- }
- // 4:招聘;5:求职;
- if ($textnum > 0 && $type == 4 && !empty($catid)) {
- // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
- $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
- ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
- ->where('job_recruiting.status', 1)
- ->where('job_recruiting.website_id', $data['website_id'])
- ->select(
- 'job_recruiting.id',
- 'job_recruiting.title',
- 'job_company.business_name',
- 'job_recruiting.updated_at',
- 'job_recruiting.cat_arr_id',
- 'job_recruiting.keyword',
- 'job_recruiting.description'
- )
- ->orderBy('job_recruiting.updated_at', 'desc')
- ->limit($textnum)
- ->get()->all();
- } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
- // 状态 审核状态,1待审核2已审核3已拒绝
- $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
- ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
- ->where('job_hunting.status', 2)
- ->where('job_hunting.website_id', $data['website_id'])
- ->select(
- 'job_hunting.id',
- 'job_hunting.name',
- 'job_hunting.cat_arr_id',
- 'job_position.zwname as job_name',
- 'job_hunting.updated_at',
- // 'job_hunting.keyword',
- 'job_hunting.slelf_evaluation'
- )
- ->orderBy('updated_at', 'desc')
- ->limit($textnum)
- ->get()->all();
- } else {
- $job = [];
- }
- // var_dump($catid.'222uuuuuuu'.$key);
- if (!empty($job)) {
- foreach ($job as $k => $value) {
- if (isset($value->cat_arr_id)) {
- $catArr = json_decode($value->cat_arr_id, true);
- $catId = end($catArr);
- } else {
- continue;
- }
- if (isset($catiall[$catId])) {
- $job[$k]->pinyin = $catiall[$catId]['pinyin'];
- }
- }
- }
- // var_dump($catid.'xxxxx'.$key);
- $result[$key] = $job ?? [];
- }
- }
- if (empty($result)) {
- return Result::error("暂无相关分类信息", 0);
- }
- return Result::success($result);
- }
- // 封装处理由问题
- function processJob($job, $data)
- {
- return $job->map(function ($job) use ($data) {
- $category = $job->cat_arr_id ?? '';
- $cityid = $job->city_arr_id ?? '';
- $city = json_decode($cityid, true);
- $pinyin = '';
- $level = json_decode($category, true);
- // 路由
- if (!empty($level) && is_array($level)) {
- $pinyin = WebsiteCategory::whereIn('category_id', $level)
- ->where('website_id', $data['website_id']) // 添加网站ID条件
- ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
- ->get(['aLIas_pinyin'])
- ->pluck('aLIas_pinyin')
- ->implode('/');
- if (empty($pinyin)) {
- $pinyin = $pinyin->aLIas_pinyin ?? '';
- }
- $job->pinyin = $pinyin;
- }
- // 取职位-城市 市??省
- if (!empty($city) && is_array($city)) {
- if (isset($city[1]) && !empty($city[1])) {
- $city = District::where('id', $city[1])->first(['name']);
- $job->city_name = $city->name ?? '';
- } else if (isset($city[0]) && !empty($city[0])) {
- $city = District::where('id', $city[0])->first(['name']);
- $job->city_name = $city->name ?? '';
- } else {
- $job->city_name = '全国';
- }
- }
- // 获取简历最后一级地区
- if (isset($job->city_id) && !empty($job->city_id)) {
- $city = District::where('id', $job->city_id)->first(['name']);
- $job->hunt_cityname = $city->name ?? '';
- }
- // 组合详细地址
- if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
- $address_id = json_decode($job->address_arr_id, true) ?? [];
- if (is_array($address_id) && !empty($address_id)) {
- $address = District::whereIn('id', $address_id)
- ->orderBy('level', 'asc')
- ->get(['name'])
- ->pluck('name')
- ->implode('');
- // $job->address_name = $address ?? '';
- $job->address_name = ($address ?? '') . ($job->address ?? '');
- }
- }
- // 取行业
- if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
- $hy_name = JobIndustry::when($job, function ($query) use ($job) {
- if (!empty($job->industry)) {
- $query->where('hyid', $job->industry);
- } else if (!empty($job->hy_id)) {
- $query->where('hyid', $job->hy_id);
- } else if (!empty($job->company_hy_id)) {
- $query->where('hyid', $job->company_hy_id);
- } else {
- $query->where('hyid', $job->job_industry);
- }
- })->first(['hyname']);
- $job->hy_name = $hy_name->hyname ?? '';
- }
- // 取职位类别
- if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
- $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
- $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
- $job->zw_name = $zw_name->zwname ?? '';
- }
- // 取具体职位
- 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))) {
- $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
- $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
- $job->jtzw_name = $jtzw_name->zwname ?? '';
- }
- // 取工作经验
- if (isset($job->experience) && !empty($job->experience)) {
- $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
- $job->experience_name = $experience->ename ?? '';
- }
- // 取学历
- if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
- $education = $job->educational ?? $job->school_education;
- $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
- $job->education_name = $education->ename ?? '';
- }
- // 语言
- if (isset($job->language) && !empty($job->language)) {
- $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
- $job->language_name = $language->ename ?? '';
- }
- // 薪资
- if (isset($job->salary) && !empty($job->salary)) {
- $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
- $job->salary_name = $salary->ename ?? '';
- }
- // 职位性质
- if (isset($job->nature_id) && !empty($job->nature_id)) {
- $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
- $job->job_nature_name = $job_nature->ename ?? '';
- }
- // 公司规模
- if (isset($job->company_size) && !empty($job->company_size)) {
- $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
- $job->company_size_name = $company_size->ename ?? '';
- }
- // 公司性质
- if (isset($job->company_nature) && !empty($job->company_nature)) {
- $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
- $job->company_nature_name = $company_nature->nature_name ?? '';
- }
- // $job->pinyin = $pinyin;
- return $job;
- });
- }
- /**
- * 获取书籍模块
- * @param array $data
- * @return array
- * */
- public function getWebsiteBook(array $data): array
- {
- $input['id'] = $data['id'];
- $input['website_id'] = $data['website_id'];
- // 将 JSON 字符串转换为 PHP 数组
- $data = json_decode($input['id'], true);
- // 使用 array_map 处理每个元素
- $result = array_map(function ($item) use ($input) {
- // 检查parent元素是否存在且不是undefined
- if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
- list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
- $website = [
- 'website_id' => $input['website_id'],
- ];
- // 查询栏目名称
- $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
- if (empty($category)) {
- $parent_alias = '';
- $parent_pinyin = null;
- $imgBooks = [];
- $textBooks = [];
- } else {
- $parent_alias = $category->alias ?? '';
- $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
- // 查找子分类ID数组
- $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
- array_push($childCategoryIds, $parentCatId);
- $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
- if ($parentImgNum != 0) {
- // 查询图片新闻
- $imgBooks = Book::where(function ($query) use ($parentCatId) {
- $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
- ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
- })
- ->where('book.status', 2)
- ->where('book.img_url', '!=', '')
- ->where('book.website_id', $website['website_id'])
- ->leftJoin('website_category', function ($join) use ($website) {
- $join->on('book.cat_id', '=', 'website_category.category_id')
- ->where('website_category.website_id', '=', $website['website_id']);
- })
- ->select(
- 'book.id',
- 'book.title',
- 'book.img_url',
- 'book.price',
- 'book.market_price',
- 'book.description',
- 'book.cat_id',
- 'book.description',
- 'book.updated_at',
- 'website_category.alias as category_name',
- DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
- ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
- )
- ->orderBy('updated_at', 'desc')
- ->limit($parentImgNum)
- ->get()->all();
- // 查询文字新闻
- }
- if ($parentTextNum != 0) {
- $textBooks = [];
- $textBooks = Book::where(function ($query) use ($parentCatId) {
- $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
- ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
- })
- ->where('book.status', 2)
- ->where('book.website_id', $website['website_id'])
- ->leftJoin('website_category', function ($join) use ($website) {
- $join->on('book.cat_id', '=', 'website_category.category_id')
- ->where('website_category.website_id', '=', $website['website_id']);
- })
- ->select(
- 'book.id',
- 'book.title',
- 'book.img_url',
- 'book.price',
- 'book.market_price',
- 'book.description',
- 'book.cat_id',
- 'book.description',
- 'book.updated_at',
- 'website_category.alias as category_name',
- DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
- ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
- )
- ->orderBy('updated_at', 'desc')
- ->limit($parentTextNum)
- ->get()->all();
- }
- }
- }
- $resultItem = [
- 'alias' => $parent_alias ?? '',
- 'category_id' => $parentCatId ?? 0,
- 'pinyin' => $parent_pinyin ?? null,
- 'imgnum' => $imgBooks ?? [],
- 'textnum' => $textBooks ?? [],
- ];
- if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
- $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
- $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
- ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
- ->get()->all();
- if (!empty($childCategory)) {
- list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
- // 查询子栏目名称
- $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
- ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
- ->first();
- if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
- $childImgArticles = [];
- $childTextArticles = [];
- $resultItem['child'] = [];
- } else {
- $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
- // 查询子栏目图片新闻
- $childImgArticles = Book::where('cat_id', $childCatId)
- ->where('status', 2)
- ->where('img_url', '!=', '')
- ->where('book.website_id', $website['website_id'])
- ->leftJoin('website_category', function ($join) use ($website) {
- $join->on('book.cat_id', '=', 'website_category.category_id')
- ->where('website_category.website_id', '=', $website['website_id']);
- })
- ->select(
- 'book.id',
- 'book.title',
- 'book.img_url',
- 'book.price',
- 'book.market_price',
- 'book.description',
- 'book.cat_id',
- 'book.description',
- 'book.updated_at',
- DB::raw("'$child_pinyin' as pinyin")
- )
- ->orderBy('updated_at', 'desc')
- ->limit($childImgNum)
- ->get()->all();
- // 查询子栏目文字新闻
- $childTextArticles = Book::where('cat_id', $childCatId)
- ->where('status', 2)
- ->where('book.website_id', $website['website_id'])
- ->leftJoin('website_category', function ($join) use ($website) {
- $join->on('book.cat_id', '=', 'website_category.category_id')
- ->where('website_category.website_id', '=', $website['website_id']);
- })
- ->select(
- 'book.id',
- 'book.title',
- 'book.img_url',
- 'book.price',
- 'book.market_price',
- 'book.description',
- 'book.cat_id',
- 'book.description',
- 'book.updated_at',
- DB::raw("'$child_pinyin' as pinyin")
- )
- ->orderBy('updated_at', 'desc')
- ->limit($childTextNum)
- ->get()->all();
- $resultItem['child'] = [
- 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
- 'category_id' => $childCatId,
- 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
- 'all_childcat' => $childCategory,
- 'imgnum' => $childImgArticles,
- 'textnum' => $childTextArticles,
- ];
- }
- }
- } else {
- $resultItem['child'] = [];
- }
- return $resultItem;
- }, $data);
- return Result::success($result);
- }
- /**
- * 获取书刊列表
- * @param array $data
- * @return array
- * */
- public function getWebsiteBookList(array $data): array
- {
- $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
- if (empty($web)) {
- return Result::error("查询失败", 0);
- }
- $catid = $data['id'];
- $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
- $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
- $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
- $category_pinyin = $category ? $category->aLias_pinyin : '';
- $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
- $categorys = WebsiteCategory::where('website_id', $data['website_id'])
- ->where('pid', $category['pid'])
- ->select(
- 'category_id',
- 'alias',
- 'aLIas_pinyin',
- 'pid',
- 'sort',
- 'is_url',
- 'web_url',
- 'seo_title',
- 'seo_keywords',
- 'seo_description',
- DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
- )
- ->orderBy('sort')
- ->get()->all();
- if (empty($category)) {
- return Result::error("查询失败", 0);
- }
- $query = Book::where('book.status', 2)
- ->where('book.website_id', $data['website_id'])
- ->where('book.cat_id', $catid)
- ->select(
- 'book.id',
- 'book.title',
- 'book.img_url',
- 'book.description',
- 'book.updated_at',
- 'book.cat_id',
- DB::raw("'$pinyin' as pinyin")
- )
- ->orderBy('book.updated_at', 'desc');
- $count = $query->count();
- $query = clone $query;
- $Book = $query
- ->limit($data['pageSize'])
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->get()->all();
- $result = [
- 'category' => $categorys,
- 'books' => $Book,
- 'count' => $count,
- ];
- // if(empty($result)){
- // return Result::error("查询失败", 0);
- // }
- return Result::success($result);
- }
- /**
- * 获取书刊详情
- * @param array $data
- * @return array
- * */
- public function getWebsiteBookInfo(array $data): array
- {
- $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
- if (empty($web)) {
- return Result::error("查询失败", 0);
- }
- $book = Book::where('status', 2)
- ->where('website_id', $data['website_id'])
- ->where('id', $data['id'])
- ->select(
- 'book.*',
- )
- ->orderBy('updated_at', 'desc')
- ->first();
- if (empty($book)) {
- return Result::error("查询失败", 0);
- }
- // 先查询当前分类的 pid
- $carpid = WebsiteCategory::where('website_id', $data['website_id'])
- ->where('category_id', $book['cat_id'])
- ->first(['pid', 'category_id']);
- $query = WebsiteCategory::where('website_id', $data['website_id']);
- if (!empty($carpid)) {
- if ($carpid->pid != 0) {
- $pid = $carpid['pid'];
- // $parent_pinyin = '';
- } else {
- $pid = $carpid['category_id'];
- // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
- }
- }
- $categorys = $query->where('pid', $pid)
- ->select(
- 'category_id',
- 'alias',
- 'aLIas_pinyin',
- 'pid',
- 'sort',
- 'is_url',
- 'web_url',
- 'category_arr_id as cat_arr_id',
- )
- ->orderBy('sort')
- ->get();
- $category = $this->processArticle($categorys, $data);
- $result = [
- 'category' => $category,
- 'books' => $book,
- ];
- return Result::success($result);
- }
- /**
- * 封装处理文章的路由问题
- * */
- function processArticle($article, $data)
- {
- return $article->map(function ($article) use ($data) {
- $catid = $article->cat_arr_id ?? '';
- $level = json_decode($catid, true);
- $pinyin = '';
- // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
- if (!empty($level) && is_array($level)) {
- $pinyin = WebsiteCategory::whereIn('category_id', $level)
- ->where('website_id', $data['website_id'])
- ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
- ->get(['aLIas_pinyin'])
- ->pluck('aLIas_pinyin')
- ->implode('/');
- } else {
- $pinyin = '';
- }
- $article->pinyin = $pinyin;
- return $article;
- });
- }
- /**
- * @param array $data
- * @return array
- */
- public function getWebsiteCompany(array $data): array
- {
- $categorys = json_decode($data['id'], true);
- $category_arr = $this->processArticlePro($data['website_id']);
- $cat_1st_arr = $category_arr['cat_1st_arr'];
- $catiall = $category_arr['catiall'];
- $categoryIds = $category_arr['categoryIds'];
- // return Result::success($category_arr);
- foreach ($categorys as $key => $value) {
- if (array_key_exists('level', $value)) {
- $parts = explode(',', $value['level']);
- $level = $parts[0] ?? null;
- $imgnum = $parts[1] ?? null;
- $textnum = $parts[2] ?? null;
- if (!empty($textnum) && $textnum > 0) {
- $text_num = Company::where('level', $level)
- ->whereIn('category_id', $categoryIds)
- ->where('status', 1)
- ->select(
- 'company.id',
- 'company.title',
- 'company.description',
- 'company.updated_at',
- 'company.category_id',
- 'company.cat_arr_id'
- )
- ->orderBy('updated_at', 'desc')
- ->limit($textnum)
- ->get()->all();
- }
- if (!empty($imgnum) && $imgnum > 0) {
- $img_num = Company::where('level', $level)
- ->whereIn('category_id', $categoryIds)
- ->where('status', 1)
- ->where('imgurl', '!=', '')
- ->whereNotNull('imgurl')
- ->select(
- 'company.id',
- 'company.title',
- 'company.description',
- 'company.updated_at',
- 'company.imgurl as imgs',
- 'company.category_id',
- 'company.cat_arr_id'
- )
- ->orderBy('updated_at', 'desc')
- ->limit($imgnum)
- ->get()->all();
- }
- }
- if (array_key_exists('id', $value)) {
- $parts = explode(',', $value['id']);
- $category_id = $parts[0] ?? null;
- $imgnum = $parts[1] ?? null;
- $textnum = $parts[2] ?? null;
- $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
- if (!empty($textnum) && $textnum > 0) {
- $text_num = Company::whereIn('category_id', $category_arr)
- // ->where('website_id', $data['website_id'])
- ->where('status', 1)
- ->select(
- 'company.id',
- 'company.title',
- 'company.description',
- 'company.updated_at',
- 'company.category_id',
- 'company.cat_arr_id'
- )
- ->orderBy('updated_at', 'desc')
- ->limit($textnum)
- ->get()->all();
- }
- if (!empty($imgnum) && $imgnum > 0) {
- $img_num = Company::whereIn('category_id', $category_arr)
- // ->where('website_id', $data['website_id'])
- ->where('status', 1)
- ->where('imgurl', '!=', '')
- ->whereNotNull('imgurl')
- ->select(
- 'company.id',
- 'company.title',
- 'company.description',
- 'company.updated_at',
- 'company.imgurl as imgs',
- 'company.category_id',
- 'company.cat_arr_id'
- )
- ->orderBy('updated_at', 'desc')
- ->limit($imgnum)
- ->get()->all();
- }
- }
- if (!empty($text_num)) {
- foreach ($text_num as $k => $v) {
- $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
- $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
- }
- }
- if (!empty($img_num)) {
- foreach ($img_num as $k => $v) {
- $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
- $imgurl = json_decode($v['imgs'], true);
- if (!empty($imgurl)) {
- $img_num[$k]->imgurl = $imgurl[0];
- }
- $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
- }
- }
- $company[$key]['img_num'] = $img_num ?? [];
- $company[$key]['text_num'] = $text_num ?? [];
- }
- if (empty($company)) {
- return Result::error("暂无相关企业信息", 0);
- }
- return Result::success($company);
- }
- /**
- * @param array $data
- * @return array
- */
- public function getWebsiteCompanyList(array $data): array
- {
- $where['website_id'] = $data['website_id'];
- $where['status'] = 1;
- $categoryIds = [];
- if (isset($data['category_id']) && !empty($data['category_id'])) {
- $category_id = $data['category_id'];
- }
- $category_arr = $this->processArticlePro($data['website_id']);
- $categoryIds = $category_arr['categoryIds'];
- // return Result::success($cat_1st_arr);
- $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
- $query->where('title', 'like', '%' . $data['keyword'] . '%');
- })
- ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
- $query->whereIn('category_id', $categoryIds);
- })
- ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
- $query->where('category_id', $category_id);
- })
- ->where('status',1)
- ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
- ->orderBy('updated_at', 'desc')
- ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
- if (empty($company)) {
- return Result::error("暂无相关公司信息", 0);
- }
- $result = [
- 'count' => $company->total(),
- 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
- ];
- return Result::success($result);
- }
- public function getWebsiteCompanyInfo(array $data): array
- {
- $company = Company::where('id', $data['id'])
- ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
- ->where('status', 1)
- // ->where('website_id', $data['website_id'])
- ->select('company.*', 'job_industry.hyname as hy_name')
- ->first();
- // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
- $jobnature_id = $company['jobnature_id'] ?? null;
- if ($jobnature_id !== null) {
- switch ($jobnature_id) {
- case 0:
- $company->jobnature_name = '市场监督';
- break;
- case 1:
- $company->jobnature_name = '信访纪检';
- break;
- case 2:
- $company->jobnature_name = '公检法司';
- break;
- case 3:
- $company->jobnature_name = '高关注机构';
- break;
- default:
- $company->jobnature_name = '';
- break;
- }
- } else {
- $company->jobnature_name = '';
- }
- $city_arr = $company->city_arr_id;
- if (!empty($city_arr)) {
- $city_arr = json_decode($city_arr, true);
- $cityNames = District::whereIn('id', $city_arr)
- ->pluck('name')
- ->implode('-');
- $company->city_name = $cityNames;
- } else {
- $company->city_name = '';
- }
- if (empty($company)) {
- return Result::error("暂无相关公司信息", 0);
- }
- return Result::success($company);
- }
- /**
- * @param array $data
- * @return array
- */
- public function getWebsiteProject(array $data): array
- {
- $categorys = json_decode($data['id'], true);
- if (!empty($categorys)) {
- $category_arr = $this->processArticlePro($data['website_id']);
- $cat_1st_arr = $category_arr['cat_1st_arr'];
- $catiall = $category_arr['catiall'];
- // return Result::success($catiall);
- foreach ($categorys as $key => $val) {
- if (isset($val['level'][0]) && !empty($val['level'][0])) {
- $level = explode(',', $val['level'])[0];
- $imgnum = explode(',', $val['level'])[1] ?? null;
- $textnum = explode(',', $val['level'])[2] ?? null;
- if ($level == 1) {
- if (!empty($textnum) && $textnum > 0) {
- $text_num = Project::where('level', $level)
- ->where('website_id', $data['website_id'])
- ->where('status', 1)
- ->select(
- 'project.id',
- 'project.title',
- 'project.description',
- 'project.updated_at',
- 'project.category_id',
- 'project.cat_arr_id'
- )
- ->orderBy('updated_at', 'desc')
- ->limit($textnum)
- ->get()->all();
- }
- if (!empty($imgnum) && $imgnum > 0) {
- $img_num = Project::where('level', $level)
- ->where('website_id', $data['website_id'])
- ->where('status', 1)
- ->where('imgurl', '!=', '')
- ->whereNotNull('imgurl')
- ->select(
- 'project.id',
- 'project.title',
- 'project.description',
- 'project.updated_at',
- 'project.imgurl as imgs',
- 'project.category_id',
- 'project.cat_arr_id'
- )
- ->orderBy('updated_at', 'desc')
- ->limit($imgnum)
- ->get()->all();
- }
- } else {
- if (!empty($textnum) && $textnum > 0) {
- $text_num = Project::where('website_id', $data['website_id'])
- ->where('status', 1)
- ->select(
- 'project.id',
- 'project.title',
- 'project.description',
- 'project.updated_at',
- 'project.category_id',
- 'project.cat_arr_id',
- 'project.website_id',
- 'project.updated_at',
- 'project.created_at'
- )
- ->orderBy('updated_at', 'desc')
- ->limit($textnum)
- ->get()->all();
- }
- if (!empty($imgnum) && $imgnum > 0) {
- $img_num = Project::where('website_id', $data['website_id'])
- ->where('status', 1)
- ->where('imgurl', '!=', '')
- ->whereNotNull('imgurl')
- ->select(
- 'project.id',
- 'project.title',
- 'project.description',
- 'project.updated_at',
- 'project.imgurl as imgs',
- 'project.category_id',
- 'project.cat_arr_id'
- )
- ->orderBy('updated_at', 'desc')
- ->limit($imgnum)
- ->get()->all();
- }
- }
- }
- if (isset($val['id'][0]) && !empty($val['id'][0])) {
- $category_ids = explode(',', $val['id'])[0];
- $cat_imgnum = explode(',', $val['id'])[1] ?? null;
- $cat_textnum = explode(',', $val['id'])[2] ?? null;
- $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
- if (!empty($cat_textnum) && $cat_textnum > 0) {
- $text_num = Project::whereIn('category_id', $category_arr)
- ->where('website_id', $data['website_id'])
- ->where('status', 1)
- ->select(
- 'project.id',
- 'project.title',
- 'project.description',
- 'project.updated_at',
- 'project.category_id',
- 'project.cat_arr_id'
- )
- ->orderBy('updated_at', 'desc')
- ->limit($cat_textnum)
- ->get()->all();
- }
- if (!empty($cat_imgnum) && $cat_imgnum > 0) {
- $img_num = Project::whereIn('category_id', $category_arr)
- ->where('website_id', $data['website_id'])
- ->where('status', 1)
- ->where('imgurl', '!=', '')
- ->whereNotNull('imgurl')
- ->select(
- 'project.id',
- 'project.title',
- 'project.description',
- 'project.updated_at',
- 'project.imgurl as imgs',
- 'project.category_id',
- 'project.cat_arr_id'
- )
- ->orderBy('updated_at', 'desc')
- ->limit($cat_imgnum)
- ->get()->all();
- }
- }
- if (!empty($img_num)) {
- foreach ($img_num as $k => $v) {
- $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
- $imgurl = json_decode($v['imgs'], true);
- if (!empty($imgurl)) {
- $img_num[$k]->imgurl = $imgurl[0];
- }
- $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
- }
- }
- if (!empty($text_num)) {
- foreach ($text_num as $k => $v) {
- $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
- $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
- }
- }
- $project[$key]['img_num'] = $img_num ?? [];
- $project[$key]['text_num'] = $text_num ?? [];
- }
- }
- if (empty($project)) {
- return Result::error("暂无相关项目信息", 0);
- }
- return Result::success($project);
- }
- /**
- * @param array $data
- * @return array
- */
- public function getWebsiteProjectInfo(array $data): array
- {
- $project = Project::where('id', $data['id'])
- ->where('status', 1)
- ->where('website_id', $data['website_id'])
- ->select('project.*')
- ->first();
- if (empty($project)) {
- return Result::error("暂无相关项目信息", 0);
- }
- return Result::success($project);
- }
- /**
- * @param array $data
- * @return array
- */
- public function getWebsiteProjectList(array $data): array
- {
- $where = [];
- if (isset($data['category_id']) && !empty($data['category_id'])) {
- $where['category_id'] = $data['category_id'];
- }
- if (isset($data['keyword']) && !empty($data['keyword'])) {
- $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
- }
- $query = Project::where($where)
- ->where('status', 1)
- ->where('website_id', $data['website_id'])
- ->select(
- 'project.id',
- 'project.title',
- 'project.description',
- 'project.imgurl as imgs',
- 'project.category_id',
- 'project.cat_arr_id'
- )
- ->orderBy('updated_at', 'desc');
- $count = $query->count();
- $project = $query->clone()
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get()->all();
- if (empty($project)) {
- return Result::error("暂无相关项目信息", 0);
- }
- $categorys = $this->processArticlePro($data['website_id']);
- $catiall = $categorys['catiall'];
- foreach ($project as $key => $val) {
- $project[$key]->category_name = $catiall[$val->category_id]['alias'];
- if (!empty($val['imgs'])) {
- $imgurl = json_decode($val['imgs'], true);
- if (!empty($imgurl)) {
- $project[$key]->imgurl = $imgurl[0];
- }
- } else {
- $project[$key]->imgurl = '';
- }
- $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
- }
- $result = [
- 'rows' => $project,
- 'count' => $count,
- ];
- return Result::success($result);
- }
- /**
- * @param array $data
- * @return array
- */
- public function getWebsiteMessage(array $data): array
- {
- $web = Website::where('id',$data['website_id'])->first();
- if (empty($web)) {
- return Result::error("暂无相关网站信息", 0);
- }
- $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
- $message = Message::whereIn('message.column_id', $column_arr)
- ->where('message.status', 1)
- ->leftJoin('user', 'message.user_id', '=', 'user.id')
- ->select('message.title', 'message.content','message.reply',
- 'message.updated_at','user.nickname')
- ->orderBy('message.updated_at', 'desc')
- ->paginate($data['page_size'], ['*'], 'page', $data['page']);
- if (empty($message->items())) {
- return Result::error("暂无相关消息信息", 0);
- }
- $result = [
- 'data' => $message->items(),
- 'count' => $message->total(),
- ];
- return Result::success($result);
- }
- /**
- * @param array $data
- * @return array
- */
- /**
- * 获取省份城市列表
- * @param array $data
- * @return array
- */
- public function getWebsiteProvinceCity(array $data): array
- {
- $province_city = District::whereIn('level', [1,2])
- ->select('id', 'name', 'pid', 'abbreviation')
- ->get()->all();
- if (empty($province_city)) {
- return Result::error("暂无相关省份城市信息", 0);
- }
- $result = Result::buildCityTree($province_city);
- return Result::success($result);
- }
- /**
- * @param array $data
- * @return array
- */
- public function getWebsiteResearchTopic(array $data): array
- {
- $web = Website::where('id',$data['website_id'])->first();
- if (empty($web)) {
- return Result::error("暂无相关网站信息", 0);
- }
- $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
- $where['level'] = 1;
- if (isset($data['province_id']) && !empty($data['province_id'])) {
- $where['province_id'] = $data['province_id'];
- }
- if (isset($data['city_id']) && !empty($data['city_id'])) {
- $where['city_id'] = $data['city_id'];
- }
- if (isset($data['county_id']) && !empty($data['county_id'])) {
- $where['county_id'] = $data['county_id'];
- }
- if(isset($data['title']) && !empty($data['title'])){
- array_push($where,['title','like','%'.$data['title'].'%']);
- }
- $research_topic = ResearchTopic::whereIn('column_id', $column_arr)
- ->where($where)
- ->select('id', 'title', 'keyword', 'description','province_id','city_id','county_id')
- ->paginate($data['page_size'], ['*'], 'page', $data['page']);
- if (empty($research_topic->items())) {
- return Result::error("暂无相关研究主题信息", 0);
- }
- $result = [
- 'rows' => $research_topic->items(),
- 'count' => $research_topic->total(),
- ];
- return Result::success($result);
- }
- }
|