WebsiteService.php 51 KB

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