WebsiteService.php 49 KB

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