WebsiteService.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\AdPlace;
  4. use App\Model\AdSize;
  5. use App\Model\Article;
  6. use App\Model\Category;
  7. use App\Model\FooterCategory;
  8. use App\Model\FooterContent;
  9. use App\Model\LetterOfComplaint;
  10. use App\Model\Sector;
  11. use App\Model\TemplateClass;
  12. use App\Model\Template;
  13. use App\Model\User;
  14. use App\Model\WebsiteRole;
  15. use App\Model\WebsiteRoleUser;
  16. use App\Model\Website;
  17. use App\Model\WebsiteColumn;
  18. use App\Model\WebsiteTemplate;
  19. use Hyperf\DbConnection\Db;
  20. use Hyperf\RpcServer\Annotation\RpcService;
  21. use App\Tools\Result;
  22. use App\Model\WebsiteCategory;
  23. use function PHPUnit\Framework\isNull;
  24. use App\Model\Component;
  25. #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  26. class WebsiteService implements WebsiteServiceInterface
  27. {
  28. /**
  29. * @param string $keyword
  30. * @param int $page
  31. * @param int $pageSize
  32. * @return array
  33. */
  34. public function getWebsitetList(array $data): array
  35. {
  36. $where = [];
  37. if(isset($data['keyword']) && !empty($data['keyword'])){
  38. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  39. }
  40. if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
  41. array_push($where,['website.website_column_id','=',$data['website_column_id']]);
  42. }
  43. if(isset($data['city_id']) && !empty($data['city_id'])){
  44. array_push($where,['website.city_id','=',$data['city_id']]);
  45. }
  46. $result = Website::where($where)
  47. ->leftJoin("website_column","website.website_column_id","website_column.id")
  48. ->leftJoin("district","district.id","website.city_id")
  49. ->select("website.*","website_column.column_name","district.name as city_name")
  50. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("website.id","desc")->get();
  51. $count = Website::where($where)->count();
  52. if (empty($result)) {
  53. return Result::error("没有数据",0);
  54. }
  55. $data = [
  56. 'rows'=>$result->toArray(),
  57. 'count'=>$count
  58. ];
  59. return Result::success($data);
  60. }
  61. /**
  62. * @param array $data
  63. * @return array
  64. */
  65. public function createWebsite(array $data): array
  66. {
  67. var_dump("网站数据:",$data);
  68. $insertData = [
  69. 'website_name'=>$data['website_name'],
  70. 'logo'=>$data['logo']??'',
  71. 'website_url'=>$data['website_url']??'',
  72. 'city_id'=>$data['city_id']??0,
  73. 'website_column_id'=>$data['website_column_id'],
  74. 'title'=>$data['title']??'',
  75. 'keywords'=>$data['keywords']??'',
  76. 'description'=>$data['description']??'',
  77. 'status'=>$data['status']??0,
  78. 'website_column_arr_id'=>$data['website_column_arr_id'],
  79. 'city_arr_id'=>$data['city_arr_id']??[0],
  80. 'template_id' =>$data['template_id']??0,
  81. ];
  82. $result = Website::insertGetId($insertData);
  83. if(empty($result)){
  84. return Result::error("创建失败",0);
  85. }else{
  86. return Result::success(["id"=>$result]);
  87. }
  88. }
  89. /**
  90. * @param int $id
  91. * @param array $data
  92. * @return array
  93. */
  94. public function updateWebsite(int $id,array $data): array
  95. {
  96. $insertData = [
  97. 'website_name'=>$data['website_name'],
  98. 'logo'=>$data['logo']??'',
  99. 'website_url'=>$data['website_url']??'',
  100. 'city_id'=>$data['city_id']??0,
  101. 'website_column_id'=>$data['website_column_id'],
  102. 'title'=>$data['title']??'',
  103. 'keywords'=>$data['keywords']??'',
  104. 'description'=>$data['description']??'',
  105. 'status'=>$data['status']??0,
  106. 'website_column_arr_id'=>$data['website_column_arr_id'],
  107. 'city_arr_id'=>$data['city_arr_id']??[0],
  108. 'template_id' =>$data['template_id']??0,
  109. ];
  110. $result = Website::where('id',$id)->update($insertData);
  111. var_dump("更新站点",$result);
  112. if(empty($result)){
  113. return Result::error("更新失败",0);
  114. }else{
  115. return Result::success();
  116. }
  117. }
  118. /**
  119. * @param int $id
  120. * @return array
  121. */
  122. public function delWebsite(int $id): array
  123. {
  124. $result = Website::where('id',$id )->delete();
  125. if(empty($result)){
  126. return Result::error("删除失败",0);
  127. }else{
  128. return Result::success();
  129. }
  130. }
  131. /**
  132. * @param int $id
  133. * @return array
  134. */
  135. public function getWebsiteInfo(int $id): array
  136. {
  137. $where = [
  138. ['website.id','=',$id]
  139. ];
  140. $result = Website::where($where )
  141. ->leftJoin("website_template_info","website_template_info.website_id","website.id")
  142. ->select("website.*",
  143. "website_template_info.template_id",
  144. "website_template_info.page_type",
  145. "website_template_info.statement",
  146. "website_template_info.organizer",
  147. "website_template_info.copyright_information",
  148. "website_template_info.contact_number",
  149. "website_template_info.company_address",
  150. "website_template_info.project_logo",
  151. "website_template_info.project_name",
  152. "website_template_info.project_url",
  153. "website_template_info.company_logo",
  154. "website_template_info.company_name",
  155. "website_template_info.company_url",
  156. "website_template_info.record_number",
  157. "website_template_info.record_number_url",
  158. "website_template_info.icp_number",
  159. "website_template_info.icp_number_url",
  160. "website_template_info.customer_service_qq",
  161. "website_template_info.communications",
  162. "website_template_info.status",
  163. )
  164. ->first();
  165. if(empty($result)){
  166. return Result::error("数据不存在",0);
  167. }else{
  168. return Result::success($result->toArray());
  169. }
  170. }
  171. /**
  172. * 查询所有的站点栏目
  173. * @return array
  174. */
  175. public function getWebsiteColumn(array $data): array
  176. {
  177. $result = WebsiteColumn::where($data)->get();
  178. if(empty($result)){
  179. return Result::error("数据不存在",0);
  180. }else{
  181. return Result::success($result->toArray());
  182. }
  183. }
  184. /**
  185. * @param string $keyword
  186. * @param int $page
  187. * @param int $pageSize
  188. * @return array
  189. */
  190. public function getWebsiteColumnList(array $data):array
  191. {
  192. $where = [];
  193. if(isset($data['keyword']) && $data['keyword']){
  194. array_push($where,['website_column.column_name','like','%'.$data['keyword'].'%']);
  195. }
  196. $result = WebsiteColumn::where($where)
  197. ->leftJoin("website_column as wc","website_column.pid","wc.id")
  198. ->select("website_column.*","wc.column_name as parent_column_name")
  199. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->get();
  200. $count = WebsiteColumn::where($where)->count();
  201. if (empty($result)) {
  202. return Result::error("没有数据",0);
  203. }
  204. $data = [
  205. 'rows'=>$result->toArray(),
  206. 'count'=>$count
  207. ];
  208. return Result::success($data);
  209. }
  210. /**
  211. * @param array $data
  212. * @return array
  213. */
  214. public function createWebsiteColumn(array $data): array
  215. {
  216. $insertData = [
  217. 'column_name'=>$data['column_name'],
  218. 'pid'=>$data['pid']??'',
  219. 'column_arr_id'=>$data['column_arr_id']??[0],
  220. 'sort'=>$data['sort']??0,
  221. 'remark'=>$data['remark']??'',
  222. ];
  223. $result = WebsiteColumn::insertGetId($insertData);
  224. if(empty($result)){
  225. return Result::error("创建失败",0);
  226. }else{
  227. return Result::success(["id"=>$result]);
  228. }
  229. }
  230. /**
  231. * @param int $id
  232. * @param array $data
  233. * @return array
  234. */
  235. public function updateWebsiteColumn(int $id,array $data): array
  236. {
  237. $insertData = [
  238. 'column_name'=>$data['column_name'],
  239. 'pid'=>$data['pid']??'',
  240. 'column_arr_id'=>$data['column_arr_id']??[0],
  241. 'sort'=>$data['sort']??0,
  242. 'remark'=>$data['remark']??'',
  243. ];
  244. $result = WebsiteColumn::where('id',$id)->update($insertData);
  245. if(empty($result)){
  246. return Result::error("更新失败",0);
  247. }else{
  248. return Result::success();
  249. }
  250. }
  251. /**
  252. * @param int $id
  253. * @return array
  254. */
  255. public function delWebsiteColumn(int $id): array
  256. {
  257. $list = WebsiteColumn::where(['pid'=>$id])->get();
  258. if($list){
  259. return Result::error("存在子网系,不能删除,请先删除子网系",0);
  260. }
  261. $result = WebsiteColumn::where('id',$id )->delete();
  262. if(empty($result)){
  263. return Result::error("删除失败",0);
  264. }else{
  265. return Result::success();
  266. }
  267. }
  268. /**
  269. * @param string $keyword
  270. * @param int $page
  271. * @param int $pageSize
  272. * @return array
  273. */
  274. public function getWebsiteRoleList(string $keyword,int $page,int $pageSize,int $websiteId):array
  275. {
  276. $where = [
  277. ['role.role_name','like','%'.$keyword.'%'],
  278. ['website_role.website_id','=',$websiteId],
  279. ];
  280. $result = WebsiteRole::where($where)
  281. ->leftJoin("role","role.id","website_role.role_id")
  282. ->select("role.*","website_role.type","website_role.role_id","website_role.id as website_role_id","website_role.website_id")
  283. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  284. $count = WebsiteRole::where($where) ->leftJoin("role","role.id","website_role.role_id")->count();
  285. if (empty($result)) {
  286. return Result::error("没有数据",0);
  287. }
  288. $data = [
  289. 'rows'=>$result->toArray(),
  290. 'count'=>$count
  291. ];
  292. return Result::success($data);
  293. }
  294. /**
  295. * @param array $data
  296. * @return array
  297. */
  298. public function createWebsiteRole(array $data): array
  299. {
  300. $insertData = [
  301. 'website_id'=>$data['website_id'],
  302. 'role_id'=>$data['role_id']??''
  303. ];
  304. $info = WebsiteRole::where($insertData)->first();
  305. if($info){
  306. return Result::error("不能重复添加角色",0);
  307. }
  308. $insertData['admin_user_id'] = $data['admin_user_id']??'';
  309. $insertData['type'] = $data['type']??'';
  310. $result = WebsiteRole::insertGetId($insertData);
  311. if(empty($result)){
  312. return Result::error("创建失败",0);
  313. }else{
  314. return Result::success(["id"=>$result]);
  315. }
  316. }
  317. /**
  318. * 暂时用不上
  319. * @param int $id
  320. * @param array $data
  321. * @return array
  322. */
  323. public function updateWebsiteRole(int $id,array $data): array
  324. {
  325. $insertData = [
  326. 'website_id'=>$data['website_id'],
  327. 'type'=>$data['type']??'',
  328. ];
  329. $result = WebsiteRole::where('id',$id)->update($insertData);
  330. if(empty($result)){
  331. return Result::error("更新失败",0);
  332. }else{
  333. return Result::success();
  334. }
  335. }
  336. /**
  337. * @param int $id
  338. * @return array
  339. */
  340. public function delWebsiteRole(int $id): array
  341. {
  342. $result = WebsiteRole::where('id',$id )->delete();
  343. if(empty($result)){
  344. return Result::error("删除失败",0);
  345. }else{
  346. return Result::success();
  347. }
  348. }
  349. /**
  350. * @param string $keyword
  351. * @param int $page
  352. * @param int $pageSize
  353. * @return array
  354. */
  355. public function getWebsiteRoleUserList(string $keyword,int $page,int $pageSize,int $websiteId,int $roleId):array
  356. {
  357. $where = [
  358. ['website_role_user.website_id','=',$websiteId],
  359. ['website_role_user.role_id','=',$roleId],
  360. ];
  361. $count = WebsiteRoleUser::where($where)->count();
  362. $where[] = ['u.user_name','like','%'.$keyword.'%'];
  363. $result = WebsiteRoleUser::where($where)
  364. ->leftJoin("user as u","website_role_user.user_id","u.id")
  365. ->leftJoin("website as w","website_role_user.website_id","u.id")
  366. ->leftJoin("role as r","website_role_user.role_id","r.id")
  367. ->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')
  368. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  369. if (empty($result)) {
  370. return Result::error("没有数据",0);
  371. }
  372. $data = [
  373. 'rows'=>$result->toArray(),
  374. 'count'=>$count
  375. ];
  376. return Result::success($data);
  377. }
  378. /**
  379. * @param array $data
  380. * @return array
  381. */
  382. public function createWebsiteRoleUser(array $data): array
  383. {
  384. $insertData = [
  385. 'website_id'=>$data['website_id'],
  386. 'user_id'=>$data['user_id']??'',
  387. ];
  388. $info = WebsiteRoleUser::where($insertData)->first();
  389. if($info){
  390. return Result::error("不能重复添加角色用户",0);
  391. }
  392. $insertData['role_id'] = $data['role_id']??'';
  393. $insertData['admin_user_id'] = $data['admin_user_id']??'';
  394. $insertData['type'] = $data['type']??'';
  395. $result = WebsiteRoleUser::insertGetId($insertData);
  396. if(empty($result)){
  397. return Result::error("创建失败",0);
  398. }else{
  399. return Result::success(["id"=>$result]);
  400. }
  401. }
  402. /**
  403. * @param int $id
  404. * @param array $data
  405. * @return array
  406. */
  407. public function updateWebsiteRoleUser(int $id,array $data): array
  408. {
  409. $insertData = [
  410. 'website_id'=>$data['website_id'],
  411. 'type'=>$data['type']??'',
  412. 'type_id'=>$data['type_id']??'',
  413. 'role_id'=>$data['role_id']??'',
  414. ];
  415. $result = WebsiteRoleUser::where('id',$id)->update($insertData);
  416. if(empty($result)){
  417. return Result::error("更新失败",0);
  418. }else{
  419. return Result::success();
  420. }
  421. }
  422. /**
  423. * @param int $id
  424. * @return array
  425. */
  426. public function delWebsiteRoleUser(int $id): array
  427. {
  428. $result = WebsiteRoleUser::where('id',$id )->delete();
  429. if(empty($result)){
  430. return Result::error("删除失败",0);
  431. }else{
  432. return Result::success();
  433. }
  434. }
  435. /**
  436. * 根据域名获取网站 站点id
  437. * @param array $data
  438. * @return array
  439. */
  440. public function getWebsiteId(array $data): array
  441. {
  442. $result = Website::whereJsonContains('website_url',$data['website_url'])->first();
  443. if(empty($result)){
  444. return Result::error("查询站点失败",0);
  445. }else{
  446. return Result::success($result);
  447. }
  448. }
  449. /**
  450. * 查询网站下面的导航
  451. * @param array $data
  452. * @return array
  453. */
  454. public function getWebsiteCategory(array $data): array
  455. {
  456. $where = [
  457. 'website_id'=>$data['website_id'],
  458. 'pid'=>0
  459. ];
  460. $result = WebsiteCategory::where($where)->orderBy('sort','asc')->get();
  461. if(empty($result)){
  462. return Result::error("查询站点栏目失败",0);
  463. }else{
  464. return Result::success($result);
  465. }
  466. }
  467. /**
  468. * 网站首页数据统计, 管理员
  469. * @return void
  470. */
  471. public function getAdminIndex(array $data): array
  472. {
  473. var_dump("用户类型:",$data['type_id']);
  474. switch ($data['type_id']){
  475. case 4:
  476. $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;');
  477. return Result::success($result);
  478. break;
  479. case 10000:
  480. $res = [];
  481. //网站
  482. $res['website']['count'] = 0;
  483. $res['website']['growth_rate'] = 0;
  484. //资讯
  485. $res['article']['count'] = 0;
  486. $res['article']['growth_rate'] = 0;
  487. //导航池
  488. $res['category']['count'] = 0;
  489. $res['category']['growth_rate'] = 0;
  490. //近一月数据
  491. $res['monthArticle']= [];
  492. //用户类型
  493. $res['userType'] = [];
  494. $res['website']['count'] = Website::where([])->count();
  495. $res['article']['count'] = Article::whereNotIn('status',['404'])->count();
  496. $res['category']['count'] = Category::where([])->count();
  497. $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;');
  498. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  499. return Result::success($res);
  500. }
  501. return [];
  502. }
  503. /**
  504. * 获取模板类型
  505. * @return void
  506. */
  507. public function getTemplateClass(array $data): array
  508. {
  509. $where = [];
  510. if(isset($data['name']) && $data['name']){
  511. array_push($where,['name','like','%'.$data['name'].'%']);
  512. }
  513. $result = TemplateClass::where($where)->orderBy('sort','asc')->get();
  514. if(empty($result)){
  515. return Result::error("没有模板类型",0);
  516. }else{
  517. return Result::success($result);
  518. }
  519. }
  520. /**
  521. * 添加模板类型
  522. * @param
  523. * @return void
  524. */
  525. public function addTemplateClass(array $data): array
  526. {
  527. $insertData = [
  528. 'name'=>$data['name']
  529. ];
  530. $result = TemplateClass::insertGetId($insertData);
  531. if(empty($result)){
  532. return Result::error("创建失败",0);
  533. }else{
  534. return Result::success(["id"=>$result]);
  535. }
  536. }
  537. /**
  538. * 更新模板
  539. * @param array $data
  540. * @return array
  541. */
  542. public function upTemplateClass(array $data): array
  543. {
  544. $where = [
  545. 'id'=>$data['id']
  546. ];
  547. $insertData = [
  548. 'name'=>$data['name']
  549. ];
  550. $result = TemplateClass::where($where)->update($insertData);
  551. if(empty($result)){
  552. return Result::error("更新失败",0);
  553. }else{
  554. return Result::success();
  555. }
  556. }
  557. /**
  558. * 删除模板
  559. * @param array $data
  560. * @return array
  561. */
  562. public function delTemplateClass(array $data): array
  563. {
  564. $where = [
  565. 'id'=>$data['id']
  566. ];
  567. $result = TemplateClass::where($where)->delete();
  568. if(empty($result)){
  569. return Result::error("删除失败",0);
  570. }else{
  571. return Result::success();
  572. }
  573. }
  574. /**
  575. * 获取分类下的模板
  576. * @param array $data
  577. * @return array
  578. */
  579. public function getTemplate(array $data): array
  580. {
  581. $page = $data['page'];
  582. $pageSize = $data['pageSize'];
  583. $where = [];
  584. if(isset($data['template_class_id']) && $data['template_class_id']){
  585. array_push($where,['template_class_id','=',$data['template_class_id']]);
  586. }
  587. $result = Template::where($where)
  588. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  589. $count = Template::where($where)->count();
  590. if (empty($result)) {
  591. return Result::error("没有数据",0);
  592. }
  593. $data = [
  594. 'rows'=>$result->toArray(),
  595. 'count'=>$count
  596. ];
  597. return Result::success($data);
  598. }
  599. /**
  600. * 创建模板
  601. * @param
  602. * @return void
  603. */
  604. public function addTemplate(array $data): array
  605. {
  606. $insertData = [
  607. 'template_name'=>$data['template_name'],
  608. 'template_img'=>json_encode($data['template_img']),
  609. 'template_class_id'=>$data['template_class_id'],
  610. ];
  611. $result = Template::insertGetId($insertData);
  612. if(empty($result)){
  613. return Result::error("创建模板失败",0);
  614. }else{
  615. return Result::success(["id"=>$result]);
  616. }
  617. }
  618. /**
  619. * 更新模板
  620. * @param array $data
  621. * @return array
  622. */
  623. public function upTemplate(array $data): array
  624. {
  625. $where = [
  626. 'id'=>$data['id']
  627. ];
  628. $insertData = [
  629. 'template_name'=>$data['template_name'],
  630. 'template_img'=>json_encode($data['template_img']),
  631. 'template_class_id'=>$data['template_class_id'],
  632. ];
  633. $result = Template::where($where)->update($insertData);
  634. if(empty($result)){
  635. return Result::error("更新模板失败",0);
  636. }else{
  637. return Result::success();
  638. }
  639. }
  640. /**
  641. * 删除模板
  642. * @param array $data
  643. * @return array
  644. */
  645. public function delTemplate(array $data): array
  646. {
  647. $where = [
  648. 'id'=>$data['id']
  649. ];
  650. $result = Template::where($where)->delete();
  651. if(empty($result)){
  652. return Result::error("删除模板失败",0);
  653. }else{
  654. return Result::success();
  655. }
  656. }
  657. /**
  658. * 搜索网站
  659. * @param array $data
  660. * @return array
  661. */
  662. public function websiteList(array $data): array
  663. {
  664. $where = [];
  665. if(isset($data['keyword']) && !empty($data['keyword'])){
  666. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  667. }
  668. $result = Website::where($where)->get();
  669. if($result){
  670. return Result::success($result);
  671. }else{
  672. return Result::error("没有网站",0);
  673. }
  674. }
  675. public function addWebsiteCategory(array $data): array
  676. {
  677. $website_id = $data['website_id'];
  678. $category_arr_id = $data['category_arr_id'];
  679. $categoryList = Category::whereIn('id',$category_arr_id)->get();
  680. $categoryListIds = [];
  681. if($categoryList){
  682. foreach ($categoryList->toArray() as $val){
  683. array_push($categoryListIds,$val['id']);
  684. }
  685. }
  686. $arr = [];
  687. if($categoryListIds){
  688. foreach ($categoryListIds as $v){
  689. $ids = $this->getUnderlingUIds(intval($v));
  690. $ids_arr = explode(",", $ids);
  691. array_push($arr,$ids_arr);
  692. }
  693. }
  694. $mergedArray = [];
  695. foreach ($arr as $subarray) {
  696. $mergedArray = array_merge($mergedArray, $subarray);
  697. }
  698. var_dump("所有:",$arr,$mergedArray);
  699. //查询出所有的分类进行分割插入 组装数据
  700. $categoryListData = Category::whereIn('id',$mergedArray)->get();
  701. $categoryListData = $categoryListData->toArray();
  702. $insertData = [];
  703. if($categoryListData){
  704. foreach ($categoryListData as $key=>$value){
  705. $insertData[$key]['website_id'] = $website_id;
  706. $insertData[$key]['name'] = $value['name'];
  707. $insertData[$key]['sort'] = $value['sort'];
  708. $insertData[$key]['pid'] = $value['pid'];
  709. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  710. $insertData[$key]['seo_title'] = $value['seo_title'];
  711. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  712. $insertData[$key]['seo_description'] = $value['seo_description'];
  713. $insertData[$key]['alias'] = $value['name'];
  714. $insertData[$key]['category_id'] = $value['id'];
  715. }
  716. }
  717. $result = WebsiteCategory::insert($insertData);
  718. var_dump("插入数据状态:",$result);
  719. if($result){
  720. return Result::success($result);
  721. }else{
  722. return Result::error("创建失败",0);
  723. }
  724. }
  725. /**
  726. * 删除网站导航
  727. * @param array $data
  728. * @return array
  729. */
  730. public function delWebsiteCategory(array $data): array
  731. {
  732. $website_id = $data['website_id']??0;
  733. $category_id = $data['category_id']??0;
  734. $ids = $this->getUnderlingUIds(intval($category_id));
  735. $ids_arr = explode(",", $ids);
  736. $result = WebsiteCategory::where(['website_id'=>$website_id])->whereIn("category_id",$ids_arr)->delete();
  737. if($result){
  738. return Result::success($result);
  739. }else{
  740. return Result::error("删除失败",0);
  741. }
  742. }
  743. /**
  744. * 获取网站导航
  745. * @param array $data
  746. * @return array
  747. */
  748. public function getAdminWebsiteCategory(array $data): array
  749. {
  750. $where = [
  751. 'website_id'=>$data['website_id'],
  752. 'pid'=>0
  753. ];
  754. $result = WebsiteCategory::where($where)->get();
  755. if($result){
  756. return Result::success($result);
  757. }else{
  758. return Result::error("查询失败",0);
  759. }
  760. }
  761. /**
  762. * 更新网站导航
  763. * @param array $data
  764. * @return array
  765. */
  766. public function upWebsiteCategory(array $data): array
  767. {
  768. Db::beginTransaction();
  769. try{
  770. //合并栏目id
  771. $reqIds = array_merge($data['old_category_arr_id'],$data['new_category_arr_id']);
  772. //对比old 数组差异化,把差异化的删除
  773. $result = WebsiteCategory::where(['website_id'=>$data['website_id'],'pid'=>0])->get();
  774. $result = $result->toArray();
  775. $categoryIds = [];
  776. if($result){
  777. foreach ($result as $val){
  778. array_push($categoryIds,$val['category_id']);
  779. }
  780. }
  781. //和原始数据对比取交际
  782. $reqidsIntersect = array_intersect($reqIds,$categoryIds);
  783. //再取差集 进行对比
  784. $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds),array_diff($categoryIds,$reqidsIntersect));
  785. var_dump("差集:",$differenceIDS);
  786. $arr_ids = [];
  787. if(count($differenceIDS)>0){
  788. foreach ($differenceIDS as $vv){
  789. $idV = $this->getUnderlingUIds(intval($vv));
  790. $ids_arrV = explode(",", $idV);
  791. array_push($arr_ids,$ids_arrV);
  792. }
  793. }
  794. $del_ids = array_reduce($arr_ids, 'array_merge', array());
  795. //有差异 删除
  796. if(count($del_ids)>0){
  797. WebsiteCategory::where(['website_id'=>$data['website_id']])->whereIn("category_id",$del_ids)->delete();
  798. }
  799. //传过来的值 和 交际 对比,选出要添加的值 进行插入
  800. $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect),array_diff($reqidsIntersect,$reqIds));
  801. var_dump("要存储的:",$insertIDS);
  802. //新的数组重新创建
  803. if(count($insertIDS)>0){
  804. $arr = [];
  805. $categoryListIds = $insertIDS;
  806. if($categoryListIds){
  807. foreach ($categoryListIds as $v){
  808. $ids = $this->getUnderlingUIds(intval($v));
  809. $ids_arr = explode(",", $ids);
  810. array_push($arr,$ids_arr);
  811. }
  812. }
  813. $mergedArray = [];
  814. foreach ($arr as $subarray) {
  815. $mergedArray = array_merge($mergedArray, $subarray);
  816. }
  817. var_dump("要插入的ID:",$mergedArray);
  818. //查询出所有的分类进行分割插入 组装数据
  819. $categoryListData = Category::whereIn('id',$mergedArray)->get();
  820. $categoryListData = $categoryListData->toArray();
  821. $insertData = [];
  822. if($categoryListData){
  823. foreach ($categoryListData as $key=>$value){
  824. $insertData[$key]['website_id'] = $data['website_id'];
  825. $insertData[$key]['name'] = $value['name'];
  826. $insertData[$key]['sort'] = $value['sort'];
  827. $insertData[$key]['pid'] = $value['pid'];
  828. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  829. $insertData[$key]['seo_title'] = $value['seo_title'];
  830. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  831. $insertData[$key]['seo_description'] = $value['seo_description'];
  832. $insertData[$key]['alias'] = $value['name'];
  833. $insertData[$key]['category_id'] = $value['id'];
  834. }
  835. }
  836. WebsiteCategory::insert($insertData);
  837. }
  838. Db::commit();
  839. } catch(\Throwable $ex){
  840. Db::rollBack();
  841. var_dump($ex->getMessage());
  842. return Result::error("修改失败",0);
  843. }
  844. return Result::success();
  845. }
  846. /**
  847. * 获取网站列表
  848. * @param array $data
  849. * @return array
  850. */
  851. public function getWebsiteCategoryList(array $data): array
  852. {
  853. $where = [];
  854. if(isset($data['keyword']) && !empty($data['keyword'])){
  855. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  856. }
  857. if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
  858. array_push($where,['website.website_column_id','=',$data['website_column_id']]);
  859. }
  860. $result = Website::where($where)
  861. ->with(["websiteCategory"=>function ($query) {
  862. $query->where(['pid'=>0])->select('website_id','name','alias','category_id');
  863. }])
  864. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
  865. ->get();
  866. $count = Website::where($where)->count();
  867. if (empty($result)) {
  868. return Result::error("没有数据",0);
  869. }
  870. $data = [
  871. 'rows'=>$result->toArray(),
  872. 'count'=>$count
  873. ];
  874. if($result){
  875. return Result::success($data);
  876. }else{
  877. return Result::error("查询失败",0);
  878. }
  879. }
  880. /**
  881. * 删除网站下的所有导航
  882. * @param array $data
  883. * @return array
  884. */
  885. public function delWebsiteAllCategory(array $data): array
  886. {
  887. $website_id = $data['website_id'];
  888. $result = WebsiteCategory::where(['website_id'=>$website_id])->delete();
  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 getWebsiteCategoryOnes(array $data): array
  901. {
  902. $website_id = $data['website_id'];
  903. $category_id = $data['category_id'];
  904. $result = WebsiteCategory::where(['website_category.website_id'=>$website_id,'website_category.category_id'=>$category_id])
  905. ->first();
  906. if($result){
  907. return Result::success($result);
  908. }else{
  909. return Result::error("查询失败",0);
  910. }
  911. }
  912. /**
  913. * 更新网闸下的某一个导航
  914. * @param array $data
  915. * @return array
  916. */
  917. public function upWebsiteCategoryones(array $data): array
  918. {
  919. $where = [
  920. 'website_id'=>$data['website_id'],
  921. 'category_id'=>$data['category_id'],
  922. ];
  923. $result = WebsiteCategory::where($where)->update($data);
  924. if($result){
  925. return Result::success($result);
  926. }else{
  927. return Result::error("更新失败",0);
  928. }
  929. }
  930. /**
  931. * 获取网站下的所有导航(包含子导航)
  932. * @param array $data
  933. * @return array
  934. */
  935. public function getWebsiteAllCategory(array $data): array
  936. {
  937. $where = [];
  938. if(isset($data['website_id']) && !empty($data['website_id'])){
  939. array_push($where,['website_category.website_id','=',$data['website_id']]);
  940. }
  941. if(isset($data['name']) && !empty($data['name'])){
  942. array_push($where,['website_category.name','like','%'.$data['name'].'%']);
  943. }
  944. if(isset($data['alias']) && !empty($data['alias'])){
  945. array_push($where,['website_category.alias','like','%'.$data['alias'].'%']);
  946. }
  947. if(isset($data['department_id']) && !empty($data['department_id'])){
  948. array_push($where,['category.department_id','=',$data['department_id']]);
  949. }
  950. if(isset($data['city_id']) && !empty($data['city_id'])){
  951. array_push($where,['category.city_id','=',$data['city_id']]);
  952. }
  953. $result = WebsiteCategory::where($where)
  954. ->leftJoin("category",'website_category.category_id','category.id')
  955. ->leftJoin("department",'category.department_id','department.id')
  956. ->leftJoin("district",'category.city_id','district.id')
  957. ->select("website_category.*","department.name as department_name","district.name as city_name")
  958. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
  959. ->get();
  960. $count = WebsiteCategory::where($where)
  961. ->leftJoin("category",'website_category.category_id','category.id')
  962. ->leftJoin("department",'category.department_id','department.id')
  963. ->leftJoin("district",'category.city_id','district.id')
  964. ->count();
  965. if (empty($result)) {
  966. return Result::error("没有数据",0);
  967. }
  968. $data = [
  969. 'rows'=>$result->toArray(),
  970. 'count'=>$count
  971. ];
  972. if($result){
  973. return Result::success($data);
  974. }else{
  975. return Result::error("查询失败",0);
  976. }
  977. if($result){
  978. return Result::success($result);
  979. }else{
  980. return Result::error("查询失败",0);
  981. }
  982. }
  983. /**
  984. * 递归查询数据
  985. * @param $id
  986. * @param $ids
  987. * @return string
  988. */
  989. public function getUnderlingUIds($id, $ids='')
  990. {
  991. $back = Category::where(['pid'=>$id])->get();
  992. $back = $back->toArray();
  993. if (!empty($back) && is_array($back)) {
  994. foreach ($back as $v) {
  995. //防止当前人的ID重复去查询,形成恶性循环
  996. if ($v['id'] == $id) {
  997. continue;
  998. }
  999. $back2 = Category::where(['pid'=>$id])->count('id');
  1000. if ($back2 > 0) {
  1001. $ids = $this->getUnderlingUIds($v['id'],$ids);
  1002. } else {
  1003. $ids .= ','.$v['id'];
  1004. }
  1005. }
  1006. }
  1007. $ids = $id.','.$ids.',';
  1008. $ids = str_replace(',,', ",", $ids);
  1009. $ids = trim($ids, ',');
  1010. return $ids;
  1011. }
  1012. /**
  1013. * 检测网站名称是否重复
  1014. * @param array $data
  1015. * @return array
  1016. */
  1017. public function checkWebsiteName(array $data): array
  1018. {
  1019. if(isset($data['id'])){
  1020. $data[] = ['id',"!=",$data['id']];
  1021. unset($data['id']);
  1022. }
  1023. $websiteInfo = Website::query()->where($data)->first();
  1024. if (empty($websiteInfo)) {
  1025. return Result::error("找不到网站",0);
  1026. }
  1027. return Result::success($websiteInfo->toArray());
  1028. }
  1029. /**
  1030. * 检测网站url是否重复
  1031. * @param array $data
  1032. * @return array
  1033. */
  1034. public function checkWebsiteUrl(array $data): array
  1035. {
  1036. $whereData = [];
  1037. if(isset($data['id'])){
  1038. $whereData = [['id',"!=",$data['id']]];
  1039. unset($data['id']);
  1040. }
  1041. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1042. if (empty($websiteInfo)) {
  1043. return Result::error("找不到URL",0);
  1044. }
  1045. return Result::success($websiteInfo->toArray());
  1046. }
  1047. /**
  1048. * 风格下的板块
  1049. * @return void
  1050. */
  1051. public function templateSectorList(array $data): array
  1052. {
  1053. $where = [
  1054. 'template_id'=>$data['template_id']
  1055. ];
  1056. $result = Sector::where($where)->whereJsonContains("page_type",$data['page_type'])
  1057. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
  1058. ->get();
  1059. $count = Sector::where($where)->count();
  1060. if (empty($result)) {
  1061. return Result::error("没有数据",0);
  1062. }
  1063. $data = [
  1064. 'rows'=>$result->toArray(),
  1065. 'count'=>$count
  1066. ];
  1067. if (empty($result)) {
  1068. return Result::error("没有数据",0);
  1069. }
  1070. return Result::success($data);
  1071. }
  1072. /**
  1073. * 板块下的组件
  1074. * @param array $data
  1075. * @return array
  1076. */
  1077. public function sectorComponentList(array $data): array
  1078. {
  1079. $where = [
  1080. 'template_id'=>$data['template_id'],
  1081. 'sector_id'=>$data['sector_id'],
  1082. ];
  1083. $result = Component::where($where)
  1084. ->select("*")
  1085. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
  1086. ->get();
  1087. $count = Component::where($where)->count();
  1088. if (empty($result)) {
  1089. return Result::error("没有数据",0);
  1090. }
  1091. $data = [
  1092. 'rows'=>$result->toArray(),
  1093. 'count'=>$count
  1094. ];
  1095. if (empty($result)) {
  1096. return Result::error("没有数据",0);
  1097. }
  1098. return Result::success($data);
  1099. }
  1100. /**
  1101. * 获取模板内容
  1102. * @return void
  1103. */
  1104. public function getWebsiteTemplateInfo(array $data): array //丢了
  1105. {
  1106. $wehre = [
  1107. "website_id" =>$data['website_id']
  1108. ];
  1109. $result = WebsiteTemplate::where($wehre)->first();
  1110. if($result){
  1111. return Result::success($result);
  1112. }else{
  1113. return Result::error("没有数据",0);
  1114. }
  1115. }
  1116. /**
  1117. * 保存网站模板
  1118. * @param array $data
  1119. * @return array
  1120. */
  1121. public function addWebsiteTemplate(array $data): array
  1122. {
  1123. // var_dump("接收参数:",$data['webSiteData']['base']);
  1124. Db::beginTransaction();
  1125. try{
  1126. $websiteTemplateInfo = WebsiteTemplate::where(['website_id'=>$data['webSiteData']['base']['websiteId']])->first();
  1127. // var_dump($websiteTemplateInfo);
  1128. //原始数据
  1129. $templateList = $data['webSiteData']['template'];
  1130. if($websiteTemplateInfo){
  1131. //模板存在-更新广告
  1132. }else{
  1133. //创建广告
  1134. $adList = $this->getAdlist($templateList);
  1135. if(!empty($adList)){
  1136. AdPlace::insert($adList);
  1137. }
  1138. }
  1139. // $result = WebsiteTemplate::updateOrInsert(['website_id'=>$data['webSiteData']['base']['websiteId']],['template_data'=>json_encode($data['webSiteData']),'updated_at'=>date("Y-m-d H:i:s",time())]);
  1140. Db::commit();
  1141. } catch(\Throwable $ex){
  1142. Db::rollBack();
  1143. var_dump($ex->getMessage());
  1144. return Result::error("创建失败",0);
  1145. }
  1146. return Result::success();
  1147. }
  1148. //获取传过来的广告列表
  1149. public function getAdlist($templateList)
  1150. {
  1151. if($templateList){
  1152. $adList = [];
  1153. foreach ($templateList as $val){
  1154. if($val){
  1155. foreach ($val as $v){
  1156. if($v['componentList']){
  1157. foreach ($v['componentList'] as $p){
  1158. if($p['component_type']==3){
  1159. // var_dump("ppppppppppppp:",$p);
  1160. $adSizeInfo = AdSize::where(['width'=>$p['componentData']['width'],'height'=>$p['componentData']['height']])->first();
  1161. $adSizeInfo = $adSizeInfo->toArray();
  1162. $adData = [
  1163. 'website_id'=> $data['webSiteData']['base']['websiteId'],
  1164. 'status'=>1,
  1165. 'name'=>$p['componentData']['text'],
  1166. 'ad_id'=>$p['componentData']['ad_id'],
  1167. 'ad_size_id'=>$adSizeInfo['id'],
  1168. ];
  1169. array_push($adList,$adData);
  1170. }
  1171. }
  1172. }
  1173. }
  1174. }
  1175. }
  1176. if(count($adList)>0){
  1177. return $adList;
  1178. }
  1179. }
  1180. }
  1181. /**
  1182. * 预览网站首页模板数据
  1183. * @param array $data
  1184. * @return array
  1185. */
  1186. public function getWebsiteTemplateData(array $data): array
  1187. {
  1188. $wehre = [
  1189. "website_id" =>$data['website_id']
  1190. ];
  1191. $result = WebsiteTemplate::where($wehre)->first();
  1192. if($result){
  1193. $templateData = json_decode($result['template_data'],true);
  1194. // var_dump("数据:",$templateData[1]);
  1195. $templateData[1] = $this->getNewsList($templateData[1]);
  1196. return Result::success($templateData);
  1197. }else{
  1198. return Result::error("没有数据",0);
  1199. }
  1200. }
  1201. /**
  1202. * 获取列表数据
  1203. * @return void
  1204. */
  1205. public function getNewsList(array $data): array
  1206. {
  1207. if($data){
  1208. foreach ($data as $key=>$val){
  1209. if($val){
  1210. foreach ($val['data'] as $k=>$item){
  1211. if($item['isReturn'] && intval($item['isReturn'])==1){
  1212. $imgList = [];
  1213. if($item['data']['imgNum'] && intval($item['data']['imgNum'])>0){
  1214. $imgList = Article::where('imgurl',"!=","")
  1215. ->where('catid',$item['data']['category_id'])
  1216. ->select($item['data']['selectField'])
  1217. ->orderBy("created_at","desc")
  1218. ->offset(0)
  1219. ->limit(intval($item['data']['imgNum']))
  1220. ->get();
  1221. $imgList = $imgList->toArray();
  1222. $listIds = [];
  1223. if ($imgList){
  1224. $listIds = array_column($imgList, 'id');
  1225. }
  1226. $dataList = Article::whereNotIn('id',$listIds)
  1227. ->where('catid',$item['data']['category_id'])
  1228. ->select($item['data']['selectField'])
  1229. ->orderBy("created_at","desc")
  1230. ->offset(0)
  1231. ->limit(intval($item['data']['pageSize'])-intval($item['data']['imgNum']))
  1232. ->get();
  1233. $dataList = $dataList->toArray();
  1234. var_dump("图片列表:",$imgList,"数据列表:",$dataList);
  1235. $datas = array_merge($imgList,$dataList);
  1236. // return $datas;
  1237. var_dump("合并列表:",$datas);
  1238. $data[$key]['data'][$k]['dataList'] = $datas;
  1239. }else{
  1240. $dataList = Article::where('catid',$item['data']['category_id'])
  1241. ->select($item['data']['selectField'])
  1242. ->orderBy("created_at","desc")
  1243. ->offset(0)
  1244. ->limit(intval($item['data']['pageSize']))
  1245. ->get();
  1246. $dataList = $dataList->toArray();
  1247. var_dump("数据列表:",$dataList);
  1248. }
  1249. }
  1250. }
  1251. }
  1252. }
  1253. }
  1254. return $data;
  1255. }
  1256. /**
  1257. * 获取底部导航列表
  1258. * @param array $data
  1259. * @return array
  1260. */
  1261. public function getFooterCategoryList(array $data): array
  1262. {
  1263. $where = [
  1264. "website_id"=>$data['website_id']
  1265. ];
  1266. $result = FooterCategory::where($where)->get();
  1267. if($result){
  1268. return Result::success($result);
  1269. }else{
  1270. return Result::error("没有数据");
  1271. }
  1272. }
  1273. //获取底部导航内容列表
  1274. public function getFooterContentList(array $data): array
  1275. {
  1276. $where = [
  1277. "fcat_id"=>$data['fcat_id'],
  1278. ];
  1279. switch (intval($data['type'])){
  1280. case 0:
  1281. $result = FooterContent::where($where)->first();
  1282. break;
  1283. case 1:
  1284. $result = FooterContent::where($where)->get();
  1285. break;
  1286. }
  1287. if($result){
  1288. return Result::success($result);
  1289. }else{
  1290. return Result::error("没有数据");
  1291. }
  1292. }
  1293. //获取底部导航内容详情
  1294. public function getFooterContentInfo(array $data): array
  1295. {
  1296. $where = [
  1297. "id"=>$data['content_id']
  1298. ];
  1299. $result = FooterContent::where($where)->first();
  1300. if($result){
  1301. return Result::success($result);
  1302. }else{
  1303. return Result::error("没有数据");
  1304. }
  1305. }
  1306. }