WebsiteService.php 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503
  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' => 1,
  458. 'id' => $data['ad_placeid']
  459. ];
  460. //查询这个广告位是否存在
  461. $ad_place = AdPlace::where($where)->orderBy('id','asc')->first();
  462. var_dump("==========",$ad_place);
  463. if(empty($ad_place)){
  464. return Result::error("error",0);
  465. }else{
  466. $adplaceid = $ad_place['id'];
  467. //查找有没有广告
  468. $ad=Ad::where('pid',$adplaceid['id'])->where('status',1)->orderBy('id','asc')->get();
  469. if(empty($ad)){
  470. //若没有生效的广告,则显示默认的缩略图
  471. $result=$adplaceid;
  472. return Result::success($result);
  473. }else{
  474. //查找在生效时间的广告
  475. $today = Carbon::now();
  476. foreach($ad as $i)
  477. {
  478. $starttime=Carbon::parse($i['fromtime']);
  479. $endtime=Carbon::parse($i['totime']);
  480. $time=$today->between($starttime,$endtime);
  481. if($time)
  482. {
  483. $result=$i;
  484. }
  485. }
  486. if(empty($result)){
  487. $result=$ad;
  488. return Result::success($result);
  489. }else{
  490. return Result::success($result);
  491. }
  492. }
  493. }
  494. }
  495. /**
  496. *
  497. * @param array $data
  498. * @return array
  499. */
  500. /**网站行政职能搜索 */
  501. public function selectWebsiteDepartment(array $data): array
  502. {
  503. $depart = Department::where('pid',0)->orderBy('id','asc')->limit(10)->get();
  504. if(isset($data['keyword']) && !empty($data['keyword'])){
  505. $departments= Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  506. if(empty($departments)){
  507. $result['message']="未查询到与此相关职能部门";
  508. }else{
  509. $count = Department::where('name','like',"%{$data['keyword']}%")->count();
  510. $m = [
  511. 'department'=>$depart,
  512. 'type'=>$departments,
  513. 'count'=>$count
  514. ];
  515. }
  516. $result['sele'] = $m;
  517. return Result::success($result['sele']);
  518. }
  519. $result=$depart;
  520. return Result::success($result);
  521. }
  522. /**
  523. * 搜索地区
  524. * @param array $data
  525. * @return array
  526. */
  527. public function selectWebsiteArea(array $data): array
  528. {
  529. $provinces=District::where('pid',0)->where('status',1)->get();
  530. if(isset($data['province'])){
  531. $province=District::where('pid',0)->where('status',1)->where('id',$data['province'])->orderBy('id')->get();
  532. $province=$province->toArray();
  533. if(!empty($province)){
  534. $citys=District::where('pid',$data['province'])->where('status',1)->orderBy('id')->get();
  535. if(!empty($citys) && isset($data['city']) && !empty($data['city'])){
  536. // $province = $province->toArray();
  537. $province_id=[];
  538. foreach($province as $val){
  539. array_push($province_id,$val['id']);
  540. }
  541. // var_dump($province_id);
  542. $city=District::whereIn('pid',$province_id)->where('status',1)->where('id',$data['city'])->orderBy('id')->get();
  543. if(!empty($city)){
  544. $city_id=[];
  545. foreach($city as $val){
  546. array_push($city_id,$val['id']);
  547. }
  548. $regions=District::whereIn('pid',$city_id)->where('status',1)->orderBy('id')->get();
  549. $result=[
  550. 'province' => $province,
  551. 'city' => $city,
  552. 'region' => $regions
  553. ];
  554. }else{
  555. return Result::error("未查询到此城市",0);
  556. }
  557. }else{
  558. $result=[
  559. 'province' => $province,
  560. 'city' => $citys,
  561. 'region' => null
  562. ];
  563. }
  564. }else{
  565. return Result::error("未查询到此省份",0);
  566. }
  567. }else{
  568. // $keys = array('data');
  569. $result = $provinces;
  570. }
  571. return Result::success($result);
  572. }
  573. /**
  574. * 获取栏目
  575. * @param array $data
  576. * @return array
  577. */
  578. public function getWebsiteModelCategory(array $data): array
  579. {
  580. $website_id=[
  581. 'website_id' => $data['website_id']
  582. ];
  583. $placeid=$data['placeid']-1;
  584. $pid=[
  585. 'pid' => $data['pid'],
  586. ];
  587. $num = $data['num'];
  588. $result=WebsiteCategory::where($website_id)->where($pid)->withCount(['children' => function ($query) use ($website_id) {
  589. $query->where($website_id);
  590. }])->orderBy('sort')->offset($placeid)->limit($num)->get();
  591. if(!empty($result)){
  592. return Result::success($result);
  593. }else{
  594. return Result::error("本网站暂无栏目",0);
  595. }
  596. }
  597. /**
  598. * 获取友情链接
  599. * @param array $data
  600. * @return array
  601. */
  602. public function selectWebsiteLinks(array $data): array
  603. {
  604. $where = [
  605. 'website_id' => $data['website_id'],
  606. 'status' => 1,
  607. 'type' => $data['type']
  608. ];
  609. $num=$data['num'];
  610. $result=Link::where($where)->orderBy('id')->limit($num)->get();
  611. if(!empty($result)){
  612. return Result::success($result);
  613. }else{
  614. return Result::error("本网站暂无此类型友情链接",0);
  615. }
  616. }
  617. /**
  618. * 网站首页数据统计, 管理员
  619. * @return void
  620. */
  621. public function getAdminIndex(array $data): array
  622. {
  623. var_dump("用户类型:",$data['type_id']);
  624. switch ($data['type_id']){
  625. case 4:
  626. $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;');
  627. return Result::success($result);
  628. break;
  629. case 10000:
  630. $res = [];
  631. //网站
  632. $res['website']['count'] = 0;
  633. $res['website']['growth_rate'] = 0;
  634. //资讯
  635. $res['article']['count'] = 0;
  636. $res['article']['growth_rate'] = 0;
  637. //导航池
  638. $res['category']['count'] = 0;
  639. $res['category']['growth_rate'] = 0;
  640. //近一月数据
  641. $res['monthArticle']= [];
  642. //用户类型
  643. $res['userType'] = [];
  644. $res['website']['count'] = Website::where([])->count();
  645. $res['article']['count'] = Article::whereNotIn('status',['404'])->count();
  646. $res['category']['count'] = Category::where([])->count();
  647. $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;');
  648. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  649. return Result::success($res);
  650. }
  651. return [];
  652. }
  653. /**
  654. * 获取模板类型
  655. * @return void
  656. */
  657. public function getTemplateClass(array $data): array
  658. {
  659. $where = [];
  660. if(isset($data['name']) && $data['name']){
  661. array_push($where,['name','like','%'.$data['name'].'%']);
  662. }
  663. $result = TemplateClass::where($where)->orderBy('sort','asc')->get();
  664. if(empty($result)){
  665. return Result::error("没有模板类型",0);
  666. }else{
  667. return Result::success($result);
  668. }
  669. }
  670. /**
  671. * 添加模板类型
  672. * @param
  673. * @return void
  674. */
  675. public function addTemplateClass(array $data): array
  676. {
  677. $insertData = [
  678. 'name'=>$data['name']
  679. ];
  680. $result = TemplateClass::insertGetId($insertData);
  681. if(empty($result)){
  682. return Result::error("创建失败",0);
  683. }else{
  684. return Result::success(["id"=>$result]);
  685. }
  686. }
  687. /**
  688. * 更新模板
  689. * @param array $data
  690. * @return array
  691. */
  692. public function upTemplateClass(array $data): array
  693. {
  694. $where = [
  695. 'id'=>$data['id']
  696. ];
  697. $insertData = [
  698. 'name'=>$data['name']
  699. ];
  700. $result = TemplateClass::where($where)->update($insertData);
  701. if(empty($result)){
  702. return Result::error("更新失败",0);
  703. }else{
  704. return Result::success();
  705. }
  706. }
  707. /**
  708. * 删除模板
  709. * @param array $data
  710. * @return array
  711. */
  712. public function delTemplateClass(array $data): array
  713. {
  714. $where = [
  715. 'id'=>$data['id']
  716. ];
  717. $result = TemplateClass::where($where)->delete();
  718. if(empty($result)){
  719. return Result::error("删除失败",0);
  720. }else{
  721. return Result::success();
  722. }
  723. }
  724. /**
  725. * 获取分类下的模板
  726. * @param array $data
  727. * @return array
  728. */
  729. public function getTemplate(array $data): array
  730. {
  731. $page = $data['page'];
  732. $pageSize = $data['pageSize'];
  733. $where = [];
  734. if(isset($data['template_class_id']) && $data['template_class_id']){
  735. array_push($where,['template_class_id','=',$data['template_class_id']]);
  736. }
  737. $result = Template::where($where)
  738. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  739. $count = Template::where($where)->count();
  740. if (empty($result)) {
  741. return Result::error("没有数据",0);
  742. }
  743. $data = [
  744. 'rows'=>$result->toArray(),
  745. 'count'=>$count
  746. ];
  747. return Result::success($data);
  748. }
  749. /**
  750. * 创建模板
  751. * @param
  752. * @return void
  753. */
  754. public function addTemplate(array $data): array
  755. {
  756. $insertData = [
  757. 'template_name'=>$data['template_name'],
  758. 'template_img'=>json_encode($data['template_img']),
  759. 'template_class_id'=>$data['template_class_id'],
  760. ];
  761. $result = Template::insertGetId($insertData);
  762. if(empty($result)){
  763. return Result::error("创建模板失败",0);
  764. }else{
  765. return Result::success(["id"=>$result]);
  766. }
  767. }
  768. /**
  769. * 更新模板
  770. * @param array $data
  771. * @return array
  772. */
  773. public function upTemplate(array $data): array
  774. {
  775. $where = [
  776. 'id'=>$data['id']
  777. ];
  778. $insertData = [
  779. 'template_name'=>$data['template_name'],
  780. 'template_img'=>json_encode($data['template_img']),
  781. 'template_class_id'=>$data['template_class_id'],
  782. ];
  783. $result = Template::where($where)->update($insertData);
  784. if(empty($result)){
  785. return Result::error("更新模板失败",0);
  786. }else{
  787. return Result::success();
  788. }
  789. }
  790. /**
  791. * 删除模板
  792. * @param array $data
  793. * @return array
  794. */
  795. public function delTemplate(array $data): array
  796. {
  797. $where = [
  798. 'id'=>$data['id']
  799. ];
  800. $result = Template::where($where)->delete();
  801. if(empty($result)){
  802. return Result::error("删除模板失败",0);
  803. }else{
  804. return Result::success();
  805. }
  806. }
  807. /**
  808. * 搜索网站
  809. * @param array $data
  810. * @return array
  811. */
  812. public function websiteList(array $data): array
  813. {
  814. $where = [];
  815. if(isset($data['keyword']) && !empty($data['keyword'])){
  816. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  817. }
  818. $result = Website::where($where)->get();
  819. if($result){
  820. return Result::success($result);
  821. }else{
  822. return Result::error("没有网站",0);
  823. }
  824. }
  825. public function addWebsiteCategory(array $data): array
  826. {
  827. $website_id = $data['website_id'];
  828. $category_arr_id = $data['category_arr_id'];
  829. $categoryList = Category::whereIn('id',$category_arr_id)->get();
  830. $categoryListIds = [];
  831. if($categoryList){
  832. foreach ($categoryList->toArray() as $val){
  833. array_push($categoryListIds,$val['id']);
  834. }
  835. }
  836. $arr = [];
  837. if($categoryListIds){
  838. foreach ($categoryListIds as $v){
  839. $ids = $this->getUnderlingUIds(intval($v));
  840. $ids_arr = explode(",", $ids);
  841. array_push($arr,$ids_arr);
  842. }
  843. }
  844. $mergedArray = [];
  845. foreach ($arr as $subarray) {
  846. $mergedArray = array_merge($mergedArray, $subarray);
  847. }
  848. var_dump("所有:",$arr,$mergedArray);
  849. //查询出所有的分类进行分割插入 组装数据
  850. $categoryListData = Category::whereIn('id',$mergedArray)->get();
  851. $categoryListData = $categoryListData->toArray();
  852. $insertData = [];
  853. if($categoryListData){
  854. foreach ($categoryListData as $key=>$value){
  855. $insertData[$key]['website_id'] = $website_id;
  856. $insertData[$key]['name'] = $value['name'];
  857. $insertData[$key]['sort'] = $value['sort'];
  858. $insertData[$key]['pid'] = $value['pid'];
  859. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  860. $insertData[$key]['seo_title'] = $value['seo_title'];
  861. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  862. $insertData[$key]['seo_description'] = $value['seo_description'];
  863. $insertData[$key]['alias'] = $value['name'];
  864. $insertData[$key]['category_id'] = $value['id'];
  865. }
  866. }
  867. $result = WebsiteCategory::insert($insertData);
  868. var_dump("插入数据状态:",$result);
  869. if($result){
  870. return Result::success($result);
  871. }else{
  872. return Result::error("创建失败",0);
  873. }
  874. }
  875. /**
  876. * 删除网站导航
  877. * @param array $data
  878. * @return array
  879. */
  880. public function delWebsiteCategory(array $data): array
  881. {
  882. $website_id = $data['website_id']??0;
  883. $category_id = $data['category_id']??0;
  884. $ids = $this->getUnderlingUIds(intval($category_id));
  885. $ids_arr = explode(",", $ids);
  886. $result = WebsiteCategory::where(['website_id'=>$website_id])->whereIn("category_id",$ids_arr)->delete();
  887. if($result){
  888. return Result::success($result);
  889. }else{
  890. return Result::error("删除失败",0);
  891. }
  892. }
  893. /**
  894. * 获取网站导航
  895. * @param array $data
  896. * @return array
  897. */
  898. public function getAdminWebsiteCategory(array $data): array
  899. {
  900. $where = [
  901. 'website_id'=>$data['website_id'],
  902. 'pid'=>0
  903. ];
  904. $result = WebsiteCategory::where($where)->get();
  905. if($result){
  906. return Result::success($result);
  907. }else{
  908. return Result::error("查询失败",0);
  909. }
  910. }
  911. /**
  912. * 更新网站导航
  913. * @param array $data
  914. * @return array
  915. */
  916. public function upWebsiteCategory(array $data): array
  917. {
  918. Db::beginTransaction();
  919. try{
  920. //合并栏目id
  921. $reqIds = array_merge($data['old_category_arr_id'],$data['new_category_arr_id']);
  922. //对比old 数组差异化,把差异化的删除
  923. $result = WebsiteCategory::where(['website_id'=>$data['website_id'],'pid'=>0])->get();
  924. $result = $result->toArray();
  925. $categoryIds = [];
  926. if($result){
  927. foreach ($result as $val){
  928. array_push($categoryIds,$val['category_id']);
  929. }
  930. }
  931. //和原始数据对比取交际
  932. $reqidsIntersect = array_intersect($reqIds,$categoryIds);
  933. //再取差集 进行对比
  934. $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds),array_diff($categoryIds,$reqidsIntersect));
  935. var_dump("差集:",$differenceIDS);
  936. $arr_ids = [];
  937. if(count($differenceIDS)>0){
  938. foreach ($differenceIDS as $vv){
  939. $idV = $this->getUnderlingUIds(intval($vv));
  940. $ids_arrV = explode(",", $idV);
  941. array_push($arr_ids,$ids_arrV);
  942. }
  943. }
  944. $del_ids = array_reduce($arr_ids, 'array_merge', array());
  945. //有差异 删除
  946. if(count($del_ids)>0){
  947. WebsiteCategory::where(['website_id'=>$data['website_id']])->whereIn("category_id",$del_ids)->delete();
  948. }
  949. //传过来的值 和 交际 对比,选出要添加的值 进行插入
  950. $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect),array_diff($reqidsIntersect,$reqIds));
  951. var_dump("要存储的:",$insertIDS);
  952. //新的数组重新创建
  953. if(count($insertIDS)>0){
  954. $arr = [];
  955. $categoryListIds = $insertIDS;
  956. if($categoryListIds){
  957. foreach ($categoryListIds as $v){
  958. $ids = $this->getUnderlingUIds(intval($v));
  959. $ids_arr = explode(",", $ids);
  960. array_push($arr,$ids_arr);
  961. }
  962. }
  963. $mergedArray = [];
  964. foreach ($arr as $subarray) {
  965. $mergedArray = array_merge($mergedArray, $subarray);
  966. }
  967. var_dump("要插入的ID:",$mergedArray);
  968. //查询出所有的分类进行分割插入 组装数据
  969. $categoryListData = Category::whereIn('id',$mergedArray)->get();
  970. $categoryListData = $categoryListData->toArray();
  971. $insertData = [];
  972. if($categoryListData){
  973. foreach ($categoryListData as $key=>$value){
  974. $insertData[$key]['website_id'] = $data['website_id'];
  975. $insertData[$key]['name'] = $value['name'];
  976. $insertData[$key]['sort'] = $value['sort'];
  977. $insertData[$key]['pid'] = $value['pid'];
  978. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  979. $insertData[$key]['seo_title'] = $value['seo_title'];
  980. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  981. $insertData[$key]['seo_description'] = $value['seo_description'];
  982. $insertData[$key]['alias'] = $value['name'];
  983. $insertData[$key]['category_id'] = $value['id'];
  984. }
  985. }
  986. WebsiteCategory::insert($insertData);
  987. }
  988. Db::commit();
  989. } catch(\Throwable $ex){
  990. Db::rollBack();
  991. var_dump($ex->getMessage());
  992. return Result::error("修改失败",0);
  993. }
  994. return Result::success();
  995. }
  996. /**
  997. * 获取网站列表
  998. * @param array $data
  999. * @return array
  1000. */
  1001. public function getWebsiteCategoryList(array $data): array
  1002. {
  1003. $where = [];
  1004. if(isset($data['keyword']) && !empty($data['keyword'])){
  1005. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  1006. }
  1007. if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
  1008. array_push($where,['website.website_column_id','=',$data['website_column_id']]);
  1009. }
  1010. $result = Website::where($where)
  1011. ->with(["websiteCategory"=>function ($query) {
  1012. $query->where(['pid'=>0])->select('website_id','name','alias','category_id');
  1013. }])
  1014. ->limit($data['pageSize'])->orderBy("updated_at","desc")->offset(($data['page']-1)*$data['pageSize'])
  1015. ->get();
  1016. $count = Website::where($where)->count();
  1017. if (empty($result)) {
  1018. return Result::error("没有数据",0);
  1019. }
  1020. $data = [
  1021. 'rows'=>$result->toArray(),
  1022. 'count'=>$count
  1023. ];
  1024. if($result){
  1025. return Result::success($data);
  1026. }else{
  1027. return Result::error("查询失败",0);
  1028. }
  1029. }
  1030. /**
  1031. * 删除网站下的所有导航
  1032. * @param array $data
  1033. * @return array
  1034. */
  1035. public function delWebsiteAllCategory(array $data): array
  1036. {
  1037. $website_id = $data['website_id'];
  1038. $result = WebsiteCategory::where(['website_id'=>$website_id])->delete();
  1039. if($result){
  1040. return Result::success($result);
  1041. }else{
  1042. return Result::error("删除失败",0);
  1043. }
  1044. }
  1045. /**
  1046. * 获取网站下的某一个导航
  1047. * @param array $data
  1048. * @return array
  1049. */
  1050. public function getWebsiteCategoryOnes(array $data): array
  1051. {
  1052. $website_id = $data['website_id'];
  1053. $category_id = $data['category_id'];
  1054. $result = WebsiteCategory::where(['website_category.website_id'=>$website_id,'website_category.category_id'=>$category_id])
  1055. ->first();
  1056. if($result){
  1057. return Result::success($result);
  1058. }else{
  1059. return Result::error("查询失败",0);
  1060. }
  1061. }
  1062. /**
  1063. * 更新网闸下的某一个导航
  1064. * @param array $data
  1065. * @return array
  1066. */
  1067. public function upWebsiteCategoryones(array $data): array
  1068. {
  1069. $where = [
  1070. 'website_id'=>$data['website_id'],
  1071. 'category_id'=>$data['category_id'],
  1072. ];
  1073. $result = WebsiteCategory::where($where)->update($data);
  1074. if($result){
  1075. return Result::success($result);
  1076. }else{
  1077. return Result::error("更新失败",0);
  1078. }
  1079. }
  1080. /**
  1081. * 获取网站下的所有导航(包含子导航)
  1082. * @param array $data
  1083. * @return array
  1084. */
  1085. public function getWebsiteAllCategory(array $data): array
  1086. {
  1087. $where = [];
  1088. if(isset($data['website_id']) && !empty($data['website_id'])){
  1089. array_push($where,['website_category.website_id','=',$data['website_id']]);
  1090. }
  1091. if(isset($data['name']) && !empty($data['name'])){
  1092. array_push($where,['website_category.name','like','%'.$data['name'].'%']);
  1093. }
  1094. if(isset($data['alias']) && !empty($data['alias'])){
  1095. array_push($where,['website_category.alias','like','%'.$data['alias'].'%']);
  1096. }
  1097. if(isset($data['department_id']) && !empty($data['department_id'])){
  1098. array_push($where,['category.department_id','=',$data['department_id']]);
  1099. }
  1100. if(isset($data['city_id']) && !empty($data['city_id'])){
  1101. array_push($where,['category.city_id','=',$data['city_id']]);
  1102. }
  1103. $result = WebsiteCategory::where($where)
  1104. ->leftJoin("category",'website_category.category_id','category.id')
  1105. ->leftJoin("department",'category.department_id','department.id')
  1106. ->leftJoin("district",'category.city_id','district.id')
  1107. ->select("website_category.*","department.name as department_name","district.name as city_name")
  1108. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
  1109. ->get();
  1110. $count = WebsiteCategory::where($where)
  1111. ->leftJoin("category",'website_category.category_id','category.id')
  1112. ->leftJoin("department",'category.department_id','department.id')
  1113. ->leftJoin("district",'category.city_id','district.id')
  1114. ->count();
  1115. if (empty($result)) {
  1116. return Result::error("没有数据",0);
  1117. }
  1118. $data = [
  1119. 'rows'=>$result->toArray(),
  1120. 'count'=>$count
  1121. ];
  1122. if($result){
  1123. return Result::success($data);
  1124. }else{
  1125. return Result::error("查询失败",0);
  1126. }
  1127. if($result){
  1128. return Result::success($result);
  1129. }else{
  1130. return Result::error("查询失败",0);
  1131. }
  1132. }
  1133. /**
  1134. * 递归查询数据
  1135. * @param $id
  1136. * @param $ids
  1137. * @return string
  1138. */
  1139. public function getUnderlingUIds($id, $ids='')
  1140. {
  1141. $back = Category::where(['pid'=>$id])->get();
  1142. $back = $back->toArray();
  1143. if (!empty($back) && is_array($back)) {
  1144. foreach ($back as $v) {
  1145. //防止当前人的ID重复去查询,形成恶性循环
  1146. if ($v['id'] == $id) {
  1147. continue;
  1148. }
  1149. $back2 = Category::where(['pid'=>$id])->count('id');
  1150. if ($back2 > 0) {
  1151. $ids = $this->getUnderlingUIds($v['id'],$ids);
  1152. } else {
  1153. $ids .= ','.$v['id'];
  1154. }
  1155. }
  1156. }
  1157. $ids = $id.','.$ids.',';
  1158. $ids = str_replace(',,', ",", $ids);
  1159. $ids = trim($ids, ',');
  1160. return $ids;
  1161. }
  1162. /**
  1163. * 检测网站名称是否重复
  1164. * @param array $data
  1165. * @return array
  1166. */
  1167. public function checkWebsiteName(array $data): array
  1168. {
  1169. if(isset($data['id'])){
  1170. $data[] = ['id',"!=",$data['id']];
  1171. unset($data['id']);
  1172. }
  1173. $websiteInfo = Website::query()->where($data)->first();
  1174. if (empty($websiteInfo)) {
  1175. return Result::error("找不到网站",0);
  1176. }
  1177. return Result::success($websiteInfo->toArray());
  1178. }
  1179. /**
  1180. * 检测网站url是否重复
  1181. * @param array $data
  1182. * @return array
  1183. */
  1184. public function checkWebsiteUrl(array $data): array
  1185. {
  1186. $whereData = [];
  1187. if(isset($data['id'])){
  1188. $whereData = [['id',"!=",$data['id']]];
  1189. unset($data['id']);
  1190. }
  1191. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1192. if (empty($websiteInfo)) {
  1193. return Result::error("找不到URL",0);
  1194. }
  1195. return Result::success($websiteInfo->toArray());
  1196. }
  1197. /**
  1198. * 获取网站底部基础信息
  1199. * @param array $data
  1200. * @return array
  1201. */
  1202. public function getWebsiteFootInfo(array $data): array
  1203. {
  1204. if(isset($data['website_id']) && !empty($data['website_id'])){
  1205. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1206. if (empty($website)) {
  1207. return Result::error("找不到网站",0);
  1208. }
  1209. }else{
  1210. return Result::error("参数错误",0);
  1211. }
  1212. $website_foot = WebsiteTemplateInfo::where('website_id',$data['website_id'])->where('status',2)->first();
  1213. $website_head = Website::where('id',$data['website_id'])
  1214. ->select('id','website_name','logo','title','keywords','description')->first();
  1215. if (empty($website_foot)) {
  1216. return Result::error("暂无底部基础信息",0);
  1217. }
  1218. if (empty($website_head)) {
  1219. return Result::error("暂无头部基础信息",0);
  1220. }
  1221. $result = [
  1222. 'website_foot'=>$website_foot,
  1223. 'website_head'=>$website_head
  1224. ];
  1225. return Result::success($result);
  1226. }
  1227. /**
  1228. * 获取网站底部导航
  1229. * @param array $data
  1230. * @return array
  1231. */
  1232. public function getWebsiteFooterCategory(array $data): array
  1233. {
  1234. if(isset($data['website_id']) && !empty($data['website_id'])){
  1235. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1236. if (empty($website)) {
  1237. return Result::error("找不到网站",0);
  1238. }
  1239. }else{
  1240. return Result::error("参数错误",0);
  1241. }
  1242. $result = FooterCategory::where('website_id',$data['website_id'])->get();
  1243. if (empty($result)) {
  1244. return Result::error("暂无底部导航",0);
  1245. }
  1246. return Result::success($result->toArray());
  1247. }
  1248. /**
  1249. * 获取网站底部导航列表
  1250. * @param array $data
  1251. * @return array
  1252. */
  1253. public function getWebsiteFooterCategoryList(array $data): array
  1254. {
  1255. if(isset($data['website_id']) && !empty($data['website_id'])){
  1256. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1257. if (empty($website)) {
  1258. return Result::error("找不到网站",0);
  1259. }
  1260. }else{
  1261. return Result::error("参数错误",0);
  1262. }
  1263. $footercategory = FooterCategory::where('website_id',$data['website_id'])->where('id',$data['fcat_id'])->first();
  1264. // '底部导航类型 0:内容型;1:列表型;',
  1265. if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
  1266. return Result::error("底部导航id错误",0);
  1267. }else{
  1268. $query = FooterContent::where('fcat_id',$data['fcat_id']);
  1269. if($query->count() == 0){
  1270. return Result::error("暂无底部导航列表",0);
  1271. }elseif($query->count() == 1){
  1272. $result = $query->first();
  1273. }else{
  1274. $result = $query->get();
  1275. }
  1276. }
  1277. return Result::success($result);
  1278. }
  1279. /**
  1280. * 获取网站底部导航
  1281. * @param array $data
  1282. * @return array
  1283. */
  1284. public function getWebsiteFooterCategoryInfo(array $data): array
  1285. {
  1286. if(isset($data['website_id']) && !empty($data['website_id'])){
  1287. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1288. if (empty($website)) {
  1289. return Result::error("找不到网站",0);
  1290. }
  1291. }else{
  1292. return Result::error("参数错误",0);
  1293. }
  1294. if (isset($data['type']) && $data['type'] == 0) {
  1295. $fcatid = FooterCategory::where('website_id',$data['website_id'])->where('id',$data['fcat_id'])->first();
  1296. if (empty($fcatid)) {
  1297. return Result::error("底部导航id错误",0);
  1298. }
  1299. $result = FooterContent::where('fcat_id',$data['fcat_id'])->first();
  1300. }else{
  1301. $result = FooterContent::where('id',$data['fcat_id'])->first();
  1302. }
  1303. if (empty($result)) {
  1304. return Result::error("暂无底部导航内容",0);
  1305. }
  1306. return Result::success($result);
  1307. }
  1308. /*
  1309. * 搜索网站二级导航
  1310. * @param array $data
  1311. * @return array
  1312. * */
  1313. public function selectWebsiteCategory(array $data): array
  1314. {
  1315. if(isset($data['website_id']) &&!empty($data['website_id'])){
  1316. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1317. if (empty($website)) {
  1318. return Result::error("暂无该网站",0);
  1319. }
  1320. $category = WebsiteCategory::where('website_id',$data['website_id'])->where('pid',$data['pid'])->pluck('category_id')->all();
  1321. // return Result::success($category);
  1322. if (empty($category)) {
  1323. return Result::error("暂无二级导航",0);
  1324. }
  1325. $query = Category::whereIn('id', $category);
  1326. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1327. $cityid = District::where('id', $data['cityid'])->first();
  1328. if (empty($cityid)) {
  1329. return Result::error("暂无此城市", 0);
  1330. } else {
  1331. $result = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->get();
  1332. // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
  1333. if (empty($result)) {
  1334. return Result::error("暂无此城市下的二级导航", 0);
  1335. }
  1336. $city = 1;
  1337. // var_dump("城市====================",$result);
  1338. }
  1339. }
  1340. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1341. $departmentid = Department::where('id', $data['department_id'])->first();
  1342. if (empty($departmentid)) {
  1343. return Result::error("暂无此部门", 0);
  1344. } else {
  1345. $result = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->get();
  1346. if (empty($result)) {
  1347. return Result::error("暂无此部门下的二级导航", 0);
  1348. }
  1349. // var_dump("职能部门*******************",$result);
  1350. $department = 1;
  1351. }
  1352. }
  1353. if(!empty($city) && !empty($department)){
  1354. // var_dump("城市和职能部门----------------------",$result);
  1355. $result = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->get();
  1356. }else{
  1357. $result = $query->get();
  1358. }
  1359. if (empty($result)) {
  1360. return Result::error("暂无二级导航",0);
  1361. }
  1362. // department_id
  1363. }else{
  1364. return Result::error("参数错误",0);
  1365. }
  1366. return Result::success($result);
  1367. }
  1368. /**
  1369. * 获取网站栏目seo
  1370. * @param array $data
  1371. * @return array
  1372. */
  1373. public function getWebsiteCategoryHead(array $data): array
  1374. {
  1375. if(isset($data['website_id']) && !empty($data['website_id'])){
  1376. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1377. if (empty($website)) {
  1378. return Result::error("找不到网站",0);
  1379. }
  1380. }else{
  1381. return Result::error("参数错误",0);
  1382. }
  1383. if (isset($data['catid']) && !empty($data['catid'])) {
  1384. $fcatid = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->first();
  1385. if (empty($fcatid)) {
  1386. return Result::error("导航id错误",0);
  1387. }
  1388. $result = Category::where('id',$data['catid'])->first();
  1389. }
  1390. if (empty($result)) {
  1391. return Result::error("暂无导航",0);
  1392. }
  1393. return Result::success($result);
  1394. }
  1395. /*
  1396. * 搜索网站二级导航
  1397. * @param array $data
  1398. * @return array
  1399. * */
  1400. public function getOneWebsiteCategory(array $data): array
  1401. {
  1402. if(isset($data['website_id']) &&!empty($data['website_id'])){
  1403. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1404. if (empty($website)) {
  1405. return Result::error("暂无该网站",0);
  1406. }
  1407. $result = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['category_id'])->select('category_id','name')->first();
  1408. // return Result::success($category);
  1409. if (empty($result)) {
  1410. return Result::error("暂无此导航",0);
  1411. }
  1412. // department_id
  1413. }else{
  1414. return Result::error("参数错误",0);
  1415. }
  1416. return Result::success($result);
  1417. }
  1418. }