WebsiteService.php 104 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\Category;
  5. use App\Model\FooterCategory;
  6. use App\Model\FooterContent;
  7. use App\Model\LetterOfComplaint;
  8. use App\Model\Sector;
  9. use App\Model\TemplateClass;
  10. use App\Model\Template;
  11. use App\Model\User;
  12. use App\Model\WebsiteRole;
  13. use App\Model\WebsiteRoleUser;
  14. use App\Model\Website;
  15. use App\Model\WebsiteColumn;
  16. use App\Model\WebsiteTemplate;
  17. use Hyperf\DbConnection\Db;
  18. use Hyperf\RpcServer\Annotation\RpcService;
  19. use App\Tools\Result;
  20. use App\Model\WebsiteCategory;
  21. use App\Model\WebsiteTemplate;
  22. use App\Model\WebsiteTemplateInfo;
  23. use function PHPUnit\Framework\isNull;
  24. use App\Model\Component;
  25. use App\Model\District;
  26. #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  27. class WebsiteService implements WebsiteServiceInterface
  28. {
  29. /**
  30. * @param string $keyword
  31. * @param int $page
  32. * @param int $pageSize
  33. * @return array
  34. */
  35. public function getWebsitetList(array $data): array
  36. {
  37. $resultWwhere = Website::when($data,function ($query) use ($data){
  38. if(isset($data['keyword']) && !empty($data['keyword'])){
  39. $query->where('website.website_name','like','%'.$data['keyword'].'%');
  40. }
  41. if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
  42. $query->whereJsonContains("website.website_column_arr_id", intval($data['website_column_id']));
  43. }
  44. if(isset($data['city_id']) && !empty($data['city_id'])){
  45. $query->whereJsonContains("website.city_arr_id", intval($data['city_id']));
  46. }
  47. });
  48. $result = $resultWwhere->leftJoin("website_column","website.website_column_id","website_column.id")
  49. ->leftJoin("district","district.id","website.city_id")
  50. ->select("website.*","website_column.column_name","district.name as city_name")
  51. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("website.id","desc")->get();
  52. $count = $resultWwhere->count();
  53. if (empty($result)) {
  54. return Result::error("没有数据",0);
  55. }
  56. $data = [
  57. 'rows'=>$result->toArray(),
  58. 'count'=>$count
  59. ];
  60. return Result::success($data);
  61. }
  62. /**
  63. * @param array $data
  64. * @return array
  65. */
  66. public function createWebsite(array $data): array
  67. {
  68. var_dump("网站数据:", $data);
  69. $insertData = [
  70. 'website_name' => $data['website_name'],
  71. 'logo' => $data['logo'] ?? '',
  72. 'website_url' => $data['website_url'] ?? '',
  73. 'city_id' => $data['city_id'] ?? 0,
  74. 'website_column_id' => $data['website_column_id'],
  75. 'title' => $data['title'] ?? '',
  76. 'keywords' => $data['keywords'] ?? '',
  77. 'description' => $data['description'] ?? '',
  78. 'status' => $data['status'] ?? 0,
  79. 'website_column_arr_id' => $data['website_column_arr_id'],
  80. 'city_arr_id' => $data['city_arr_id'] ?? [0],
  81. 'template_id' => $data['template_id'] ?? 0,
  82. ];
  83. $result = Website::insertGetId($insertData);
  84. if (empty($result)) {
  85. return Result::error("创建失败", 0);
  86. } else {
  87. return Result::success(["id" => $result]);
  88. }
  89. }
  90. /**
  91. * @param int $id
  92. * @param array $data
  93. * @return array
  94. */
  95. public function updateWebsite(int $id, array $data): array
  96. {
  97. $insertData = [
  98. 'website_name' => $data['website_name'],
  99. 'logo' => $data['logo'] ?? '',
  100. 'website_url' => $data['website_url'] ?? '',
  101. 'city_id' => $data['city_id'] ?? 0,
  102. 'website_column_id' => $data['website_column_id'],
  103. 'title' => $data['title'] ?? '',
  104. 'keywords' => $data['keywords'] ?? '',
  105. 'description' => $data['description'] ?? '',
  106. 'status' => $data['status'] ?? 0,
  107. 'website_column_arr_id' => $data['website_column_arr_id'],
  108. 'city_arr_id' => $data['city_arr_id'] ?? [0],
  109. 'template_id' => $data['template_id'] ?? 0,
  110. ];
  111. $result = Website::where('id', $id)->update($insertData);
  112. var_dump("更新站点", $result);
  113. if (empty($result)) {
  114. return Result::error("更新失败", 0);
  115. } else {
  116. return Result::success();
  117. }
  118. }
  119. /**
  120. * @param int $id
  121. * @return array
  122. */
  123. public function delWebsite(int $id): array
  124. {
  125. $result = Website::where('id', $id)->delete();
  126. if (empty($result)) {
  127. return Result::error("删除失败", 0);
  128. } else {
  129. return Result::success();
  130. }
  131. }
  132. /**
  133. * @param int $id
  134. * @return array
  135. */
  136. public function getWebsiteInfo(int $id): array
  137. {
  138. $where = [
  139. ['website.id', '=', $id]
  140. ];
  141. $result = Website::where($where)
  142. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  143. ->select("website.*",
  144. "website_template_info.template_id",
  145. "website_template_info.page_type",
  146. "website_template_info.statement",
  147. "website_template_info.organizer",
  148. "website_template_info.copyright_information",
  149. "website_template_info.contact_number",
  150. "website_template_info.company_address",
  151. "website_template_info.project_logo",
  152. "website_template_info.project_name",
  153. "website_template_info.project_url",
  154. "website_template_info.company_logo",
  155. "website_template_info.company_name",
  156. "website_template_info.company_url",
  157. "website_template_info.record_number",
  158. "website_template_info.record_number_url",
  159. "website_template_info.icp_number",
  160. "website_template_info.icp_number_url",
  161. "website_template_info.customer_service_qq",
  162. "website_template_info.communications",
  163. "website_template_info.status",
  164. )
  165. ->first();
  166. if (empty($result)) {
  167. return Result::error("数据不存在", 0);
  168. } else {
  169. return Result::success($result->toArray());
  170. }
  171. }
  172. /**
  173. * 查询所有的站点栏目
  174. * @return array
  175. */
  176. public function getWebsiteColumn(array $data): array
  177. {
  178. $result = WebsiteColumn::where($data)->get();
  179. if (empty($result)) {
  180. return Result::error("数据不存在", 0);
  181. } else {
  182. return Result::success($result->toArray());
  183. }
  184. }
  185. /**
  186. * @param string $keyword
  187. * @param int $page
  188. * @param int $pageSize
  189. * @return array
  190. */
  191. public function getWebsiteColumnList(array $data): array
  192. {
  193. $where = [];
  194. if (isset($data['keyword']) && $data['keyword']) {
  195. array_push($where, ['website_column.column_name', 'like', '%' . $data['keyword'] . '%']);
  196. }
  197. $result = WebsiteColumn::where($where)
  198. ->leftJoin("website_column as wc", "website_column.pid", "wc.id")
  199. ->select("website_column.*", "wc.column_name as parent_column_name")
  200. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->get();
  201. $count = WebsiteColumn::where($where)->count();
  202. if (empty($result)) {
  203. return Result::error("没有数据", 0);
  204. }
  205. $data = [
  206. 'rows' => $result->toArray(),
  207. 'count' => $count
  208. ];
  209. return Result::success($data);
  210. }
  211. /**
  212. * @param array $data
  213. * @return array
  214. */
  215. public function createWebsiteColumn(array $data): array
  216. {
  217. $insertData = [
  218. 'column_name' => $data['column_name'],
  219. 'pid' => $data['pid'] ?? '',
  220. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  221. 'sort' => $data['sort'] ?? 0,
  222. 'remark' => $data['remark'] ?? '',
  223. ];
  224. $result = WebsiteColumn::insertGetId($insertData);
  225. if (empty($result)) {
  226. return Result::error("创建失败", 0);
  227. } else {
  228. return Result::success(["id" => $result]);
  229. }
  230. }
  231. /**
  232. * @param int $id
  233. * @param array $data
  234. * @return array
  235. */
  236. public function updateWebsiteColumn(int $id, array $data): array
  237. {
  238. $insertData = [
  239. 'column_name' => $data['column_name'],
  240. 'pid' => $data['pid'] ?? '',
  241. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  242. 'sort' => $data['sort'] ?? 0,
  243. 'remark' => $data['remark'] ?? '',
  244. ];
  245. $result = WebsiteColumn::where('id', $id)->update($insertData);
  246. if (empty($result)) {
  247. return Result::error("更新失败", 0);
  248. } else {
  249. return Result::success();
  250. }
  251. }
  252. /**
  253. * @param int $id
  254. * @return array
  255. */
  256. public function delWebsiteColumn(int $id): array
  257. {
  258. $list = WebsiteColumn::where(['pid' => $id])->get();
  259. if ($list) {
  260. return Result::error("存在子网系,不能删除,请先删除子网系", 0);
  261. }
  262. $result = WebsiteColumn::where('id', $id)->delete();
  263. if (empty($result)) {
  264. return Result::error("删除失败", 0);
  265. } else {
  266. return Result::success();
  267. }
  268. }
  269. /**
  270. * @param string $keyword
  271. * @param int $page
  272. * @param int $pageSize
  273. * @return array
  274. */
  275. public function getWebsiteRoleList(string $keyword, int $page, int $pageSize, int $websiteId): array
  276. {
  277. $where = [
  278. ['role.role_name', 'like', '%' . $keyword . '%'],
  279. ['website_role.website_id', '=', $websiteId],
  280. ];
  281. $result = WebsiteRole::where($where)
  282. ->leftJoin("role", "role.id", "website_role.role_id")
  283. ->select("role.*", "website_role.type", "website_role.role_id", "website_role.id as website_role_id", "website_role.website_id")
  284. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  285. $count = WebsiteRole::where($where)->leftJoin("role", "role.id", "website_role.role_id")->count();
  286. if (empty($result)) {
  287. return Result::error("没有数据", 0);
  288. }
  289. $data = [
  290. 'rows' => $result->toArray(),
  291. 'count' => $count
  292. ];
  293. return Result::success($data);
  294. }
  295. /**
  296. * @param array $data
  297. * @return array
  298. */
  299. public function createWebsiteRole(array $data): array
  300. {
  301. $insertData = [
  302. 'website_id' => $data['website_id'],
  303. 'role_id' => $data['role_id'] ?? ''
  304. ];
  305. $info = WebsiteRole::where($insertData)->first();
  306. if ($info) {
  307. return Result::error("不能重复添加角色", 0);
  308. }
  309. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  310. $insertData['type'] = $data['type'] ?? '';
  311. $result = WebsiteRole::insertGetId($insertData);
  312. if (empty($result)) {
  313. return Result::error("创建失败", 0);
  314. } else {
  315. return Result::success(["id" => $result]);
  316. }
  317. }
  318. /**
  319. * 暂时用不上
  320. * @param int $id
  321. * @param array $data
  322. * @return array
  323. */
  324. public function updateWebsiteRole(int $id, array $data): array
  325. {
  326. $insertData = [
  327. 'website_id' => $data['website_id'],
  328. 'type' => $data['type'] ?? '',
  329. ];
  330. $result = WebsiteRole::where('id', $id)->update($insertData);
  331. if (empty($result)) {
  332. return Result::error("更新失败", 0);
  333. } else {
  334. return Result::success();
  335. }
  336. }
  337. /**
  338. * @param int $id
  339. * @return array
  340. */
  341. public function delWebsiteRole(int $id): array
  342. {
  343. $result = WebsiteRole::where('id', $id)->delete();
  344. if (empty($result)) {
  345. return Result::error("删除失败", 0);
  346. } else {
  347. return Result::success();
  348. }
  349. }
  350. /**
  351. * @param string $keyword
  352. * @param int $page
  353. * @param int $pageSize
  354. * @return array
  355. */
  356. public function getWebsiteRoleUserList(string $keyword, int $page, int $pageSize, int $websiteId, int $roleId): array
  357. {
  358. $where = [
  359. ['website_role_user.website_id', '=', $websiteId],
  360. ['website_role_user.role_id', '=', $roleId],
  361. ];
  362. $count = WebsiteRoleUser::where($where)->count();
  363. $where[] = ['u.user_name', 'like', '%' . $keyword . '%'];
  364. $result = WebsiteRoleUser::where($where)
  365. ->leftJoin("user as u", "website_role_user.user_id", "u.id")
  366. ->leftJoin("website as w", "website_role_user.website_id", "u.id")
  367. ->leftJoin("role as r", "website_role_user.role_id", "r.id")
  368. ->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')
  369. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  370. if (empty($result)) {
  371. return Result::error("没有数据", 0);
  372. }
  373. $data = [
  374. 'rows' => $result->toArray(),
  375. 'count' => $count
  376. ];
  377. return Result::success($data);
  378. }
  379. /**
  380. * @param array $data
  381. * @return array
  382. */
  383. public function createWebsiteRoleUser(array $data): array
  384. {
  385. $insertData = [
  386. 'website_id' => $data['website_id'],
  387. 'user_id' => $data['user_id'] ?? '',
  388. ];
  389. $info = WebsiteRoleUser::where($insertData)->first();
  390. if ($info) {
  391. return Result::error("不能重复添加角色用户", 0);
  392. }
  393. $insertData['role_id'] = $data['role_id'] ?? '';
  394. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  395. $insertData['type'] = $data['type'] ?? '';
  396. $result = WebsiteRoleUser::insertGetId($insertData);
  397. if (empty($result)) {
  398. return Result::error("创建失败", 0);
  399. } else {
  400. return Result::success(["id" => $result]);
  401. }
  402. }
  403. /**
  404. * @param int $id
  405. * @param array $data
  406. * @return array
  407. */
  408. public function updateWebsiteRoleUser(int $id, array $data): array
  409. {
  410. $insertData = [
  411. 'website_id' => $data['website_id'],
  412. 'type' => $data['type'] ?? '',
  413. 'type_id' => $data['type_id'] ?? '',
  414. 'role_id' => $data['role_id'] ?? '',
  415. ];
  416. $result = WebsiteRoleUser::where('id', $id)->update($insertData);
  417. if (empty($result)) {
  418. return Result::error("更新失败", 0);
  419. } else {
  420. return Result::success();
  421. }
  422. }
  423. /**
  424. * @param int $id
  425. * @return array
  426. */
  427. public function delWebsiteRoleUser(int $id): array
  428. {
  429. $result = WebsiteRoleUser::where('id', $id)->delete();
  430. if (empty($result)) {
  431. return Result::error("删除失败", 0);
  432. } else {
  433. return Result::success();
  434. }
  435. }
  436. /**
  437. * 根据域名获取网站 站点id
  438. * @param array $data
  439. * @return array
  440. */
  441. public function getWebsiteId(array $data): array
  442. {
  443. $result = Website::whereJsonContains('website_url', $data['website_url'])->first();
  444. if (empty($result)) {
  445. return Result::error("查询站点失败", 0);
  446. } else {
  447. return Result::success($result);
  448. }
  449. }
  450. /**
  451. * 查询网站下面的导航
  452. * @param array $data
  453. * @return array
  454. */
  455. public function getWebsiteCategory(array $data): array
  456. {
  457. $where = [
  458. 'website_id' => $data['website_id'],
  459. 'pid' => 0
  460. ];
  461. $result = WebsiteCategory::where($where)->orderBy('sort', 'asc')->get();
  462. if (empty($result)) {
  463. return Result::error("查询站点栏目失败", 0);
  464. } else {
  465. return Result::success($result);
  466. }
  467. }
  468. /**
  469. * 查询网站的广告
  470. * @param array $data
  471. * @return array
  472. */
  473. public function getWebsiteAdvertisement(array $data): array
  474. {
  475. $where = [
  476. 'website_id' => $data['website_id'],
  477. 'id' => $data['ad_placeid']
  478. ];
  479. $ad_place = AdPlace::where($where)->orderBy('id', 'asc')->limit(1)->get();
  480. $today = Carbon::now();
  481. if (empty($ad_place)) {
  482. return Result::error("error", 0);
  483. } else {
  484. foreach ($ad_place as $val) {
  485. $adplaceid = $val;
  486. }
  487. $ad = Ad::where('pid', $adplaceid['id'])->where('status', 1)->orderBy('id', 'asc')->get();
  488. if (empty($ad)) {
  489. $result = $adplaceid;
  490. return Result::success($result);
  491. } else {
  492. foreach ($ad as $i) {
  493. $starttime = Carbon::parse($i['fromtime']);
  494. $endtime = Carbon::parse($i['totime']);
  495. $time = $today->between($starttime, $endtime);
  496. if ($time) {
  497. $result = $i;
  498. }
  499. }
  500. if (empty($result)) {
  501. $result = $ad;
  502. return Result::success($result);
  503. } else {
  504. return Result::success($result);
  505. }
  506. }
  507. }
  508. }
  509. /**
  510. * 网站行政职能搜索
  511. * @param array $data
  512. * @return array
  513. */
  514. public function selectWebsiteDepartment(array $data): array
  515. {
  516. $depart = Department::where('pid', 0)->orderBy('id', 'asc')->limit(10)->get();
  517. if (isset($data['keyword']) && !empty($data['keyword'])) {
  518. $departments = Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  519. if (empty($departments)) {
  520. $result['message'] = "未查询到与此相关职能部门";
  521. } else {
  522. $count = Department::where('name', 'like', "%{$data['keyword']}%")->count();
  523. $m = [
  524. 'department' => $depart,
  525. 'type' => $departments,
  526. 'count' => $count
  527. ];
  528. }
  529. $result['sele'] = $m;
  530. return Result::success($result['sele']);
  531. }
  532. $result = $depart;
  533. return Result::success($result['data']);
  534. }
  535. /**
  536. * 搜索地区
  537. */
  538. public function selectWebsiteArea(array $data): array
  539. {
  540. $provinces = District::where('pid', 0)->where('status', 1)->get();
  541. if (isset($data['province'])) {
  542. $province = District::where('pid', 0)->where('status', 1)->where('id', $data['province'])->orderBy('id')->get();
  543. $province = $province->toArray();
  544. if (!empty($province)) {
  545. $citys = District::where('pid', $data['province'])->where('status', 1)->orderBy('id')->get();
  546. if (!empty($citys) && isset($data['city']) && !empty($data['city'])) {
  547. // $province = $province->toArray();
  548. $province_id = [];
  549. foreach ($province as $val) {
  550. array_push($province_id, $val['id']);
  551. }
  552. // var_dump($province_id);
  553. $city = District::whereIn('pid', $province_id)->where('status', 1)->where('id', $data['city'])->orderBy('id')->get();
  554. if (!empty($city)) {
  555. $city_id = [];
  556. foreach ($city as $val) {
  557. array_push($city_id, $val['id']);
  558. }
  559. $regions = District::whereIn('pid', $city_id)->where('status', 1)->orderBy('id')->get();
  560. $result = [
  561. 'province' => $province,
  562. 'city' => $city,
  563. 'region' => $regions
  564. ];
  565. } else {
  566. return Result::error("未查询到此城市", 0);
  567. }
  568. } else {
  569. $result = [
  570. 'province' => $province,
  571. 'city' => $citys,
  572. 'region' => null
  573. ];
  574. }
  575. } else {
  576. return Result::error("未查询到此省份", 0);
  577. }
  578. } else {
  579. // $keys = array('data');
  580. $result = $provinces;
  581. }
  582. return Result::success($result);
  583. }
  584. /**
  585. * 获取栏目
  586. * @param array $data
  587. * @return array
  588. */
  589. public function getWebsiteModelCategory(array $data): array
  590. {
  591. $website_id = [
  592. 'website_id' => $data['website_id']
  593. ];
  594. $placeid = $data['placeid'] - 1;
  595. $pid = [
  596. 'pid' => $data['pid'],
  597. ];
  598. $num = $data['num'];
  599. $result = WebsiteCategory::where($website_id)->where($pid)->orderBy('sort')->offset($placeid)->limit($num)->get();
  600. $result = $result->toArray();
  601. if (!empty($result)) {
  602. return Result::success($result);
  603. } else {
  604. return Result::error("本网站暂无栏目", 0);
  605. }
  606. }
  607. /**
  608. *获取友情链接
  609. * @param array $data
  610. * @return array
  611. */
  612. public function selectWebsiteLinks(array $data): array
  613. {
  614. $where = [
  615. 'website_id' => $data['website_id'],
  616. 'status' => 1,
  617. 'type' => $data['type']
  618. ];
  619. $num=$data['num'];
  620. $result=Link::where($where)->orderBy('id')->limit($num)->get();
  621. if(!empty($result)){
  622. return Result::success($result);
  623. }else{
  624. return Result::error("本网站暂无此类型友情链接",0);
  625. }
  626. }
  627. /**
  628. * 网站首页数据统计, 管理员
  629. * @return void
  630. */
  631. public function getAdminIndex(array $data): array
  632. {
  633. var_dump("用户类型:", $data['type_id']);
  634. switch ($data['type_id']) {
  635. case 4:
  636. $result = Db::select('SELECT DATE(created_at) AS date,COUNT(*) AS total_count FROM letter_of_complaint WHERE created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(created_at) ORDER BY date ASC;');
  637. return Result::success($result);
  638. break;
  639. case 10000:
  640. $res = [];
  641. //网站
  642. $res['website']['count'] = 0;
  643. $res['website']['growth_rate'] = 0;
  644. //资讯
  645. $res['article']['count'] = 0;
  646. $res['article']['growth_rate'] = 0;
  647. //导航池
  648. $res['category']['count'] = 0;
  649. $res['category']['growth_rate'] = 0;
  650. //近一月数据
  651. $res['monthArticle'] = [];
  652. //用户类型
  653. $res['userType'] = [];
  654. $res['website']['count'] = Website::where([])->count();
  655. $res['article']['count'] = Article::whereNotIn('status', ['404'])->count();
  656. $res['category']['count'] = Category::where([])->count();
  657. $res['monthArticle'] = Db::select('SELECT DATE(created_at) AS date,COUNT(*) AS total_count FROM article WHERE created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(created_at) ORDER BY date ASC;');
  658. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  659. return Result::success($res);
  660. }
  661. return [];
  662. }
  663. /**
  664. * 获取模板类型
  665. * @return void
  666. */
  667. public function getTemplateClass(array $data): array
  668. {
  669. $where = [];
  670. if (isset($data['name']) && $data['name']) {
  671. array_push($where, ['name', 'like', '%' . $data['name'] . '%']);
  672. }
  673. $result = TemplateClass::where($where)->orderBy('sort', 'asc')->get();
  674. if (empty($result)) {
  675. return Result::error("没有模板类型", 0);
  676. } else {
  677. return Result::success($result);
  678. }
  679. }
  680. /**
  681. * 添加模板类型
  682. * @param
  683. * @return void
  684. */
  685. public function addTemplateClass(array $data): array
  686. {
  687. $insertData = [
  688. 'name' => $data['name']
  689. ];
  690. $result = TemplateClass::insertGetId($insertData);
  691. if (empty($result)) {
  692. return Result::error("创建失败", 0);
  693. } else {
  694. return Result::success(["id" => $result]);
  695. }
  696. }
  697. /**
  698. * 更新模板
  699. * @param array $data
  700. * @return array
  701. */
  702. public function upTemplateClass(array $data): array
  703. {
  704. $where = [
  705. 'id' => $data['id']
  706. ];
  707. $insertData = [
  708. 'name' => $data['name']
  709. ];
  710. $result = TemplateClass::where($where)->update($insertData);
  711. if (empty($result)) {
  712. return Result::error("更新失败", 0);
  713. } else {
  714. return Result::success();
  715. }
  716. }
  717. /**
  718. * 删除模板
  719. * @param array $data
  720. * @return array
  721. */
  722. public function delTemplateClass(array $data): array
  723. {
  724. $where = [
  725. 'id' => $data['id']
  726. ];
  727. $result = TemplateClass::where($where)->delete();
  728. if (empty($result)) {
  729. return Result::error("删除失败", 0);
  730. } else {
  731. return Result::success();
  732. }
  733. }
  734. /**
  735. * 获取分类下的模板
  736. * @param array $data
  737. * @return array
  738. */
  739. public function getTemplate(array $data): array
  740. {
  741. $page = $data['page'];
  742. $pageSize = $data['pageSize'];
  743. $where = [];
  744. if (isset($data['template_class_id']) && $data['template_class_id']) {
  745. array_push($where, ['template_class_id', '=', $data['template_class_id']]);
  746. }
  747. $result = Template::where($where)
  748. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  749. $count = Template::where($where)->count();
  750. if (empty($result)) {
  751. return Result::error("没有数据", 0);
  752. }
  753. $data = [
  754. 'rows' => $result->toArray(),
  755. 'count' => $count
  756. ];
  757. return Result::success($data);
  758. }
  759. /**
  760. * 创建模板
  761. * @param
  762. * @return void
  763. */
  764. public function addTemplate(array $data): array
  765. {
  766. $insertData = [
  767. 'template_name' => $data['template_name'],
  768. 'template_img' => json_encode($data['template_img']),
  769. 'template_class_id' => $data['template_class_id'],
  770. ];
  771. $result = Template::insertGetId($insertData);
  772. if (empty($result)) {
  773. return Result::error("创建模板失败", 0);
  774. } else {
  775. return Result::success(["id" => $result]);
  776. }
  777. }
  778. /**
  779. * 更新模板
  780. * @param array $data
  781. * @return array
  782. */
  783. public function upTemplate(array $data): array
  784. {
  785. $where = [
  786. 'id' => $data['id']
  787. ];
  788. $insertData = [
  789. 'template_name' => $data['template_name'],
  790. 'template_img' => json_encode($data['template_img']),
  791. 'template_class_id' => $data['template_class_id'],
  792. ];
  793. $result = Template::where($where)->update($insertData);
  794. if (empty($result)) {
  795. return Result::error("更新模板失败", 0);
  796. } else {
  797. return Result::success();
  798. }
  799. }
  800. /**
  801. * 删除模板
  802. * @param array $data
  803. * @return array
  804. */
  805. public function delTemplate(array $data): array
  806. {
  807. $where = [
  808. 'id' => $data['id']
  809. ];
  810. $result = Template::where($where)->delete();
  811. if (empty($result)) {
  812. return Result::error("删除模板失败", 0);
  813. } else {
  814. return Result::success();
  815. }
  816. }
  817. /**
  818. * 搜索网站
  819. * @param array $data
  820. * @return array
  821. */
  822. public function websiteList(array $data): array
  823. {
  824. $where = [];
  825. if (isset($data['keyword']) && !empty($data['keyword'])) {
  826. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  827. }
  828. $result = Website::where($where)->get();
  829. if ($result) {
  830. return Result::success($result);
  831. } else {
  832. return Result::error("没有网站", 0);
  833. }
  834. }
  835. public function addWebsiteCategory(array $data): array
  836. {
  837. $website_id = $data['website_id'];
  838. $category_arr_id = $data['category_arr_id'];
  839. $categoryList = Category::whereIn('id', $category_arr_id)->get();
  840. $categoryListIds = [];
  841. if ($categoryList) {
  842. foreach ($categoryList->toArray() as $val) {
  843. array_push($categoryListIds, $val['id']);
  844. }
  845. }
  846. $arr = [];
  847. if ($categoryListIds) {
  848. foreach ($categoryListIds as $v) {
  849. $ids = $this->getUnderlingUIds(intval($v));
  850. $ids_arr = explode(",", $ids);
  851. array_push($arr, $ids_arr);
  852. }
  853. }
  854. $mergedArray = [];
  855. foreach ($arr as $subarray) {
  856. $mergedArray = array_merge($mergedArray, $subarray);
  857. }
  858. var_dump("所有:", $arr, $mergedArray);
  859. //查询出所有的分类进行分割插入 组装数据
  860. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  861. $categoryListData = $categoryListData->toArray();
  862. $insertData = [];
  863. if ($categoryListData) {
  864. foreach ($categoryListData as $key => $value) {
  865. $insertData[$key]['website_id'] = $website_id;
  866. $insertData[$key]['name'] = $value['name'];
  867. $insertData[$key]['sort'] = $value['sort'];
  868. $insertData[$key]['pid'] = $value['pid'];
  869. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  870. $insertData[$key]['seo_title'] = $value['seo_title'];
  871. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  872. $insertData[$key]['seo_description'] = $value['seo_description'];
  873. $insertData[$key]['alias'] = $value['name'];
  874. $insertData[$key]['category_id'] = $value['id'];
  875. }
  876. }
  877. $result = WebsiteCategory::insert($insertData);
  878. var_dump("插入数据状态:", $result);
  879. if ($result) {
  880. return Result::success($result);
  881. } else {
  882. return Result::error("创建失败", 0);
  883. }
  884. }
  885. /**
  886. * 删除网站导航
  887. * @param array $data
  888. * @return array
  889. */
  890. public function delWebsiteCategory(array $data): array
  891. {
  892. $website_id = $data['website_id'] ?? 0;
  893. $category_id = $data['category_id'] ?? 0;
  894. $ids = $this->getUnderlingUIds(intval($category_id));
  895. $ids_arr = explode(",", $ids);
  896. $result = WebsiteCategory::where(['website_id' => $website_id])->whereIn("category_id", $ids_arr)->delete();
  897. if ($result) {
  898. return Result::success($result);
  899. } else {
  900. return Result::error("删除失败", 0);
  901. }
  902. }
  903. /**
  904. * 获取网站导航
  905. * @param array $data
  906. * @return array
  907. */
  908. public function getAdminWebsiteCategory(array $data): array
  909. {
  910. $where = [
  911. 'website_id' => $data['website_id'],
  912. 'pid' => 0
  913. ];
  914. $result = WebsiteCategory::where($where)->get();
  915. if ($result) {
  916. return Result::success($result);
  917. } else {
  918. return Result::error("查询失败", 0);
  919. }
  920. }
  921. /**
  922. * 更新网站导航
  923. * @param array $data
  924. * @return array
  925. */
  926. public function upWebsiteCategory(array $data): array
  927. {
  928. Db::beginTransaction();
  929. try {
  930. //合并栏目id
  931. $reqIds = array_merge($data['old_category_arr_id'], $data['new_category_arr_id']);
  932. //对比old 数组差异化,把差异化的删除
  933. $result = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])->get();
  934. $result = $result->toArray();
  935. $categoryIds = [];
  936. if ($result) {
  937. foreach ($result as $val) {
  938. array_push($categoryIds, $val['category_id']);
  939. }
  940. }
  941. //和原始数据对比取交际
  942. $reqidsIntersect = array_intersect($reqIds, $categoryIds);
  943. //再取差集 进行对比
  944. $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds), array_diff($categoryIds, $reqidsIntersect));
  945. var_dump("差集:", $differenceIDS);
  946. $arr_ids = [];
  947. if (count($differenceIDS) > 0) {
  948. foreach ($differenceIDS as $vv) {
  949. $idV = $this->getUnderlingUIds(intval($vv));
  950. $ids_arrV = explode(",", $idV);
  951. array_push($arr_ids, $ids_arrV);
  952. }
  953. }
  954. $del_ids = array_reduce($arr_ids, 'array_merge', array());
  955. //有差异 删除
  956. if (count($del_ids) > 0) {
  957. WebsiteCategory::where(['website_id' => $data['website_id']])->whereIn("category_id", $del_ids)->delete();
  958. }
  959. //传过来的值 和 交际 对比,选出要添加的值 进行插入
  960. $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect), array_diff($reqidsIntersect, $reqIds));
  961. var_dump("要存储的:", $insertIDS);
  962. //新的数组重新创建
  963. if (count($insertIDS) > 0) {
  964. $arr = [];
  965. $categoryListIds = $insertIDS;
  966. if ($categoryListIds) {
  967. foreach ($categoryListIds as $v) {
  968. $ids = $this->getUnderlingUIds(intval($v));
  969. $ids_arr = explode(",", $ids);
  970. array_push($arr, $ids_arr);
  971. }
  972. }
  973. $mergedArray = [];
  974. foreach ($arr as $subarray) {
  975. $mergedArray = array_merge($mergedArray, $subarray);
  976. }
  977. var_dump("要插入的ID:", $mergedArray);
  978. //查询出所有的分类进行分割插入 组装数据
  979. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  980. $categoryListData = $categoryListData->toArray();
  981. $insertData = [];
  982. if ($categoryListData) {
  983. foreach ($categoryListData as $key => $value) {
  984. $insertData[$key]['website_id'] = $data['website_id'];
  985. $insertData[$key]['name'] = $value['name'];
  986. $insertData[$key]['sort'] = $value['sort'];
  987. $insertData[$key]['pid'] = $value['pid'];
  988. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  989. $insertData[$key]['seo_title'] = $value['seo_title'];
  990. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  991. $insertData[$key]['seo_description'] = $value['seo_description'];
  992. $insertData[$key]['alias'] = $value['name'];
  993. $insertData[$key]['category_id'] = $value['id'];
  994. }
  995. }
  996. WebsiteCategory::insert($insertData);
  997. }
  998. Db::commit();
  999. } catch (\Throwable $ex) {
  1000. Db::rollBack();
  1001. var_dump($ex->getMessage());
  1002. return Result::error("修改失败", 0);
  1003. }
  1004. return Result::success();
  1005. }
  1006. /**
  1007. * 获取网站列表
  1008. * @param array $data
  1009. * @return array
  1010. */
  1011. public function getWebsiteCategoryList(array $data): array
  1012. {
  1013. $where = [];
  1014. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1015. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  1016. }
  1017. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  1018. array_push($where, ['website.website_column_id', '=', $data['website_column_id']]);
  1019. }
  1020. $result = Website::where($where)
  1021. ->with(["websiteCategory" => function ($query) {
  1022. $query->where(['pid' => 0])->select('website_id', 'name', 'alias', 'category_id');
  1023. }])
  1024. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1025. ->get();
  1026. $count = Website::where($where)->count();
  1027. if (empty($result)) {
  1028. return Result::error("没有数据", 0);
  1029. }
  1030. $data = [
  1031. 'rows' => $result->toArray(),
  1032. 'count' => $count
  1033. ];
  1034. if ($result) {
  1035. return Result::success($data);
  1036. } else {
  1037. return Result::error("查询失败", 0);
  1038. }
  1039. }
  1040. /**
  1041. * 删除网站下的所有导航
  1042. * @param array $data
  1043. * @return array
  1044. */
  1045. public function delWebsiteAllCategory(array $data): array
  1046. {
  1047. $website_id = $data['website_id'];
  1048. $result = WebsiteCategory::where(['website_id' => $website_id])->delete();
  1049. if ($result) {
  1050. return Result::success($result);
  1051. } else {
  1052. return Result::error("删除失败", 0);
  1053. }
  1054. }
  1055. /**
  1056. * 获取网站下的某一个导航
  1057. * @param array $data
  1058. * @return array
  1059. */
  1060. public function getWebsiteCategoryOnes(array $data): array
  1061. {
  1062. $website_id = $data['website_id'];
  1063. $category_id = $data['category_id'];
  1064. $result = WebsiteCategory::where(['website_category.website_id' => $website_id, 'website_category.category_id' => $category_id])
  1065. ->first();
  1066. if ($result) {
  1067. return Result::success($result);
  1068. } else {
  1069. return Result::error("查询失败", 0);
  1070. }
  1071. }
  1072. /**
  1073. * 更新网闸下的某一个导航
  1074. * @param array $data
  1075. * @return array
  1076. */
  1077. public function upWebsiteCategoryones(array $data): array
  1078. {
  1079. $where = [
  1080. 'website_id' => $data['website_id'],
  1081. 'category_id' => $data['category_id'],
  1082. ];
  1083. $result = WebsiteCategory::where($where)->update($data);
  1084. if ($result) {
  1085. return Result::success($result);
  1086. } else {
  1087. return Result::error("更新失败", 0);
  1088. }
  1089. }
  1090. /**
  1091. * 获取网站下的所有导航(包含子导航)
  1092. * @param array $data
  1093. * @return array
  1094. */
  1095. public function getWebsiteAllCategory(array $data): array
  1096. {
  1097. $where = [];
  1098. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1099. array_push($where, ['website_category.website_id', '=', $data['website_id']]);
  1100. }
  1101. if (isset($data['name']) && !empty($data['name'])) {
  1102. array_push($where, ['website_category.name', 'like', '%' . $data['name'] . '%']);
  1103. }
  1104. if (isset($data['alias']) && !empty($data['alias'])) {
  1105. array_push($where, ['website_category.alias', 'like', '%' . $data['alias'] . '%']);
  1106. }
  1107. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1108. array_push($where, ['category.department_id', '=', $data['department_id']]);
  1109. }
  1110. if (isset($data['city_id']) && !empty($data['city_id'])) {
  1111. array_push($where, ['category.city_id', '=', $data['city_id']]);
  1112. }
  1113. $result = WebsiteCategory::where($where)
  1114. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1115. ->leftJoin("department", 'category.department_id', 'department.id')
  1116. ->leftJoin("district", 'category.city_id', 'district.id')
  1117. ->select("website_category.*", "department.name as department_name", "district.name as city_name")
  1118. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1119. ->get();
  1120. $count = WebsiteCategory::where($where)
  1121. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1122. ->leftJoin("department", 'category.department_id', 'department.id')
  1123. ->leftJoin("district", 'category.city_id', 'district.id')
  1124. ->count();
  1125. if (empty($result)) {
  1126. return Result::error("没有数据", 0);
  1127. }
  1128. $data = [
  1129. 'rows' => $result->toArray(),
  1130. 'count' => $count
  1131. ];
  1132. if ($result) {
  1133. return Result::success($data);
  1134. } else {
  1135. return Result::error("查询失败", 0);
  1136. }
  1137. if ($result) {
  1138. return Result::success($result);
  1139. } else {
  1140. return Result::error("查询失败", 0);
  1141. }
  1142. }
  1143. /**
  1144. * 递归查询数据
  1145. * @param $id
  1146. * @param $ids
  1147. * @return string
  1148. */
  1149. public function getUnderlingUIds($id, $ids = '')
  1150. {
  1151. $back = Category::where(['pid' => $id])->get();
  1152. $back = $back->toArray();
  1153. if (!empty($back) && is_array($back)) {
  1154. foreach ($back as $v) {
  1155. //防止当前人的ID重复去查询,形成恶性循环
  1156. if ($v['id'] == $id) {
  1157. continue;
  1158. }
  1159. $back2 = Category::where(['pid' => $id])->count('id');
  1160. if ($back2 > 0) {
  1161. $ids = $this->getUnderlingUIds($v['id'], $ids);
  1162. } else {
  1163. $ids .= ',' . $v['id'];
  1164. }
  1165. }
  1166. }
  1167. $ids = $id . ',' . $ids . ',';
  1168. $ids = str_replace(',,', ",", $ids);
  1169. $ids = trim($ids, ',');
  1170. return $ids;
  1171. }
  1172. /**
  1173. * 检测网站名称是否重复
  1174. * @param array $data
  1175. * @return array
  1176. */
  1177. public function checkWebsiteName(array $data): array
  1178. {
  1179. if (isset($data['id'])) {
  1180. $data[] = ['id', "!=", $data['id']];
  1181. unset($data['id']);
  1182. }
  1183. $websiteInfo = Website::query()->where($data)->first();
  1184. if (empty($websiteInfo)) {
  1185. return Result::error("找不到网站", 0);
  1186. }
  1187. return Result::success($websiteInfo->toArray());
  1188. }
  1189. /**
  1190. * 检测网站url是否重复
  1191. * @param array $data
  1192. * @return array
  1193. */
  1194. public function checkWebsiteUrl(array $data): array
  1195. {
  1196. $whereData = [];
  1197. if (isset($data['id'])) {
  1198. $whereData = [['id', "!=", $data['id']]];
  1199. unset($data['id']);
  1200. }
  1201. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1202. if (empty($websiteInfo)) {
  1203. return Result::error("找不到URL", 0);
  1204. }
  1205. return Result::success($websiteInfo->toArray());
  1206. }
  1207. /**
  1208. * 获取并搜索 网站模板信息
  1209. * @param array $data
  1210. * @return array
  1211. */
  1212. public function getWebsiteTemplateintel(array $data): array
  1213. {
  1214. $where = []; // 初始化 $where 数组
  1215. //若存在条件;则在$rep的基础上进行筛选
  1216. if(isset($data['website_name'])){
  1217. array_push($where, ['website.website_name','like','%'.$data['website_name'].'%']);
  1218. }
  1219. if(isset($data['status'])){
  1220. if($data['status'] == 0){
  1221. array_push($where, ['website_template_info.status','=',null]);
  1222. }else{
  1223. array_push($where, ['website_template_info.status','=',$data['status']]);
  1224. }
  1225. }
  1226. //查询所有网站模板信息
  1227. if(empty($where)){
  1228. $rep = Website::where('website.status', 1)
  1229. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  1230. ->leftJoin("template", "template.id", "website_template_info.template_id")
  1231. ->select(
  1232. "website.website_name",
  1233. "website.website_url",
  1234. "website_template_info.id as tid",
  1235. "website_template_info.created_at",
  1236. "website_template_info.updated_at",
  1237. "website_template_info.page_type",
  1238. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  1239. "template.template_name"
  1240. )
  1241. ->limit($data['pageSize'])
  1242. ->offset(($data['page'] - 1) * $data['pageSize'])
  1243. ->orderBy("website_template_info.updated_at", "asc")
  1244. ->get();
  1245. }else{
  1246. $rep = Website::where($where)
  1247. ->where('website.status', 1)
  1248. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  1249. ->leftJoin("template", "template.id", "website_template_info.template_id")
  1250. ->select(
  1251. "website.website_name",
  1252. "website.website_url",
  1253. "website_template_info.id as tid",
  1254. "website_template_info.created_at",
  1255. "website_template_info.updated_at",
  1256. "website_template_info.page_type",
  1257. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  1258. "template.template_name"
  1259. )
  1260. ->limit($data['pageSize'])
  1261. ->offset(($data['page'] - 1) * $data['pageSize'])
  1262. ->orderBy("website_template_info.updated_at", "asc")
  1263. ->get();
  1264. }
  1265. $result = [
  1266. "rows" => $rep->toArray(),
  1267. "count" => $rep->count()
  1268. ];
  1269. if($rep->count()==0){
  1270. return Result::error("没有查找到相关数据",0);
  1271. } else {
  1272. return Result::success($result); // 返回结果应该是 $result,而不是 $where
  1273. }
  1274. // return Result::success($result);
  1275. }
  1276. /**
  1277. * 添加网站基础信息
  1278. * @param array $data
  1279. * @return array
  1280. */
  1281. public function addWebsiteTemplateintel(array $data): array
  1282. {
  1283. $website = Website::where('website.id',$data['website_id'])->first();
  1284. if(empty($website)){
  1285. $message = "请输入正确的网站id!";
  1286. }else{
  1287. if(empty($website['website_column_id'])){
  1288. $message = "请先关联导航池!";
  1289. }
  1290. if(isset($data['page_type'])){
  1291. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1292. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1293. $result = 'yes';
  1294. $data['page_type'] = json_encode($data['page_type'])??''; // 将数组转换为 JSON 字符串
  1295. $result = WebsiteTemplateInfo::insertGetId($data);
  1296. } else {
  1297. $message = "请先选择首页和底部导航详情页!";
  1298. }
  1299. }else{
  1300. $footer = FooterCategory::where('website_id',$data['website_id'])->select('type')->get();
  1301. if(empty($footer)){
  1302. $types = '2';
  1303. }else{
  1304. $types = 2;
  1305. foreach ($footer as $v) {
  1306. if ($v['type'] == 1) {
  1307. $types = 1;
  1308. } else {
  1309. $types = 0;
  1310. }
  1311. }
  1312. }
  1313. $result['type'] = $types;
  1314. }
  1315. }
  1316. if(empty($result)){
  1317. return Result::error($message,0);
  1318. }else{
  1319. return Result::success($result);
  1320. }
  1321. }
  1322. /**
  1323. * 获取所有网站风格信息
  1324. *
  1325. * @return array
  1326. */
  1327. public function getAllTemplateClass(array $data): array
  1328. {
  1329. $result = TemplateClass::all();
  1330. if(empty($result)){
  1331. return Result::error("没有查找到相关数据!",0);
  1332. }else{
  1333. return Result::success($result);
  1334. }
  1335. }
  1336. /**
  1337. * 获取网站模板信息
  1338. * @param array $data
  1339. * @return array
  1340. */
  1341. public function getWebsiteTemplateList(array $data): array
  1342. {
  1343. $website = Website::where('website.id',$data['website_id'])->first();
  1344. if(empty($website)){
  1345. $message = "请输入正确的网站id!";
  1346. }else{
  1347. $where = $data["page_type"];
  1348. if(isset($data['template_class_id'])){
  1349. $template_class = TemplateClass::where('id',$data['template_class_id'])->first();
  1350. if(empty($template_class)){
  1351. $message = "请输入正确的模板风格id!";
  1352. }else{
  1353. // 获取指定风格下的模板
  1354. $rep = Template::where('template_class_id', $data['template_class_id'])
  1355. ->where(function ($query) use ($where) {
  1356. foreach ($where as $value) {
  1357. $query->whereJsonContains('template_img', ['value' => $value]);
  1358. }
  1359. })
  1360. ->leftJoin('template_class','template_class.id','template.template_class_id')
  1361. ->select('template.*','template_class.name')
  1362. ->limit($data['pageSize'])
  1363. ->offset(($data['page'] - 1) * $data['pageSize'])
  1364. ->orderBy("template.updated_at", "desc")
  1365. ->get();
  1366. }
  1367. }else{
  1368. //获取所有模板
  1369. $rep = Template::where(function ($query) use ($where) {
  1370. foreach ($where as $value) {
  1371. $query->whereJsonContains('template_img', ['value' => $value]);
  1372. }
  1373. })
  1374. ->offset(($data['page'] - 1) * $data['pageSize'])
  1375. ->limit($data['pageSize'])
  1376. ->orderBy("template.updated_at", "desc")
  1377. ->get();
  1378. }
  1379. if(empty($rep)){
  1380. $message = "没有查找到相关数据!";
  1381. }else{
  1382. $result = [
  1383. "rows" => $rep->toArray(),
  1384. "count" => $rep->count()
  1385. ];
  1386. }
  1387. }
  1388. if(empty($rep)){
  1389. return Result::error($message,0);
  1390. }else{
  1391. return Result::success($result);
  1392. }
  1393. }
  1394. /**
  1395. * 添加网站模板
  1396. * @param array $data
  1397. */
  1398. public function addWebsiteTemplateclassintel(array $data): array
  1399. {
  1400. $template = Template::where('id',$data['template_id'])->first();
  1401. $web = Website::where('id',$data['website_id'])->first();
  1402. if(empty($template)){
  1403. return Result::error("请输入正确的模板id",0);
  1404. }
  1405. if(empty($web)){
  1406. return Result::error("请输入正确的网站id",0);
  1407. }
  1408. $result = WebsiteTemplateInfo::where('website_id',$data['website_id'])->update(['template_id' => $data['template_id']]);
  1409. if(empty($result)){
  1410. return Result::error("添加失败",0);
  1411. }else{
  1412. return Result::success($result);
  1413. }
  1414. }
  1415. /**
  1416. * 风格下的板块
  1417. * @return void
  1418. */
  1419. public function templateSectorList(array $data): array
  1420. {
  1421. $where = [
  1422. 'template_id' => $data['template_id']
  1423. ];
  1424. $result = Sector::where($where)->whereJsonContains("page_type", $data['page_type'])
  1425. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1426. ->get();
  1427. $count = Sector::where($where)->count();
  1428. if (empty($result)) {
  1429. return Result::error("没有数据", 0);
  1430. }
  1431. $data = [
  1432. 'rows' => $result->toArray(),
  1433. 'count' => $count
  1434. ];
  1435. if (empty($result)) {
  1436. return Result::error("没有数据", 0);
  1437. }
  1438. return Result::success($data);
  1439. }
  1440. /**
  1441. * 板块下的组件
  1442. * @param array $data
  1443. * @return array
  1444. */
  1445. public function sectorComponentList(array $data): array
  1446. {
  1447. $where = [
  1448. 'template_id' => $data['template_id'],
  1449. 'sector_id' => $data['sector_id'],
  1450. ];
  1451. $result = Component::where($where)
  1452. ->select("*")
  1453. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1454. ->get();
  1455. $count = Component::where($where)->count();
  1456. if (empty($result)) {
  1457. return Result::error("没有数据", 0);
  1458. }
  1459. $data = [
  1460. 'rows' => $result->toArray(),
  1461. 'count' => $count
  1462. ];
  1463. if (empty($result)) {
  1464. return Result::error("没有数据", 0);
  1465. }
  1466. return Result::success($data);
  1467. }
  1468. /**
  1469. * 获取模板内容
  1470. * @return void
  1471. */
  1472. public function getWebsiteTemplateInfo(array $data): array
  1473. {
  1474. $wehre = [
  1475. "website_id" => $data['website_id']
  1476. ];
  1477. $result = WebsiteTemplate::where($wehre)->first();
  1478. if ($result) {
  1479. return Result::success($result);
  1480. } else {
  1481. return Result::error("没有数据", 0);
  1482. }
  1483. }
  1484. /**
  1485. * 保存网站模板
  1486. * @param array $data
  1487. * @return array
  1488. */
  1489. public function addWebsiteTemplate(array $data): array
  1490. {
  1491. var_dump("接收参数:", $data['template_data']);
  1492. $result = WebsiteTemplate::updateOrInsert(['website_id' => $data['website_id']], ['template_data' => json_encode($data['template_data'])]);
  1493. if ($result) {
  1494. return Result::success($result);
  1495. } else {
  1496. return Result::error("创建失败", 0);
  1497. }
  1498. }
  1499. /**
  1500. * 预览网站首页模板数据
  1501. * @param array $data
  1502. * @return array
  1503. */
  1504. public function getWebsiteTemplateData(array $data): array
  1505. {
  1506. $wehre = [
  1507. "website_id" => $data['website_id']
  1508. ];
  1509. $result = WebsiteTemplate::where($wehre)->first();
  1510. if ($result) {
  1511. $templateData = json_decode($result['template_data'], true);
  1512. // var_dump("数据:",$templateData[1]);
  1513. $templateData[1] = $this->getNewsList($templateData[1]);
  1514. return Result::success($templateData);
  1515. } else {
  1516. return Result::error("没有数据", 0);
  1517. }
  1518. }
  1519. /**
  1520. * 获取数据
  1521. * @return void
  1522. */
  1523. public function getNewsList(array $data): array
  1524. {
  1525. if ($data) {
  1526. foreach ($data as $key => $val) {
  1527. if ($val) {
  1528. foreach ($val['data'] as $k => $item) {
  1529. if ($item['isReturn'] && intval($item['isReturn']) == 1) {
  1530. $imgList = [];
  1531. if ($item['data']['imgNum'] && intval($item['data']['imgNum']) > 0) {
  1532. $imgList = Article::where('imgurl', "!=", "")
  1533. ->where('catid', $item['data']['category_id'])
  1534. ->select($item['data']['selectField'])
  1535. ->orderBy("created_at", "desc")
  1536. ->offset(0)
  1537. ->limit(intval($item['data']['imgNum']))
  1538. ->get();
  1539. $imgList = $imgList->toArray();
  1540. $listIds = [];
  1541. if ($imgList) {
  1542. $listIds = array_column($imgList, 'id');
  1543. }
  1544. $dataList = Article::whereNotIn('id', $listIds)
  1545. ->where('catid', $item['data']['category_id'])
  1546. ->select($item['data']['selectField'])
  1547. ->orderBy("created_at", "desc")
  1548. ->offset(0)
  1549. ->limit(intval($item['data']['pageSize']) - intval($item['data']['imgNum']))
  1550. ->get();
  1551. $dataList = $dataList->toArray();
  1552. var_dump("图片列表:", $imgList, "数据列表:", $dataList);
  1553. $datas = array_merge($imgList, $dataList);
  1554. // return $datas;
  1555. var_dump("合并列表:", $datas);
  1556. $data[$key]['data'][$k]['dataList'] = $datas;
  1557. } else {
  1558. $dataList = Article::where('catid', $item['data']['category_id'])
  1559. ->select($item['data']['selectField'])
  1560. ->orderBy("created_at", "desc")
  1561. ->offset(0)
  1562. ->limit(intval($item['data']['pageSize']))
  1563. ->get();
  1564. $dataList = $dataList->toArray();
  1565. var_dump("数据列表:", $dataList);
  1566. }
  1567. }
  1568. }
  1569. }
  1570. }
  1571. }
  1572. return $data;
  1573. }
  1574. /**
  1575. * 获取底部导航列表
  1576. * @param array $data
  1577. * @return array
  1578. */
  1579. public function getFooterCategoryList(array $data): array
  1580. {
  1581. $where = [
  1582. "website_id" => $data['website_id']
  1583. ];
  1584. $result = FooterCategory::where($where)->get();
  1585. if ($result) {
  1586. return Result::success($result);
  1587. } else {
  1588. return Result::error("没有数据");
  1589. }
  1590. }
  1591. //获取底部导航内容列表
  1592. public function getFooterContentList(array $data): array
  1593. {
  1594. $where = [
  1595. "fcat_id" => $data['fcat_id'],
  1596. ];
  1597. switch (intval($data['type'])) {
  1598. case 0:
  1599. $result = FooterContent::where($where)->first();
  1600. break;
  1601. case 1:
  1602. $result = FooterContent::where($where)->get();
  1603. break;
  1604. }
  1605. if ($result) {
  1606. return Result::success($result);
  1607. } else {
  1608. return Result::error("没有数据");
  1609. }
  1610. }
  1611. //获取底部导航内容详情
  1612. public function getFooterContentInfo(array $data): array
  1613. {
  1614. $where = [
  1615. "id" => $data['content_id']
  1616. ];
  1617. $result = FooterContent::where($where)->first();
  1618. if ($result) {
  1619. return Result::success($result);
  1620. } else {
  1621. return Result::error("没有数据");
  1622. }
  1623. }
  1624. <?php
  1625. namespace App\JsonRpc;
  1626. use App\Model\Article;
  1627. use App\Model\Category;
  1628. use App\Model\FooterCategory;
  1629. use App\Model\FooterContent;
  1630. use App\Model\LetterOfComplaint;
  1631. use App\Model\TemplateClass;
  1632. use App\Model\Template;
  1633. use App\Model\User;
  1634. use App\Model\WebsiteRole;
  1635. use App\Model\WebsiteRoleUser;
  1636. use App\Model\Website;
  1637. use App\Model\WebsiteColumn;
  1638. use Hyperf\DbConnection\Db;
  1639. use Hyperf\RpcServer\Annotation\RpcService;
  1640. use App\Tools\Result;
  1641. use App\Model\WebsiteCategory;
  1642. use App\Model\WebsiteTemplate;
  1643. use App\Model\WebsiteTemplateInfo;
  1644. use function PHPUnit\Framework\isNull;
  1645. // use Illuminate\Support\Facades\DB;
  1646. #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  1647. class WebsiteService implements WebsiteServiceInterface
  1648. {
  1649. /**
  1650. * @param string $keyword
  1651. * @param int $page
  1652. * @param int $pageSize
  1653. * @return array
  1654. */
  1655. public function getWebsitetList(array $data): array
  1656. {
  1657. $where = [];
  1658. if(isset($data['keyword']) && !empty($data['keyword'])){
  1659. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  1660. }
  1661. if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
  1662. array_push($where,['website.website_column_id','=',$data['website_column_id']]);
  1663. }
  1664. if(isset($data['city_id']) && !empty($data['city_id'])){
  1665. array_push($where,['website.city_id','=',$data['city_id']]);
  1666. }
  1667. $result = Website::where($where)
  1668. ->leftJoin("website_column","website.website_column_id","website_column.id")
  1669. ->leftJoin("district","district.id","website.city_id")
  1670. ->select("website.*","website_column.column_name","district.name as city_name")
  1671. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("website.id","desc")->get();
  1672. $count = Website::where($where)->count();
  1673. if (empty($result)) {
  1674. return Result::error("没有数据",0);
  1675. }
  1676. $data = [
  1677. 'rows'=>$result->toArray(),
  1678. 'count'=>$count
  1679. ];
  1680. return Result::success($data);
  1681. }
  1682. /**
  1683. * @param array $data
  1684. * @return array
  1685. */
  1686. public function createWebsite(array $data): array
  1687. {
  1688. var_dump("网站数据:",$data);
  1689. $insertData = [
  1690. 'website_name'=>$data['website_name'],
  1691. 'logo'=>$data['logo']??'',
  1692. 'website_url'=>$data['website_url']??'',
  1693. 'city_id'=>$data['city_id']??0,
  1694. 'website_column_id'=>$data['website_column_id'],
  1695. 'title'=>$data['title']??'',
  1696. 'keywords'=>$data['keywords']??'',
  1697. 'description'=>$data['description']??'',
  1698. 'status'=>$data['status']??0,
  1699. 'website_column_arr_id'=>$data['website_column_arr_id'],
  1700. 'city_arr_id'=>$data['city_arr_id']??[0],
  1701. 'template_id' =>$data['template_id']??0,
  1702. ];
  1703. $result = Website::insertGetId($insertData);
  1704. if(empty($result)){
  1705. return Result::error("创建失败",0);
  1706. }else{
  1707. return Result::success(["id"=>$result]);
  1708. }
  1709. }
  1710. /**
  1711. * @param int $id
  1712. * @param array $data
  1713. * @return array
  1714. */
  1715. public function updateWebsite(int $id,array $data): array
  1716. {
  1717. $insertData = [
  1718. 'website_name'=>$data['website_name'],
  1719. 'logo'=>$data['logo']??'',
  1720. 'website_url'=>$data['website_url']??'',
  1721. 'city_id'=>$data['city_id']??0,
  1722. 'website_column_id'=>$data['website_column_id'],
  1723. 'title'=>$data['title']??'',
  1724. 'keywords'=>$data['keywords']??'',
  1725. 'description'=>$data['description']??'',
  1726. 'status'=>$data['status']??0,
  1727. 'website_column_arr_id'=>$data['website_column_arr_id'],
  1728. 'city_arr_id'=>$data['city_arr_id']??[0],
  1729. 'template_id' =>$data['template_id']??0,
  1730. ];
  1731. $result = Website::where('id',$id)->update($insertData);
  1732. var_dump("更新站点",$result);
  1733. if(empty($result)){
  1734. return Result::error("更新失败",0);
  1735. }else{
  1736. return Result::success();
  1737. }
  1738. }
  1739. /**
  1740. * @param int $id
  1741. * @return array
  1742. */
  1743. public function delWebsite(int $id): array
  1744. {
  1745. $result = Website::where('id',$id )->delete();
  1746. if(empty($result)){
  1747. return Result::error("删除失败",0);
  1748. }else{
  1749. return Result::success();
  1750. }
  1751. }
  1752. /**
  1753. * @param int $id
  1754. * @return array
  1755. */
  1756. public function getWebsiteInfo(int $id): array
  1757. {
  1758. $where = [
  1759. ['website.id','=',$id]
  1760. ];
  1761. $result = Website::where($where )
  1762. ->leftJoin("template","template.id","website.template_id")
  1763. ->select("website.*","template.template_name","template.template_img")
  1764. ->first();
  1765. if(empty($result)){
  1766. return Result::error("数据不存在",0);
  1767. }else{
  1768. return Result::success($result->toArray());
  1769. }
  1770. }
  1771. /**
  1772. * 查询所有的站点栏目
  1773. * @return array
  1774. */
  1775. public function getWebsiteColumn(array $data): array
  1776. {
  1777. $result = WebsiteColumn::where($data)->get();
  1778. if(empty($result)){
  1779. return Result::error("数据不存在",0);
  1780. }else{
  1781. return Result::success($result->toArray());
  1782. }
  1783. }
  1784. /**
  1785. * @param string $keyword
  1786. * @param int $page
  1787. * @param int $pageSize
  1788. * @return array
  1789. */
  1790. public function getWebsiteColumnList(array $data):array
  1791. {
  1792. $where = [];
  1793. if(isset($data['keyword']) && $data['keyword']){
  1794. array_push($where,['website_column.column_name','like','%'.$data['keyword'].'%']);
  1795. }
  1796. $result = WebsiteColumn::where($where)
  1797. ->leftJoin("website_column as wc","website_column.pid","wc.id")
  1798. ->select("website_column.*","wc.column_name as parent_column_name")
  1799. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->get();
  1800. $count = WebsiteColumn::where($where)->count();
  1801. if (empty($result)) {
  1802. return Result::error("没有数据",0);
  1803. }
  1804. $data = [
  1805. 'rows'=>$result->toArray(),
  1806. 'count'=>$count
  1807. ];
  1808. return Result::success($data);
  1809. }
  1810. /**
  1811. * @param array $data
  1812. * @return array
  1813. */
  1814. public function createWebsiteColumn(array $data): array
  1815. {
  1816. $insertData = [
  1817. 'column_name'=>$data['column_name'],
  1818. 'pid'=>$data['pid']??'',
  1819. 'column_arr_id'=>$data['column_arr_id']??[0],
  1820. 'sort'=>$data['sort']??0,
  1821. 'remark'=>$data['remark']??'',
  1822. ];
  1823. $result = WebsiteColumn::insertGetId($insertData);
  1824. if(empty($result)){
  1825. return Result::error("创建失败",0);
  1826. }else{
  1827. return Result::success(["id"=>$result]);
  1828. }
  1829. }
  1830. /**
  1831. * @param int $id
  1832. * @param array $data
  1833. * @return array
  1834. */
  1835. public function updateWebsiteColumn(int $id,array $data): array
  1836. {
  1837. $insertData = [
  1838. 'column_name'=>$data['column_name'],
  1839. 'pid'=>$data['pid']??'',
  1840. 'column_arr_id'=>$data['column_arr_id']??[0],
  1841. 'sort'=>$data['sort']??0,
  1842. 'remark'=>$data['remark']??'',
  1843. ];
  1844. $result = WebsiteColumn::where('id',$id)->update($insertData);
  1845. if(empty($result)){
  1846. return Result::error("更新失败",0);
  1847. }else{
  1848. return Result::success();
  1849. }
  1850. }
  1851. /**
  1852. * @param int $id
  1853. * @return array
  1854. */
  1855. public function delWebsiteColumn(int $id): array
  1856. {
  1857. $list = WebsiteColumn::where(['pid'=>$id])->get();
  1858. if($list){
  1859. return Result::error("存在子网系,不能删除,请先删除子网系",0);
  1860. }
  1861. $result = WebsiteColumn::where('id',$id )->delete();
  1862. if(empty($result)){
  1863. return Result::error("删除失败",0);
  1864. }else{
  1865. return Result::success();
  1866. }
  1867. }
  1868. /**
  1869. * @param string $keyword
  1870. * @param int $page
  1871. * @param int $pageSize
  1872. * @return array
  1873. */
  1874. public function getWebsiteRoleList(string $keyword,int $page,int $pageSize,int $websiteId):array
  1875. {
  1876. $where = [
  1877. ['role.role_name','like','%'.$keyword.'%'],
  1878. ['website_role.website_id','=',$websiteId],
  1879. ];
  1880. $result = WebsiteRole::where($where)
  1881. ->leftJoin("role","role.id","website_role.role_id")
  1882. ->select("role.*","website_role.type","website_role.role_id","website_role.id as website_role_id","website_role.website_id")
  1883. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  1884. $count = WebsiteRole::where($where) ->leftJoin("role","role.id","website_role.role_id")->count();
  1885. if (empty($result)) {
  1886. return Result::error("没有数据",0);
  1887. }
  1888. $data = [
  1889. 'rows'=>$result->toArray(),
  1890. 'count'=>$count
  1891. ];
  1892. return Result::success($data);
  1893. }
  1894. /**
  1895. * @param array $data
  1896. * @return array
  1897. */
  1898. public function createWebsiteRole(array $data): array
  1899. {
  1900. $insertData = [
  1901. 'website_id'=>$data['website_id'],
  1902. 'role_id'=>$data['role_id']??''
  1903. ];
  1904. $info = WebsiteRole::where($insertData)->first();
  1905. if($info){
  1906. return Result::error("不能重复添加角色",0);
  1907. }
  1908. $insertData['admin_user_id'] = $data['admin_user_id']??'';
  1909. $insertData['type'] = $data['type']??'';
  1910. $result = WebsiteRole::insertGetId($insertData);
  1911. if(empty($result)){
  1912. return Result::error("创建失败",0);
  1913. }else{
  1914. return Result::success(["id"=>$result]);
  1915. }
  1916. }
  1917. /**
  1918. * 暂时用不上
  1919. * @param int $id
  1920. * @param array $data
  1921. * @return array
  1922. */
  1923. public function updateWebsiteRole(int $id,array $data): array
  1924. {
  1925. $insertData = [
  1926. 'website_id'=>$data['website_id'],
  1927. 'type'=>$data['type']??'',
  1928. ];
  1929. $result = WebsiteRole::where('id',$id)->update($insertData);
  1930. if(empty($result)){
  1931. return Result::error("更新失败",0);
  1932. }else{
  1933. return Result::success();
  1934. }
  1935. }
  1936. /**
  1937. * @param int $id
  1938. * @return array
  1939. */
  1940. public function delWebsiteRole(int $id): array
  1941. {
  1942. $result = WebsiteRole::where('id',$id )->delete();
  1943. if(empty($result)){
  1944. return Result::error("删除失败",0);
  1945. }else{
  1946. return Result::success();
  1947. }
  1948. }
  1949. /**
  1950. * @param string $keyword
  1951. * @param int $page
  1952. * @param int $pageSize
  1953. * @return array
  1954. */
  1955. public function getWebsiteRoleUserList(string $keyword,int $page,int $pageSize,int $websiteId,int $roleId):array
  1956. {
  1957. $where = [
  1958. ['website_role_user.website_id','=',$websiteId],
  1959. ['website_role_user.role_id','=',$roleId],
  1960. ];
  1961. $count = WebsiteRoleUser::where($where)->count();
  1962. $where[] = ['u.user_name','like','%'.$keyword.'%'];
  1963. $result = WebsiteRoleUser::where($where)
  1964. ->leftJoin("user as u","website_role_user.user_id","u.id")
  1965. ->leftJoin("website as w","website_role_user.website_id","u.id")
  1966. ->leftJoin("role as r","website_role_user.role_id","r.id")
  1967. ->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')
  1968. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  1969. if (empty($result)) {
  1970. return Result::error("没有数据",0);
  1971. }
  1972. $data = [
  1973. 'rows'=>$result->toArray(),
  1974. 'count'=>$count
  1975. ];
  1976. return Result::success($data);
  1977. }
  1978. /**
  1979. * @param array $data
  1980. * @return array
  1981. */
  1982. public function createWebsiteRoleUser(array $data): array
  1983. {
  1984. $insertData = [
  1985. 'website_id'=>$data['website_id'],
  1986. 'user_id'=>$data['user_id']??'',
  1987. ];
  1988. $info = WebsiteRoleUser::where($insertData)->first();
  1989. if($info){
  1990. return Result::error("不能重复添加角色用户",0);
  1991. }
  1992. $insertData['role_id'] = $data['role_id']??'';
  1993. $insertData['admin_user_id'] = $data['admin_user_id']??'';
  1994. $insertData['type'] = $data['type']??'';
  1995. $result = WebsiteRoleUser::insertGetId($insertData);
  1996. if(empty($result)){
  1997. return Result::error("创建失败",0);
  1998. }else{
  1999. return Result::success(["id"=>$result]);
  2000. }
  2001. }
  2002. /**
  2003. * @param int $id
  2004. * @param array $data
  2005. * @return array
  2006. */
  2007. public function updateWebsiteRoleUser(int $id,array $data): array
  2008. {
  2009. $insertData = [
  2010. 'website_id'=>$data['website_id'],
  2011. 'type'=>$data['type']??'',
  2012. 'type_id'=>$data['type_id']??'',
  2013. 'role_id'=>$data['role_id']??'',
  2014. ];
  2015. $result = WebsiteRoleUser::where('id',$id)->update($insertData);
  2016. if(empty($result)){
  2017. return Result::error("更新失败",0);
  2018. }else{
  2019. return Result::success();
  2020. }
  2021. }
  2022. /**
  2023. * @param int $id
  2024. * @return array
  2025. */
  2026. public function delWebsiteRoleUser(int $id): array
  2027. {
  2028. $result = WebsiteRoleUser::where('id',$id )->delete();
  2029. if(empty($result)){
  2030. return Result::error("删除失败",0);
  2031. }else{
  2032. return Result::success();
  2033. }
  2034. }
  2035. /**
  2036. * 根据域名获取网站 站点id
  2037. * @param array $data
  2038. * @return array
  2039. */
  2040. public function getWebsiteId(array $data): array
  2041. {
  2042. $result = Website::whereJsonContains('website_url',$data['website_url'])->first();
  2043. if(empty($result)){
  2044. return Result::error("查询站点失败",0);
  2045. }else{
  2046. return Result::success($result);
  2047. }
  2048. }
  2049. /**
  2050. * 查询网站下面的导航
  2051. * @param array $data
  2052. * @return array
  2053. */
  2054. public function getWebsiteCategory(array $data): array
  2055. {
  2056. $where = [
  2057. 'website_id'=>$data['website_id'],
  2058. 'pid'=>0
  2059. ];
  2060. $result = WebsiteCategory::where($where)->orderBy('sort','asc')->get();
  2061. if(empty($result)){
  2062. return Result::error("查询站点栏目失败",0);
  2063. }else{
  2064. return Result::success($result);
  2065. }
  2066. }
  2067. /**
  2068. * 网站首页数据统计, 管理员
  2069. * @return void
  2070. */
  2071. public function getAdminIndex(array $data): array
  2072. {
  2073. var_dump("用户类型:",$data['type_id']);
  2074. switch ($data['type_id']){
  2075. case 4:
  2076. $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;');
  2077. return Result::success($result);
  2078. break;
  2079. case 10000:
  2080. $res = [];
  2081. //网站
  2082. $res['website']['count'] = 0;
  2083. $res['website']['growth_rate'] = 0;
  2084. //资讯
  2085. $res['article']['count'] = 0;
  2086. $res['article']['growth_rate'] = 0;
  2087. //导航池
  2088. $res['category']['count'] = 0;
  2089. $res['category']['growth_rate'] = 0;
  2090. //近一月数据
  2091. $res['monthArticle']= [];
  2092. //用户类型
  2093. $res['userType'] = [];
  2094. $res['website']['count'] = Website::where([])->count();
  2095. $res['article']['count'] = Article::whereNotIn('status',['404'])->count();
  2096. $res['category']['count'] = Category::where([])->count();
  2097. $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;');
  2098. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  2099. return Result::success($res);
  2100. }
  2101. return [];
  2102. }
  2103. /**
  2104. * 获取模板类型
  2105. * @return void
  2106. */
  2107. public function getTemplateClass(array $data): array
  2108. {
  2109. $where = [];
  2110. if(isset($data['name']) && $data['name']){
  2111. array_push($where,['name','like','%'.$data['name'].'%']);
  2112. }
  2113. $result = TemplateClass::where($where)->orderBy('sort','asc')->get();
  2114. if(empty($result)){
  2115. return Result::error("没有模板类型",0);
  2116. }else{
  2117. return Result::success($result);
  2118. }
  2119. }
  2120. /**
  2121. * 添加模板类型
  2122. * @param
  2123. * @return void
  2124. */
  2125. public function addTemplateClass(array $data): array
  2126. {
  2127. $insertData = [
  2128. 'name'=>$data['name']
  2129. ];
  2130. $result = TemplateClass::insertGetId($insertData);
  2131. if(empty($result)){
  2132. return Result::error("创建失败",0);
  2133. }else{
  2134. return Result::success(["id"=>$result]);
  2135. }
  2136. }
  2137. /**
  2138. * 更新模板
  2139. * @param array $data
  2140. * @return array
  2141. */
  2142. public function upTemplateClass(array $data): array
  2143. {
  2144. $where = [
  2145. 'id'=>$data['id']
  2146. ];
  2147. $insertData = [
  2148. 'name'=>$data['name']
  2149. ];
  2150. $result = TemplateClass::where($where)->update($insertData);
  2151. if(empty($result)){
  2152. return Result::error("更新失败",0);
  2153. }else{
  2154. return Result::success();
  2155. }
  2156. }
  2157. /**
  2158. * 删除模板
  2159. * @param array $data
  2160. * @return array
  2161. */
  2162. public function delTemplateClass(array $data): array
  2163. {
  2164. $where = [
  2165. 'id'=>$data['id']
  2166. ];
  2167. $result = TemplateClass::where($where)->delete();
  2168. if(empty($result)){
  2169. return Result::error("删除失败",0);
  2170. }else{
  2171. return Result::success();
  2172. }
  2173. }
  2174. /**
  2175. * 获取分类下的模板
  2176. * @param array $data
  2177. * @return array
  2178. */
  2179. public function getTemplate(array $data): array
  2180. {
  2181. $page = $data['page'];
  2182. $pageSize = $data['pageSize'];
  2183. $where = [];
  2184. if(isset($data['template_class_id']) && $data['template_class_id']){
  2185. array_push($where,['template_class_id','=',$data['template_class_id']]);
  2186. }
  2187. $result = Template::where($where)
  2188. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  2189. $count = Template::where($where)->count();
  2190. if (empty($result)) {
  2191. return Result::error("没有数据",0);
  2192. }
  2193. $data = [
  2194. 'rows'=>$result->toArray(),
  2195. 'count'=>$count
  2196. ];
  2197. return Result::success($data);
  2198. }
  2199. /**
  2200. * 创建模板
  2201. * @param
  2202. * @return void
  2203. */
  2204. public function addTemplate(array $data): array
  2205. {
  2206. $insertData = [
  2207. 'template_name'=>$data['template_name'],
  2208. 'template_img'=>json_encode($data['template_img']),
  2209. 'template_class_id'=>$data['template_class_id'],
  2210. ];
  2211. $result = Template::insertGetId($insertData);
  2212. if(empty($result)){
  2213. return Result::error("创建模板失败",0);
  2214. }else{
  2215. return Result::success(["id"=>$result]);
  2216. }
  2217. }
  2218. /**
  2219. * 更新模板
  2220. * @param array $data
  2221. * @return array
  2222. */
  2223. public function upTemplate(array $data): array
  2224. {
  2225. $where = [
  2226. 'id'=>$data['id']
  2227. ];
  2228. $insertData = [
  2229. 'template_name'=>$data['template_name'],
  2230. 'template_img'=>json_encode($data['template_img']),
  2231. 'template_class_id'=>$data['template_class_id'],
  2232. ];
  2233. $result = Template::where($where)->update($insertData);
  2234. if(empty($result)){
  2235. return Result::error("更新模板失败",0);
  2236. }else{
  2237. return Result::success();
  2238. }
  2239. }
  2240. /**
  2241. * 删除模板
  2242. * @param array $data
  2243. * @return array
  2244. */
  2245. public function delTemplate(array $data): array
  2246. {
  2247. $where = [
  2248. 'id'=>$data['id']
  2249. ];
  2250. $result = Template::where($where)->delete();
  2251. if(empty($result)){
  2252. return Result::error("删除模板失败",0);
  2253. }else{
  2254. return Result::success();
  2255. }
  2256. }
  2257. /**
  2258. * 搜索网站
  2259. * @param array $data
  2260. * @return array
  2261. */
  2262. public function websiteList(array $data): array
  2263. {
  2264. $where = [];
  2265. if(isset($data['keyword']) && !empty($data['keyword'])){
  2266. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  2267. }
  2268. $result = Website::where($where)->get();
  2269. if($result){
  2270. return Result::success($result);
  2271. }else{
  2272. return Result::error("没有网站",0);
  2273. }
  2274. }
  2275. public function addWebsiteCategory(array $data): array
  2276. {
  2277. $website_id = $data['website_id'];
  2278. $category_arr_id = $data['category_arr_id'];
  2279. $categoryList = Category::whereIn('id',$category_arr_id)->get();
  2280. $categoryListIds = [];
  2281. if($categoryList){
  2282. foreach ($categoryList->toArray() as $val){
  2283. array_push($categoryListIds,$val['id']);
  2284. }
  2285. }
  2286. $arr = [];
  2287. if($categoryListIds){
  2288. foreach ($categoryListIds as $v){
  2289. $ids = $this->getUnderlingUIds(intval($v));
  2290. $ids_arr = explode(",", $ids);
  2291. array_push($arr,$ids_arr);
  2292. }
  2293. }
  2294. $mergedArray = [];
  2295. foreach ($arr as $subarray) {
  2296. $mergedArray = array_merge($mergedArray, $subarray);
  2297. }
  2298. var_dump("所有:",$arr,$mergedArray);
  2299. //查询出所有的分类进行分割插入 组装数据
  2300. $categoryListData = Category::whereIn('id',$mergedArray)->get();
  2301. $categoryListData = $categoryListData->toArray();
  2302. $insertData = [];
  2303. if($categoryListData){
  2304. foreach ($categoryListData as $key=>$value){
  2305. $insertData[$key]['website_id'] = $website_id;
  2306. $insertData[$key]['name'] = $value['name'];
  2307. $insertData[$key]['sort'] = $value['sort'];
  2308. $insertData[$key]['pid'] = $value['pid'];
  2309. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  2310. $insertData[$key]['seo_title'] = $value['seo_title'];
  2311. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  2312. $insertData[$key]['seo_description'] = $value['seo_description'];
  2313. $insertData[$key]['alias'] = $value['name'];
  2314. $insertData[$key]['category_id'] = $value['id'];
  2315. }
  2316. }
  2317. $result = WebsiteCategory::insert($insertData);
  2318. var_dump("插入数据状态:",$result);
  2319. if($result){
  2320. return Result::success($result);
  2321. }else{
  2322. return Result::error("创建失败",0);
  2323. }
  2324. }
  2325. /**
  2326. * 删除网站导航
  2327. * @param array $data
  2328. * @return array
  2329. */
  2330. public function delWebsiteCategory(array $data): array
  2331. {
  2332. $website_id = $data['website_id']??0;
  2333. $category_id = $data['category_id']??0;
  2334. $ids = $this->getUnderlingUIds(intval($category_id));
  2335. $ids_arr = explode(",", $ids);
  2336. $result = WebsiteCategory::where(['website_id'=>$website_id])->whereIn("category_id",$ids_arr)->delete();
  2337. if($result){
  2338. return Result::success($result);
  2339. }else{
  2340. return Result::error("删除失败",0);
  2341. }
  2342. }
  2343. /**
  2344. * 获取网站导航
  2345. * @param array $data
  2346. * @return array
  2347. */
  2348. public function getAdminWebsiteCategory(array $data): array
  2349. {
  2350. $where = [
  2351. 'website_id'=>$data['website_id'],
  2352. 'pid'=>0
  2353. ];
  2354. $result = WebsiteCategory::where($where)->get();
  2355. if($result){
  2356. return Result::success($result);
  2357. }else{
  2358. return Result::error("查询失败",0);
  2359. }
  2360. }
  2361. /**
  2362. * 更新网站导航
  2363. * @param array $data
  2364. * @return array
  2365. */
  2366. public function upWebsiteCategory(array $data): array
  2367. {
  2368. Db::beginTransaction();
  2369. try{
  2370. //合并栏目id
  2371. $reqIds = array_merge($data['old_category_arr_id'],$data['new_category_arr_id']);
  2372. //对比old 数组差异化,把差异化的删除
  2373. $result = WebsiteCategory::where(['website_id'=>$data['website_id'],'pid'=>0])->get();
  2374. $result = $result->toArray();
  2375. $categoryIds = [];
  2376. if($result){
  2377. foreach ($result as $val){
  2378. array_push($categoryIds,$val['category_id']);
  2379. }
  2380. }
  2381. //和原始数据对比取交际
  2382. $reqidsIntersect = array_intersect($reqIds,$categoryIds);
  2383. //再取差集 进行对比
  2384. $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds),array_diff($categoryIds,$reqidsIntersect));
  2385. var_dump("差集:",$differenceIDS);
  2386. $arr_ids = [];
  2387. if(count($differenceIDS)>0){
  2388. foreach ($differenceIDS as $vv){
  2389. $idV = $this->getUnderlingUIds(intval($vv));
  2390. $ids_arrV = explode(",", $idV);
  2391. array_push($arr_ids,$ids_arrV);
  2392. }
  2393. }
  2394. $del_ids = array_reduce($arr_ids, 'array_merge', array());
  2395. //有差异 删除
  2396. if(count($del_ids)>0){
  2397. WebsiteCategory::where(['website_id'=>$data['website_id']])->whereIn("category_id",$del_ids)->delete();
  2398. }
  2399. //传过来的值 和 交际 对比,选出要添加的值 进行插入
  2400. $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect),array_diff($reqidsIntersect,$reqIds));
  2401. var_dump("要存储的:",$insertIDS);
  2402. //新的数组重新创建
  2403. if(count($insertIDS)>0){
  2404. $arr = [];
  2405. $categoryListIds = $insertIDS;
  2406. if($categoryListIds){
  2407. foreach ($categoryListIds as $v){
  2408. $ids = $this->getUnderlingUIds(intval($v));
  2409. $ids_arr = explode(",", $ids);
  2410. array_push($arr,$ids_arr);
  2411. }
  2412. }
  2413. $mergedArray = [];
  2414. foreach ($arr as $subarray) {
  2415. $mergedArray = array_merge($mergedArray, $subarray);
  2416. }
  2417. var_dump("要插入的ID:",$mergedArray);
  2418. //查询出所有的分类进行分割插入 组装数据
  2419. $categoryListData = Category::whereIn('id',$mergedArray)->get();
  2420. $categoryListData = $categoryListData->toArray();
  2421. $insertData = [];
  2422. if($categoryListData){
  2423. foreach ($categoryListData as $key=>$value){
  2424. $insertData[$key]['website_id'] = $data['website_id'];
  2425. $insertData[$key]['name'] = $value['name'];
  2426. $insertData[$key]['sort'] = $value['sort'];
  2427. $insertData[$key]['pid'] = $value['pid'];
  2428. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  2429. $insertData[$key]['seo_title'] = $value['seo_title'];
  2430. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  2431. $insertData[$key]['seo_description'] = $value['seo_description'];
  2432. $insertData[$key]['alias'] = $value['name'];
  2433. $insertData[$key]['category_id'] = $value['id'];
  2434. }
  2435. }
  2436. WebsiteCategory::insert($insertData);
  2437. }
  2438. Db::commit();
  2439. } catch(\Throwable $ex){
  2440. Db::rollBack();
  2441. var_dump($ex->getMessage());
  2442. return Result::error("修改失败",0);
  2443. }
  2444. return Result::success();
  2445. }
  2446. /**
  2447. * 获取网站列表
  2448. * @param array $data
  2449. * @return array
  2450. */
  2451. public function getWebsiteCategoryList(array $data): array
  2452. {
  2453. $where = [];
  2454. if(isset($data['keyword']) && !empty($data['keyword'])){
  2455. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  2456. }
  2457. if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
  2458. array_push($where,['website.website_column_id','=',$data['website_column_id']]);
  2459. }
  2460. $result = Website::where($where)
  2461. ->with(["websiteCategory"=>function ($query) {
  2462. $query->where(['pid'=>0])->select('website_id','name','alias','category_id');
  2463. }])
  2464. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
  2465. ->get();
  2466. $count = Website::where($where)->count();
  2467. if (empty($result)) {
  2468. return Result::error("没有数据",0);
  2469. }
  2470. $data = [
  2471. 'rows'=>$result->toArray(),
  2472. 'count'=>$count
  2473. ];
  2474. if($result){
  2475. return Result::success($data);
  2476. }else{
  2477. return Result::error("查询失败",0);
  2478. }
  2479. }
  2480. /**
  2481. * 删除网站下的所有导航
  2482. * @param array $data
  2483. * @return array
  2484. */
  2485. public function delWebsiteAllCategory(array $data): array
  2486. {
  2487. $website_id = $data['website_id'];
  2488. $result = WebsiteCategory::where(['website_id'=>$website_id])->delete();
  2489. if($result){
  2490. return Result::success($result);
  2491. }else{
  2492. return Result::error("删除失败",0);
  2493. }
  2494. }
  2495. /**
  2496. * 获取网站下的某一个导航
  2497. * @param array $data
  2498. * @return array
  2499. */
  2500. public function getWebsiteCategoryOnes(array $data): array
  2501. {
  2502. $website_id = $data['website_id'];
  2503. $category_id = $data['category_id'];
  2504. $result = WebsiteCategory::where(['website_category.website_id'=>$website_id,'website_category.category_id'=>$category_id])
  2505. ->first();
  2506. if($result){
  2507. return Result::success($result);
  2508. }else{
  2509. return Result::error("查询失败",0);
  2510. }
  2511. }
  2512. /**
  2513. * 更新网闸下的某一个导航
  2514. * @param array $data
  2515. * @return array
  2516. */
  2517. public function upWebsiteCategoryones(array $data): array
  2518. {
  2519. $where = [
  2520. 'website_id'=>$data['website_id'],
  2521. 'category_id'=>$data['category_id'],
  2522. ];
  2523. $result = WebsiteCategory::where($where)->update($data);
  2524. if($result){
  2525. return Result::success($result);
  2526. }else{
  2527. return Result::error("更新失败",0);
  2528. }
  2529. }
  2530. /**
  2531. * 获取网站下的所有导航(包含子导航)
  2532. * @param array $data
  2533. * @return array
  2534. */
  2535. public function getWebsiteAllCategory(array $data): array
  2536. {
  2537. $where = [];
  2538. if(isset($data['website_id']) && !empty($data['website_id'])){
  2539. array_push($where,['website_category.website_id','=',$data['website_id']]);
  2540. }
  2541. if(isset($data['name']) && !empty($data['name'])){
  2542. array_push($where,['website_category.name','like','%'.$data['name'].'%']);
  2543. }
  2544. if(isset($data['alias']) && !empty($data['alias'])){
  2545. array_push($where,['website_category.alias','like','%'.$data['alias'].'%']);
  2546. }
  2547. if(isset($data['department_id']) && !empty($data['department_id'])){
  2548. array_push($where,['category.department_id','=',$data['department_id']]);
  2549. }
  2550. if(isset($data['city_id']) && !empty($data['city_id'])){
  2551. array_push($where,['category.city_id','=',$data['city_id']]);
  2552. }
  2553. $result = WebsiteCategory::where($where)
  2554. ->leftJoin("category",'website_category.category_id','category.id')
  2555. ->leftJoin("department",'category.department_id','department.id')
  2556. ->leftJoin("district",'category.city_id','district.id')
  2557. ->select("website_category.*","department.name as department_name","district.name as city_name")
  2558. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
  2559. ->get();
  2560. $count = WebsiteCategory::where($where)
  2561. ->leftJoin("category",'website_category.category_id','category.id')
  2562. ->leftJoin("department",'category.department_id','department.id')
  2563. ->leftJoin("district",'category.city_id','district.id')
  2564. ->count();
  2565. if (empty($result)) {
  2566. return Result::error("没有数据",0);
  2567. }
  2568. $data = [
  2569. 'rows'=>$result->toArray(),
  2570. 'count'=>$count
  2571. ];
  2572. if($result){
  2573. return Result::success($data);
  2574. }else{
  2575. return Result::error("查询失败",0);
  2576. }
  2577. if($result){
  2578. return Result::success($result);
  2579. }else{
  2580. return Result::error("查询失败",0);
  2581. }
  2582. }
  2583. /**
  2584. * 递归查询数据
  2585. * @param $id
  2586. * @param $ids
  2587. * @return string
  2588. */
  2589. public function getUnderlingUIds($id, $ids='')
  2590. {
  2591. $back = Category::where(['pid'=>$id])->get();
  2592. $back = $back->toArray();
  2593. if (!empty($back) && is_array($back)) {
  2594. foreach ($back as $v) {
  2595. //防止当前人的ID重复去查询,形成恶性循环
  2596. if ($v['id'] == $id) {
  2597. continue;
  2598. }
  2599. $back2 = Category::where(['pid'=>$id])->count('id');
  2600. if ($back2 > 0) {
  2601. $ids = $this->getUnderlingUIds($v['id'],$ids);
  2602. } else {
  2603. $ids .= ','.$v['id'];
  2604. }
  2605. }
  2606. }
  2607. $ids = $id.','.$ids.',';
  2608. $ids = str_replace(',,', ",", $ids);
  2609. $ids = trim($ids, ',');
  2610. return $ids;
  2611. }
  2612. /**
  2613. * 检测网站名称是否重复
  2614. * @param array $data
  2615. * @return array
  2616. */
  2617. public function checkWebsiteName(array $data): array
  2618. {
  2619. if(isset($data['id'])){
  2620. $data[] = ['id',"!=",$data['id']];
  2621. unset($data['id']);
  2622. }
  2623. $websiteInfo = Website::query()->where($data)->first();
  2624. if (empty($websiteInfo)) {
  2625. return Result::error("找不到网站",0);
  2626. }
  2627. return Result::success($websiteInfo->toArray());
  2628. }
  2629. /**
  2630. * 检测网站url是否重复
  2631. * @param array $data
  2632. * @return array
  2633. */
  2634. public function checkWebsiteUrl(array $data): array
  2635. {
  2636. $whereData = [];
  2637. if(isset($data['id'])){
  2638. $whereData = [['id',"!=",$data['id']]];
  2639. unset($data['id']);
  2640. }
  2641. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  2642. if (empty($websiteInfo)) {
  2643. return Result::error("找不到URL",0);
  2644. }
  2645. return Result::success($websiteInfo->toArray());
  2646. }
  2647. /**
  2648. * 获取并搜索 网站模板信息
  2649. * @param array $data
  2650. * @return array
  2651. */
  2652. public function getWebsiteTemplateintel(array $data): array
  2653. {
  2654. $where = []; // 初始化 $where 数组
  2655. //若存在条件;则在$rep的基础上进行筛选
  2656. if(isset($data['website_name'])){
  2657. array_push($where, ['website.website_name','like','%'.$data['website_name'].'%']);
  2658. }
  2659. if(isset($data['status'])){
  2660. if($data['status'] == 0){
  2661. array_push($where, ['website_template_info.status','=',null]);
  2662. }else{
  2663. array_push($where, ['website_template_info.status','=',$data['status']]);
  2664. }
  2665. }
  2666. //查询所有网站模板信息
  2667. if(empty($where)){
  2668. $rep = Website::where('website.status', 1)
  2669. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  2670. ->leftJoin("template", "template.id", "website_template_info.template_id")
  2671. ->select(
  2672. "website.website_name",
  2673. "website.website_url",
  2674. "website_template_info.id as tid",
  2675. "website_template_info.created_at",
  2676. "website_template_info.updated_at",
  2677. "website_template_info.page_type",
  2678. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  2679. "template.template_name"
  2680. )
  2681. ->limit($data['pageSize'])
  2682. ->offset(($data['page'] - 1) * $data['pageSize'])
  2683. ->orderBy("website_template_info.updated_at", "asc")
  2684. ->get();
  2685. }else{
  2686. $rep = Website::where($where)
  2687. ->where('website.status', 1)
  2688. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  2689. ->leftJoin("template", "template.id", "website_template_info.template_id")
  2690. ->select(
  2691. "website.website_name",
  2692. "website.website_url",
  2693. "website_template_info.id as tid",
  2694. "website_template_info.created_at",
  2695. "website_template_info.updated_at",
  2696. "website_template_info.page_type",
  2697. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  2698. "template.template_name"
  2699. )
  2700. ->limit($data['pageSize'])
  2701. ->offset(($data['page'] - 1) * $data['pageSize'])
  2702. ->orderBy("website_template_info.updated_at", "asc")
  2703. ->get();
  2704. }
  2705. $result = [
  2706. "rows" => $rep->toArray(),
  2707. "count" => $rep->count()
  2708. ];
  2709. if($rep->count()==0){
  2710. return Result::error("没有查找到相关数据",0);
  2711. } else {
  2712. return Result::success($result);
  2713. }
  2714. // return Result::success($result);
  2715. }
  2716. /**
  2717. * 添加网站基础信息
  2718. * @param array $data
  2719. * @return array
  2720. */
  2721. public function addWebsiteTemplateintel(array $data): array
  2722. {
  2723. $website = Website::where('website.id',$data['website_id'])->first();
  2724. if(empty($website)){
  2725. $message = "请输入正确的网站id!";
  2726. }else{
  2727. if(empty($website['website_column_id'])){
  2728. $message = "请先关联导航池!";
  2729. }
  2730. // $data['page_type'] = WebsiteTemplateInfo::where('website_id',$data['website_id'])->select('page_type')->first();
  2731. if(isset($data['page_type'])){
  2732. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  2733. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  2734. // $result = 'yes';
  2735. $data['page_type'] = json_encode($data['page_type'])??''; // 将数组转换为 JSON 字符串
  2736. $result = WebsiteTemplateInfo::insertGetId($data);
  2737. } else {
  2738. $message = "请先选择首页和底部导航详情页!";
  2739. }
  2740. }else{
  2741. $footer = FooterCategory::where('website_id',$data['website_id'])->select('type')->get();
  2742. if(empty($footer)){
  2743. $types = '2';
  2744. }else{
  2745. $types = 2;
  2746. foreach ($footer as $v) {
  2747. if ($v['type'] == 1) {
  2748. $types = 1;
  2749. } else {
  2750. $types = 0;
  2751. }
  2752. }
  2753. }
  2754. $result['type'] = $types;
  2755. }
  2756. }
  2757. if(empty($result)){
  2758. return Result::error($message,0);
  2759. }else{
  2760. return Result::success($result);
  2761. }
  2762. }
  2763. /**
  2764. * 获取所有网站风格信息
  2765. *
  2766. * @return array
  2767. */
  2768. public function getAllTemplateClass(array $data): array
  2769. {
  2770. $result = TemplateClass::all();
  2771. if(empty($result)){
  2772. return Result::error("没有查找到相关数据!",0);
  2773. }else{
  2774. return Result::success($result);
  2775. }
  2776. }
  2777. /**
  2778. * 获取网站模板信息
  2779. * @param array $data
  2780. * @return array
  2781. */
  2782. public function getWebsiteTemplateList(array $data): array
  2783. {
  2784. $website = Website::where('website.id',$data['website_id'])->first();
  2785. if(empty($website)){
  2786. $message = "请输入正确的网站id!";
  2787. }else{
  2788. $where = $data["page_type"];
  2789. if(isset($data['template_class_id'])){
  2790. $template_class = TemplateClass::where('id',$data['template_class_id'])->first();
  2791. if(empty($template_class)){
  2792. $message = "请输入正确的模板风格id!";
  2793. }else{
  2794. // 获取指定风格下的模板
  2795. $rep = Template::where('template_class_id', $data['template_class_id'])
  2796. ->where(function ($query) use ($where) {
  2797. foreach ($where as $value) {
  2798. $query->whereJsonContains('template_img', ['value' => $value]);
  2799. }
  2800. })
  2801. ->leftJoin('template_class','template_class.id','template.template_class_id')
  2802. ->select('template.*','template_class.name')
  2803. ->limit($data['pageSize'])
  2804. ->offset(($data['page'] - 1) * $data['pageSize'])
  2805. ->orderBy("template.updated_at", "desc")
  2806. ->get();
  2807. }
  2808. }else{
  2809. //获取所有模板
  2810. $rep = Template::where(function ($query) use ($where) {
  2811. foreach ($where as $value) {
  2812. $query->whereJsonContains('template_img', ['value' => $value]);
  2813. }
  2814. })
  2815. ->offset(($data['page'] - 1) * $data['pageSize'])
  2816. ->limit($data['pageSize'])
  2817. ->orderBy("template.updated_at", "desc")
  2818. ->get();
  2819. }
  2820. if(empty($rep)){
  2821. $message = "没有查找到相关数据!";
  2822. }else{
  2823. $result = [
  2824. "rows" => $rep->toArray(),
  2825. "count" => $rep->count()
  2826. ];
  2827. }
  2828. }
  2829. if(empty($rep)){
  2830. return Result::error($message,0);
  2831. }else{
  2832. return Result::success($result);
  2833. }
  2834. }
  2835. /**
  2836. * 添加网站模板
  2837. * @param array $data
  2838. */
  2839. public function addWebsiteTemplateclassintel(array $data): array
  2840. {
  2841. $template = Template::where('id',$data['template_id'])->first();
  2842. $web = Website::where('id',$data['website_id'])->first();
  2843. if(empty($template)){
  2844. return Result::error("请输入正确的模板id",0);
  2845. }
  2846. if(empty($web)){
  2847. return Result::error("请输入正确的网站id",0);
  2848. }
  2849. $result = WebsiteTemplateInfo::where('website_id',$data['website_id'])->update(['template_id' => $data['template_id']]);
  2850. if(empty($result)){
  2851. return Result::error("添加失败",0);
  2852. }else{
  2853. return Result::success($result);
  2854. }
  2855. }
  2856. }