WebsiteService.php 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\Ad;
  5. use App\Model\Category;
  6. use App\Model\AdPlace;
  7. use App\Model\Department;
  8. use App\Model\District;
  9. use App\Model\FooterCategory;
  10. use App\Model\FooterContent;
  11. use App\Model\WebsiteTemplateInfo;
  12. use App\Model\Link;
  13. use App\Model\LetterOfComplaint;
  14. use App\Model\TemplateClass;
  15. use App\Model\Template;
  16. use App\Model\User;
  17. use App\Model\WebsiteRole;
  18. use App\Model\WebsiteRoleUser;
  19. use App\Model\Website;
  20. use App\Model\WebsiteColumn;
  21. use Hyperf\DbConnection\Db;
  22. use Hyperf\RpcServer\Annotation\RpcService;
  23. use App\Tools\Result;
  24. use Carbon\Carbon;
  25. use App\Model\WebsiteCategory;
  26. use function PHPUnit\Framework\isNull;
  27. #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  28. class WebsiteService implements WebsiteServiceInterface
  29. {
  30. /**
  31. * 获取网站列表
  32. * @param string $keyword
  33. * @param int $page
  34. * @param int $pageSize
  35. * @return array
  36. */
  37. public function getWebsitetList(array $data): array
  38. {
  39. $resultWwhere = Website::when($data,function ($query) use ($data){
  40. if(isset($data['keyword']) && !empty($data['keyword'])){
  41. $query->where('website.website_name','like','%'.$data['keyword'].'%');
  42. }
  43. if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
  44. $query->whereJsonContains("website.website_column_arr_id", intval($data['website_column_id']));
  45. }
  46. if(isset($data['city_id']) && !empty($data['city_id'])){
  47. $query->whereJsonContains("website.city_arr_id", intval($data['city_id']));
  48. }
  49. });
  50. $result = $resultWwhere->leftJoin("website_column","website.website_column_id","website_column.id")
  51. ->leftJoin("district","district.id","website.city_id")
  52. ->select("website.*","website_column.column_name","district.name as city_name")
  53. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("website.id","desc")->get();
  54. $count = $resultWwhere->count();
  55. if (empty($result)) {
  56. return Result::error("没有数据",0);
  57. }
  58. $data = [
  59. 'rows'=>$result->toArray(),
  60. 'count'=>$count
  61. ];
  62. return Result::success($data);
  63. }
  64. /**
  65. * @param array $data
  66. * @return array
  67. */
  68. public function createWebsite(array $data): array
  69. {
  70. var_dump("网站数据:",$data);
  71. $insertData = [
  72. 'website_name'=>$data['website_name'],
  73. 'logo'=>$data['logo']??'',
  74. 'website_url'=>$data['website_url']??'',
  75. // 'city_id'=>$data['city_id']??0,
  76. 'website_column_id'=>$data['website_column_id'],
  77. 'title'=>$data['title']??'',
  78. 'keywords'=>$data['keywords']??'',
  79. 'description'=>$data['description']??'',
  80. 'status'=>$data['status']??0,
  81. 'website_column_arr_id'=>$data['website_column_arr_id'],
  82. // 'city_arr_id'=>$data['city_arr_id']??[0],
  83. 'template_id' =>$data['template_id']??0,
  84. ];
  85. $result = Website::insertGetId($insertData);
  86. if(empty($result)){
  87. return Result::error("创建失败",0);
  88. }else{
  89. return Result::success(["id"=>$result]);
  90. }
  91. }
  92. /**
  93. * @param int $id
  94. * @param array $data
  95. * @return array
  96. */
  97. public function updateWebsite(int $id,array $data): array
  98. {
  99. $insertData = [
  100. 'website_name'=>$data['website_name'],
  101. 'logo'=>$data['logo']??'',
  102. 'website_url'=>$data['website_url']??'',
  103. // 'city_id'=>$data['city_id']??0,
  104. 'website_column_id'=>$data['website_column_id'],
  105. 'title'=>$data['title']??'',
  106. 'keywords'=>$data['keywords']??'',
  107. 'description'=>$data['description']??'',
  108. 'status'=>$data['status']??0,
  109. 'website_column_arr_id'=>$data['website_column_arr_id'],
  110. // 'city_arr_id'=>$data['city_arr_id']??[0],
  111. 'template_id' =>$data['template_id']??0,
  112. ];
  113. $result = Website::where('id',$id)->update($insertData);
  114. var_dump("更新站点",$result);
  115. if(empty($result)){
  116. return Result::error("更新失败",0);
  117. }else{
  118. return Result::success();
  119. }
  120. }
  121. /**
  122. * @param int $id
  123. * @return array
  124. */
  125. public function delWebsite(int $id): array
  126. {
  127. $result = Website::where('id',$id )->delete();
  128. if(empty($result)){
  129. return Result::error("删除失败",0);
  130. }else{
  131. return Result::success();
  132. }
  133. }
  134. /**
  135. * @param int $id
  136. * @return array
  137. */
  138. public function getWebsiteInfo(int $id): array
  139. {
  140. $where = [
  141. ['website.id','=',$id]
  142. ];
  143. $result = Website::where($where )
  144. ->leftJoin("template","template.id","website.template_id")
  145. ->select("website.*","template.template_name","template.template_img")
  146. ->first();
  147. if(empty($result)){
  148. return Result::error("数据不存在",0);
  149. }else{
  150. return Result::success($result->toArray());
  151. }
  152. }
  153. /**
  154. * 查询所有的站点栏目
  155. * @return array
  156. */
  157. public function getWebsiteColumn(array $data): array
  158. {
  159. $result = WebsiteColumn::where($data)->get();
  160. if(empty($result)){
  161. return Result::error("数据不存在",0);
  162. }else{
  163. return Result::success($result->toArray());
  164. }
  165. }
  166. /**
  167. * @param string $keyword
  168. * @param int $page
  169. * @param int $pageSize
  170. * @return array
  171. */
  172. public function getWebsiteColumnList(array $data):array
  173. {
  174. $where = [];
  175. if(isset($data['keyword']) && $data['keyword']){
  176. array_push($where,['website_column.column_name','like','%'.$data['keyword'].'%']);
  177. }
  178. $result = WebsiteColumn::where($where)
  179. ->leftJoin("website_column as wc","website_column.pid","wc.id")
  180. ->select("website_column.*","wc.column_name as parent_column_name")
  181. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->get();
  182. $count = WebsiteColumn::where($where)->count();
  183. if (empty($result)) {
  184. return Result::error("没有数据",0);
  185. }
  186. $data = [
  187. 'rows'=>$result->toArray(),
  188. 'count'=>$count
  189. ];
  190. return Result::success($data);
  191. }
  192. /**
  193. * @param array $data
  194. * @return array
  195. */
  196. public function createWebsiteColumn(array $data): array
  197. {
  198. $insertData = [
  199. 'column_name'=>$data['column_name'],
  200. 'pid'=>$data['pid']??'',
  201. 'column_arr_id'=>$data['column_arr_id']??[0],
  202. 'sort'=>$data['sort']??0,
  203. 'remark'=>$data['remark']??'',
  204. ];
  205. $result = WebsiteColumn::insertGetId($insertData);
  206. if(empty($result)){
  207. return Result::error("创建失败",0);
  208. }else{
  209. return Result::success(["id"=>$result]);
  210. }
  211. }
  212. /**
  213. * @param int $id
  214. * @param array $data
  215. * @return array
  216. */
  217. public function updateWebsiteColumn(int $id,array $data): array
  218. {
  219. $insertData = [
  220. 'column_name'=>$data['column_name'],
  221. 'pid'=>$data['pid']??'',
  222. 'column_arr_id'=>$data['column_arr_id']??[0],
  223. 'sort'=>$data['sort']??0,
  224. 'remark'=>$data['remark']??'',
  225. ];
  226. $result = WebsiteColumn::where('id',$id)->update($insertData);
  227. if(empty($result)){
  228. return Result::error("更新失败",0);
  229. }else{
  230. return Result::success();
  231. }
  232. }
  233. /**
  234. * @param int $id
  235. * @return array
  236. */
  237. public function delWebsiteColumn(int $id): array
  238. {
  239. $list = WebsiteColumn::where(['pid'=>$id])->get();
  240. if($list){
  241. return Result::error("存在子网系,不能删除,请先删除子网系",0);
  242. }
  243. $result = WebsiteColumn::where('id',$id )->delete();
  244. if(empty($result)){
  245. return Result::error("删除失败",0);
  246. }else{
  247. return Result::success();
  248. }
  249. }
  250. /**
  251. * @param string $keyword
  252. * @param int $page
  253. * @param int $pageSize
  254. * @return array
  255. */
  256. public function getWebsiteRoleList(string $keyword,int $page,int $pageSize,int $websiteId):array
  257. {
  258. $where = [
  259. ['role.role_name','like','%'.$keyword.'%'],
  260. ['website_role.website_id','=',$websiteId],
  261. ];
  262. $result = WebsiteRole::where($where)
  263. ->leftJoin("role","role.id","website_role.role_id")
  264. ->select("role.*","website_role.type","website_role.role_id","website_role.id as website_role_id","website_role.website_id")
  265. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  266. $count = WebsiteRole::where($where) ->leftJoin("role","role.id","website_role.role_id")->count();
  267. if (empty($result)) {
  268. return Result::error("没有数据",0);
  269. }
  270. $data = [
  271. 'rows'=>$result->toArray(),
  272. 'count'=>$count
  273. ];
  274. return Result::success($data);
  275. }
  276. /**
  277. * @param array $data
  278. * @return array
  279. */
  280. public function createWebsiteRole(array $data): array
  281. {
  282. $insertData = [
  283. 'website_id'=>$data['website_id'],
  284. 'role_id'=>$data['role_id']??''
  285. ];
  286. $info = WebsiteRole::where($insertData)->first();
  287. if($info){
  288. return Result::error("不能重复添加角色",0);
  289. }
  290. $insertData['admin_user_id'] = $data['admin_user_id']??'';
  291. $insertData['type'] = $data['type']??'';
  292. $result = WebsiteRole::insertGetId($insertData);
  293. if(empty($result)){
  294. return Result::error("创建失败",0);
  295. }else{
  296. return Result::success(["id"=>$result]);
  297. }
  298. }
  299. /**
  300. * 暂时用不上
  301. * @param int $id
  302. * @param array $data
  303. * @return array
  304. */
  305. public function updateWebsiteRole(int $id,array $data): array
  306. {
  307. $insertData = [
  308. 'website_id'=>$data['website_id'],
  309. 'type'=>$data['type']??'',
  310. ];
  311. $result = WebsiteRole::where('id',$id)->update($insertData);
  312. if(empty($result)){
  313. return Result::error("更新失败",0);
  314. }else{
  315. return Result::success();
  316. }
  317. }
  318. /**
  319. * @param int $id
  320. * @return array
  321. */
  322. public function delWebsiteRole(int $id): array
  323. {
  324. $result = WebsiteRole::where('id',$id )->delete();
  325. if(empty($result)){
  326. return Result::error("删除失败",0);
  327. }else{
  328. return Result::success();
  329. }
  330. }
  331. /**
  332. * @param string $keyword
  333. * @param int $page
  334. * @param int $pageSize
  335. * @return array
  336. */
  337. public function getWebsiteRoleUserList(string $keyword,int $page,int $pageSize,int $websiteId,int $roleId):array
  338. {
  339. $where = [
  340. ['website_role_user.website_id','=',$websiteId],
  341. ['website_role_user.role_id','=',$roleId],
  342. ];
  343. $count = WebsiteRoleUser::where($where)->count();
  344. $where[] = ['u.user_name','like','%'.$keyword.'%'];
  345. $result = WebsiteRoleUser::where($where)
  346. ->leftJoin("user as u","website_role_user.user_id","u.id")
  347. ->leftJoin("website as w","website_role_user.website_id","u.id")
  348. ->leftJoin("role as r","website_role_user.role_id","r.id")
  349. ->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')
  350. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  351. if (empty($result)) {
  352. return Result::error("没有数据",0);
  353. }
  354. $data = [
  355. 'rows'=>$result->toArray(),
  356. 'count'=>$count
  357. ];
  358. return Result::success($data);
  359. }
  360. /**
  361. * @param array $data
  362. * @return array
  363. */
  364. public function createWebsiteRoleUser(array $data): array
  365. {
  366. $insertData = [
  367. 'website_id'=>$data['website_id'],
  368. 'user_id'=>$data['user_id']??'',
  369. ];
  370. $info = WebsiteRoleUser::where($insertData)->first();
  371. if($info){
  372. return Result::error("不能重复添加角色用户",0);
  373. }
  374. $insertData['role_id'] = $data['role_id']??'';
  375. $insertData['admin_user_id'] = $data['admin_user_id']??'';
  376. $insertData['type'] = $data['type']??'';
  377. $result = WebsiteRoleUser::insertGetId($insertData);
  378. if(empty($result)){
  379. return Result::error("创建失败",0);
  380. }else{
  381. return Result::success(["id"=>$result]);
  382. }
  383. }
  384. /**
  385. * @param int $id
  386. * @param array $data
  387. * @return array
  388. */
  389. public function updateWebsiteRoleUser(int $id,array $data): array
  390. {
  391. $insertData = [
  392. 'website_id'=>$data['website_id'],
  393. 'type'=>$data['type']??'',
  394. 'type_id'=>$data['type_id']??'',
  395. 'role_id'=>$data['role_id']??'',
  396. ];
  397. $result = WebsiteRoleUser::where('id',$id)->update($insertData);
  398. if(empty($result)){
  399. return Result::error("更新失败",0);
  400. }else{
  401. return Result::success();
  402. }
  403. }
  404. /**
  405. * @param int $id
  406. * @return array
  407. */
  408. public function delWebsiteRoleUser(int $id): array
  409. {
  410. $result = WebsiteRoleUser::where('id',$id )->delete();
  411. if(empty($result)){
  412. return Result::error("删除失败",0);
  413. }else{
  414. return Result::success();
  415. }
  416. }
  417. /**
  418. * 根据域名获取网站 站点id
  419. * @param array $data
  420. * @return array
  421. */
  422. public function getWebsiteId(array $data): array
  423. {
  424. $result = Website::whereJsonContains('website_url',$data['website_url'])->first();
  425. if(empty($result)){
  426. return Result::error("查询站点失败",0);
  427. }else{
  428. return Result::success($result);
  429. }
  430. }
  431. /**
  432. * 查询网站下面的导航
  433. * @param array $data
  434. * @return array
  435. */
  436. public function getWebsiteCategory(array $data): array
  437. {
  438. $where = [
  439. 'website_id'=>$data['website_id'],
  440. 'pid'=>0
  441. ];
  442. $result = WebsiteCategory::where($where)->orderBy('sort','asc')->get();
  443. if(empty($result)){
  444. return Result::error("查询站点栏目失败",0);
  445. }else{
  446. return Result::success($result);
  447. }
  448. }
  449. /**
  450. * 查询网站的广告
  451. * @param array $data
  452. * @return array
  453. */
  454. public function getWebsiteAdvertisement(array $data): array
  455. {
  456. $where = [
  457. 'website_id' => $data['website_id'],
  458. 'ad_place.status' => 1,
  459. 'ad.status' => 1,
  460. ];
  461. if(isset($data['ad_tag']) && !empty($data['ad_tag'])){
  462. $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
  463. $where[] = ['ad_tag','like','%'.$data['ad_tag'].'%'];
  464. $result = AdPlace::where($where)
  465. ->leftJoin("ad","ad.pid","ad_place.id")
  466. ->select("ad_place.*","ad.*",'ad.name as ad_name','ad.id as ad_id')
  467. ->where('ad.fromtime', '<=', $now)
  468. ->where('ad.totime', '>=', $now)
  469. // ->whereBetween('ad.fromtime', [$now, 'ad.totime'])
  470. ->get()->all();
  471. if(empty($result)){
  472. return Result::error("此广告位不存在!",0);
  473. }
  474. }else{
  475. return Result::error("请选择广告位!",0);
  476. }
  477. return Result::success($result);
  478. }
  479. /**
  480. *
  481. * @param array $data
  482. * @return array
  483. */
  484. /**网站行政职能搜索 */
  485. public function selectWebsiteDepartment(array $data): array
  486. {
  487. $depart = Department::where('pid',0)->orderBy('id','asc')->limit(10)->get();
  488. if(isset($data['keyword']) && !empty($data['keyword'])){
  489. $departments= Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  490. if(empty($departments)){
  491. $result['message']="未查询到与此相关职能部门";
  492. }else{
  493. $count = Department::where('name','like',"%{$data['keyword']}%")->count();
  494. $m = [
  495. 'department'=>$depart,
  496. 'type'=>$departments,
  497. 'count'=>$count
  498. ];
  499. }
  500. $result['sele'] = $m;
  501. return Result::success($result['sele']);
  502. }
  503. $result=$depart;
  504. return Result::success($result);
  505. }
  506. /**
  507. * 搜索地区
  508. * @param array $data
  509. * @return array
  510. */
  511. public function selectWebsiteArea(array $data): array
  512. {
  513. $provinces=District::where('pid',0)->where('status',1)->get();
  514. if(isset($data['province'])){
  515. $province=District::where('pid',0)->where('status',1)->where('id',$data['province'])->orderBy('id')->get();
  516. $province=$province->toArray();
  517. if(!empty($province)){
  518. $citys=District::where('pid',$data['province'])->where('status',1)->orderBy('id')->get();
  519. if(!empty($citys) && isset($data['city']) && !empty($data['city'])){
  520. // $province = $province->toArray();
  521. $province_id=[];
  522. foreach($province as $val){
  523. array_push($province_id,$val['id']);
  524. }
  525. // var_dump($province_id);
  526. $city=District::whereIn('pid',$province_id)->where('status',1)->where('id',$data['city'])->orderBy('id')->get();
  527. if(!empty($city)){
  528. $city_id=[];
  529. foreach($city as $val){
  530. array_push($city_id,$val['id']);
  531. }
  532. $regions=District::whereIn('pid',$city_id)->where('status',1)->orderBy('id')->get();
  533. $result=[
  534. 'province' => $province,
  535. 'city' => $city,
  536. 'region' => $regions
  537. ];
  538. }else{
  539. return Result::error("未查询到此城市",0);
  540. }
  541. }else{
  542. $result=[
  543. 'province' => $province,
  544. 'city' => $citys,
  545. 'region' => null
  546. ];
  547. }
  548. }else{
  549. return Result::error("未查询到此省份",0);
  550. }
  551. }else{
  552. // $keys = array('data');
  553. $result = $provinces;
  554. }
  555. return Result::success($result);
  556. }
  557. /**
  558. * 获取栏目
  559. * @param array $data
  560. * @return array
  561. */
  562. public function getWebsiteModelCategory(array $data): array
  563. {
  564. $website_id=[
  565. 'website_category.website_id' => $data['website_id']
  566. ];
  567. $placeid=$data['placeid']-1;
  568. $pid=[
  569. 'website_category.pid' => $data['pid'],
  570. ];
  571. var_dump( "=======",$pid);
  572. $num = $data['num'];
  573. // return Result::success($data);
  574. $result=WebsiteCategory::where($website_id)
  575. ->leftJoin("category",'website_category.category_id','category.id')
  576. ->select('website_category.*','category.is_url','category.web_url')
  577. ->where($pid)
  578. // ->with(['children' => function ($query) use ($data) {
  579. // $query->where('website_category.website_id', $data['website_id']);
  580. // }])
  581. ->orderBy('website_category.sort')
  582. ->offset($placeid)
  583. ->limit($num)
  584. ->get();
  585. foreach($result as $k=>$v){
  586. $child[$k]['children_countent']=WebsiteCategory::where($website_id)
  587. ->where('website_category.pid',$v['category_id'])
  588. ->count();
  589. if(!empty($child[$k]['children_countent'])){
  590. $result[$k]['children_count']=$child[$k]['children_countent'];
  591. }else{
  592. $result[$k]['children_count']=0;
  593. }
  594. }
  595. return Result::success($result);
  596. if(!empty($result)){
  597. return Result::success($result);
  598. }else{
  599. return Result::error("本网站暂无栏目",0);
  600. }
  601. }
  602. /**
  603. * 获取友情链接
  604. * @param array $data
  605. * @return array
  606. */
  607. public function selectWebsiteLinks(array $data): array
  608. {
  609. $where = [
  610. 'website_id' => $data['website_id'],
  611. 'status' => 1,
  612. 'type' => $data['type']
  613. ];
  614. $num=$data['num'];
  615. $result=Link::where($where)->orderBy('id')->limit($num)->get();
  616. if(!empty($result)){
  617. return Result::success($result);
  618. }else{
  619. return Result::error("本网站暂无此类型友情链接",0);
  620. }
  621. }
  622. /**
  623. * 网站首页数据统计, 管理员
  624. * @return void
  625. */
  626. public function getAdminIndex(array $data): array
  627. {
  628. var_dump("用户类型:",$data['type_id']);
  629. switch ($data['type_id']){
  630. case 4:
  631. $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;');
  632. return Result::success($result);
  633. break;
  634. case 10000:
  635. $res = [];
  636. //网站
  637. $res['website']['count'] = 0;
  638. $res['website']['growth_rate'] = 0;
  639. //资讯
  640. $res['article']['count'] = 0;
  641. $res['article']['growth_rate'] = 0;
  642. //导航池
  643. $res['category']['count'] = 0;
  644. $res['category']['growth_rate'] = 0;
  645. //近一月数据
  646. $res['monthArticle']= [];
  647. //用户类型
  648. $res['userType'] = [];
  649. $res['website']['count'] = Website::where([])->count();
  650. $res['article']['count'] = Article::whereNotIn('status',['404'])->count();
  651. $res['category']['count'] = Category::where([])->count();
  652. $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;');
  653. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  654. return Result::success($res);
  655. }
  656. return [];
  657. }
  658. /**
  659. * 获取模板类型
  660. * @return void
  661. */
  662. public function getTemplateClass(array $data): array
  663. {
  664. $where = [];
  665. if(isset($data['name']) && $data['name']){
  666. array_push($where,['name','like','%'.$data['name'].'%']);
  667. }
  668. $result = TemplateClass::where($where)->orderBy('sort','asc')->get();
  669. if(empty($result)){
  670. return Result::error("没有模板类型",0);
  671. }else{
  672. return Result::success($result);
  673. }
  674. }
  675. /**
  676. * 添加模板类型
  677. * @param
  678. * @return void
  679. */
  680. public function addTemplateClass(array $data): array
  681. {
  682. $insertData = [
  683. 'name'=>$data['name']
  684. ];
  685. $result = TemplateClass::insertGetId($insertData);
  686. if(empty($result)){
  687. return Result::error("创建失败",0);
  688. }else{
  689. return Result::success(["id"=>$result]);
  690. }
  691. }
  692. /**
  693. * 更新模板
  694. * @param array $data
  695. * @return array
  696. */
  697. public function upTemplateClass(array $data): array
  698. {
  699. $where = [
  700. 'id'=>$data['id']
  701. ];
  702. $insertData = [
  703. 'name'=>$data['name']
  704. ];
  705. $result = TemplateClass::where($where)->update($insertData);
  706. if(empty($result)){
  707. return Result::error("更新失败",0);
  708. }else{
  709. return Result::success();
  710. }
  711. }
  712. /**
  713. * 删除模板
  714. * @param array $data
  715. * @return array
  716. */
  717. public function delTemplateClass(array $data): array
  718. {
  719. $where = [
  720. 'id'=>$data['id']
  721. ];
  722. $result = TemplateClass::where($where)->delete();
  723. if(empty($result)){
  724. return Result::error("删除失败",0);
  725. }else{
  726. return Result::success();
  727. }
  728. }
  729. /**
  730. * 获取分类下的模板
  731. * @param array $data
  732. * @return array
  733. */
  734. public function getTemplate(array $data): array
  735. {
  736. $page = $data['page'];
  737. $pageSize = $data['pageSize'];
  738. $where = [];
  739. if(isset($data['template_class_id']) && $data['template_class_id']){
  740. array_push($where,['template_class_id','=',$data['template_class_id']]);
  741. }
  742. $result = Template::where($where)
  743. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  744. $count = Template::where($where)->count();
  745. if (empty($result)) {
  746. return Result::error("没有数据",0);
  747. }
  748. $data = [
  749. 'rows'=>$result->toArray(),
  750. 'count'=>$count
  751. ];
  752. return Result::success($data);
  753. }
  754. /**
  755. * 创建模板
  756. * @param
  757. * @return void
  758. */
  759. public function addTemplate(array $data): array
  760. {
  761. $insertData = [
  762. 'template_name'=>$data['template_name'],
  763. 'template_img'=>json_encode($data['template_img']),
  764. 'template_class_id'=>$data['template_class_id'],
  765. ];
  766. $result = Template::insertGetId($insertData);
  767. if(empty($result)){
  768. return Result::error("创建模板失败",0);
  769. }else{
  770. return Result::success(["id"=>$result]);
  771. }
  772. }
  773. /**
  774. * 更新模板
  775. * @param array $data
  776. * @return array
  777. */
  778. public function upTemplate(array $data): array
  779. {
  780. $where = [
  781. 'id'=>$data['id']
  782. ];
  783. $insertData = [
  784. 'template_name'=>$data['template_name'],
  785. 'template_img'=>json_encode($data['template_img']),
  786. 'template_class_id'=>$data['template_class_id'],
  787. ];
  788. $result = Template::where($where)->update($insertData);
  789. if(empty($result)){
  790. return Result::error("更新模板失败",0);
  791. }else{
  792. return Result::success();
  793. }
  794. }
  795. /**
  796. * 删除模板
  797. * @param array $data
  798. * @return array
  799. */
  800. public function delTemplate(array $data): array
  801. {
  802. $where = [
  803. 'id'=>$data['id']
  804. ];
  805. $result = Template::where($where)->delete();
  806. if(empty($result)){
  807. return Result::error("删除模板失败",0);
  808. }else{
  809. return Result::success();
  810. }
  811. }
  812. /**
  813. * 搜索网站
  814. * @param array $data
  815. * @return array
  816. */
  817. public function websiteList(array $data): array
  818. {
  819. $where = [];
  820. if(isset($data['keyword']) && !empty($data['keyword'])){
  821. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  822. }
  823. $result = Website::where($where)->get();
  824. if($result){
  825. return Result::success($result);
  826. }else{
  827. return Result::error("没有网站",0);
  828. }
  829. }
  830. public function addWebsiteCategory(array $data): array
  831. {
  832. $website_id = $data['website_id'];
  833. $category_arr_id = $data['category_arr_id'];
  834. $categoryList = Category::whereIn('id',$category_arr_id)->get();
  835. $categoryListIds = [];
  836. if($categoryList){
  837. foreach ($categoryList->toArray() as $val){
  838. array_push($categoryListIds,$val['id']);
  839. }
  840. }
  841. $arr = [];
  842. if($categoryListIds){
  843. foreach ($categoryListIds as $v){
  844. $ids = $this->getUnderlingUIds(intval($v));
  845. $ids_arr = explode(",", $ids);
  846. array_push($arr,$ids_arr);
  847. }
  848. }
  849. $mergedArray = [];
  850. foreach ($arr as $subarray) {
  851. $mergedArray = array_merge($mergedArray, $subarray);
  852. }
  853. var_dump("所有:",$arr,$mergedArray);
  854. //查询出所有的分类进行分割插入 组装数据
  855. $categoryListData = Category::whereIn('id',$mergedArray)->get();
  856. $categoryListData = $categoryListData->toArray();
  857. $insertData = [];
  858. if($categoryListData){
  859. foreach ($categoryListData as $key=>$value){
  860. $insertData[$key]['website_id'] = $website_id;
  861. $insertData[$key]['name'] = $value['name'];
  862. $insertData[$key]['sort'] = $value['sort'];
  863. $insertData[$key]['pid'] = $value['pid'];
  864. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  865. $insertData[$key]['seo_title'] = $value['seo_title'];
  866. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  867. $insertData[$key]['seo_description'] = $value['seo_description'];
  868. $insertData[$key]['alias'] = $value['name'];
  869. $insertData[$key]['category_id'] = $value['id'];
  870. }
  871. }
  872. $result = WebsiteCategory::insert($insertData);
  873. var_dump("插入数据状态:",$result);
  874. if($result){
  875. return Result::success($result);
  876. }else{
  877. return Result::error("创建失败",0);
  878. }
  879. }
  880. /**
  881. * 删除网站导航
  882. * @param array $data
  883. * @return array
  884. */
  885. public function delWebsiteCategory(array $data): array
  886. {
  887. $website_id = $data['website_id']??0;
  888. $category_id = $data['category_id']??0;
  889. $ids = $this->getUnderlingUIds(intval($category_id));
  890. $ids_arr = explode(",", $ids);
  891. $result = WebsiteCategory::where(['website_id'=>$website_id])->whereIn("category_id",$ids_arr)->delete();
  892. if($result){
  893. return Result::success($result);
  894. }else{
  895. return Result::error("删除失败",0);
  896. }
  897. }
  898. /**
  899. * 获取网站导航
  900. * @param array $data
  901. * @return array
  902. */
  903. public function getAdminWebsiteCategory(array $data): array
  904. {
  905. $where = [
  906. 'website_id'=>$data['website_id'],
  907. 'pid'=>0
  908. ];
  909. $result = WebsiteCategory::where($where)->get();
  910. if($result){
  911. return Result::success($result);
  912. }else{
  913. return Result::error("查询失败",0);
  914. }
  915. }
  916. /**
  917. * 更新网站导航
  918. * @param array $data
  919. * @return array
  920. */
  921. public function upWebsiteCategory(array $data): array
  922. {
  923. Db::beginTransaction();
  924. try{
  925. //合并栏目id
  926. $reqIds = array_merge($data['old_category_arr_id'],$data['new_category_arr_id']);
  927. //对比old 数组差异化,把差异化的删除
  928. $result = WebsiteCategory::where(['website_id'=>$data['website_id'],'pid'=>0])->get();
  929. $result = $result->toArray();
  930. $categoryIds = [];
  931. if($result){
  932. foreach ($result as $val){
  933. array_push($categoryIds,$val['category_id']);
  934. }
  935. }
  936. //和原始数据对比取交际
  937. $reqidsIntersect = array_intersect($reqIds,$categoryIds);
  938. //再取差集 进行对比
  939. $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds),array_diff($categoryIds,$reqidsIntersect));
  940. var_dump("差集:",$differenceIDS);
  941. $arr_ids = [];
  942. if(count($differenceIDS)>0){
  943. foreach ($differenceIDS as $vv){
  944. $idV = $this->getUnderlingUIds(intval($vv));
  945. $ids_arrV = explode(",", $idV);
  946. array_push($arr_ids,$ids_arrV);
  947. }
  948. }
  949. $del_ids = array_reduce($arr_ids, 'array_merge', array());
  950. //有差异 删除
  951. if(count($del_ids)>0){
  952. WebsiteCategory::where(['website_id'=>$data['website_id']])->whereIn("category_id",$del_ids)->delete();
  953. }
  954. //传过来的值 和 交际 对比,选出要添加的值 进行插入
  955. $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect),array_diff($reqidsIntersect,$reqIds));
  956. var_dump("要存储的:",$insertIDS);
  957. //新的数组重新创建
  958. if(count($insertIDS)>0){
  959. $arr = [];
  960. $categoryListIds = $insertIDS;
  961. if($categoryListIds){
  962. foreach ($categoryListIds as $v){
  963. $ids = $this->getUnderlingUIds(intval($v));
  964. $ids_arr = explode(",", $ids);
  965. array_push($arr,$ids_arr);
  966. }
  967. }
  968. $mergedArray = [];
  969. foreach ($arr as $subarray) {
  970. $mergedArray = array_merge($mergedArray, $subarray);
  971. }
  972. var_dump("要插入的ID:",$mergedArray);
  973. //查询出所有的分类进行分割插入 组装数据
  974. $categoryListData = Category::whereIn('id',$mergedArray)->get();
  975. $categoryListData = $categoryListData->toArray();
  976. $insertData = [];
  977. if($categoryListData){
  978. foreach ($categoryListData as $key=>$value){
  979. $insertData[$key]['website_id'] = $data['website_id'];
  980. $insertData[$key]['name'] = $value['name'];
  981. $insertData[$key]['sort'] = $value['sort'];
  982. $insertData[$key]['pid'] = $value['pid'];
  983. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  984. $insertData[$key]['seo_title'] = $value['seo_title'];
  985. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  986. $insertData[$key]['seo_description'] = $value['seo_description'];
  987. $insertData[$key]['alias'] = $value['name'];
  988. $insertData[$key]['category_id'] = $value['id'];
  989. }
  990. }
  991. WebsiteCategory::insert($insertData);
  992. }
  993. Db::commit();
  994. } catch(\Throwable $ex){
  995. Db::rollBack();
  996. var_dump($ex->getMessage());
  997. return Result::error("修改失败",0);
  998. }
  999. return Result::success();
  1000. }
  1001. /**
  1002. * 获取网站列表
  1003. * @param array $data
  1004. * @return array
  1005. */
  1006. public function getWebsiteCategoryList(array $data): array
  1007. {
  1008. $where = [];
  1009. if(isset($data['keyword']) && !empty($data['keyword'])){
  1010. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  1011. }
  1012. if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
  1013. array_push($where,['website.website_column_id','=',$data['website_column_id']]);
  1014. }
  1015. $result = Website::where($where)
  1016. ->with(["websiteCategory"=>function ($query) {
  1017. $query->where(['pid'=>0])->select('website_id','name','alias','category_id');
  1018. }])
  1019. ->limit($data['pageSize'])->orderBy("updated_at","desc")->offset(($data['page']-1)*$data['pageSize'])
  1020. ->get();
  1021. $count = Website::where($where)->count();
  1022. if (empty($result)) {
  1023. return Result::error("没有数据",0);
  1024. }
  1025. $data = [
  1026. 'rows'=>$result->toArray(),
  1027. 'count'=>$count
  1028. ];
  1029. if($result){
  1030. return Result::success($data);
  1031. }else{
  1032. return Result::error("查询失败",0);
  1033. }
  1034. }
  1035. /**
  1036. * 删除网站下的所有导航
  1037. * @param array $data
  1038. * @return array
  1039. */
  1040. public function delWebsiteAllCategory(array $data): array
  1041. {
  1042. $website_id = $data['website_id'];
  1043. $result = WebsiteCategory::where(['website_id'=>$website_id])->delete();
  1044. if($result){
  1045. return Result::success($result);
  1046. }else{
  1047. return Result::error("删除失败",0);
  1048. }
  1049. }
  1050. /**
  1051. * 获取网站下的某一个导航
  1052. * @param array $data
  1053. * @return array
  1054. */
  1055. public function getWebsiteCategoryOnes(array $data): array
  1056. {
  1057. $website_id = $data['website_id'];
  1058. $category_id = $data['category_id'];
  1059. $result = WebsiteCategory::where(['website_category.website_id'=>$website_id,'website_category.category_id'=>$category_id])
  1060. ->first();
  1061. if($result){
  1062. return Result::success($result);
  1063. }else{
  1064. return Result::error("查询失败",0);
  1065. }
  1066. }
  1067. /**
  1068. * 更新网闸下的某一个导航
  1069. * @param array $data
  1070. * @return array
  1071. */
  1072. public function upWebsiteCategoryones(array $data): array
  1073. {
  1074. $where = [
  1075. 'website_id'=>$data['website_id'],
  1076. 'category_id'=>$data['category_id'],
  1077. ];
  1078. $result = WebsiteCategory::where($where)->update($data);
  1079. if($result){
  1080. return Result::success($result);
  1081. }else{
  1082. return Result::error("更新失败",0);
  1083. }
  1084. }
  1085. /**
  1086. * 获取网站下的所有导航(包含子导航)
  1087. * @param array $data
  1088. * @return array
  1089. */
  1090. public function getWebsiteAllCategory(array $data): array
  1091. {
  1092. $where = [];
  1093. if(isset($data['website_id']) && !empty($data['website_id'])){
  1094. array_push($where,['website_category.website_id','=',$data['website_id']]);
  1095. }
  1096. if(isset($data['name']) && !empty($data['name'])){
  1097. array_push($where,['website_category.name','like','%'.$data['name'].'%']);
  1098. }
  1099. if(isset($data['alias']) && !empty($data['alias'])){
  1100. array_push($where,['website_category.alias','like','%'.$data['alias'].'%']);
  1101. }
  1102. if(isset($data['department_id']) && !empty($data['department_id'])){
  1103. array_push($where,['category.department_id','=',$data['department_id']]);
  1104. }
  1105. if(isset($data['city_id']) && !empty($data['city_id'])){
  1106. array_push($where,['category.city_id','=',$data['city_id']]);
  1107. }
  1108. $result = WebsiteCategory::where($where)
  1109. ->leftJoin("category",'website_category.category_id','category.id')
  1110. ->leftJoin("department",'category.department_id','department.id')
  1111. ->leftJoin("district",'category.city_id','district.id')
  1112. ->select("website_category.*","department.name as department_name","district.name as city_name")
  1113. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
  1114. ->get();
  1115. $count = WebsiteCategory::where($where)
  1116. ->leftJoin("category",'website_category.category_id','category.id')
  1117. ->leftJoin("department",'category.department_id','department.id')
  1118. ->leftJoin("district",'category.city_id','district.id')
  1119. ->count();
  1120. if (empty($result)) {
  1121. return Result::error("没有数据",0);
  1122. }
  1123. $data = [
  1124. 'rows'=>$result->toArray(),
  1125. 'count'=>$count
  1126. ];
  1127. if($result){
  1128. return Result::success($data);
  1129. }else{
  1130. return Result::error("查询失败",0);
  1131. }
  1132. if($result){
  1133. return Result::success($result);
  1134. }else{
  1135. return Result::error("查询失败",0);
  1136. }
  1137. }
  1138. /**
  1139. * 递归查询数据
  1140. * @param $id
  1141. * @param $ids
  1142. * @return string
  1143. */
  1144. public function getUnderlingUIds($id, $ids='')
  1145. {
  1146. $back = Category::where(['pid'=>$id])->get();
  1147. $back = $back->toArray();
  1148. if (!empty($back) && is_array($back)) {
  1149. foreach ($back as $v) {
  1150. //防止当前人的ID重复去查询,形成恶性循环
  1151. if ($v['id'] == $id) {
  1152. continue;
  1153. }
  1154. $back2 = Category::where(['pid'=>$id])->count('id');
  1155. if ($back2 > 0) {
  1156. $ids = $this->getUnderlingUIds($v['id'],$ids);
  1157. } else {
  1158. $ids .= ','.$v['id'];
  1159. }
  1160. }
  1161. }
  1162. $ids = $id.','.$ids.',';
  1163. $ids = str_replace(',,', ",", $ids);
  1164. $ids = trim($ids, ',');
  1165. return $ids;
  1166. }
  1167. /**
  1168. * 检测网站名称是否重复
  1169. * @param array $data
  1170. * @return array
  1171. */
  1172. public function checkWebsiteName(array $data): array
  1173. {
  1174. if(isset($data['id'])){
  1175. $data[] = ['id',"!=",$data['id']];
  1176. unset($data['id']);
  1177. }
  1178. $websiteInfo = Website::query()->where($data)->first();
  1179. if (empty($websiteInfo)) {
  1180. return Result::error("找不到网站",0);
  1181. }
  1182. return Result::success($websiteInfo->toArray());
  1183. }
  1184. /**
  1185. * 检测网站url是否重复
  1186. * @param array $data
  1187. * @return array
  1188. */
  1189. public function checkWebsiteUrl(array $data): array
  1190. {
  1191. $whereData = [];
  1192. if(isset($data['id'])){
  1193. $whereData = [['id',"!=",$data['id']]];
  1194. unset($data['id']);
  1195. }
  1196. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1197. if (empty($websiteInfo)) {
  1198. return Result::error("找不到URL",0);
  1199. }
  1200. return Result::success($websiteInfo->toArray());
  1201. }
  1202. /**
  1203. * 获取网站底部基础信息
  1204. * @param array $data
  1205. * @return array
  1206. */
  1207. public function getWebsiteFootInfo(array $data): array
  1208. {
  1209. if(isset($data['website_id']) && !empty($data['website_id'])){
  1210. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1211. if (empty($website)) {
  1212. return Result::error("找不到网站",0);
  1213. }
  1214. }else{
  1215. return Result::error("参数错误",0);
  1216. }
  1217. $website_foot = WebsiteTemplateInfo::where('website_id',$data['website_id'])->where('status',2)->first();
  1218. $website_head = Website::where('id',$data['website_id'])
  1219. ->select('id','website_name','logo','title','keywords','description')->first();
  1220. if (empty($website_foot)) {
  1221. return Result::error("暂无底部基础信息",0);
  1222. }
  1223. if (empty($website_head)) {
  1224. return Result::error("暂无头部基础信息",0);
  1225. }
  1226. $result = [
  1227. 'website_foot'=>$website_foot,
  1228. 'website_head'=>$website_head
  1229. ];
  1230. return Result::success($result);
  1231. }
  1232. /**
  1233. * 获取网站底部导航
  1234. * @param array $data
  1235. * @return array
  1236. */
  1237. public function getWebsiteFooterCategory(array $data): array
  1238. {
  1239. if(isset($data['website_id']) && !empty($data['website_id'])){
  1240. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1241. if (empty($website)) {
  1242. return Result::error("找不到网站",0);
  1243. }
  1244. }else{
  1245. return Result::error("参数错误",0);
  1246. }
  1247. $result = FooterCategory::where('website_id',$data['website_id'])->get();
  1248. if (empty($result)) {
  1249. return Result::error("暂无底部导航",0);
  1250. }
  1251. return Result::success($result->toArray());
  1252. }
  1253. /**
  1254. * 获取网站底部导航列表
  1255. * @param array $data
  1256. * @return array
  1257. */
  1258. public function getWebsiteFooterCategoryList(array $data): array
  1259. {
  1260. if(isset($data['website_id']) && !empty($data['website_id'])){
  1261. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1262. if (empty($website)) {
  1263. return Result::error("找不到网站",0);
  1264. }
  1265. }else{
  1266. return Result::error("参数错误",0);
  1267. }
  1268. $footercategory = FooterCategory::where('website_id',$data['website_id'])->where('id',$data['fcat_id'])->first();
  1269. // '底部导航类型 0:内容型;1:列表型;',
  1270. if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
  1271. return Result::error("底部导航id错误",0);
  1272. }else{
  1273. $query = FooterContent::where('fcat_id',$data['fcat_id']);
  1274. if($query->count() == 0){
  1275. return Result::error("暂无底部导航列表",0);
  1276. }elseif($query->count() == 1){
  1277. $result = $query->first();
  1278. }else{
  1279. $result = $query->get();
  1280. }
  1281. }
  1282. return Result::success($result);
  1283. }
  1284. /**
  1285. * 获取网站底部导航
  1286. * @param array $data
  1287. * @return array
  1288. */
  1289. public function getWebsiteFooterCategoryInfo(array $data): array
  1290. {
  1291. if(isset($data['website_id']) && !empty($data['website_id'])){
  1292. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1293. if (empty($website)) {
  1294. return Result::error("找不到网站",0);
  1295. }
  1296. }else{
  1297. return Result::error("参数错误",0);
  1298. }
  1299. if (isset($data['type']) && $data['type'] == 0) {
  1300. $fcatid = FooterCategory::where('website_id',$data['website_id'])->where('id',$data['fcat_id'])->first();
  1301. if (empty($fcatid)) {
  1302. return Result::error("底部导航id错误",0);
  1303. }
  1304. $result = FooterContent::where('fcat_id',$data['fcat_id'])->first();
  1305. }else{
  1306. $result = FooterContent::where('id',$data['fcat_id'])->first();
  1307. }
  1308. if (empty($result)) {
  1309. return Result::error("暂无底部导航内容",0);
  1310. }
  1311. return Result::success($result);
  1312. }
  1313. /*
  1314. * 搜索网站二级导航
  1315. * @param array $data
  1316. * @return array
  1317. * */
  1318. public function selectWebsiteCategory(array $data): array
  1319. {
  1320. if(isset($data['website_id']) &&!empty($data['website_id'])){
  1321. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1322. if (empty($website)) {
  1323. return Result::error("暂无该网站",0);
  1324. }
  1325. $category = WebsiteCategory::where('website_id',$data['website_id'])->pluck('category_id')->all();
  1326. // return Result::success($category);
  1327. if (empty($category)) {
  1328. return Result::error("暂无此导航",0);
  1329. }
  1330. $query = Category::whereIn('id', $category);
  1331. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1332. $cityid = District::where('id', $data['cityid'])->first();
  1333. if (empty($cityid)) {
  1334. return Result::error("暂无此城市", 0);
  1335. } else {
  1336. $city_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->pluck('id');
  1337. // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
  1338. if (empty($city_category)) {
  1339. return Result::error("暂无此城市下的导航", 0);
  1340. }
  1341. $result['catid'] = $city_category;
  1342. $city = 1;
  1343. // var_dump("城市====================",$result);
  1344. }
  1345. }
  1346. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1347. $departmentid = Department::where('id', $data['department_id'])->first();
  1348. if (empty($departmentid)) {
  1349. return Result::error("暂无此部门", 0);
  1350. } else {
  1351. $depart_category = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1352. if (empty($depart_category)) {
  1353. return Result::error("暂无此部门下的导航", 0);
  1354. }
  1355. $result['catid'] = $depart_category;
  1356. // var_dump("职能部门*******************",$result);
  1357. $department = 1;
  1358. }
  1359. }
  1360. if(!empty($city) && !empty($department)){
  1361. // var_dump("城市和职能部门----------------------",$result);
  1362. $sel_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1363. if (empty($sel_category)) {
  1364. return Result::error("暂无此城市和职能部门下的导航", 0);
  1365. }
  1366. $result['catid'] = $sel_category;
  1367. }
  1368. if (empty($result)) {
  1369. return Result::error("暂无导航",0);
  1370. }
  1371. // department_id
  1372. }else{
  1373. return Result::error("参数错误",0);
  1374. }
  1375. return Result::success($result);
  1376. }
  1377. /**
  1378. * 获取网站栏目seo
  1379. * @param array $data
  1380. * @return array
  1381. */
  1382. public function getWebsiteCategoryHead(array $data): array
  1383. {
  1384. if(isset($data['website_id']) && !empty($data['website_id'])){
  1385. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1386. if (empty($website)) {
  1387. return Result::error("找不到网站",0);
  1388. }
  1389. }else{
  1390. return Result::error("参数错误",0);
  1391. }
  1392. if (isset($data['catid']) && !empty($data['catid'])) {
  1393. $fcatid = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->first();
  1394. if (empty($fcatid)) {
  1395. return Result::error("导航id错误",0);
  1396. }
  1397. $result = Category::where('id',$data['catid'])->first();
  1398. }
  1399. if (empty($result)) {
  1400. return Result::error("暂无导航",0);
  1401. }
  1402. return Result::success($result);
  1403. }
  1404. /*
  1405. * 获取某个栏目
  1406. * @param array $data
  1407. * @return array
  1408. * */
  1409. public function getOneWebsiteCategory(array $data): array
  1410. {
  1411. if(isset($data['website_id']) &&!empty($data['website_id'])){
  1412. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1413. if (empty($website)) {
  1414. return Result::error("暂无该网站",0);
  1415. }
  1416. $result = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['category_id'])->select('category_id','name')->first();
  1417. // return Result::success($category);
  1418. if (empty($result)) {
  1419. return Result::error("暂无此导航",0);
  1420. }
  1421. // department_id
  1422. }else{
  1423. return Result::error("参数错误",0);
  1424. }
  1425. return Result::success($result);
  1426. }
  1427. }