WebsiteService.php 49 KB

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