WebsiteService.php 51 KB

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