1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692 |
- <?php
- namespace App\JsonRpc;
- use App\Model\Article;
- use App\Model\ArticleData;
- use App\Model\Category;
- use App\Model\Website;
- use App\Model\WebsiteCategory;
- use App\Model\Good;
- use Hyperf\DbConnection\Db;
- use Hyperf\RpcServer\Annotation\RpcService;
- use App\Tools\Result;
- use App\Model\ArticleSurvey;
- use App\Model\District;
- use App\Tools\buildMenuTree;
- use App\Model\Book;
- use App\Model\JobHunting;
- use App\Model\JobRecruiting;
- use App\Model\JobPosition;
- use App\Model\JobIndustry;
- use App\Model\JobEnum;
- use App\Model\JobCompany;
- use App\Model\JobNature;
- use App\Model\User;
- use App\Model\JobApply;
- use App\Model\JobRemuse;
- #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
- class NewsService implements NewsServiceInterface
- {
- /**
- * 获取导航池列表
- * @param array $data
- * @return array
- */
- public function getCategoryList(array $data): array
- {
- $where = [];
- if(isset($data['name']) && $data['name']){
- array_push($where, ['category.name','like','%'.$data['name'].'%']);
- }
- if(isset($data['department_id']) && $data['department_id']){
- array_push($where, ['category.department_id','=',$data['department_id']]);
- }
- if(isset($data['city_id']) && $data['city_id']){
- array_push($where, ['category.city_id','=',$data['city_id']]);
- }
- $rep = Category::where($where)
- ->leftJoin('district','category.city_id','district.id')
- ->leftJoin('department','category.department_id','department.id')
- ->select("category.*","district.name as city_name","department.name as department_name")
- ->limit($data['pageSize'])->orderBy("category.sort","desc")->orderByDesc('category.updated_at')->offset(($data['page']-1)*$data['pageSize'])->get();
- $count = Category::where($where)->count();
- $data = [
- 'rows'=>$rep->toArray(),
- 'count'=>$count
- ];
- if(empty($rep->toArray())){
- return Result::error("没有导航池数据");
- }
- return Result::success($data);
- }
- /**
- * @param array $data
- * @return array
- */
- public function categoryList(array $data): array
- {
- $where[] = [
- 'pid','=',$data['pid']
- ];
- if(isset($data['name'])){
- array_push($where, ['category.name','like','%'.$data['name'].'%']);
- }
- var_dump($where);
- $result = Category::where($where)->select('category.*','category.id as category_id')->get();
- if(empty($result)){
- return Result::error("没有栏目数据");
- }
- return Result::success($result);
- }
- /**
- * @param array $data
- * @return array
- */
- public function addCategory(array $data): array
- {
- $id = Category::insertGetId($data);
- if(empty($id)){
- return Result::error("添加失败");
- }
- return Result::success(['id'=>$id]);
- }
- /**
- * @param array $data
- * @return array
- */
- public function delCategory(array $data): array
- {
- $categoryList = Category::where(['pid'=>$data['id']])->get();
- var_dump("分类列表:",$data,$categoryList);
- if($categoryList->toArray()){
- return Result::error("分类下面有子分类不能删除");
- }
- $articleList = Article::where(['catid'=>$data['id']])->get();
- var_dump("文章列表:",$articleList);
- if($articleList->toArray()){
- return Result::error("分类下面有资讯不能删除");
- }
- $result = Category::where($data)->delete();
- if(!$result){
- return Result::error("删除失败");
- }
- return Result::success($result);
- }
- /**
- * @param array $data
- * @return array
- */
- public function updateCategory(array $data): array
- {
- $where = [
- 'id'=>$data['id']
- ];
- $result = Category::where($where)->update($data);
- if($result){
- return Result::success($result);
- }else{
- return Result::error("更新失败");
- }
- }
- /**
- * 获取导航池信息
- * @param array $data
- * @return array
- */
- public function getCategoryInfo(array $data): array
- {
- $where = [
- 'id'=>$data['id']
- ];
- $result = Category::where($where)->first();
- if($result){
- return Result::success($result);
- }else{
- return Result::error("更新失败");
- }
- }
- /**
- * @param array $data
- * @return array
- */
- public function getArticleList(array $data): array
- {
- $where= [];
- if(isset($data['title']) && $data['title']){
- array_push($where,['article.title','like','%'.$data['title'].'%']);
- }
- if(isset($data['category_name']) && $data['category_name']){
- array_push($where,['category.name','like','%'.$data['category_name'].'%']);
- }
- if(isset($data['author']) && $data['author']){
- array_push($where,['article.author','=',$data['author']]);
- }
- if(isset($data['islink']) && $data['islink']!==""){
- array_push($where,['article.islink','=',$data['islink']]);
- }
- if(isset($data['status']) && $data['status']!==""){
- array_push($where,['article.status','=',$data['status']]);
- }
-
- $rep = Article::where($where)
- ->whereNotIn('article.status',[404])
- ->leftJoin('category','article.catid','category.id')
- ->select("article.*","category.name as category_name")
- ->orderBy("article.id","desc")
- ->limit($data['pageSize'])
- ->offset(($data['page']-1)*$data['pageSize'])->get();
- $count = Article::where($where)->whereNotIn('article.status',[404])
- ->leftJoin('category','article.catid','category.id')->count();
- $data = [
- 'rows'=>$rep->toArray(),
- 'count'=>$count
- ];
- if(empty($rep)){
- return Result::error("没有信息数据");
- }
- return Result::success($data);
- }
- /**
- * @param array $data
- * @return array
- */
- public function addArticle(array $data): array
- {
- Db::beginTransaction();
- try{
- $articleData = $data;
- unset($articleData['content']);
- $id = Article::insertGetId($articleData);
- $articleDataContent = [
- 'article_id'=>$id,
- 'content'=>$data['content']
- ];
- ArticleData::insertGetId($articleDataContent);
- Db::commit();
- } catch(\Throwable $ex){
- Db::rollBack();
- var_dump($ex->getMessage());
- return Result::error("创建失败",0);
- }
- return Result::success(['id'=>$id]);
- }
- /**
- * @param array $data
- * @return array
- */
- public function delArticle(array $data): array
- {
- $result = Article::where($data)->update(['status'=>404]);
- if(!$result){
- return Result::error("删除失败");
- }
- return Result::success($result);
- }
- /**
- * @param array $data
- * @return array
- */
- public function updateArticle(array $data): array
- {
- Db::beginTransaction();
- try{
- $data['cat_arr_id'] = isset($data['cat_arr_id'])?json_encode($data['cat_arr_id']):'';
- $data['tag'] = isset($data['tag'])?json_encode($data['tag']):'';
- $articleData = $data;
- unset($articleData['content']);
- unset($articleData['status_name']);
- unset($articleData['name']);
- unset($articleData['content']);
- unset($articleData['pid_arr']);
- unset($articleData['pid']);
- $id = Article::where(['id'=>$data['id']])->update($articleData);
- $articleDataContent = [
- 'content'=>$data['content']
- ];
- ArticleData::where(['article_id'=>$data['id']])->update($articleDataContent);
- } catch(\Throwable $ex){
- Db::rollBack();
- var_dump($ex->getMessage());
- return Result::error("更新失败",0);
- }
- return Result::success([]);
- }
- /**
- * 更新资讯状态
- * @param array $data
- * @return array
- */
- public function upArticleStatus(array $data):array
- {
- $result = Article::where(['id'=>$data['id']])->update($data);
- if($result){
- return Result::success();
- }else{
- return Result::error("更新状态失败",0);
- }
- }
- /**
- * 获取新闻详情
- * @param array $data
- * @return array
- */
- public function getArticleInfo(array $data): array
- {
- $where = [
- 'article.id'=>$data['id'],
- // 'article.status'=>1
- ];
- $result = Article::where($where)->leftJoin("article_data","article.id","article_data.article_id")->first();
- if(empty($result)){
- return Result::error("查询失败",0);
- }
- return Result::success($result);
- }
- /**
- * 获取头条新闻
- * @param array $data
- * @return array
- */
- public function getWebsiteArticlett(array $data): array
- {
- // return Result::success($data['website_id']);
- $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
- $category = array_values(array_unique($category->toArray()));
- $web['website_id'] = $data['website_id'];
- if ($category) {
- $where = [
- 'status' => 1,
- ];
- var_dump($data, 'data-----------------');
- // level=7 根据文章key来匹配文章
- if (isset($data['level']) && $data['level'] == 7) {
- // 根据文章id获取key
- // $data['id'] = 50142;
- 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 . '%'];
- }
- // 原始查询
- $result['level7'] = Article::where($whereL7)
- ->when(!empty($data['imgnum']), function ($query) use ($data) {
- $query->where('article.imgurl', '!=', '')
- ->select('article.*')
- ->offset($data['placeid'])
- ->limit($data['imgnum']);
- })
- ->when(!empty($data['textnum']), function ($query) use ($data) {
- $query->select('article.*')
- ->offset($data['placeid'])
- ->limit($data['textnum']);
- })
- ->orderBy('updated_at', 'desc')
- ->get();
- $result['level7'] = $this->processArticle($result['level7'],$web);
- if (empty($result)) {
- return Result::success();
- }
- return Result::success($result);
- } else {
- return Result::error("参数错误level=7,id不能为空", 0);
- }
- }
- //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
- // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
- var_dump($where, 'where-----------------');
- // 初始化基础查询
- $query = Article::where($where)
- ->whereIn("catid", $category)
- ->where(function ($query) use ($data) {
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
- ->orWhereNull("ignore_ids");
- });
- // 处理 level 相关查询条件
- $query->when($data['level'] == 5, function ($query) {
- $query->inRandomOrder()
- ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
- })->when($data['level'] == 4, function ($query) {
- $query->orderBy("article.updated_at", "desc");
- })->when(!empty($data['level']), function ($query) use ($data) {
- if ($data['level'] != 4 && $data['level'] != 5) {
- $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
- ->orderBy("article.updated_at", "desc");
- }
- });
- // 初始化结果数组
- $result = [];
- // $input = $data['website_id'];
- // 处理图片新闻查询
- if (!empty($data['imgnum'])) {
- // 原错误提示表明 cleanBindings 方法需要传入数组类型的参数,而实际传入了 null。
- // 这里克隆查询构建器,确保绑定参数为数组,避免该错误。
- $imgQuery = clone $query;
- if ($imgQuery->getBindings() === null) {
- $imgQuery->setBindings([]);
- }
- $result['img'] = $imgQuery->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')
- ->offset($data['placeid'])
- ->limit($data['imgnum'])
- ->get();
- $result['img'] = $this->processArticles( $result['img'], $web);
- }
-
- // 处理文字新闻查询
- if (!empty($data['textnum'])) {
- $textQuery = clone $query;
- $result['text'] = $textQuery
- ->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')
- ->offset($data['placeid'])
- ->limit($data['textnum'])
- ->get();
- $result['text'] = $this->processArticles($result['text'], $web);
- }
-
- if (empty($result) || count($result) == 0) {
- return Result::error("暂无头条新闻");
- }
- return Result::success($result);
- } else {
- return Result::error("本网站下暂无相关栏目", 0);
- }
- }
- /**
- * 获取模块新闻
- * @param array $data
- * @return array
- */
-
- public function getWebsiteModelArticles(array $data): array
- {
- $catid = $data['catid'];
- $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
- $category = $category->toArray();
- if (!empty($category)) {
- $where = [
- 'status' => 1,
- 'catid' => $catid,
- ];
- $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
- // 1:文字新闻;2:轮播图;3:图文;
- // 级别:0:未分类
- // 3:推荐图片
- if ($data['level'] == 1) {
- $data['level'] = 0;
- }
- $result = Article::where($where)
- ->where(function ($query) use ($data) {
- $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
- ->orWhereNull("level")
- ->orWhereRaw("level = '[]'");
- })
- ->where(function ($query) use ($data) {
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
- ->orWhereNull("ignore_ids");
- })
- ->orderBy("updated_at", "desc")
- ->offset($placeid)
- ->limit($data['pagesize'])
- ->get();
- if (empty($result)) {
- return Result::error("此栏目暂无相关新闻", 0);
- }
- } else {
- return Result::error("此网站暂无此栏目", 0);
- }
- return Result::success($result);
- }
-
- /**
- *获取新闻列表
- * @param array $data
- * @return array
- */
- public function getWebsiteArticleList(array $data): array
- {
- // return Result::success($data);
- $where[] = ['status', '=', 1];
- if (isset($data['catid']) && !empty($data['catid'])) {
- $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
- array_push($where, ['catid', '=', $data['catid']]);
- if (empty($category)) {
- return Result::error("此网站暂无此栏目", 0);
- }
- }
- // return Result::success($where);
- $rep = Article::where($where)
- ->where(function ($query) use ($data) {
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
- ->orWhereNull("ignore_ids");
- })
- ->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")
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get();
- $web['website_id'] = $data['website_id'];
- $rep = $this->processArticles($rep,$web);
- $count = Article::where($where)
- ->where(function ($query) use ($data) {
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
- ->orWhereNull("ignore_ids");
- })->count();
- $data = [
- 'rows' => $rep->toArray(),
- '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")
- ->where(function ($query) use ($data) {
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
- ->orWhereNull("ignore_ids");
- })
- ->first();
- if(empty($result)){
- return Result::error("暂无此新闻!",0);
- }
- $category = WebsiteCategory::where('website_id',$data['website_id'])->where(['category_id'=>$result['catid']])->first();
- if(empty($category)){
- return Result::error("查询失败",0);
- }
- $result['category_id'] = $category['category_id'];
- $result['cat_name'] = $category['alias'];
- 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("参数必填!");
- }
- /**
- * 后端-获取网站调查问卷列表
- * @param array $data
- * @return array
- */
- public function getSurveyList(array $data): array
- {
- $where = [];
- if(isset($data['survey_name']) &&!empty($data['survey_name'])){
- array_push($where,['survey_name','like','%'.$data['survey_name'].'%']);
- }
- if(isset($data['survey_type']) && $data['survey_type'] != null){
- array_push($where,['survey_type','=',$data['survey_type']]);
- }
- if(isset($data['is_survey']) && $data['is_survey'] != null){
- array_push($where,['is_survey','=',$data['is_survey']]);
- }
- // return Result::success($where);
-
- if (!empty($where)) {
- $query = Article::where($where)->where(function ($q) {
- $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
- });
- } else {
- $query = Article::where(function ($q) {
- $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
- });
- }
-
- $count = $query->count();
- $survey = $query->orderByDesc('id')
- ->limit($data['pageSize'])
- ->offset(($data['page']-1)*$data['pageSize'])
- ->get();
- if(empty($survey->toArray())){
- return Result::error("暂无调查问卷!",0);
- }
- $result = [
- 'rows'=>$survey,
- 'count'=>$count
- ];
- return Result::success($result);
- }
- /**
- * 后端-获取网站调查问卷详情
- * @param array $data
- * @return array
- */
- public function getSurveyInfo(array $data): array
- {
- if(isset($data['sur_id']) &&!empty($data['sur_id'])){
- $where = [ 'sur_id'=>$data['sur_id']];
- $choose = ArticleSurvey::where($where)->where('is_other',0)
- ->leftJoin('article','article_survey.art_id','article.id')
- ->select('article_survey.*','article.survey_type')
- ->get()->all();
- if(empty($choose)){
- return Result::error("此调查问卷不存在",0);
- }
- $resultsArray = array_column($choose, 'results');
- $total = array_sum($resultsArray);
- $other = ArticleSurvey::where($where)->where('is_other',1)->where('other_id',0)->first();
- $others = ArticleSurvey::where($where)->where('is_other',1)->where('other_id','!=',0)->orderByDesc('created_at')->get()->all();
- // $total = 0;
- if(!empty($other)){
- $total = $total + $other['results'];
- $other['choice_name'] ='(其他)';
- if(!empty($others)){
- $other['hasChildren'] = true;
- // array_push($other,['hasChildren','=',true]);
- $other['children'] = $others;
- $other_choices = [$other->toArray()];
- $mer_choice = array_merge($choose,$other_choices);
- $value_choice = array_values($mer_choice);
- }
- else{
- // return Result::error('1111');
- $other_choices = [$other->toArray()];
- $other_choices = array_merge($choose,$other_choices);
- $value_choice = array_values($other_choices);
- // return Result::success($result);
- }
- }else{
- $value_choice = $choose;
- }
- $result = [
- 'choose'=>$value_choice,
- 'total'=>$total
- ];
- }
- return Result::success($result);
- }
- /**
- * 前端-搜索新闻列表
- * @param array $data
- * @return array
- */
- public function selectWebsiteArticle(array $data): array
- {
- $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
- $query = Article::where('status', 1)
- ->whereIn('catid', $category)
- ->where(function ($query) use ($data) {
- $query->where(function ($subQuery) use ($data) {
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
- })->orWhereNull("ignore_ids");
- });
- // return Result::success($all_articles);
- if (isset($data['cityid']) && !empty($data['cityid'])) {
- $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
- }
- if (isset($data['department_id']) && !empty($data['department_id'])) {
- $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
- }
- if (isset($data['keyword']) && !empty($data['keyword'])) {
- $query->where('title', 'like', '%' . $data['keyword'] . '%');
- }
- // 计算总数
- $count = $query->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',)
- ->orderBy("updated_at", "desc")
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get();
- $web['website_id'] = $data['website_id'];
- $articles = $this->processArticles($articles,$web);
- if (empty($articles)) {
- return Result::error("没有符合条件的资讯数据");
- }
- $result = [
- 'rows' => $articles,
- 'count' => $count,
- ];
- return Result::success($result);
- }
-
- /**
- * 模块新闻加强版
- * @param array $data
- * @return array
- */
- public function getWebsiteCatidArticle(array $data): array
- {
- $where = [
- 'website_category.category_id' => $data['catid'],
- 'website_category.website_id' => $data['website_id'],
- ];
- if(isset($data['child_catnum']) && !empty($data['child_catnum'])){
- $child_catnum = $data['child_catnum']?? 1;
- $category['child'] = WebsiteCategory::where('pid',$data['catid'])->where('website_id',$data['website_id'])->select('category_id','alias')->limit($child_catnum)->get()->toArray();
- $childCategoryIds = array_column($category['child'], 'category_id');
- if(empty($childCategoryIds)){
- return Result::error("暂无子栏目",0);
- }
- $imgArticles = [];
- $textArticles = [];
- if(isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum']!=0){
- // 初始化子分类图片新闻和文字新闻数组
-
- // 查询所有子级栏目的图文新闻
- $imgArticles = Article::where('catid', $childCategoryIds[0])
- ->where(function ($query) use ($data) {
- $query->where(function ($subQuery) use ($data) {
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
- })->orWhereNull("ignore_ids");
- })
- ->where('status', 1)
- ->where('imgurl', '!=', '')
- ->select('*')
- ->orderBy('updated_at', 'desc')
- ->limit($data['child_imgnum'])
- ->get();
- }
- if( isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum']!=0){
- // 查询所有子级栏目的文字新闻
- $textArticles = Article::where('catid', $childCategoryIds[0])
- ->where('status', 1)
- ->where(function ($query) use ($data) {
- $query->where(function ($subQuery) use ($data) {
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
- })->orWhereNull("ignore_ids");
- })
- ->select('*')
- ->orderBy('updated_at', 'desc')
- ->limit($data['child_textnum'])
- ->get();
- }
- // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
- $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
- $child['img'] = $imgArticles? $imgArticles->where('catid', $child['category_id']) : [];
- $child['text'] = $textArticles? $textArticles->where('catid', $child['category_id']) : [];
- return $child;
- }, $category['child']);
-
- }
- // }
- if (isset($data['img_num']) && !empty($data['img_num'])) {
- $category['img'] = WebsiteCategory::where($where)
- ->leftJoin('article', 'article.catid', 'website_category.category_id')
- ->where('article.status', 1)
- ->where('article.imgurl', '!=', '')
- ->select('article.*','website_category.category_id','website_category.alias')
- ->orderBy('article.updated_at', 'desc')
- ->limit($data['img_num'])
- ->get();
- }
- if (isset($data['text_num']) && !empty($data['text_num'])) {
- $category['text'] = WebsiteCategory::where($where)
- ->leftJoin('article', 'article.catid', 'website_category.category_id')
- ->where('article.status', 1)
- ->select('article.*','website_category.category_id','website_category.alias')
- ->orderBy('article.updated_at', 'desc')
- ->limit($data['text_num'])
- ->get();
- }
- // $category = $category->get();
-
- if(empty($category)){
- return Result::error("查询失败", 0);
- }
- return Result::success($category);
- }
- /**
- * 模块新闻加强plus版
- * @param array $data
- * @return array
- */
- public function getWebsiteAllArticle(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']!= "" ) {
- $count = explode(',', $item['parent']);
- if(count($count)!=3){
- return Result::error("父级栏目:缺少必需参数错误",0);
- }
- list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
- $website = [
- 'website_id' => $input['website_id'],
- ];
- // 查询栏目名称
- $categroy = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin','type']);
- // 查询图片新闻
- if(isset($parentImgNum) && $parentImgNum!=0 && !empty($categroy)){
- $imgArticles = Article::where('article.status', 1)
- ->where(function($query) use ($parentCatId) {
- $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
- ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
- })
- ->where(function ($query) use ($website) {
- $query->where(function ($subQuery) use ($website) {
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0")
- ->orWhereNull("ignore_ids");
- });
- })
- ->where('imgurl', '!=', '')
- ->leftJoin('website_category', function($join) use ($website) {
- $join->on('article.catid', '=', 'website_category.category_id')
- ->where('website_category.website_id', '=', $website['website_id']);
- })
- ->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','website_category.alias as category_name',
- )
- ->orderBy('updated_at', 'desc')
- ->limit($parentImgNum)
- ->get();
- //调取封装路由的方法,处理新闻路由
- if(!empty($imgArticles)){
- $imgArticles = $this->processArticles($imgArticles , $website);
- }
- }
- // 查询文字新闻
- if(isset($parentTextNum) && $parentTextNum!=0 && !empty($categroy)){
- $textArticles = [];
- $textArticles = Article::where('article.status', 1)
- ->where(function($query) use ($parentCatId) {
- $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
- ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
- })
- ->where(function ($query) use ($website) {
- $query->where(function ($subQuery) use ($website) {
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0")
- ->orWhereNull("ignore_ids");
- });
- })
- ->leftJoin('website_category', function($join) use ($website) {
- $join->on('article.catid', '=', 'website_category.category_id')
- ->where('website_category.website_id', '=', $website['website_id']);
- })
- ->select(
- 'article.id','article.title','article.author','article.updated_at','article.cat_arr_id',
- 'article.introduce','article.islink','article.linkurl','article.copyfrom',
- 'article.catid','website_category.alias as category_name',
- )
- ->orderBy('updated_at', 'desc')
- ->limit($parentTextNum)
- ->get();
- if(!empty($textArticles)){
- $textArticles = $this->processArticles($textArticles , $website);
- }
- }
- }
- $resultItem = [
- 'alias' => $categroy ? $categroy->alias : null,
- 'category_id' => $categroy ? $categroy->category_id : null,
- 'pinyin' => $categroy ? $categroy->aLIas_pinyin : null,
- 'imgnum' => $imgArticles ?? [],
- 'textnum' => $textArticles ?? [],
- ];
- // 子级栏目
- if(isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != ""){
- $count = explode(',', $item['child']);
- if(count($count)!=3){
- return Result::error("子级栏目:缺少必需参数错误",0);
- }
- list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
- $childCategory = WebsiteCategory::where($website)
- ->where("category_id", $childCatId)
- ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($childCatId)."') = 1")
- ->first(['alias', 'category_id','aLIas_pinyin','pid','category_arr_id as cat_arr_id']);
- if (!empty($childCategory)) {
- $childCategory = $this->processArticles($childCategory, $website);
- // 查询此层级的所有子栏目
- $all_childcat = WebsiteCategory::where($website)
- ->where("pid", $childCategory['pid'])
- // ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($childCatId)."') = 1")
- ->get(['alias', 'category_id','aLIas_pinyin','pid','category_arr_id as cat_arr_id']);
- $all_childcat = $this->processArticles($all_childcat, $website);
- // 查询子栏目图片新闻
- if( isset($childImgNum) && $childImgNum!=0 ){
- $childImgArticles = Article::where(function($query) use ($childCatId) {
- $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$childCatId\"')")
- ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$childCatId')");
- })
- ->where('status', 1)
- ->where(function ($query) use ($website) {
- $query->where(function ($subQuery) use ($website) {
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
- })->orWhereNull("ignore_ids");
- })
- ->select('article.id','article.title','article.imgurl','article.author',
- 'article.updated_at','article.introduce','article.islink','article.linkurl',
- 'article.catid','article.cat_arr_id','article.copyfrom',)
- ->where('imgurl', '!=', '')
- ->orderBy('updated_at', 'desc')
- ->limit($childImgNum)
- ->get();
- $childImgArticles = $this->processArticles($childImgArticles, $website);
- }
- // 查询子栏目文字新闻
- if( isset($childTextNum) && $childTextNum!=0 ){
- $childTextArticles = Article::where(function($query) use ($childCatId) {
- $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$childCatId\"')")
- ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$childCatId')");
- })
- ->where('status', 1)
- ->where(function ($query) use ($website) {
- $query->where(function ($subQuery) use ($website) {
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
- })->orWhereNull("ignore_ids");
- })
- ->select('article.id','article.title','article.author','article.updated_at','article.introduce',
- 'article.islink','article.linkurl','article.catid','article.cat_arr_id','article.copyfrom',)
- ->orderBy('updated_at', 'desc')
- ->limit($childTextNum)
- ->get();
- $childTextArticles = $this->processArticles($childTextArticles, $website);
- }
- }
- $resultItem['child'] = [
- 'alias' => $childCategory ? $childCategory->alias : null,
- 'category_id' => $childCategory ? $childCategory->category_id : null,
- 'pinyin' => $childCategory ? $childCategory->pinyin : null,
- 'all_childcat' => $all_childcat ?? [],
- 'imgnum' => $childImgArticles ?? [],
- 'textnum' => $childTextArticles ?? [],
- ];
- }else{
- $resultItem['child'] = [];
- }
- return $resultItem;
- }, $data);
- return Result::success($result);
- // return Result::success($data);
- }
- /**
- * 乡村网-获取特殊新闻模块
- * @param array $data
- * @return array
- */
- public function getWebsiteArticles(array $data): array
- {
- $input['id'] = $data['id'];
- $input['website_id'] = $data['website_id'];
- $data = json_decode($input['id'], true);
- // 使用 array_map 处理每个元素
- $result = array_map(function ($item) use ($input) {
- 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']);
- $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
- if(empty($category)){
- $imgArticles = [];
- $textArticles = [];
- // return Result::error("暂无此栏目",0);
- }else{
- $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
- $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin.'/' : null;
- // return Result::success($website);
- // 查询图片新闻
- // 合并查询条件
- $baseQuery = Article::where(function ($query) use ($website) {
- $query->where(function ($subQuery) use ($website) {
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
- })->orWhereNull("ignore_ids");
- })
- ->where('website_category.website_id', $website['website_id'])
- ->where('article.status', 1)
- ->leftJoin('website_category', 'website_category.category_id', 'article.catid');
-
- // 查询文字新闻
- $textArticles = clone $baseQuery;
- $textArticles = $textArticles->whereIn('catid',$child_category)
- ->select(
- 'article.id',
- 'article.title',
- // 'article.imgurl',
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- 'website_category.category_id',
- 'website_category.alias',
- 'website_category.aLIas_pinyin'
- )
- ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
- ->orderBy('article.updated_at', 'desc')
- ->limit($parentTextNum)
- ->get()
- ->all();
- if(empty($textArticles)){
- $textArticles = clone $baseQuery;
- $textArticles = $textArticles->where('catid',$parentCatId)
- ->select(
- 'article.id',
- 'article.title',
- // 'article.imgurl',
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- 'website_category.category_id',
- 'website_category.alias',
- 'website_category.aLIas_pinyin'
- )
- ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
- ->orderBy('article.updated_at', 'desc')
- ->limit($parentTextNum)
- ->get()
- ->all();
- }
- // 查询图片新闻
- $imgArticles = clone $baseQuery;
- $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid',$child_category)
- ->select(
- 'article.id',
- 'article.title',
- 'article.imgurl',
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- 'website_category.category_id',
- 'website_category.alias',
- 'website_category.aLIas_pinyin'
- )
- ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
- ->orderBy('article.updated_at', 'desc')
- ->limit($parentImgNum)
- ->get()
- ->all();
- if(empty($imgArticles)){
- $imgArticles = clone $baseQuery;
- $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid',$parentCatId)
- ->select(
- 'article.id',
- 'article.title',
- 'article.imgurl',
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- 'website_category.category_id',
- 'website_category.alias',
- 'website_category.aLIas_pinyin'
- )
- ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
- ->orderBy('article.updated_at', 'desc')
- ->limit($parentImgNum)
- ->get()
- ->all();
- }
-
- }
- $resultItem = [
- 'alias' => $category ? $category->alias : null,
- 'category_id' => $parentCatId,
- 'pinyin' => $pinyin ? $pinyin : null,
- 'imgnum' => $imgArticles ?? [],
- 'textnum' => $textArticles ?? [],
-
- ];
- return $resultItem;
- }, $data);
- return Result::success($result);
- }
- // 封装处理商品的路由问题
- 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);
- $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;
- });
- }
- /**
- * 获取商城首页-根据栏目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')
- ->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');
- $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 processArticles($articles, $data) {
- // 检查 $articles 是否为数组或可迭代对象
- if (is_array($articles) || is_iterable($articles) &&!empty($articles)) {
- return $articles->map(function ($article) use ($data) {
- $catid = $article->cat_arr_id?? '';
- $level = json_decode($catid, true);
- if (!is_array($level)) {
- return $article;
- } else {
- $level = array_map('intval', $level);
- }
- $pinyin = WebsiteCategory::whereIn('category_id', $level)
- ->where($data)
- ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
- ->pluck('aLIas_pinyin')
- ->implode('/');
- $article->pinyin = $pinyin ?? '';
- return $article;
- });
- } else {
- // 若 $articles 不是数组或可迭代对象,直接处理单条数据
- $catid = $articles->cat_arr_id?? '';
- $level = json_decode($catid, true);
- if (!is_array($level)) {
- return $articles;
- } else {
- $level = array_map('intval', $level);
- }
- $pinyin = WebsiteCategory::whereIn('category_id', $level)
- ->where($data)
- ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
- ->pluck('aLIas_pinyin')
- ->implode('/');
- $articles->pinyin = $pinyin ?? '';
- return $articles;
- }
- }
- // 封装处理由问题
- 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', '!=', '')
- ->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)
- ->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', '!=', '')
- ->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)
- ->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);
- }
- /**
- * 尝试
- * @param array $data
- * @return array
- * */
- public function test(array $data): array
- {
- $input['id'] = $data['id'];
- $input['website_id'] = $data['website_id'];
- // 将 JSON 字符串转换为 PHP 数组
- $data = json_decode($input['id'], true);
- $result = [];
- $article = $data;
- $result = array_map(function ($item) use ($input) {
- $website = [
- 'website_id' => $input['website_id'],
- ];
- list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
- $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
- $parent = [
- 0 => $category['category_id'] ?? [],
- 1 => $parentImgNum?? [],
- 2 => $parentTextNum?? [],
- ];
- list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
- $child = [];
-
- $resultItem = [
- // 'alias' => $parent_alias ?? '',
- 'category_id' => $parentCatId ?? 0,
- 'pinyin' => $parentImgNum ?? null,
- 'imgnum' => $parentTextNum ?? [],
- // 'textnum' => $textArticles ?? [],
- ]; return $parent;
- }, $data);
- 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;
- });
- }
- /**
- * 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.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')
- ->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.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')
- ->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']]);
- }
- $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.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')
- ->orderBy('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',$data['zw_id']]);
- }
- if(isset($data['jtzw_id']) &&!empty($data['jtzw_id'])){
- array_push($hunt_where, ['job_name_get',$data['jtzw_id']]);
- }
- if(isset($data['hy_id']) && !empty($data['hy_id'])){
- array_push($hunt_where, ['industry',$data['hy_id']]);
- }
- $query = JobHunting::where('status', 2)
- ->where('job_hunting.website_id', $data['website_id'])
- ->where($hunt_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_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('id','sexy','experience','origin','industry','name','job','job_name_get','city_arr_id','cat_arr_id','created_at','updated_at')
- ->orderBy('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')
- ->orderBy('updated_at', 'desc')
- ->limit($data['pageSize'])
- ->get();
- if(empty($result)){
- return Result::error("暂无相关职位信息", 0);
- }
- return Result::success($result);
- }
- /**
- * c端 - 验证路由
- * @param array $data
- * @return array
- */
- public function checkWebsiteRoute(array $data): array
- {
- $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
- if(empty($web)){
- return Result::error("该网站不存在", 0);
- }
- // 验证栏目路由
- $last_category = WebsiteCategory::where('website_id', $data['website_id'])
- ->where('aLIas_pinyin', $data['last_route'])
- ->first();
- if(empty($last_category)){
- return Result::error("该栏目不存在", 0);
- }
- 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(['cat_arr_id']);
- 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 '审核状态,1待审核2已审核3已拒绝',
- $article = JobRecruiting::where('website_id', $data['website_id'])
- ->where('status', 1)
- ->where('id', $data['id'])
- ->first(['cat_arr_id']);
- if(empty($article)){
- $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;
- default:
- return Result::error("该数据不存在", 0);
- break;
- }
- $catid = json_decode($article['cat_arr_id'], true);
- if(empty($catid)){
- return Result::error("该数据不存在", 0);
- }
- $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
- ->orderByRaw('FIELD(category_id, '. implode(',', $catid). ')')
- ->whereIn('category_id', $catid)
- ->pluck('aLIas_pinyin')
- ->implode('/');
-
- }
- if($last_category['pid']!=0){
- $cat_arr = json_decode($last_category['category_arr_id'], true);
- $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
- ->orderByRaw('FIELD(category_id, '. implode(',', $cat_arr). ')')
- ->whereIn('category_id', $cat_arr)
- ->pluck('aLIas_pinyin')
- ->implode('/');
- }else{
- $pinyin = $last_category['aLIas_pinyin'];
- }
- if(empty($pinyin) || $pinyin!=$data['all_route']){
- return Result::error('非法路径!');
- }else{
- return Result::success($pinyin);
- }
- }
-
- }
|