1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653 |
- <?php
- namespace App\JsonRpc;
- use App\Model\Article;
- use App\Model\ArticleData;
- use App\Model\Category;
- use App\Model\WebsiteCategory;
- use App\Model\ArticleSurvey;
- use App\Model\jobHunting;
- use App\Model\District;
- use App\Model\Good;
- use App\Model\JobCompany;
- use App\Model\Website;
- use App\Model\JobRecruiting;
- use App\Model\JobIndustry;
- use App\Model\JobPosition;
- use App\Model\JobNature;
- use App\Model\JobEnum;
- use App\Model\User;
- use App\Model\UserRole;
- use App\Model\News;
- use App\Model\UserInfo;
- use App\Model\WebsiteGroup;
- ;
- use Hyperf\DbConnection\Db;
- use Hyperf\RpcServer\Annotation\RpcService;
- use App\Tools\Result;
- use Directory;
- use Ramsey\Uuid\Uuid;
- use Hyperf\Utils\Random;
- use Fukuball\Jieba\Jieba;
- use Fukuball\Jieba\Finalseg;
- use App\Model\ChatRecords;
- use Hyperf\Utils\Collection;
- use function Hyperf\Support\retry;
- #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
- class NewsService implements NewsServiceInterface
- {
- /**
- * 获取导航池列表
- * @param array $data
- * @return array
- */
- public function getCategoryList(array $data): array
- {
- $page = (int) $data['page'] ?? 1;
- $perPage = (int) $data['pageSize'] ?? 10;
- $search = $data['name'] ?? '';
- // 查找所有匹配的分类
- $matchedCategories = $this->findMatchedCategories($search);
- // 查找所有匹配分类的父级分类
- $allRequiredCategories = $this->findAllParents($matchedCategories);
- // 提取一级分类
- $topLevelCategories = [];
- foreach ($allRequiredCategories as $category) {
- if ($category->pid === 0) {
- $topLevelCategories[] = $category;
- }
- }
- // 分页处理
- $offset = ($page - 1) * $perPage;
- $paginatedTopLevelCategories = array_slice($topLevelCategories, $offset, $perPage);
- $categoryTree = [];
- foreach ($paginatedTopLevelCategories as $category) {
- $categoryTree[] = $this->buildCategoryTree($category, $allRequiredCategories);
- }
- $return = [
- 'rows' => $categoryTree,
- 'total' => count($topLevelCategories),
- ];
- return Result::success($return);
- }
- private function findMatchedCategories($search)
- {
- if ($search) {
- return Category::where('name', 'like', "%{$search}%")
- ->orderBy('updated_at', 'desc')
- ->get();
- }
- return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
- ->get();
- }
- private function findAllParents($categories)
- {
- $allCategories = [];
- foreach ($categories as $category) {
- $parentId = $category->pid;
- while ($parentId > 0) {
- $parent = Category::find($parentId);
- if ($parent) {
- $allCategories[$parent->id] = $parent;
- $parentId = $parent->pid;
- } else {
- break;
- }
- }
- $allCategories[$category->id] = $category;
- }
- return array_values($allCategories);
- }
- private function buildCategoryTree($category, $allRequiredCategories)
- {
- $categoryData = $category->toArray();
- $children = [];
- foreach ($allRequiredCategories as $c) {
- if ($c->pid === $category->id) {
- $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
- }
- }
- if (!empty($children)) {
- $categoryData['children'] = $children;
- }
- return $categoryData;
- }
- public function myCategoryList(array $data): array
- {
- $sszq = $data['sszq'] ?? '';
- unset($data['sszq']);
- //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
- $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
- $where[] = [
- 'pid', '=', $data['pid'],
- ];
- if (isset($data['name'])) {
- array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
- }
- var_dump($where);
- //根据分类id,从category表中取出分类信息
- $result = Category::where($where)
- ->whereIn('category.id', $catorytids)
- ->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 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
- {
- if (isset($data['id'])) {
- unset($data['id']);
- }
- $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
- {
- Db::beginTransaction();
- try {
- $categoryList = Category::where(['pid' => $data['id']])->get();
- if ($categoryList->toArray()) {
- Db::rollBack();
- return Result::error("分类下面有子分类不能删除");
- }
- $articleList = Article::where(['catid' => $data['id']])->get();
- if ($articleList->toArray()) {
- Db::rollBack();
- return Result::error("分类下面有资讯不能删除");
- }
- $result = Category::where($data)->delete();
- WebsiteCategory::where(['category_id' => $data['id']])->delete();
- if (!$result) {
- return Result::error("删除失败");
- }
- return Result::success($result);
- Db::commit();
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error("删除失败");
- }
- }
- /**
- * @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
- {
- //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
- $type_id = $data['type_id'];
- unset($data['type_id']);
- $user_id = $data['user_id'];
- unset($data['user_id']);
- $where = [];
- $status1 = [];
- if (isset($data['id']) && $data['id']) {
- array_push($where, ['article.id', '=', $data['id']]);
- }
- 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']]);
- }
- if (isset($data['status1'])) {
- $status1 = json_decode(($data['status1']));
- }
- //不是管理员展示个人数据;
- if ($type_id != 10000) {
- $where[] = ['article.admin_user_id', '=', $user_id];
- }
- $rep = Article::where($where)
- ->whereNotIn('article.status', [404])
- ->when($status1, function ($query) use ($status1) {
- if (isset($status1) && $status1) {
- $query->whereIn('article.status', $status1);
- }
- })
- ->leftJoin('category', 'article.catid', 'category.id')
- ->select("article.*", "category.name as category_name")
- ->orderBy("article.updated_at", "desc")
- ->limit($data['pageSize'])
- ->offset(($data['page'] - 1) * $data['pageSize'])->get();
- $count = Article::where($where)->whereNotIn('article.status', [404])
- ->when($status1, function ($query) use ($status1) {
- if (isset($status1) && $status1) {
- $query->whereIn('article.status', $status1);
- }
- })
- ->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
- {
- var_dump($data, '----------12-----------1');
- unset($data['user_type']);
- unset($data['nav_add_pool_id']);
- // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
- Db::beginTransaction();
- try {
- //处理投票
- $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
- $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
- $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
- $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
- unset($data['is_survey']);
- unset($data['survey_name']);
- unset($data['suvey_array']);
- // unset($data['website_id']);
- // unset($data['web_site_id']);
- // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
- if ($data['hits'] == '') {
- $data['hits'] = 0;
- }
- if ($data['is_original'] == '') {
- $data['is_original'] = 0;
- }
- if ($data['status'] == '') {
- $data['status'] = 0;
- }
- $articleData = $data;
- unset($articleData['content']);
- //自动处理缩略图、关键字、描述
- if ($articleData['imgurl'] == '') {
- //如果没有图,设置level=0
- $levelArr = json_decode($articleData['level'], true);
- var_dump($levelArr, '----------levelArr-----------1');
- //content中提取图片第一个图,正则提取
- $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
- preg_match_all($reg, $data['content'], $matches);
- if (isset($matches[1][0])) {
- //截取varchar240
- $articleData['imgurl'] = substr($matches[1][0], 0, 240);
- //如果有图,设置level=3
- if (!in_array(3, $levelArr)) {$levelArr[] = 3;}
- $articleData['level'] = json_encode($levelArr);
- } else {
- if (!in_array(0, $levelArr)) {
- $levelArr[] = 0;
- }
- $articleData['level'] = json_encode($levelArr);
- }
- }
- var_dump($articleData['level'], '----------$articleData[level]----------1');
- if ($articleData['keyword'] == '') {
- //提取标题+内容中的关键词
- $articleData['keyword'] = $data['title'];
- // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
- Jieba::init(); // 初始化 jieba-php
- Finalseg::init();
- $segList = Jieba::cut($articleData['keyword']);
- $segList1 = array_slice($segList, 0, 8);
- $articleData['keyword'] = implode(',', $segList1);
- }
- if ($articleData['introduce'] == '') {
- //提取内容中的描述
- $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
- }
- $id = Article::insertGetId($articleData);
- $articleDataContent = [
- 'article_id' => $id,
- 'content' => $data['content'],
- ];
- ArticleData::insertGetId($articleDataContent);
- //处理投票
- if ($is_survey == 1) {
- //生成年月日时分秒+8位随机数
- $uuid = date('YmdHis') . rand(10000000, 99999999);
- var_dump($suvey_array, 'suvey_array________');
- $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
- var_dump($suveys_array, '---------------------1');
- var_dump($suvey_array, '---------------------2');
- $suvey_data = [];
- foreach ($suveys_array as $key => $value) {
- if ($value == '') {
- continue;
- }
- if (is_array($value)) {
- $suvey_data[] = [
- 'sur_id' => $uuid,
- 'art_id' => $id,
- 'website_id' => $website_id ?? 2,
- 'survey_name' => $survey_name,
- 'choice_name' => $value[1],
- 'is_other' => 1,
- 'other_id' => 0,
- 'results' => 0,
- ];
- } else {
- $suvey_data[] = [
- 'sur_id' => $uuid,
- 'art_id' => $id,
- 'website_id' => $website_id ?? 2,
- 'survey_name' => $survey_name,
- 'choice_name' => $value,
- 'is_other' => 0,
- 'other_id' => 0,
- 'results' => 0,
- ];
- }
- if (empty($suvey_data)) {
- throw new \Exception("投票数据为空");
- }
- }
- $result = ArticleSurvey::insert($suvey_data);
- if (!$result) {
- throw new \Exception("投票失败,ArticleSurvey插入失败");
- }
- $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
- if (!$result) {
- throw new \Exception("投票失败,更新主表失败");
- }
- }
- Db::commit();
- return Result::success(['id' => $id]);
- } catch (\Throwable $ex) {
- Db::rollBack();
- var_dump($ex->getMessage());
- return Result::error("创建失败", 0);
- }
- }
- /**
- * @param array $data
- * @return array
- */
- public function delArticle(array $data): array
- {
- $result = Article::where($data)->delete();
- //survey投票删除
- articleSurvey::where(['art_id' => $data['id']])->delete();
- if (!$result) {
- return Result::error("删除失败");
- }
- return Result::success($result);
- }
- /**
- * @param array $data
- * @return array
- */
- public function updateArticle(array $data): array
- {
- var_dump($data, '----------12-----------1');
- Db::beginTransaction();
- unset($data['user_type']);
- // unset($data['web_site_id']);
- unset($data['nav_add_pool_id']);
- try {
- //处理投票
- $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
- $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
- $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
- $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
- unset($data['is_survey']);
- unset($data['survey_name']);
- unset($data['suvey_array']);
- unset($data['website_id']);
- $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
- if ($data['hits'] == '') {
- $data['hits'] = 0;
- }
- if ($data['is_original'] == '') {
- $data['is_original'] = 0;
- }
- if ($data['status'] == '') {
- $data['status'] = 0;
- }
- $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $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']);
- //自动处理缩略图、关键字、描述
- if ($articleData['imgurl'] == '') {
- //如果没有图,设置level=0
- $levelArr = json_decode($articleData['level'], true);
- var_dump($levelArr, '----------levelArr-----------1');
- //content中提取图片第一个图,正则提取
- $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
- preg_match_all($reg, $data['content'], $matches);
- if (isset($matches[1][0])) {
- //截取varchar240
- // 截取到第一个<
- $articleData['imgurl'] = $matches[1][0];
- var_dump($articleData['imgurl'], '----------imgurl-----------1');
- $pos = strpos($articleData['imgurl'], '"');
- if ($pos !== false) {
- $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
- }
- //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
- //如果有图,设置level=3
- if (!in_array(3, $levelArr)) {$levelArr[] = 3;}
- $articleData['level'] = json_encode($levelArr);
- } else {
- if (!in_array(0, $levelArr)) {
- $levelArr[] = 0;
- }
- $articleData['level'] = json_encode($levelArr);
- }
- }
- var_dump($articleData['level'], '----------$articleData[level]----------1');
- if ($articleData['keyword'] == '') {
- //提取标题+内容中的关键词
- $articleData['keyword'] = $data['title'];
- // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
- Jieba::init(); // 初始化 jieba-php
- Finalseg::init();
- $segList = Jieba::cut($articleData['keyword']);
- $segList1 = array_slice($segList, 0, 8);
- $articleData['keyword'] = implode(',', $segList1);
- }
- if ($articleData['introduce'] == '') {
- //提取内容中的描述
- $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
- }
- $id = Article::where(['id' => $data['id']])->update($articleData);
- $articleDataContent = [
- 'content' => $data['content'],
- ];
- ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
- //处理投票
- $id = $data['id'];
- $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
- var_dump($suvey_array, 'suvey_array________delete');
- //处理投票
- if ($is_survey == 1) {
- //生成年月日时分秒+8位随机数
- $uuid = date('YmdHis') . rand(10000000, 99999999);
- $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
- var_dump($suveys_array, '---------------------1');
- $suvey_data = [];
- if (is_array($suveys_array)) {
- foreach ($suveys_array as $key => $value) {
- if ($value == '') {
- continue;
- }
- if (is_array($value)) {
- $suvey_data[] = [
- 'sur_id' => $uuid,
- 'art_id' => $id,
- 'website_id' => $website_id ?? 2,
- 'survey_name' => $survey_name,
- 'choice_name' => $value[1],
- 'is_other' => 1,
- 'other_id' => 0,
- 'results' => 0,
- ];
- } else {
- $suvey_data[] = [
- 'sur_id' => $uuid,
- 'art_id' => $id,
- 'website_id' => $website_id ?? 2,
- 'survey_name' => $survey_name,
- 'choice_name' => $value,
- 'is_other' => 0,
- 'other_id' => 0,
- 'results' => 0,
- ];
- }
- if (empty($suvey_data)) {
- throw new \Exception("投票数据为空");
- }
- }
- }
- $result = ArticleSurvey::insert($suvey_data);
- if (!$result) {
- throw new \Exception("投票失败");
- }
- $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
- if (!$result) {
- throw new \Exception("投票失败");
- }
- } else {
- $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
- }
- Db::commit();
- return Result::success([]);
- } catch (\Throwable $ex) {
- Db::rollBack();
- var_dump($ex->getMessage());
- return Result::error("更新失败" . $ex->getMessage(), 0);
- }
- }
- /**
- * 更新资讯状态
- * @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();
- $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
- $info = $result;
- // var_dump($info, 'info');
- $info['survey_array'] = $articleSurvey;
- if ($result) {
- return Result::success($info);
- } else {
- return Result::error("查询失败", 0);
- }
- }
- /**
- * 获取新闻
- * @param array $data
- * @return array
- */
- public function getWebsiteArticlett(array $data): array
- {
- $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
- $category = array_values(array_unique($category->toArray()));
- $result = [];
- if ($category) {
- $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
- $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 = Article::where($whereL7)
- ->offset($placeid)
- ->limit($data['pageSize'])
- ->orderBy('updated_at', 'desc')
- ->get()
- ->map(function ($article ) use ($data) {
- $catid = $article->catid;
- $pinyin = '';
- $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
- $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
- if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
- $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
- $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
- }
- $article->pinyin = $pinyin;
- return $article;
- });
- 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-----------------');
- $result = Article::where($where)
- ->whereIn("catid", $category)
- // ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
- // ->where('website_category.website_id', $data['website_id'])
- ->where(function ($query) use ($data) {
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
- ->orWhereNull("ignore_ids");
- })
- //$data['level'] == 4 || $data['level'] == 5 查询随机
- ->when($data['level'] == 5, function ($query) {
- $query->inRandomOrder()
- //updated_at最近三十天;
- ->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");
- }
- })
- ->select('article.*')
- ->offset($placeid)
- ->limit($data['pageSize'])
- ->get()
- ->map(function ($article ) use ($data) {
- $catid = $article->catid;
- $pinyin = '';
- // $category = WebsiteCategory::whereIn('category_id', $catArrId)->where('website_category.website_id', $data['website_id'])->get()->all();
- // if ($catArrId) {
- // foreach ($catArrId as $categoryId) {
- $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
- $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
- if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
- $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
- $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
- }
- // }
- // }
- $article->pinyin = $pinyin;
- return $article;
- });
- if (empty($result)) {
- return Result::error("暂无头条新闻", 0);
- }
- 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'])) {
- if (is_array($data['catid'])) {
- $category = WebsiteCategory::where('website_id', $data['website_id'])->whereIn('category_id', $data['catid'])->pluck('category_id');
- array_push($where, ['catid', 'in', $data['catid']]);
- } else {
- $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(function ($query) use ($where) {
- foreach ($where as $condition) {
- if ($condition[1] === 'in') {
- $query->whereIn($condition[0], $condition[2]);
- } else {
- $query->where($condition[0], $condition[1], $condition[2]);
- }
- }
- })
- ->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.catid')
- ->orderBy("updated_at", "desc")
- ->limit($data['pageSize'])
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->get()
- ->map(function ($article ) use ($data) {
- $catid = $article->catid ?? 0;
- $pinyin = '';
- $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
- $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
- if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
- $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
- $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
- }
- $article->pinyin = $pinyin;
- return $article;
- });
- $count = Article::where(function ($query) use ($where) {
- foreach ($where as $condition) {
- if ($condition[1] === 'in') {
- $query->whereIn($condition[0], $condition[2]);
- } else {
- $query->where($condition[0], $condition[1], $condition[2]);
- }
- }
- })->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::leftJoin('website', 'website.id', '=', 'website_category.website_id')
- ->select('website_category.*', 'website.website_name', 'website.suffix')
- ->where('website_category.website_id', $data['website_id'])
- ->where(['website_category.category_id' => $result['catid']])
- ->first();
- if (empty($category)) {
- return Result::error("查询失败", 0);
- }
- //手动推荐文章
- $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
- $commendArticle = Article::whereIn('id', $commend_ids)
- ->where('status', 1)
- ->select('id', 'title', 'catid', 'imgurl', 'hits', 'created_at')
- ->orderBy('updated_at', 'desc')
- ->limit(5)
- ->get();
- $result['category_id'] = $category['category_id'];
- $result['cat_name'] = $category['alias'];
- $result['website_name'] = $category['website_name'] ?? "";
- $result['suffix'] = $category['suffix'] ?? "";
- $result['commendArticle'] = $commendArticle;
- 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('website_id', $data['website_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
- {
- $where = [];
- // 初始化查询构造器
- $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);
- // 检查是否存在 cityid 参数
- if (isset($data['cityid']) && !empty($data['cityid'])) {
- $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
- }
- // 检查是否存在 department_id 参数
- if (isset($data['department_id']) && !empty($data['department_id'])) {
- $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
- }
- // 检查是否存在 keyword 参数
- 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.catid',
- 'article.department_arr_id',
- 'article.city_arr_id',)
- ->orderBy("updated_at", "desc")
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get()
- ->map(function ($article ) use ($data) {
- $catid = $article->catid ?? 0;
- $pinyin = '';
- $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
- $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
- if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
- $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
- $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
- }
- $article->pinyin = $pinyin;
- return $article;
- });
- if (empty($articles)) {
- return Result::error("没有符合条件的资讯数据");
- }
- $data = [
- 'rows' => $articles,
- 'count' => $count,
- ];
- return Result::success($data);
- }
- /**
- * 模块新闻加强版
- * @param array $data
- * @return array
- */
- public function getWebsiteCatidArticle(array $data): array
- {
- // return Result::success($data);
- $where = [
- // 'category.status' => 1,
- 'website_category.category_id' => $data['catid'],
- 'website_category.website_id' => $data['website_id'],
- // 'article.status' => 1,
- ];
- // $category = WebsiteCategory::where($where);
- 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 = [];
- // return Result::success($childCategoryIds);
- 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");
- })
- // ->where(function ($query) {
- // $query->whereNull('imgurl')
- // ->orWhere('imgurl', '');
- // })
- ->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)
- // ->where(function ($query) {
- // $query->whereNull('article.imgurl')
- // ->orWhere('article.imgurl', '');
- // })
- ->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) {
- 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)) {
- $imgArticles = [];
- $textArticles = [];
- // return Result::error("暂无此栏目",0);
- }else{
- $parent_alias = $category->alias ?? '';
- $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
- // 查询图片新闻
- $imgArticles = Article::where('catid', $parentCatId)
- ->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");
- })
- ->where('imgurl', '!=', '')
- ->select(
- 'article.id',
- 'article.title',
- 'article.imgurl',
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- DB::raw("'$parent_pinyin' as pinyin") // 添加 pinyin 字段
- )
- ->orderBy('updated_at', 'desc')
- ->limit($parentImgNum)
- ->get()->all();
- // 查询文字新闻
- $textArticles = Article::where('catid', $parentCatId)
- ->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.copyfrom',
- DB::raw("'$parent_pinyin' as pinyin"))
- ->orderBy('updated_at', 'desc')
- ->limit($parentTextNum)
- ->get()->all();
- }
- $resultItem = [
- 'alias' => $parent_alias,
- 'category_id' => $parentCatId,
- 'pinyin' => $parent_pinyin,
- 'imgnum' => $imgArticles,
- 'textnum' => $textArticles,
- ];
- if (!empty($item['child']) && $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 ($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();
- $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
- if(empty($childCategoryInfo)){
- $childImgArticles = [];
- $childTextArticles = [];
- } else {
- // 查询子栏目图片新闻
- $childImgArticles = Article::where('catid', $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.copyfrom',
- DB::raw("'$child_pinyin' as pinyin"))
- ->where('imgurl', '!=', '')
- ->orderBy('updated_at', 'desc')
- ->limit($childImgNum)
- ->get()->all();
- // 查询子栏目文字新闻
- $childTextArticles = Article::where('catid', $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.copyfrom',
- 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,
- ];
- // $resultItem['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
- }
- }
- 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{
- $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");
- })
- ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "')")
- ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
- ->where('website_category.website_id', $website['website_id'])
- ->where('article.status', 1);
-
- // 查询文字新闻
- $textArticles = clone $baseQuery;
- $textArticles = $textArticles
- ->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
- ->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')
- ->where('imgurl', '!=', '')
- ->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);
- }
- /**
- *获取头条类新闻模块-合集
- * @param array $data
- * @return array
- */
- public function getWebsiteAllArticlett(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('website_id', $input['website_id'])->pluck('category_id');
- $category = array_values(array_unique($category->toArray()));
- $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
- $where = [
- 'status' => 1,
- ];
- return $category;
- }, $data); // 添加第二个参数 $data,确保 array_map 函数有两个参数
-
- return Result::success($result);
- }
- /**
- * 验证导航名称是否重复
- * @return void
- */
- public function checkCategoryName(array $data): array
- {
- $result = Category::when($data, function ($query) use ($data) {
- if (isset($data['name']) && $data['name']) {
- $query->where("name", $data['name']);
- }
- if (isset($data['id']) && $data['id']) {
- $query->where("id", "!=", $data['id']);
- }
- })->first();
- if ($result) {
- return Result::error("已存在");
- } else {
- return Result::success();
- }
- }
- //20250226 产品列表
- public function getGoodList(array $data): array
- {
- $type_id = isset($data['type_id']) ? $data['type_id'] : '';
- unset($data['type_id']);
- $user_id = isset($data['user_id']) ? $data['user_id'] : '';
- $where = [];
- if ($type_id != '10000') {
- $where = [
- 'good.user_id' => $user_id,
- ];
- }
- //类型
- if (isset($data['type_id']) && $data['type_id']) {
- $where = [
- 'type_id' => $data['type_id'],
- ];
- }
- //名称
- if (isset($data['name']) && $data['name']) {
- $where = [
- 'good.name' => $data['name'],
- ];
- }
- $where1 = [];
- //website_id
- // if (isset($data['website_id']) && $data['website_id']) {
- // $where1 = [
- // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
- // ];
- // }
- // website_name
- if (isset($data['website_name']) && $data['website_name']) {
- $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
- }
- // catid
- if (isset($data['category_name']) && $data['category_name']) {
- $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
- }
- // $result = Good::where($where)
- // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
- $result = Good::where($where)
- ->when(!empty($where1), function ($query) use ($where1) {
- return $query->where($where1);
- })
- ->leftJoin('district', 'good.city_id', '=', 'district.id')
- ->leftJoin('website', 'good.website_id', '=', 'website.id')
- ->leftJoin('category', 'good.catid', '=', 'category.id')
- ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
- ->orderBy("id", "desc")
- ->limit($data['page_size'])
- ->offset(($data['page'] - 1) * $data['page_size'])
- ->get();
- $count = Good::where($where)
- ->leftJoin('district', 'good.city_id', '=', 'district.id')
- ->leftJoin('website', 'good.website_id', '=', 'website.id')
- ->leftJoin('category', 'good.catid', '=', 'category.id')
- ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
- ->orderBy("updated_at", "desc")->count();
- $data = [
- 'rows' => $result->toArray(),
- 'count' => $count,
- ];
- if (empty($result)) {
- return Result::error("此栏目暂无相关产品", 0);
- }
- return Result::success($data);
- }
- public function getGoodInfo(array $data): array
- {
- $result = Good::where('id', $data['id'])->first();
- if (empty($result)) {
- return Result::error("此产品不存在", 0);
- }
- return Result::success($result);
- }
- public function addGood(array $data): array
- {
- // unset($data['city_arr_id']);
- // unset($data['cat_arr_id']);
- $data['city_id'] = end($data['city_arr_id']);
- $data['catid'] = end($data['cat_arr_id']);
- $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
- $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
- $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
- unset($data['imgUrl']);
- $result = Good::insert($data);
- if (empty($result)) {
- return Result::error("添加失败", 0);
- }
- return Result::success($result);
- }
- public function updateGood(array $data): array
- {
- $data['city_id'] = end($data['city_arr_id']);
- $data['catid'] = end($data['cat_arr_id']);
- $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
- $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
- $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
- //设置东八区
- date_default_timezone_set('Asia/Shanghai');
- $data['updated_at'] = date('Y-m-d H:i:s');
- $result = Good::where('id', $data['id'])->update($data);
- if (empty($result)) {
- return Result::error("更新失败", 0);
- }
- return Result::success($result);
- }
- public function delGood(array $data): array
- {
- $result = Good::where('id', $data['id'])->delete();
- if (empty($result)) {
- return Result::error("删除失败", 0);
- }
- return Result::success($result);
- }
- //20250226 产品列表
- //20250306 求职信息
- public function getJobHuntingList(array $data): array
- {
- $where = [];
- if (isset($data['username']) && !empty($data['username'])) {
- $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
- }
- $type_id = isset($data['type_id']) ? $data['type_id'] : '';
- $user_id = isset($data['user_id']) ? $data['user_id'] : '';
- unset($data['type_id']);
- if ($type_id != '10000') {
- $where[] = ['job_hunting.user_id', '=', $user_id];
- }
- $result = JobHunting::where($where)
- ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
- ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
- ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
- ->orderBy("id", "desc")
- ->limit($data['page_size'])
- ->offset(($data['page'] - 1) * $data['page_size'])
- ->get();
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- $count = JobHunting::where($where)
- ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
- ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
- ->count();
- $data = [
- 'rows' => $result->toArray(),
- 'count' => $count,
- ];
- return Result::success($data);
- }
- public function addJobHunting(array $data): array
- {
- date_default_timezone_set('Asia/Shanghai');
- unset($data['company_name']);
- unset($data['job_industry']);
- unset($data['job_name']);
- unset($data['department']);
- unset($data['job_timeList']);
- unset($data['job_content']);
- $data['created_at'] = date('Y-m-d H:i:s');
- $data['updated_at'] = date('Y-m-d H:i:s');
- var_dump($data, '-----------------test---------');
- $result = JobHunting::create($data);
- if (empty($result)) {
- return Result::error("添加失败", 0);
- }
- return Result::success($result);
- }
- public function delJobHunting(array $data): array
- {
- $result = JobHunting::where('id', $data['id'])->delete();
- if (empty($result)) {
- return Result::error("删除失败", 0);
- }
- return Result::success($result);
- }
- public function updateJobHunting(array $data): array
- {
- //设置东八区
- date_default_timezone_set('Asia/Shanghai');
- unset($data['company_name']);
- unset($data['job_industry']);
- unset($data['job_name']);
- unset($data['department']);
- unset($data['job_timeList']);
- unset($data['job_content']);
- $data['created_at'] = date('Y-m-d H:i:s');
- $data['updated_at'] = date('Y-m-d H:i:s');
- $result = JobHunting::where('id', $data['id'])->update($data);
- if (empty($result)) {
- return Result::error("更新失败", 0);
- }
- return Result::success($result);
- }
- public function getJobHuntingInfo(array $data): array
- {
- $result = JobHunting::where('id', $data['id'])->first();
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- return Result::success($result);
- }
- public function getJobHuntingData(array $data): array
- {
- $jobEnum = JobEnum::get();
- $jobIndustry = JobIndustry::get();
- $jobNature = JobNature::get();
- $jobPosition = JobPosition::get();
- $data = [
- 'jobEnum' => $jobEnum,
- 'jobIndustry' => $jobIndustry,
- 'jobNature' => $jobNature,
- 'jobPosition' => $jobPosition,
- ];
- return Result::success($data);
- }
- public function delJobHuntingInfo(array $data): array
- {
- $result = JobHunting::where('id', $data['id'])->delete();
- return Result::success();
- }
- //20250324 通知,公告,消息
- public function delNotice(array $data): array
- {
- return Result::success();
- }
- public function getNoticeInfo(array $data): array
- {
- $result = Notice::where('id', $data['id'])->first();
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- return Result::success($result);
- }
- public function addNotice(array $data): array
- {
- $result = Notice::create($data);
- return Result::success($result);
- }
- public function updateNotice(array $data): array
- {
- $result = Notice::where('id', $data['id'])->update($data);
- return Result::success($result);
- }
- public function getNoticeList(array $data): array
- {
- $result = Notice::where('status', 1)->get();
- return Result::success($result);
- }
- public function getNoticeDetail(array $data): array
- {
- $result = Notice::where('id', $data['id'])->first();
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- return Result::success($result);
- }
- public function deleteNotice(array $data): array
- {
- $result = Notice::where('id', $data['id'])->delete();
- return Result::success($result);
- }
- public function getMSG(array $data): array
- {
- $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
- // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
- $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
- $result = [];
- if ($type_id == 1) {
- //最近的5篇已审的文章
- $apply_articale = Article::where('status', 1)
- ->where('admin_user_id', $user_id)
- ->orderBy('updated_at', 'desc')
- ->limit(5)->get();
- //获取5条单聊未读聊天消息
- $chat = ChatRecords::where('is_read', 0)
- ->where('user_id', $user_id)
- ->where('talk_type', 1)
- ->orderBy('created_at', 'desc')
- ->limit(5)->get();
- //获取5条未读群聊信息
- $chat_group = ChatRecords::where('is_read', 0)
- ->where('user_id', $user_id)
- ->where('talk_type', 2)
- ->orderBy('created_at', 'desc')
- ->limit(5)->get();
- $count = count($chat) + count($chat_group) + count($apply_articale);
- $result = [
- 'apply_articale' => $apply_articale,
- 'chat' => $chat,
- 'chat_group' => $chat_group,
- 'count' => $count,
- ];
- } elseif ($type_id == 2) {
- //最近的5篇已审的文章
- $apply_articale = Article::where('status', 1)
- ->where('admin_user_id', $user_id)
- ->limit(5)->get();
- //获取5条单聊未读聊天消息
- $chat = ChatRecords::where('is_read', 0)
- ->where('user_id', $user_id)
- ->where('talk_type', 1)
- ->orderBy('created_at', 'desc')
- ->limit(5)->get();
- //获取5条未读群聊信息
- $chat_group = ChatRecords::where('is_read', 0)
- ->where('user_id', $user_id)
- ->where('talk_type', 2)
- ->orderBy('created_at', 'desc')
- ->limit(5)->get();
- $count = count($chat) + count($chat_group) + count($apply_articale);
- $result = [
- 'apply_articale' => $apply_articale,
- 'chat' => $chat,
- 'chat_group' => $chat_group,
- 'count' => $count,
- ];
- } elseif ($type_id == 3) {
- //最近的5篇已审的文章
- $apply_articale = Article::where('status', 1)
- ->where('admin_user_id', $user_id)
- ->limit(5)->get();
- //获取5条单聊未读聊天消息
- $chat = ChatRecords::where('is_read', 0)
- ->where('user_id', $user_id)
- ->where('talk_type', 1)
- ->orderBy('created_at', 'desc')
- ->limit(5)->get();
- //获取5条未读群聊信息
- $chat_group = ChatRecords::where('is_read', 0)
- ->where('user_id', $user_id)
- ->where('talk_type', 2)
- ->orderBy('created_at', 'desc')
- ->limit(5)->get();
- $count = count($chat) + count($chat_group) + count($apply_articale);
- $result = [
- 'apply_articale' => $apply_articale,
- 'chat' => $chat,
- 'chat_group' => $chat_group,
- 'count' => $count,
- ];
- } elseif ($type_id == 4) {
- //最近的5篇已审的文章
- $apply_articale = Article::where('status', 1)
- ->where('admin_user_id', $user_id)
- ->limit(5)->get();
- $count = count($apply_articale);
- $result = [
- 'apply_articale' => $apply_articale,
- 'count' => $count,
- ];
- } elseif ($type_id == 10000) {
- //获取未审核的5篇文章
- $apply_articale = Article::where('status', 0)
- ->orderBy('updated_at', 'desc')
- ->limit(5)->get();
- //获取5条单聊未读聊天消息
- $chat = ChatRecords::where('is_read', 0)
- ->where('user_id', $user_id)
- ->where('talk_type', 1)
- ->orderBy('created_at', 'desc')
- ->limit(5)->get();
- //获取5条未读群聊信息
- $chat_group = ChatRecords::where('is_read', 0)
- ->where('user_id', $user_id)
- ->where('talk_type', 2)
- ->orderBy('created_at', 'desc')
- ->limit(5)->get();
- $count = count($chat) + count($chat_group) + count($apply_articale);
- $result = [
- 'apply_articale' => $apply_articale,
- 'chat' => $chat,
- 'chat_group' => $chat_group,
- 'count' => $count,
- ];
- } elseif ($type_id == 20000) {
- }
- var_dump($type_id, '-----------------test---------');
- return Result::success($result);
- }
- public function getComplaintList(array $data): array
- {
- $result = Notice::where('status', 1)->get();
- return Result::success($result);
- }
- public function getComplaintInfo(array $data): array
- {
- $result = Notice::where('id', $data['id'])->first();
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- return Result::success($result);
- }
- public function addComplaint(array $data): array
- {
- $result = Notice::create($data);
- return Result::success($result);
- }
- public function updateComplaint(array $data): array
- {
- $result = Notice::where('id', $data['id'])->update($data);
- return Result::success($result);
- }
- public function deleteComplaint(array $data): array
- {
- $result = Notice::where('id', $data['id'])->delete();
- return Result::success($result);
- }
- public function getComplainInfo(array $data): array
- {
- $result = Notice::where('id', $data['id'])->first();
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- return Result::success($result);
- }
- //20250324 通知,公告,消息
-
- // 20250306 -------招聘--------fr
- /*
- * 招聘列表
- * */
- public function getJobRecruitingList(array $data): array
- {
- $where = [];
- if(isset($data['keyword']) && !empty($data['keyword'])){
- array_push($where, ['job_recruiting.title', 'like', '%'. $data['keyword']. '%']);
- }
- $user = User::where('id', $data['user_id'])->first();
- if(empty($user)){
- return Result::error("用户不存在", 0);
- }
- // 3:企业会员
- if($user['type_id'] == 3){
- array_push($where,['job_recruiting.user_id', $data['user_id']]);
- array_push($where,['job_recruiting.website_id', $data['website_id']]);
- }
- // 如果 $where 为空,则不添加 where 条件
- $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
- return $query->where($where);
- })
- ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
- ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
- ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
- ->orderBy("updated_at", "desc")
- ->offset(($data['page'] - 1) * $data['page_size'])
- ->limit($data['page_size'])
- ->get()
- ->all();
- $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
- return $query->where($where);
- })
- ->count();
- if (empty($result)) {
- return Result::error("暂无招聘信息", 0);
- }
- return Result::success($result);
- }
-
-
- /*
- * 招聘信息添加
- * */
- public function addJobRecruiting(array $data): array
- {
- // return Result::success($data);
- $user = User::where('user.id', $data['user_id'])
- ->where('user.status',1)
- ->leftJoin('user_info', 'user_info.user_id', 'user.id')
- ->select(
- 'user.type_id', 'user.mobile','user.email',
- 'user_info.business_name',
- 'user_info.hy_id',
- 'user_info.company_nature',
- 'user_info.company_size',
- 'user_info.introduction',
- 'user_info.real_name',
- 'user_info.company_url',
- 'user_info.address_arr_id',
- 'user_info.address'
- )
- ->first();
- if(empty($user) || $user['type_id'] != $data['user_type']){
- return Result::error("用户不存在", 0);
- }
- $web = Website::where('id', $data['website_id'])->first();
- if(empty($web)){
- return Result::error("网站不存在", 0);
- }
- // return Result::success($user);
- $data['action_id'] = $data['user_id'];
- $data['user_type'] = $user['type_id'];
- $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
- $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
- $data['cat_arr_id'] = isset($data['cat_arr_id'])? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
- $data['city_arr_id'] = isset($data['city_arr_id'])? json_encode(array_map('intval', $data['city_arr_id'])) : '';
- // 公司地址 管理员必填
- $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
- $data['address_arr_id'] = isset($data['address_arr_id'])? json_encode(array_map('intval', $data['address_arr_id'])) : '';
- // 管理员-企业相关信息
- $company = [
- // 'user_id' => $data['user_id']?? null,
- 'business_name' => $data['business_name']?? null,
- 'company_hy_id' => $data['company_hy_id']?? null,
- 'company_size' => $data['company_size']?? null,
- 'company_nature' => $data['company_nature']?? null,
- 'introduction' => $data['introduction']?? null,
- 'real_name' => $data['real_name']?? null,
- 'mobile' => $data['mobile']?? null,
- 'company_url' => $data['company_url']?? null,
- 'address_arr_id' => $data['address_arr_id']?? null,
- 'address' => $data['address']?? null,
- 'email' => $data['email']?? null,
- ];
- //去掉相关企业信息
- $job = array_diff_key($data, array_flip(array_keys($company)));
- Db::beginTransaction();
- try {
- // 先添加职位相关信息
- $jobId = JobRecruiting::insertGetId($job);
- if (empty($jobId)) {
- Db::rollBack();
- return Result::error("添加失败");
- }
- // 添加公司信息
- $company['user_id'] = $data['user_id']?? null;
- $company['job_id'] = $jobId;
- $company['user_type'] = $user['type_id']?? null;
- $company['website_id'] = $data['website_id']?? null;
- if($user['type_id'] == 10000){
- // 管理员添加企业信息
- // return Result::success($company);
- $companyId = JobCompany::insertGetId($company);
- if (empty($companyId)) {
- Db::rollBack();
- return Result::error("添加失败");
- }
- }else{
- // 企业会员添加企业信息
- $company = [
- 'user_id' => $data['user_id']?? null,
- 'business_name' => $user['business_name']?? null,
- 'company_hy_id' => $user['hy_id']?? null,
- 'company_size' => $user['company_size']?? null,
- 'company_nature' => $user['company_nature']?? null,
- 'introduction' => $user['introduction']?? null,
- 'real_name' => $user['real_name']?? null,
- 'mobile' => $user['mobile']?? null,
- 'company_url' => $user['company_url']?? null,
- 'address_arr_id' => $user['address_arr_id']?? null,
- 'address' => $user['address']?? null,
- 'email' => $user['email']?? null,
- 'website_id' => $data['website_id']?? null,
- 'user_type' => $user['type_id']?? null,
- 'job_id' => $jobId,
- ];
- $companyId = JobCompany::insertGetId($company);
- if (empty($companyId)) {
- Db::rollBack();
- return Result::error("添加失败");
- }
- // return Result::success($company);
- }
- Db::commit();
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error($e->getMessage(), 0);
- }
- $result = [
- 'job_id' => $jobId,
- 'company_id' => $companyId,
- ];
- if (empty($result)) {
- return Result::error("添加失败", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取招聘信息详情
- * */
- public function getJobRecruitingInfo(array $data): array
- {
- $result = JobRecruiting::where('job_recruiting.id', $data['id'])
- ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
- ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
- ->select('job_recruiting.*', 'website.website_name as website_name',
- 'job_company.business_name',
- 'job_company.company_hy_id',
- 'job_company.company_size',
- 'job_company.company_nature',
- 'job_company.introduction',
- 'job_company.real_name',
- 'job_company.mobile',
- 'job_company.company_url',
- 'job_company.address_arr_id',
- 'job_company.address',
- 'job_company.email'
- )
- ->first();
- if(empty($result)){
- return Result::error("招聘信息不存在", 0);
- }
- // return Result::success($job);
- return Result::success($result);
- }
- /*
- * 修改招聘信息
- * */
- public function upJobRecruiting(array $data): array
- {
- $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
- // return Result::success($job);
- if(empty($job)){
- return Result::error("招聘信息不存在", 0);
- }
- $user = User::where('id', $data['user_id'])->first();
- // return Result::success($user);
- if(empty($user) || $user['type_id']!= $data['user_type']){
- return Result::error("用户不存在", 0);
- }
- if($user['type_id']==3 && $job['user_id']!= $user['id']){
- return Result::error("用户暂无权限修改此招聘信息!", 0);
- }
- $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
- $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
- $data['cat_arr_id'] = isset($data['cat_arr_id'])? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
- $data['city_arr_id'] = isset($data['city_arr_id'])? json_encode(array_map('intval', $data['city_arr_id'])) : '';
-
- // 公司地址 管理员必填
- $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
- $data['address_arr_id'] = isset($data['address_arr_id'])? json_encode(array_map('intval', $data['address_arr_id'])) : '';
- // 管理员-企业相关信息
- $company = [
- 'business_name' => $data['business_name']?? null,
- 'company_hy_id' => $data['hy_id']?? null,
- 'company_size' => $data['company_size']?? null,
- 'company_nature' => $data['company_nature']?? null,
- 'introduction' => $data['introduction']?? null,
- 'real_name' => $data['real_name']?? null,
- 'mobile' => $data['mobile']?? null,
- 'company_url' => $data['company_url']?? null,
- 'address_arr_id' => $data['address_arr_id']?? null,
- 'address' => $data['address']?? null,
- 'email' => $data['email']?? null,
- ];
- //去掉相关企业信息
- $data = array_diff_key($data, array_flip(array_keys($company)));
- $jobId = $data['id'];
- $web = $data['website_id'];
- $data['action_id'] = $data['user_id'];
- unset($data['user_id']);
- unset($data['user_type']);
- unset($data['id']);
- unset($data['website_id']);
- // return Result::success($data);
- Db::beginTransaction();
- try {
- // 管理员修改招聘信息
- if($user['type_id'] == 10000){
- $data['website_id'] = $web;
- $company['website_id'] = $data['website_id'];
- }
- // Db::rollBack();
- // return Result::success($company);
- $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
- if (empty($result['job'])) {
- Db::rollBack();
- return Result::error("修改招聘信息失败");
- }
- // 管理员修改企业相关信息
- $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
- if (empty($result['company'])) {
- Db::rollBack();
- return Result::error("修改企业相关信息失败");
- }
- Db::commit();
- // return Result::success($result);
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error($e->getMessage(), 0);
- }
- return Result::success($result);
- }
- /*
- * 招聘信息删除
- * */
- public function delJobRecruiting(array $data): array
- {
- $user = User::where('id', $data['user_id'])->first();
- if(empty($user)){
- return Result::error("用户不存在", 0);
- }
- $job = JobRecruiting::where('id', $data['id'])->first();
- if(empty($job)){
- return Result::error("招聘信息不存在", 0);
- }
- if($user['type_id']==3 && $job['user_id']!= $user['id']){
- return Result::error("用户暂无权限修改此招聘信息!", 0);
- }
- Db::beginTransaction();
- try {
- $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
- if (empty($result['job'])) {
- Db::rollBack();
- return Result::error("删除招聘信息失败");
- }
- $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
- if (empty($result['company'])) {
- Db::rollBack();
- return Result::error("删除企业相关信息失败");
- }
- Db::commit();
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error($e->getMessage(), 0);
- }
- return Result::success($result);
- }
- /*
- * 获取公司信息
- * */
- public function getJobCompany(array $data): array
- {
- $user = User::where('user.id', $data['user_id'])
- ->leftJoin('user_info', 'user_info.user_id', 'user.id')
- ->select('user.user_name','user.mobile','user.email','user.type_id', 'user_info.*')
- ->first();
- // return Result::success($user);
- if(empty($user)){
- return Result::error("用户不存在", 0);
- }
- if($user['type_id'] == 3){
- $result = [
- // 'id' => 0,
- 'user_id' => $data['user_id'],
- 'website_id' => $data['website_id'],
- 'business_name' => $user['business_name'], // 企业名称
- 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
- 'company_nature' => $user['company_nature'], // 公司性质
- 'company_size' => $user['company_size'], // 公司规模
- 'introduction' => $user['introduction'], // 公司简介
- 'real_name' => $user['real_name'], // 企业联系人
- 'mobile' => $user['mobile'], // 企业联系电话
- 'company_url' => $user['company_url'], // 企业网址
- 'address_arr_id' => $user['address_arr_id'], // 企业网址
- 'address' => $user['address'], // 企业地址
- 'email' => $user['email'], // 企业邮箱
- ];
- }else{
- return Result::error("用户类型错误", 0);
- }
- if(empty($result)){
- return Result::error("公司信息不存在", 0);
- }
- return Result::success($result);
- }
- /*
- * 修改公司信息
- * */
- public function upJobCompany(array $data): array
- {
- // return Result::success($data);
- $user = User::where('user.id', $data['user_id'])
- ->where('user.status',1)
- ->leftJoin('user_info', 'user_info.user_id', 'user.id')
- ->select('user.user_name','user.type_id', 'user_info.*')
- ->first();
- if(empty($user)){
- return Result::error("用户不存在", 0);
- }
- $data['address_arr_id'] = isset($data['address_arr_id'])? json_encode(array_map('intval', $data['address_arr_id'])) : '';
- $company = [
- 'business_name' => $data['business_name'], // 企业名称
- 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
- 'company_nature' => $data['company_nature'], // 公司性质
- 'company_size' => $data['company_size'], // 公司规模
- 'introduction' => $data['introduction'], // 公司简介
- 'real_name' => $data['real_name'], // 企业联系人
- 'company_url' => $data['company_url'], // 企业网址
- 'address_arr_id' => $data['address_arr_id'], // 企业地址
- 'address' => $data['address'], // 企业详细地址
- ];
- if($user['type_id'] == 3){
- $result['user'] = User::where('user.id', $data['user_id'])->update([
- 'mobile' => $data['mobile'], // 企业联系电话
- 'email' => $data['email'], // 企业邮箱
- ]);
- $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
- 'business_name' => $data['business_name'], // 企业名称
- 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
- 'company_nature' => $data['company_nature'], // 公司性质
- 'company_size' => $data['company_size'], // 公司规模
- 'introduction' => $data['introduction'], // 公司简介
- 'real_name' => $data['real_name'], // 企业联系人
- 'company_url' => $data['company_url'], // 企业网址
- 'address_arr_id' => $data['address_arr_id'], // 企业地址
- 'address' => $data['address'], // 企业详细地址
- ]);
- $result = JobCompany::where('user_id', $data['user_id'])->update($company);
- }else{
- return Result::error("用户类型错误", 0);
- }
- if(empty($result)){
- return Result::error("修改失败", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取省-市
- * */
- public function getJobRecruitingArea(array $data): array
- {
- if(isset($data['province_id']) && $data['province_id']!=null){
- $result = District::where('pid',$data['pid'])->get()->all();
- }else{
- $result = District::where('level',1)->get()->all();
- }
- if (empty($result)) {
- return Result::error("暂无此省市", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取行业分类
- * */
- public function getIndustry(array $data): array
- {
- $result = JobIndustry::get()->all();
- if (empty($result)) {
- return Result::error("暂无行业分类", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取职位
- * */
- public function getPositionList(array $data): array
- {
- if(isset($data['zwpid']) && $data['zwpid']!=null){
- $result = JobPosition::where('zwpid',$data['zwpid'])->get()->all();
- }else{
- $result = JobPosition::where('zwpid',0)->get()->all();
- }
- if (empty($result)) {
- return Result::error("暂无此职位", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取工作性质-菜单
- * */
- public function getJobNature(array $data): array
- {
- $result = JobEnum::where('egroup','nature')->get()->all();
- if (empty($result)) {
- return Result::error("暂无工作性质", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取工作经验-菜单
- * */
- public function getExperience(array $data): array
- {
- $result = JobEnum::where('egroup','years')->get()->all();
- if (empty($result)) {
- return Result::error("暂无工作经验", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取学历-菜单
- * */
- public function getEducation(array $data): array
- {
- $result = JobEnum::where('egroup','education')->get()->all();
- if (empty($result)) {
- return Result::error("暂无学历", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取薪资-菜单
- * */
- public function getSalary(array $data): array
- {
- $result = JobEnum::where('egroup','income')->get()->all();
- if (empty($result)) {
- return Result::error("暂无薪资", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取语言-菜单
- * */
- public function getLanguage(array $data): array
- {
- $result = JobEnum::where('egroup','language')->get()->all();
- if (empty($result)) {
- return Result::error("暂无语言", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取掌握程度-菜单
- * */
- public function getLevel(array $data): array
- {
- $result = JobEnum::where('egroup','languagetype')->get()->all();
- if (empty($result)) {
- return Result::error("暂无工作性质", 0);
- }
- return Result::success($result);
- }
- // 公司信息
- /*
- * 获取公司性质-菜单
- * */
- public function getCompanyNature(array $data): array
- {
- $result = JobNature::get()->all();
- if (empty($result)) {
- return Result::error("暂无公司性质", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取公司规模-菜单
- * */
- public function getCompanySize(array $data): array
- {
- $result = JobEnum::where('egroup','cosize')->get()->all();
- if (empty($result)) {
- return Result::error("暂无公司规模", 0);
- }
- return Result::success($result);
- }
- // 20250306 招聘
- }
|