WebsiteService.php 50 KB

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