1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095 |
- <?php
- namespace App\JsonRpc;
- use App\Model\Article;
- use App\Model\Ad;
- use App\Model\Category;
- use App\Model\AdPlace;
- use App\Model\Department;
- use App\Model\District;
- use App\Model\FooterCategory;
- use App\Model\FooterContent;
- use App\Model\WebsiteTemplateInfo;
- use App\Model\Link;
- use App\Model\LetterOfComplaint;
- use App\Model\TemplateClass;
- use App\Model\Template;
- use App\Model\User;
- use App\Model\WebsiteRole;
- use App\Model\WebsiteRoleUser;
- use App\Model\Website;
- use App\Model\WebsiteColumn;
- use Hyperf\DbConnection\Db;
- use Hyperf\RpcServer\Annotation\RpcService;
- use App\Tools\Result;
- use Carbon\Carbon;
- use App\Model\WebsiteCategory;
- use App\Model\WebsiteTemplate;
- use App\Model\Sector;
- use PhpParser\Node\Stmt\Return_;
- use function PHPUnit\Framework\isNull;
- #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
- class WebsiteService implements WebsiteServiceInterface
- {
- /**
- * @param string $keyword
- * @param int $page
- * @param int $pageSize
- * @return array
- */
- public function getWebsitetList(array $data): array
- {
- $where = [];
- if(isset($data['keyword']) && !empty($data['keyword'])){
- array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
- }
- if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
- array_push($where,['website.website_column_id','=',$data['website_column_id']]);
- }
- if(isset($data['city_id']) && !empty($data['city_id'])){
- array_push($where,['website.city_id','=',$data['city_id']]);
- }
- $result = Website::where($where)
- ->leftJoin("website_column","website.website_column_id","website_column.id")
- ->leftJoin("district","district.id","website.city_id")
- ->select("website.*","website_column.column_name","district.name as city_name")
- ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("website.id","desc")->get();
- $count = Website::where($where)->count();
- if (empty($result)) {
- return Result::error("没有数据",0);
- }
- $data = [
- 'rows'=>$result->toArray(),
- 'count'=>$count
- ];
- return Result::success($data);
- }
- /**
- * @param array $data
- * @return array
- */
- public function createWebsite(array $data): array
- {
- var_dump("网站数据:",$data);
- $insertData = [
- 'website_name'=>$data['website_name'],
- 'logo'=>$data['logo']??'',
- 'website_url'=>$data['website_url']??'',
- 'city_id'=>$data['city_id']??0,
- 'website_column_id'=>$data['website_column_id'],
- 'title'=>$data['title']??'',
- 'keywords'=>$data['keywords']??'',
- 'description'=>$data['description']??'',
- 'status'=>$data['status']??0,
- 'website_column_arr_id'=>$data['website_column_arr_id'],
- 'city_arr_id'=>$data['city_arr_id']??[0],
- 'template_id' =>$data['template_id']??0,
- ];
- $result = Website::insertGetId($insertData);
- if(empty($result)){
- return Result::error("创建失败",0);
- }else{
- return Result::success(["id"=>$result]);
- }
- }
- /**
- * @param int $id
- * @param array $data
- * @return array
- */
- public function updateWebsite(int $id,array $data): array
- {
- $insertData = [
- 'website_name'=>$data['website_name'],
- 'logo'=>$data['logo']??'',
- 'website_url'=>$data['website_url']??'',
- 'city_id'=>$data['city_id']??0,
- 'website_column_id'=>$data['website_column_id'],
- 'title'=>$data['title']??'',
- 'keywords'=>$data['keywords']??'',
- 'description'=>$data['description']??'',
- 'status'=>$data['status']??0,
- 'website_column_arr_id'=>$data['website_column_arr_id'],
- 'city_arr_id'=>$data['city_arr_id']??[0],
- 'template_id' =>$data['template_id']??0,
- ];
- $result = Website::where('id',$id)->update($insertData);
- var_dump("更新站点",$result);
- if(empty($result)){
- return Result::error("更新失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * @param int $id
- * @return array
- */
- public function delWebsite(int $id): array
- {
- $result = Website::where('id',$id )->delete();
- if(empty($result)){
- return Result::error("删除失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * @param int $id
- * @return array
- */
- public function getWebsiteInfo(int $id): array
- {
- $where = [
- ['website.id','=',$id]
- ];
- $result = Website::where($where )
- ->leftJoin("template","template.id","website.template_id")
- ->select("website.*","template.template_name","template.template_img")
- ->first();
- if(empty($result)){
- return Result::error("数据不存在",0);
- }else{
- return Result::success($result->toArray());
- }
- }
- /**
- * 查询所有的站点栏目
- * @return array
- */
- public function getWebsiteColumn(array $data): array
- {
- $result = WebsiteColumn::where($data)->get();
- if(empty($result)){
- return Result::error("数据不存在",0);
- }else{
- return Result::success($result->toArray());
- }
- }
- /**
- * @param string $keyword
- * @param int $page
- * @param int $pageSize
- * @return array
- */
- public function getWebsiteColumnList(array $data):array
- {
- $where = [];
- if(isset($data['keyword']) && $data['keyword']){
- array_push($where,['website_column.column_name','like','%'.$data['keyword'].'%']);
- }
- $result = WebsiteColumn::where($where)
- ->leftJoin("website_column as wc","website_column.pid","wc.id")
- ->select("website_column.*","wc.column_name as parent_column_name")
- ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->get();
- $count = WebsiteColumn::where($where)->count();
- if (empty($result)) {
- return Result::error("没有数据",0);
- }
- $data = [
- 'rows'=>$result->toArray(),
- 'count'=>$count
- ];
- return Result::success($data);
- }
- /**
- * @param array $data
- * @return array
- */
- public function createWebsiteColumn(array $data): array
- {
- $insertData = [
- 'column_name'=>$data['column_name'],
- 'pid'=>$data['pid']??'',
- 'column_arr_id'=>$data['column_arr_id']??[0],
- 'sort'=>$data['sort']??0,
- 'remark'=>$data['remark']??'',
- ];
- $result = WebsiteColumn::insertGetId($insertData);
- if(empty($result)){
- return Result::error("创建失败",0);
- }else{
- return Result::success(["id"=>$result]);
- }
- }
- /**
- * @param int $id
- * @param array $data
- * @return array
- */
- public function updateWebsiteColumn(int $id,array $data): array
- {
- $insertData = [
- 'column_name'=>$data['column_name'],
- 'pid'=>$data['pid']??'',
- 'column_arr_id'=>$data['column_arr_id']??[0],
- 'sort'=>$data['sort']??0,
- 'remark'=>$data['remark']??'',
- ];
- $result = WebsiteColumn::where('id',$id)->update($insertData);
- if(empty($result)){
- return Result::error("更新失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * @param int $id
- * @return array
- */
- public function delWebsiteColumn(int $id): array
- {
- $list = WebsiteColumn::where(['pid'=>$id])->get();
- if($list){
- return Result::error("存在子网系,不能删除,请先删除子网系",0);
- }
- $result = WebsiteColumn::where('id',$id )->delete();
- if(empty($result)){
- return Result::error("删除失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * @param string $keyword
- * @param int $page
- * @param int $pageSize
- * @return array
- */
- public function getWebsiteRoleList(string $keyword,int $page,int $pageSize,int $websiteId):array
- {
- $where = [
- ['role.role_name','like','%'.$keyword.'%'],
- ['website_role.website_id','=',$websiteId],
- ];
- $result = WebsiteRole::where($where)
- ->leftJoin("role","role.id","website_role.role_id")
- ->select("role.*","website_role.type","website_role.role_id","website_role.id as website_role_id","website_role.website_id")
- ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
- $count = WebsiteRole::where($where) ->leftJoin("role","role.id","website_role.role_id")->count();
- if (empty($result)) {
- return Result::error("没有数据",0);
- }
- $data = [
- 'rows'=>$result->toArray(),
- 'count'=>$count
- ];
- return Result::success($data);
- }
- /**
- * @param array $data
- * @return array
- */
- public function createWebsiteRole(array $data): array
- {
- $insertData = [
- 'website_id'=>$data['website_id'],
- 'role_id'=>$data['role_id']??''
- ];
- $info = WebsiteRole::where($insertData)->first();
- if($info){
- return Result::error("不能重复添加角色",0);
- }
- $insertData['admin_user_id'] = $data['admin_user_id']??'';
- $insertData['type'] = $data['type']??'';
- $result = WebsiteRole::insertGetId($insertData);
- if(empty($result)){
- return Result::error("创建失败",0);
- }else{
- return Result::success(["id"=>$result]);
- }
- }
- /**
- * 暂时用不上
- * @param int $id
- * @param array $data
- * @return array
- */
- public function updateWebsiteRole(int $id,array $data): array
- {
- $insertData = [
- 'website_id'=>$data['website_id'],
- 'type'=>$data['type']??'',
- ];
- $result = WebsiteRole::where('id',$id)->update($insertData);
- if(empty($result)){
- return Result::error("更新失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * @param int $id
- * @return array
- */
- public function delWebsiteRole(int $id): array
- {
- $result = WebsiteRole::where('id',$id )->delete();
- if(empty($result)){
- return Result::error("删除失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * @param string $keyword
- * @param int $page
- * @param int $pageSize
- * @return array
- */
- public function getWebsiteRoleUserList(string $keyword,int $page,int $pageSize,int $websiteId,int $roleId):array
- {
- $where = [
- ['website_role_user.website_id','=',$websiteId],
- ['website_role_user.role_id','=',$roleId],
- ];
- $count = WebsiteRoleUser::where($where)->count();
- $where[] = ['u.user_name','like','%'.$keyword.'%'];
- $result = WebsiteRoleUser::where($where)
- ->leftJoin("user as u","website_role_user.user_id","u.id")
- ->leftJoin("website as w","website_role_user.website_id","u.id")
- ->leftJoin("role as r","website_role_user.role_id","r.id")
- ->select("u.*","u.user_name",'w.website_name','r.role_name','website_role_user.id as website_role_user_id','website_role_user.updated_at as user_update_at')
- ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
- if (empty($result)) {
- return Result::error("没有数据",0);
- }
- $data = [
- 'rows'=>$result->toArray(),
- 'count'=>$count
- ];
- return Result::success($data);
- }
- /**
- * @param array $data
- * @return array
- */
- public function createWebsiteRoleUser(array $data): array
- {
- $insertData = [
- 'website_id'=>$data['website_id'],
- 'user_id'=>$data['user_id']??'',
- ];
- $info = WebsiteRoleUser::where($insertData)->first();
- if($info){
- return Result::error("不能重复添加角色用户",0);
- }
- $insertData['role_id'] = $data['role_id']??'';
- $insertData['admin_user_id'] = $data['admin_user_id']??'';
- $insertData['type'] = $data['type']??'';
- $result = WebsiteRoleUser::insertGetId($insertData);
- if(empty($result)){
- return Result::error("创建失败",0);
- }else{
- return Result::success(["id"=>$result]);
- }
- }
- /**
- * @param int $id
- * @param array $data
- * @return array
- */
- public function updateWebsiteRoleUser(int $id,array $data): array
- {
- $insertData = [
- 'website_id'=>$data['website_id'],
- 'type'=>$data['type']??'',
- 'type_id'=>$data['type_id']??'',
- 'role_id'=>$data['role_id']??'',
- ];
- $result = WebsiteRoleUser::where('id',$id)->update($insertData);
- if(empty($result)){
- return Result::error("更新失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * @param int $id
- * @return array
- */
- public function delWebsiteRoleUser(int $id): array
- {
- $result = WebsiteRoleUser::where('id',$id )->delete();
- if(empty($result)){
- return Result::error("删除失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * 根据域名获取网站 站点id
- * @param array $data
- * @return array
- */
- public function getWebsiteId(array $data): array
- {
- $result = Website::whereJsonContains('website_url',$data['website_url'])->first();
- if(empty($result)){
- return Result::error("查询站点失败",0);
- }else{
- return Result::success($result);
- }
- }
- /**
- * 查询网站下面的导航
- * @param array $data
- * @return array
- */
- public function getWebsiteCategory(array $data): array
- {
- $where = [
- 'website_id'=>$data['website_id']
- ];
- // 使用递归查询构建树状结构
- $category = WebsiteCategory::where($where)
- ->with([
- 'children' => function ($query) {
- $query->orderBy('sort', 'asc');
- }
- ])
- ->orderBy('sort', 'asc')
- ->where('pid', 0) // 仅查询顶级节点
- ->get()->all();
- if(empty($category)){
- return Result::error("查询站点栏目失败",0);
- }else{
- $count = WebsiteCategory::where($where)->count();
- $result = [
- 'rep' => $category,
- 'count' => $count
- ];
- return Result::success($result);
- }
- }
- /**
- * 查询网站的广告
- * @param array $data
- * @return array
- */
- public function getWebsiteAdvertisement(array $data): array
- {
- $where = [
- 'ad_place.status' => 1,
- ];
- if(isset($data['ad_tag']) && !empty($data['ad_tag'])){
- $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
- $where[] = ['ad_place.ad_tag','like','%'.$data['ad_tag'].'%'];
- // return Result::success($where);
- $result = AdPlace::where($where)
- ->leftJoin("ad", function ($join) use ($now) {
- $join->on("ad.pid", "=", "ad_place.id")
- ->where('ad.status', 1)
- ->where('ad.fromtime', '<=', $now)
- ->where('ad.totime', '>=', $now);
- })
- ->select("ad_place.*",'ad.*',"ad_place.id as ad_place_id","ad.name as ad_name")
- ->get()->all();
- if(empty($result)){
- return Result::error("此广告位不存在!",0);
- }
- }else{
- return Result::error("请选择广告位!",0);
- }
- return Result::success($result);
- }
- /**
- *
- * @param array $data
- * @return array
- */
- /**网站行政职能搜索 */
- public function selectWebsiteDepartment(array $data): array
- {
- $depart = Department::where('pid',0)->orderBy('id','asc')->get();
- if(isset($data['keyword']) && !empty($data['keyword'])){
- $departments= Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
- if(empty($departments)){
- $result['message']="未查询到与此相关职能部门";
- }else{
- $count = Department::where('name','like',"%{$data['keyword']}%")->count();
- $m = [
- 'department'=>$depart,
- 'type'=>$departments,
- 'count'=>$count
- ];
- }
-
- $result['sele'] = $m;
- return Result::success($result['sele']);
-
- }
- $result=$depart;
- return Result::success($result);
- }
- /**
- * 搜索地区
- * @param array $data
- * @return array
- */
- public function selectWebsiteArea(array $data): array
- {
- // return Result::success($data);
- $pid = $data['pid'] ?? 0;
- $result = District::where('pid',$pid)->where('status',1)->orderBy('code')->get();
- if(empty($result)){
- return Result::error("未查询到此地区",0);
- }else{
- return Result::success($result);
- }
-
- }
- /**
- * 获取栏目
- * @param array $data
- * @return array
- */
- public function getWebsiteModelCategory(array $data): array
- {
- // return Result::success($data);
- $website_id=[
- 'website_id' => $data['website_id']
- ];
- // 初始化 $pid 数组
- // $pid = [];
- // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
- $pid = WebsiteCategory::where($website_id)
- ->where('pid', '!=', 0)
- ->pluck('pid');
- $pid = array_values(array_unique($pid->toArray()));
- // 构建查询语句
- $query = WebsiteCategory::where($website_id)
- ->where('pid', $data['pid'])
- ->offset($data['placeid'])
- ->limit($data['num'])
- ->orderBy('sort');
- // 如果 $pid 数组不为空,添加 CASE WHEN 条件
- if (!empty($pid)) {
- $placeholders = implode(',', array_fill(0, count($pid), '?'));
- $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
- } else {
- // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
- $query->select('website_category.*', DB::raw('0 as children_count'));
- }
- // 执行查询
- $placeid = $data['placeid']-1;
- $result = $query->offset($placeid)->limit($data['num'])->get();
- if(!empty($result)){
- return Result::success($result);
- }else{
- return Result::error("本网站暂无栏目",0);
- }
- }
- /**
- * 获取友情链接
- * @param array $data
- * @return array
- */
- public function selectWebsiteLinks(array $data): array
- {
- $where = [
- 'website_id' => $data['website_id'],
- 'status' => 1,
- 'type' => $data['type']
- ];
- $num=$data['num'];
- $result=Link::where($where)->orderBy('sort')->limit($num)->get();
- if(!empty($result)){
- return Result::success($result);
- }else{
- return Result::error("本网站暂无此类型友情链接",0);
- }
- }
- /**
- * 网站首页数据统计, 管理员
- * @return void
- */
- public function getAdminIndex(array $data): array
- {
- var_dump("用户类型:",$data['type_id']);
- switch ($data['type_id']){
- case 4:
- $result = Db::select('SELECT DATE(created_at) AS date,COUNT(*) AS total_count FROM letter_of_complaint WHERE created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(created_at) ORDER BY date ASC;');
- return Result::success($result);
- break;
- case 10000:
- $res = [];
- //网站
- $res['website']['count'] = 0;
- $res['website']['growth_rate'] = 0;
- //资讯
- $res['article']['count'] = 0;
- $res['article']['growth_rate'] = 0;
- //导航池
- $res['category']['count'] = 0;
- $res['category']['growth_rate'] = 0;
- //近一月数据
- $res['monthArticle']= [];
- //用户类型
- $res['userType'] = [];
- $res['website']['count'] = Website::where([])->count();
- $res['article']['count'] = Article::whereNotIn('status',['404'])->count();
- $res['category']['count'] = Category::where([])->count();
- $res['monthArticle'] = Db::select('SELECT DATE(created_at) AS date,COUNT(*) AS total_count FROM article WHERE created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(created_at) ORDER BY date ASC;');
- $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
- return Result::success($res);
- }
- return [];
- }
- /**
- * 获取模板类型
- * @return void
- */
- public function getTemplateClass(array $data): array
- {
- $where = [];
- if(isset($data['name']) && $data['name']){
- array_push($where,['name','like','%'.$data['name'].'%']);
- }
- $result = TemplateClass::where($where)->orderBy('sort','asc')->get();
- if(empty($result)){
- return Result::error("没有模板类型",0);
- }else{
- return Result::success($result);
- }
- }
- /**
- * 添加模板类型
- * @param
- * @return void
- */
- public function addTemplateClass(array $data): array
- {
- $insertData = [
- 'name'=>$data['name']
- ];
- $result = TemplateClass::insertGetId($insertData);
- if(empty($result)){
- return Result::error("创建失败",0);
- }else{
- return Result::success(["id"=>$result]);
- }
- }
- /**
- * 更新模板
- * @param array $data
- * @return array
- */
- public function upTemplateClass(array $data): array
- {
- $where = [
- 'id'=>$data['id']
- ];
- $insertData = [
- 'name'=>$data['name']
- ];
- $result = TemplateClass::where($where)->update($insertData);
- if(empty($result)){
- return Result::error("更新失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * 删除模板
- * @param array $data
- * @return array
- */
- public function delTemplateClass(array $data): array
- {
- $where = [
- 'id'=>$data['id']
- ];
- $result = TemplateClass::where($where)->delete();
- if(empty($result)){
- return Result::error("删除失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * 获取分类下的模板
- * @param array $data
- * @return array
- */
- public function getTemplate(array $data): array
- {
- $page = $data['page'];
- $pageSize = $data['pageSize'];
- $where = [];
- if(isset($data['template_class_id']) && $data['template_class_id']){
- array_push($where,['template_class_id','=',$data['template_class_id']]);
- }
- $result = Template::where($where)
- ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
- $count = Template::where($where)->count();
- if (empty($result)) {
- return Result::error("没有数据",0);
- }
- $data = [
- 'rows'=>$result->toArray(),
- 'count'=>$count
- ];
- return Result::success($data);
- }
- /**
- * 创建模板
- * @param
- * @return void
- */
- public function addTemplate(array $data): array
- {
- $insertData = [
- 'template_name'=>$data['template_name'],
- 'template_img'=>json_encode($data['template_img']),
- 'template_class_id'=>$data['template_class_id'],
- ];
- $result = Template::insertGetId($insertData);
- if(empty($result)){
- return Result::error("创建模板失败",0);
- }else{
- return Result::success(["id"=>$result]);
- }
- }
- /**
- * 更新模板
- * @param array $data
- * @return array
- */
- public function upTemplate(array $data): array
- {
- $where = [
- 'id'=>$data['id']
- ];
- $insertData = [
- 'template_name'=>$data['template_name'],
- 'template_img'=>json_encode($data['template_img']),
- 'template_class_id'=>$data['template_class_id'],
- ];
- $result = Template::where($where)->update($insertData);
- if(empty($result)){
- return Result::error("更新模板失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * 删除模板
- * @param array $data
- * @return array
- */
- public function delTemplate(array $data): array
- {
- $where = [
- 'id'=>$data['id']
- ];
- $result = Template::where($where)->delete();
- if(empty($result)){
- return Result::error("删除模板失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * 搜索网站
- * @param array $data
- * @return array
- */
- public function websiteList(array $data): array
- {
- $where = [];
- if(isset($data['keyword']) && !empty($data['keyword'])){
- array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
- }
- $result = Website::where($where)->get();
- if($result){
- return Result::success($result);
- }else{
- return Result::error("没有网站",0);
- }
- }
- public function addWebsiteCategory(array $data): array
- {
- $website_id = $data['website_id'];
- $category_arr_id = $data['category_arr_id'];
- $categoryList = Category::whereIn('id',$category_arr_id)->get();
- $categoryListIds = [];
- if($categoryList){
- foreach ($categoryList->toArray() as $val){
- array_push($categoryListIds,$val['id']);
- }
- }
- $arr = [];
- if($categoryListIds){
- foreach ($categoryListIds as $v){
- $ids = $this->getUnderlingUIds(intval($v));
- $ids_arr = explode(",", $ids);
- array_push($arr,$ids_arr);
- }
- }
- $mergedArray = [];
- foreach ($arr as $subarray) {
- $mergedArray = array_merge($mergedArray, $subarray);
- }
- var_dump("所有:",$arr,$mergedArray);
- //查询出所有的分类进行分割插入 组装数据
- $categoryListData = Category::whereIn('id',$mergedArray)->get();
- $categoryListData = $categoryListData->toArray();
- $insertData = [];
- if($categoryListData){
- foreach ($categoryListData as $key=>$value){
- $insertData[$key]['website_id'] = $website_id;
- $insertData[$key]['name'] = $value['name'];
- $insertData[$key]['sort'] = $value['sort'];
- $insertData[$key]['pid'] = $value['pid'];
- $insertData[$key]['pid_arr'] = $value['pid_arr'];
- $insertData[$key]['seo_title'] = $value['seo_title'];
- $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
- $insertData[$key]['seo_description'] = $value['seo_description'];
- $insertData[$key]['alias'] = $value['name'];
- $insertData[$key]['category_id'] = $value['id'];
- }
- }
- $result = WebsiteCategory::insert($insertData);
- var_dump("插入数据状态:",$result);
- if($result){
- return Result::success($result);
- }else{
- return Result::error("创建失败",0);
- }
- }
- /**
- * 删除网站导航
- * @param array $data
- * @return array
- */
- public function delWebsiteCategory(array $data): array
- {
- $website_id = $data['website_id']??0;
- $category_id = $data['category_id']??0;
- $ids = $this->getUnderlingUIds(intval($category_id));
- $ids_arr = explode(",", $ids);
- $result = WebsiteCategory::where(['website_id'=>$website_id])->whereIn("category_id",$ids_arr)->delete();
- if($result){
- return Result::success($result);
- }else{
- return Result::error("删除失败",0);
- }
- }
- /**
- * 获取网站导航
- * @param array $data
- * @return array
- */
- public function getAdminWebsiteCategory(array $data): array
- {
- $where = [
- 'website_id'=>$data['website_id'],
- 'pid'=>0
- ];
- $result = WebsiteCategory::where($where)->get();
- if($result){
- return Result::success($result);
- }else{
- return Result::error("查询失败",0);
- }
- }
- /**
- * 更新网站导航
- * @param array $data
- * @return array
- */
- public function upWebsiteCategory(array $data): array
- {
- Db::beginTransaction();
- try{
- //合并栏目id
- $reqIds = array_merge($data['old_category_arr_id'],$data['new_category_arr_id']);
- //对比old 数组差异化,把差异化的删除
- $result = WebsiteCategory::where(['website_id'=>$data['website_id'],'pid'=>0])->get();
- $result = $result->toArray();
- $categoryIds = [];
- if($result){
- foreach ($result as $val){
- array_push($categoryIds,$val['category_id']);
- }
- }
- //和原始数据对比取交际
- $reqidsIntersect = array_intersect($reqIds,$categoryIds);
- //再取差集 进行对比
- $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds),array_diff($categoryIds,$reqidsIntersect));
- var_dump("差集:",$differenceIDS);
- $arr_ids = [];
- if(count($differenceIDS)>0){
- foreach ($differenceIDS as $vv){
- $idV = $this->getUnderlingUIds(intval($vv));
- $ids_arrV = explode(",", $idV);
- array_push($arr_ids,$ids_arrV);
- }
- }
- $del_ids = array_reduce($arr_ids, 'array_merge', array());
- //有差异 删除
- if(count($del_ids)>0){
- WebsiteCategory::where(['website_id'=>$data['website_id']])->whereIn("category_id",$del_ids)->delete();
- }
- //传过来的值 和 交际 对比,选出要添加的值 进行插入
- $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect),array_diff($reqidsIntersect,$reqIds));
- var_dump("要存储的:",$insertIDS);
- //新的数组重新创建
- if(count($insertIDS)>0){
- $arr = [];
- $categoryListIds = $insertIDS;
- if($categoryListIds){
- foreach ($categoryListIds as $v){
- $ids = $this->getUnderlingUIds(intval($v));
- $ids_arr = explode(",", $ids);
- array_push($arr,$ids_arr);
- }
- }
- $mergedArray = [];
- foreach ($arr as $subarray) {
- $mergedArray = array_merge($mergedArray, $subarray);
- }
- var_dump("要插入的ID:",$mergedArray);
- //查询出所有的分类进行分割插入 组装数据
- $categoryListData = Category::whereIn('id',$mergedArray)->get();
- $categoryListData = $categoryListData->toArray();
- $insertData = [];
- if($categoryListData){
- foreach ($categoryListData as $key=>$value){
- $insertData[$key]['website_id'] = $data['website_id'];
- $insertData[$key]['name'] = $value['name'];
- $insertData[$key]['sort'] = $value['sort'];
- $insertData[$key]['pid'] = $value['pid'];
- $insertData[$key]['pid_arr'] = $value['pid_arr'];
- $insertData[$key]['seo_title'] = $value['seo_title'];
- $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
- $insertData[$key]['seo_description'] = $value['seo_description'];
- $insertData[$key]['alias'] = $value['name'];
- $insertData[$key]['category_id'] = $value['id'];
- }
- }
- WebsiteCategory::insert($insertData);
- }
- Db::commit();
- } catch(\Throwable $ex){
- Db::rollBack();
- var_dump($ex->getMessage());
- return Result::error("修改失败",0);
- }
- return Result::success();
- }
- /**
- * 获取网站列表
- * @param array $data
- * @return array
- */
- public function getWebsiteCategoryList(array $data): array
- {
- $where = [];
- if(isset($data['keyword']) && !empty($data['keyword'])){
- array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
- }
- if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
- array_push($where,['website.website_column_id','=',$data['website_column_id']]);
- }
- $result = Website::where($where)
- ->with(["websiteCategory"=>function ($query) {
- $query->where(['pid'=>0])->select('website_id','name','alias','category_id');
- }])
- ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
- ->get();
- $count = Website::where($where)->count();
- if (empty($result)) {
- return Result::error("没有数据",0);
- }
- $data = [
- 'rows'=>$result->toArray(),
- 'count'=>$count
- ];
- if($result){
- return Result::success($data);
- }else{
- return Result::error("查询失败",0);
- }
- }
- /**
- * 删除网站下的所有导航
- * @param array $data
- * @return array
- */
- public function delWebsiteAllCategory(array $data): array
- {
- $website_id = $data['website_id'];
- $result = WebsiteCategory::where(['website_id'=>$website_id])->delete();
- if($result){
- return Result::success($result);
- }else{
- return Result::error("删除失败",0);
- }
- }
- /**
- * 获取网站下的某一个导航
- * @param array $data
- * @return array
- */
- public function getWebsiteCategoryOnes(array $data): array
- {
- $website_id = $data['website_id'];
- $category_id = $data['category_id'];
- $result = WebsiteCategory::where(['website_category.website_id'=>$website_id,'website_category.category_id'=>$category_id])
- ->first();
- if($result){
- return Result::success($result);
- }else{
- return Result::error("查询失败",0);
- }
- }
- /**
- * 更新网闸下的某一个导航
- * @param array $data
- * @return array
- */
- public function upWebsiteCategoryones(array $data): array
- {
- $where = [
- 'website_id'=>$data['website_id'],
- 'category_id'=>$data['category_id'],
- ];
- $result = WebsiteCategory::where($where)->update($data);
- if($result){
- return Result::success($result);
- }else{
- return Result::error("更新失败",0);
- }
- }
- /**
- * 获取网站下的所有导航(包含子导航)
- * @param array $data
- * @return array
- */
- public function getWebsiteAllCategory(array $data): array
- {
- $where = [];
- if(isset($data['website_id']) && !empty($data['website_id'])){
- array_push($where,['website_category.website_id','=',$data['website_id']]);
- }
- if(isset($data['name']) && !empty($data['name'])){
- array_push($where,['website_category.name','like','%'.$data['name'].'%']);
- }
- if(isset($data['alias']) && !empty($data['alias'])){
- array_push($where,['website_category.alias','like','%'.$data['alias'].'%']);
- }
- if(isset($data['department_id']) && !empty($data['department_id'])){
- array_push($where,['category.department_id','=',$data['department_id']]);
- }
- if(isset($data['city_id']) && !empty($data['city_id'])){
- array_push($where,['category.city_id','=',$data['city_id']]);
- }
- $result = WebsiteCategory::where($where)
- ->leftJoin("category",'website_category.category_id','category.id')
- ->leftJoin("department",'category.department_id','department.id')
- ->leftJoin("district",'category.city_id','district.id')
- ->select("website_category.*","department.name as department_name","district.name as city_name")
- ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
- ->get();
- $count = WebsiteCategory::where($where)
- ->leftJoin("category",'website_category.category_id','category.id')
- ->leftJoin("department",'category.department_id','department.id')
- ->leftJoin("district",'category.city_id','district.id')
- ->count();
- if (empty($result)) {
- return Result::error("没有数据",0);
- }
- $data = [
- 'rows'=>$result->toArray(),
- 'count'=>$count
- ];
- if($result){
- return Result::success($data);
- }else{
- return Result::error("查询失败",0);
- }
- if($result){
- return Result::success($result);
- }else{
- return Result::error("查询失败",0);
- }
- }
- /**
- * 递归查询数据
- * @param $id
- * @param $ids
- * @return string
- */
- public function getUnderlingUIds($id, $ids='')
- {
- $back = Category::where(['pid'=>$id])->get();
- $back = $back->toArray();
- if (!empty($back) && is_array($back)) {
- foreach ($back as $v) {
- //防止当前人的ID重复去查询,形成恶性循环
- if ($v['id'] == $id) {
- continue;
- }
- $back2 = Category::where(['pid'=>$id])->count('id');
- if ($back2 > 0) {
- $ids = $this->getUnderlingUIds($v['id'],$ids);
- } else {
- $ids .= ','.$v['id'];
- }
- }
- }
- $ids = $id.','.$ids.',';
- $ids = str_replace(',,', ",", $ids);
- $ids = trim($ids, ',');
- return $ids;
- }
- /**
- * 检测网站名称是否重复
- * @param array $data
- * @return array
- */
- public function checkWebsiteName(array $data): array
- {
- if(isset($data['id'])){
- $data[] = ['id',"!=",$data['id']];
- unset($data['id']);
- }
- $websiteInfo = Website::query()->where($data)->first();
- if (empty($websiteInfo)) {
- return Result::error("找不到网站",0);
- }
- return Result::success($websiteInfo->toArray());
- }
- /**
- * 检测网站url是否重复
- * @param array $data
- * @return array
- */
- public function checkWebsiteUrl(array $data): array
- {
- $whereData = [];
- if(isset($data['id'])){
- $whereData = [['id',"!=",$data['id']]];
- unset($data['id']);
- }
- $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
- if (empty($websiteInfo)) {
- return Result::error("找不到URL",0);
- }
- return Result::success($websiteInfo->toArray());
- }
- /**
- * 获取网站底部基础信息
- * @param array $data
- * @return array
- */
- public function getWebsiteFootInfo(array $data): array
- {
- if(isset($data['website_id']) && !empty($data['website_id'])){
- $website_head = Website::where('id',$data['website_id'])
- ->where('status',1)
- ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')
- ->first();
- if (empty($website_head)) {
- return Result::error("找不到网站",0);
- }
- }else{
- return Result::error("参数错误",0);
- }
- $website_foot = WebsiteTemplateInfo::where('website_id',$data['website_id'])->where('status',2)->first();
- if (empty($website_foot)) {
- return Result::error("暂无底部基础信息",0);
- }
- $website_head['website_url'] = $website_head['website_url'] ? json_decode($website_head['website_url']) : [];
- $result = [
- 'website_foot'=>$website_foot,
- 'website_head'=>$website_head
- ];
- return Result::success($result);
-
- }
- /**
- * 获取网站底部导航
- * @param array $data
- * @return array
- */
- public function getWebsiteFooterCategory(array $data): array
- {
- if(isset($data['website_id']) && !empty($data['website_id'])){
- $website = Website::where('id',$data['website_id'])->where('status',1)->first();
- if (empty($website)) {
- return Result::error("找不到网站",0);
- }
- }else{
- return Result::error("参数错误",0);
- }
- $result = FooterCategory::where('website_id',$data['website_id'])->get();
- if (empty($result)) {
- return Result::error("暂无底部导航",0);
- }
- return Result::success($result->toArray());
- }
- /**
- * 获取网站底部导航列表
- * @param array $data
- * @return array
- */
- public function getWebsiteFooterCategoryList(array $data): array
- {
- if(isset($data['website_id']) && !empty($data['website_id'])){
- $website = Website::where('id',$data['website_id'])->where('status',1)->first();
- if (empty($website)) {
- return Result::error("找不到网站",0);
- }
- }else{
- return Result::error("参数错误",0);
- }
- $footercategory = FooterCategory::where('website_id',$data['website_id'])->where('id',$data['fcat_id'])->first();
- // '底部导航类型 0:内容型;1:列表型;',
- if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
- return Result::error("底部导航id错误",0);
- }else{
- $query = FooterContent::where('fcat_id',$data['fcat_id']);
- if($query->count() == 0){
- return Result::error("暂无底部导航列表",0);
- }elseif($query->count() == 1){
- $result = $query->first();
- }else{
- $result = $query->get();
- }
- }
- return Result::success($result);
- }
- /**
- * 获取网站底部导航
- * @param array $data
- * @return array
- */
- public function getWebsiteFooterCategoryInfo(array $data): array
- {
- if(isset($data['website_id']) && !empty($data['website_id'])){
- $website = Website::where('id',$data['website_id'])->where('status',1)->first();
- if (empty($website)) {
- return Result::error("找不到网站",0);
- }
- }else{
- return Result::error("参数错误",0);
- }
- if (isset($data['type']) && $data['type'] == 0) {
- $fcatid = FooterCategory::where('website_id',$data['website_id'])->where('id',$data['fcat_id'])->first();
- if (empty($fcatid)) {
- return Result::error("底部导航id错误",0);
- }
- $result = FooterContent::where('fcat_id',$data['fcat_id'])->first();
- }else{
- $result = FooterContent::where('id',$data['fcat_id'])->first();
- }
- if (empty($result)) {
- return Result::error("暂无底部导航内容",0);
- }
- return Result::success($result);
- }
- /*
- * 搜索网站二级导航
- * @param array $data
- * @return array
- * */
- public function selectWebsiteCategory(array $data): array
- {
- if(isset($data['website_id']) &&!empty($data['website_id'])){
- $website = Website::where('id',$data['website_id'])->where('status',1)->first();
- if (empty($website)) {
- return Result::error("暂无该网站",0);
- }
- $category = WebsiteCategory::where('website_id',$data['website_id'])->pluck('category_id')->all();
- // return Result::success($category);
- if (empty($category)) {
- return Result::error("暂无此导航",0);
- }
- $query = Category::whereIn('id', $category);
- if (isset($data['cityid']) && !empty($data['cityid'])) {
- $cityid = District::where('id', $data['cityid'])->first();
- if (empty($cityid)) {
- return Result::error("暂无此城市", 0);
- } else {
- $city_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->pluck('id');
- // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
- if (empty($city_category)) {
- return Result::error("暂无此城市下的导航", 0);
- }
- $result['catid'] = $city_category;
- $city = 1;
- // var_dump("城市====================",$result);
- }
- }
- if (isset($data['department_id']) && !empty($data['department_id'])) {
- $departmentid = Department::where('id', $data['department_id'])->first();
- if (empty($departmentid)) {
- return Result::error("暂无此部门", 0);
- } else {
- $depart_category = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
- if (empty($depart_category)) {
- return Result::error("暂无此部门下的导航", 0);
- }
- $result['catid'] = $depart_category;
- // var_dump("职能部门*******************",$result);
- $department = 1;
- }
- }
- if(!empty($city) && !empty($department)){
- // var_dump("城市和职能部门----------------------",$result);
- $sel_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
- if (empty($sel_category)) {
- return Result::error("暂无此城市和职能部门下的导航", 0);
- }
- $result['catid'] = $sel_category;
- }
- if (empty($result)) {
- return Result::error("暂无导航",0);
- }
-
- // department_id
- }else{
- return Result::error("参数错误",0);
- }
- return Result::success($result);
- }
- /**
- * 获取网站栏目seo
- * @param array $data
- * @return array
- */
- public function getWebsiteCategoryHead(array $data): array
- {
- if(isset($data['website_id']) && !empty($data['website_id'])){
- $website = Website::where('id',$data['website_id'])->where('status',1)->first();
- if (empty($website)) {
- return Result::error("找不到网站",0);
- }
- }else{
- return Result::error("参数错误",0);
- }
- if (isset($data['catid']) && !empty($data['catid'])) {
- $fcatid = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->first();
- if (empty($fcatid)) {
- return Result::error("导航id错误",0);
- }
- $result = Category::where('id',$data['catid'])->first();
- }
- if (empty($result)) {
- return Result::error("暂无导航",0);
- }
- return Result::success($result);
- }
- /*
- * 获取某个栏目
- * @param array $data
- * @return array
- * */
- public function getOneWebsiteCategory(array $data): array
- {
- if(isset($data['website_id']) &&!empty($data['website_id'])){
- $website = Website::where('id',$data['website_id'])->where('status',1)->first();
- if (empty($website)) {
- return Result::error("暂无该网站",0);
- }
- $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['category_id'])->first();
- if (empty($category)) {
- return Result::error("暂无此导航",0);
- }
- $category['children_count'] = WebsiteCategory::where('website_id',$data['website_id'])->where('pid',$data['category_id'])->count();
- $parent = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$category['pid'])->select('category_id as parent_id','alias as parent_name')->first();
- $category['parent_id'] = $parent['parent_id']?? '';
- $category['parent_name'] = $parent['parent_name']?? '';
- return Result::success($category);
- }else{
- return Result::error("参数错误",0);
- }
- }
-
- // 自助建站--fr-------------------
- /**
- * 获取并搜索 网站模板信息
- * @param array $data
- * @return array
- */
- public function getWebsiteintel(array $data): array
- {
- //查询所有网站模板信息
- $query = Website::where('website.status', 1)
- ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
- ->leftJoin("template", "template.id", "website_template_info.template_id")
- ->leftJoin("template_class", "template_class.id", "template.template_class_id")
- ->select(
- "website_template_info.id",
- "template_class.name",
- "website.id as website_id",
- "website.website_name",
- "website.website_url",
- "website_template_info.action_id",
- "website_template_info.created_at",
- "website_template_info.updated_at",
- "website_template_info.page_type",
- DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
- "template.template_name"
- );
- //若存在条件;则在$query的基础上进行筛选
- if(isset($data['website_name']) && !empty($data['website_name'])){
- $query->where('website.website_name', 'like', '%' . $data['website_name'] . '%');
- }
- if(isset($data['status']) && !empty($data['status'])){
- $query->where('website_template_info.status', $data['status']);
- }
- $count = $query->count();
- $query->limit($data['pageSize'])
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->orderBy("website_template_info.updated_at", "desc");
- $rep = $query->get();
- if($rep->count()==0){
- return Result::error("没有查找到相关数据",0);
- } else {
- $rep->each(function ($item) {
- if (!empty($item->page_type)) {
- $pageTypeArray = json_decode($item->page_type, true);
- if (is_array($pageTypeArray)) {
- $item->page_type = $pageTypeArray;
- }
- }
- });
-
- $result = [
- "rows" => $rep->toArray(),
- "count" => $count
- ];
- return Result::success($result);
- }
- // return Result::success($result);
- }
- /**
- * 添加网站基础信息
- * @param array $data
- * @return array
- */
- public function addWebsiteTemplateintel(array $data): array
- {
- $website = Website::where('website.id',$data['website_id'])->first();
- if(empty($website)){
- return Result::error("请输入正确的网站id!", 0);
- }
- if(empty($website['website_column_id'])){
- return Result::error("请先关联导航池!", 0);
- }
- // 获取此网站的底部导航 类型 type: 0:内容型底部导航(只有一条详情内容);1:列表型底部导航(可以有多条详情内容)
- $foot_type = FooterCategory::where('website_id',$data['website_id'])->pluck('type')->toArray();
- if (empty($foot_type)) {
- return Result::error("请先关联底部导航池!", 0);
- } elseif (in_array(1, $foot_type)) {
- $foot_type = 1;
- } else {
- $foot_type = 0;
- }
- $result['foot_type'] = $foot_type;
- // 友情链接类型'1:图片 2:文字 3:底部';
- $types = Link::where('website_id', $data['website_id'])->pluck('type')->toArray();
- $missingTypes = [];
- if (!in_array(1, $types)) {
- $missingTypes[] = "文字链接";
- }
- if (!in_array(2, $types)) {
- $missingTypes[] = "图片链接";
- }
- if (!in_array(3, $types)) {
- $missingTypes[] = "底部链接";
- }
- if (!empty($missingTypes)) {
- $errorMessage = "请先添加 " . implode(" 和 ", $missingTypes) . "!";
- return Result::error($errorMessage, 0);
- }
- if(isset($data['page_type'])){
- // 删除重复元素并重新索引数组
- $data['page_type'] = array_unique($data['page_type']);
- $data['page_type'] = array_values($data['page_type']);
- if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
- // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
- $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
- if (empty($info)) {
- // 将数组转换为 JSON 字符串
- $data['page_type'] = json_encode($data['page_type'])??'';
- // 操作状态:1:填写完成基础信息;2:选择完成模板;0:未构建
- $data['action_id'] = 1;
-
- try {
- $result = WebsiteTemplateInfo::insertGetId($data);
- } catch (\Exception $e) {
- if ($e->getCode() == 22001) {
- $errorMessage = $e->getMessage();
- return Result::error("请检查表单,某个字段超出了长度限制!");
- } else {
- // 处理其他类型的数据库错误
- return Result::error("插入操作失败: " . $e->getMessage());
- }
- return Result::error("添加失败!", 0);
- }
- } else {
- return Result::error("该网站已经构建过了!", 0);
- }
- } else {
- return Result::error("请先选择首页和底部导航详情页!", 0);
- }
- }
- if(empty($result)){
- return Result::error("添加失败!",0);
- }else{
- return Result::success($result);
- }
- }
- /**
- * 获取网站基础信息
- *
- * @return array
- */
- public function getWebsiteTemplateintel(array $data): array
- {
-
- $result = WebsiteTemplateInfo::where('website_template_info.website_id',$data['website_id'])
- ->leftJoin('footer_category','footer_category.website_id','website_template_info.website_id')
- ->leftJoin('website','website.id','website_template_info.website_id')
- ->select(
- "website_template_info.*",
- "footer_category.type",
- "website.website_name",
- "website.id as website_id"
- )
- ->first();
- if(empty($result['website_name'])){
- return Result::error("请输入正确的网站id!", 0);
- }
- if($result){
- $result['page_type'] = json_decode($result['page_type'],true);
- return Result::success($result);
- }else{
- return Result::error("请先添加网站基础信息!",0);
- }
- }
- /**
- * 修改网站基础信息
- *
- * @return array
- */
- public function upWebsiteTemplateintel(array $data): array
- {
- $web = Website::where('website.id',$data['website_id'])->first();
- if(empty($web)){
- return Result::error("请输入正确的网站id!", 0);
- }
- $where = ['website_id'=>$data['website_id']];
- $result = WebsiteTemplateInfo::where($where)->first();
- if(empty($result)){
- return Result::error("请先添加网站基础信息!",0);
- }else{
- unset($data['website_id']);
- // 删除重复元素
- $data['page_type'] = array_unique($data['page_type']);
- // 重新索引数组
- $data['page_type'] = array_values($data['page_type']);
- // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
- if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
- // 将数组转换为 JSON 字符串
- $data['page_type'] = json_encode($data['page_type'])??'';
- try {
- $result = WebsiteTemplateInfo::where($where)->update($data);
- } catch (\Exception $e) {
- if ($e->getCode() == 22001) {
- $errorMessage = $e->getMessage();
- return Result::error("请检查表单,某个字段超出了长度限制!");
- } else {
- // 处理其他类型的数据库错误
- return Result::error("修改操作失败: " . $e->getMessage());
- }
- return Result::error("修改失败!", 0);
- }
- }else{
- return Result::error("请先选择首页和底部导航详情页!",0);
- }
- }
- if(empty($result)){
- return Result::error("修改失败!",0);
- }else{
- return Result::success($result);
- }
- }
- /**
- * 获取所有网站风格信息
- *
- * @return array
- */
- public function getAllTemplateClass(array $data): array
- {
- $result = TemplateClass::all();
- if(empty($result)){
- return Result::error("没有查找到相关数据!",0);
- }else{
- return Result::success($result);
- }
- }
- /**
- * 搜索并获取网站模板信息
- * @param array $data
- * @return array
- */
- public function getWebsiteTemplateList(array $data): array
- {
- $website = Website::where('website.id',$data['website_id'])->first();
- if(empty($website)){
- return Result::error("请输入正确的网站id!",0);
- }else{
- $page_type = WebsiteTemplateInfo::where('website_id',$data['website_id'])->select('page_type')->first();
- if(empty($page_type)){
- return Result::error("此网站还未添加基础信息!",0);
- } else{
- $where = json_decode($page_type['page_type'], true);
- // $where = $data["page_type"];
- if(isset($data['template_class_id']) && !empty($data['template_class_id'])){
- $template_class = TemplateClass::where('id',$data['template_class_id'])->first();
- if(empty($template_class)){
- return Result::error("请输入正确的模板风格id!",0);
- }else{
- // 获取指定风格下的模板
- $rep = Template::where('template_class_id', $data['template_class_id'])
- ->where(function ($query) use ($where) {
- foreach ($where as $value) {
- $query->whereJsonContains('template_img', ['value' => $value]);
- }
- })
- ->limit($data['pageSize'])
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->orderBy("template.updated_at", "desc")
- ->get();
- $count = Template::where('template_class_id', $data['template_class_id'])
- ->where(function ($query) use ($where) {
- foreach ($where as $value) {
- $query->whereJsonContains('template_img', ['value' => $value]);
- }
- })->count();
- }
- }else{
- //获取所有模板
- $rep = Template::where(function ($query) use ($where) {
- foreach ($where as $value) {
- $query->whereJsonContains('template_img', ['value' => $value]);
- }
- })
- ->limit($data['pageSize'])
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->orderBy("template.updated_at", "desc")
- ->get();
- $count = Template::where(function ($query) use ($where) {
- foreach ($where as $value) {
- $query->whereJsonContains('template_img', ['value' => $value]);
- }
- })->count();
-
-
- }
- if(empty($rep) || $rep->count()==0){
- return Result::error("没有查找到相关数据!",0);
- }else{
- // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
- // $rep->each(function ($item) use ($where) {
- // $template_img = json_decode($item->template_img, true);
- // if(is_array($template_img)){
- // $filtered_img = array_filter($template_img, function ($img) use ($where) {
- // return isset($img['value']) && in_array($img['value'], $where);
- // });
- // }
-
- // $item->template_img = $filtered_img;
- // });
- // $result = [
- // "rows" => $rep->toArray(),
- // "count" => $count
- // ];
- $rep->each(function ($item) use ($where) {
- $template_img = json_decode($item->template_img, true);
- if (is_array($template_img)) {
- $filtered_img = array_filter($template_img, function ($img) use ($where) {
- return isset($img['value']) && in_array($img['value'], $where);
- });
- // 对过滤后的数组进行重新排序
- $sorted_img = array_values($filtered_img);
- $item->template_img = $sorted_img;
- } else {
- $item->template_img = []; // 如果无法解码为数组,则设置为空数组
- }
- });
-
- $result = [
- "rows" => $rep->toArray(),
- "count" => $count
- ];
- }
- }
- }
- return Result::success($result);
-
- }
- /**
- * 添加网站模板
- * @param array $data
- */
- public function addWebsiteTemplateclassintel(array $data): array
- {
- $template = Template::where('id',$data['template_id'])->first();
- $web = Website::where('id',$data['website_id'])->first();
- if(empty($template)){
- return Result::error("请输入正确的模板id",0);
- }
- if(empty($web)){
- return Result::error("请输入正确的网站id",0);
- }
- $result = WebsiteTemplateInfo::where('website_id',$data['website_id'])->update(['template_id'=>$data['template_id'],'action_id'=>2]);
- if(empty($result)){
- return Result::error("添加失败",0);
- }else{
- return Result::success($result);
- }
-
- }
- /**
- * 获取网站模板信息
- * @param array $data
- */
- public function getWebsiteTemplateclassintel(array $data): array
- {
- // return Result::success($data);
- $template = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
- if(empty($template)){
- return Result::error("请输入正确的搭建网站id",0);
- }
- $page_type = json_decode($template['page_type'], true);
- // 获取指定网站下的基础信息和模板及风格信息
- $result = WebsiteTemplateInfo::where([
- ['website_template_info.website_id',$data['website_id']],
- ['template_id','!=',null]
- ])
- ->leftJoin('template','template.id','website_template_info.template_id')
- ->leftJoin('template_class','template_class.id','template.template_class_id')
- ->where(function ($query) use ($page_type) {
- // 假设 $data['page_type'] 是一个数组,包含需要匹配的 page_type 值
- foreach ($page_type as $pageType) {
- $query->orWhereJsonContains('template.template_img', ['value' => $pageType]);
- }
- })
- ->select(
- 'template.template_name',
- 'template.template_img',
- 'template.id as tid',
- 'template_class.name',
- 'template_class.id as class_id',
- 'website_template_info.page_type',
- 'website_template_info.website_id')
- ->first();
- if(empty($result)){
- return Result::error("没有查找到相关数据",0);
- }
-
- // return Result::success($result);
- // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
- $template_img = $result['template_img'] !== null ? json_decode($result['template_img'], true) : [];
- $page_type = $result['page_type'] !== null ? json_decode($result['page_type'], true) : [];
- foreach ($template_img as $key => $value) {
- if (!in_array($value['value'], $page_type)) {
- unset($template_img[$key]);
- }
- }
- // return Result::success($result);
- $result['template_img'] = array_values($template_img);
- $result['page_type'] = $page_type;
- // $templateList = $this->getWebsiteTemplateList($data);
- // $count = $templateList['data']['count']??'';
- // $pages = $count / $data['pageSize'];
- // $found = false;
- // while ($pages && !$found) {
- // $templates = $this->getWebsiteTemplateList($pages,$data['pageSize']);
- // $index = array_search($template['template_id'], array_column($templates['rows'], 'id'));
- // if ($index !== false) {
- // $found = true;
- // $result['page'] = $pages;
- // $pages = 0;
- // // echo "查询到的 template 在第 $page 页";
- // }
- // $pages--;
- // }
- return Result::success($result);
- }
- /**
- * 获取网站模板下的板块信息
- * @param array $data
- */
- public function getWebsiteSectorList(array $data): array
- {
- $website = Website::where('id',$data['website_id'])->first();
- if(empty($website)){
- return Result::error("请输入正确的网站id",0);
- }
- $template = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
- if(empty($template['template_id'])){
- return Result::error("请先添加网站模板",0);
- }
- $query = Sector::where('template_id',$template['template_id']);
- if($query->count() == 0){
- return Result::error("没有查找到相关板块数据",0);
- }elseif($query->count() == 1){
- $sector = $query->first();
- }else{
- $sector = $query->get();
- }
- $result['page_type'] = $template['page_type'];
- $result['tid'] = $template['template_id'];
- $result = [
- "tid" => $template['template_id'],
- "page_type" => $template['page_type'],
- "sector" => $sector
- ];
- return Result::success($result);
- }
- // 自助建站---------------fr---------------
- // 网站底基础信息--fr-------------------
- /**
- * 添加网站底基础信息
- * @param array $data
- */
- public function addWebFootInfo(array $data): array
- {
- $website = Website::where('id',$data['website_id'])->first();
- if(empty($website)){
- return Result::error("请输入正确的网站id!", 0);
- }
- $info = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
- if(!empty($info)){
- return Result::error("该网站已经添加过了!", 0);
- }
- $result = WebsiteTemplateInfo::where('website_id',$data['website_id'])->insertGetId($data);
- if(empty($result)){
- return Result::error("请先添加网站基础信息!",0);
- }else{
- return Result::success($result);
- }
- }
- /**
- * 获取网站底基础信息
- * @param array $data
- */
- public function getWebFootInfo(array $data): array
- {
- $website = Website::where('id',$data['website_id'])->first();
- if(empty($website)){
- return Result::error("请输入正确的网站id!", 0);
- }
- $result = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
- if(empty($result)){
- return Result::error("请先添加网站基础信息!",0);
- }
- return Result::success($result);
- }
- /**
- * 修改网站底基础信息
- * @param array $data
- */
- public function upWebFootInfo(array $data): array
- {
- // return Result::success($data['website_id']);
- $website = Website::where('id',$data['website_id'])->first();
- if(empty($website)){
- return Result::error("请输入正确的网站id!", 0);
-
- }
- $where = ['website_id'=>$data['website_id']];
- unset($data['website_id']);
- // $result = WebsiteTemplateInfo::where($where)->first();
- // if(empty($result)){
- // return Result::error("请先添加网站基础信息!",0);
- // }
- // $where = ['website_id'=>$data['website_id']];
- // unset($data['website_id']);
- $result = WebsiteTemplateInfo::updateOrInsert($where, $data);
- if(empty($result)){
- return Result::error("修改失败!",0);
- }
- return Result::success($result);
- }
- /*
- * 获取父级/子级栏目
- * @param array $data
- * @return array
- * */
- public function getWebsiteParentCategory(array $data): array
- {
- if(isset($data['website_id']) &&!empty($data['website_id'])){
- $website = Website::where('id',$data['website_id'])->where('status',1)->first();
- }
- if (empty($website)) {
- return Result::error("暂无该网站",0);
- }
- if($data['id']==0){
- $category = WebsiteCategory::where('website_id', $data['website_id'])
- ->where('pid', 0)
- ->pluck('aLIas_pinyin')
- ->map(function ($alias) {
- return "/{$alias}/:id";
- })
- ->values()
- ->all();
- }else{
- $category = WebsiteCategory::where('website_id', $data['website_id'])
- ->where('pid','!=', 0)
- ->pluck('aLIas_pinyin')
- ->map(function ($alias) {
- return "/{$alias}/:id";
- })
- ->values()
- ->all();
- }
- if (empty($category)) {
- return Result::error("暂无此导航",0);
- }
- // $result = [];
- return Result::success($category);
- }
- /**
- * 获取网站栏目信息
- * @param array $data
- */
- public function getWebsiteFootAll(array $data): array
- {
- $website = Website::where('id',$data['website_id'])->where('status',1)->first();
- if (empty($website)) {
- return Result::error("暂无该网站",0);
- }
- // 1:图片 2:文字 3:底部
- $result['foot_cate'] = FooterCategory::where('website_id',$data['website_id'])->get()->all();
- $result['link_img'] = Link::where('website_id',$data['website_id'])->where('type',1)->where('status',1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all();
- $result['link_text'] = Link::where('website_id',$data['website_id'])->where('type',2)->where('status',1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
- $result['link_foot'] = Link::where('website_id',$data['website_id'])->where('type',3)->where('status',1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
- $result['foot_info'] = WebsiteTemplateInfo::where('website_id',$data['website_id'])->where('status',2)->first();
- if(empty($result)){
- return Result::error("暂无此网站信息",0);
- }
- return Result::success($result);
- }
- /**
- * 获取网站顶部信息
- * @param array $data
- */
- public function getWebsiteHead(array $data): array
- {
- $result = Website::where('id',$data['website_id'])->where('status',1)->select('website_name','logo')->first();
- if (empty($result)) {
- return Result::error("暂无该网站",0);
- }
- return Result::success($result);
- }
- }
|