WebsiteService.php 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\AdSize;
  4. use App\Model\Article;
  5. use App\Model\Ad;
  6. use App\Model\Category;
  7. use App\Model\AdPlace;
  8. use App\Model\Department;
  9. use App\Model\District;
  10. use App\Model\FooterCategory;
  11. use App\Model\FooterContent;
  12. use App\Model\LetterOfComplaint;
  13. use App\Model\Link;
  14. use App\Model\TemplateClass;
  15. use App\Model\Template;
  16. use App\Model\User;
  17. use App\Model\UserInfo;
  18. use App\Model\WebsiteRole;
  19. use App\Model\WebsiteRoleUser;
  20. use App\Model\Website;
  21. use App\Model\WebsiteColumn;
  22. use App\Model\Sector;
  23. use Hyperf\DbConnection\Db;
  24. use Hyperf\RpcServer\Annotation\RpcService;
  25. use App\Tools\Result;
  26. use Carbon\Carbon;
  27. use App\Model\WebsiteCategory;
  28. use App\Model\WebsiteTemplate;
  29. use App\Model\WebsiteTemplateInfo;
  30. use Hamcrest\Arrays\IsArray;
  31. use PhpParser\Node\Stmt\Return_;
  32. use App\Model\WebsiteGroup;
  33. use function PHPUnit\Framework\isNull;
  34. use App\Model\Component;
  35. // use Illuminate\Support\Facades\DB;
  36. #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  37. class WebsiteService implements WebsiteServiceInterface
  38. {
  39. /**
  40. * @param string $keyword
  41. * @param int $page
  42. * @param int $pageSize
  43. * @return array
  44. */
  45. public function getWebsitetList(array $data): array
  46. {
  47. $resultWwhere = Website::when($data, function ($query) use ($data) {
  48. if (isset($data['keyword']) && !empty($data['keyword'])) {
  49. $query->where('website.website_name', 'like', '%' . $data['keyword'] . '%');
  50. }
  51. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  52. $query->whereJsonContains("website.website_column_arr_id", intval($data['website_column_id']));
  53. }
  54. if (isset($data['city_id']) && !empty($data['city_id'])) {
  55. $query->whereJsonContains("website.city_arr_id", intval($data['city_id']));
  56. }
  57. });
  58. $count = $resultWwhere->leftJoin("website_column", "website.website_column_id", "website_column.id")
  59. ->leftJoin("district", "district.id", "website.city_id")->count();
  60. $result = $resultWwhere->select("website.*", "website_column.column_name", "district.name as city_name")
  61. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("website.id", "desc")->get();
  62. if (empty($result)) {
  63. return Result::error("没有数据", 0);
  64. }
  65. $data = [
  66. 'rows' => $result->toArray(),
  67. 'count' => $count,
  68. ];
  69. return Result::success($data);
  70. }
  71. /**
  72. * @param array $data
  73. * @return array
  74. */
  75. public function createWebsite(array $data): array
  76. {
  77. var_dump("网站数据:", $data);
  78. $insertData = [
  79. 'website_name' => $data['website_name'],
  80. 'logo' => $data['logo'] ?? '',
  81. 'website_url' => $data['website_url'] ?? '',
  82. // 'city_id'=>$data['city_id']??0,
  83. 'website_column_id' => $data['website_column_id'],
  84. 'title' => $data['title'] ?? '',
  85. 'keywords' => $data['keywords'] ?? '',
  86. 'description' => $data['description'] ?? '',
  87. 'status' => $data['status'] ?? 0,
  88. 'website_column_arr_id' => $data['website_column_arr_id'],
  89. // 'city_arr_id'=>$data['city_arr_id']??[0],
  90. 'template_id' => $data['template_id'] ?? 0,
  91. ];
  92. $result = Website::insertGetId($insertData);
  93. if (empty($result)) {
  94. return Result::error("创建失败", 0);
  95. } else {
  96. return Result::success(["id" => $result]);
  97. }
  98. }
  99. /**
  100. * @param int $id
  101. * @param array $data
  102. * @return array
  103. */
  104. public function updateWebsite(int $id, array $data): array
  105. {
  106. $insertData = [
  107. 'website_name' => $data['website_name'],
  108. 'logo' => $data['logo'] ?? '',
  109. 'website_url' => $data['website_url'] ?? '',
  110. // 'city_id'=>$data['city_id']??0,
  111. 'website_column_id' => $data['website_column_id'],
  112. 'title' => $data['title'] ?? '',
  113. 'keywords' => $data['keywords'] ?? '',
  114. 'description' => $data['description'] ?? '',
  115. 'status' => $data['status'] ?? 0,
  116. 'website_column_arr_id' => $data['website_column_arr_id'],
  117. // 'city_arr_id'=>$data['city_arr_id']??[0],
  118. 'template_id' => $data['template_id'] ?? 0,
  119. ];
  120. $result = Website::where('id', $id)->update($insertData);
  121. var_dump("更新站点", $result);
  122. if (empty($result)) {
  123. return Result::error("更新失败", 0);
  124. } else {
  125. return Result::success();
  126. }
  127. }
  128. /**
  129. * @param int $id
  130. * @return array
  131. */
  132. public function delWebsite(int $id): array
  133. {
  134. $result = Website::where('id', $id)->delete();
  135. if (empty($result)) {
  136. return Result::error("删除失败", 0);
  137. } else {
  138. return Result::success();
  139. }
  140. }
  141. /**
  142. * @param int $id
  143. * @return array
  144. */
  145. public function getWebsiteInfo(int $id): array
  146. {
  147. $where = [
  148. ['website.id', '=', $id],
  149. ];
  150. $result = Website::where($where)
  151. ->leftJoin("template", "template.id", "website.template_id")
  152. ->select("website.*", "template.template_name", "template.template_img")
  153. ->first();
  154. if (empty($result)) {
  155. return Result::error("数据不存在", 0);
  156. } else {
  157. return Result::success($result->toArray());
  158. }
  159. }
  160. /**
  161. * 查询所有的站点栏目
  162. * @return array
  163. */
  164. public function getWebsiteColumn(array $data): array
  165. {
  166. $result = WebsiteColumn::where($data)->get();
  167. if (empty($result)) {
  168. return Result::error("数据不存在", 0);
  169. } else {
  170. return Result::success($result->toArray());
  171. }
  172. }
  173. /**
  174. * @param string $keyword
  175. * @param int $page
  176. * @param int $pageSize
  177. * @return array
  178. */
  179. public function getWebsiteColumnList(array $data): array
  180. {
  181. $where = [];
  182. if (isset($data['keyword']) && $data['keyword']) {
  183. array_push($where, ['website_column.column_name', 'like', '%' . $data['keyword'] . '%']);
  184. }
  185. $result = WebsiteColumn::where($where)
  186. ->leftJoin("website_column as wc", "website_column.pid", "wc.id")
  187. ->select("website_column.*", "wc.column_name as parent_column_name")
  188. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->get();
  189. $count = WebsiteColumn::where($where)->count();
  190. if (empty($result)) {
  191. return Result::error("没有数据", 0);
  192. }
  193. $data = [
  194. 'rows' => $result->toArray(),
  195. 'count' => $count,
  196. ];
  197. return Result::success($data);
  198. }
  199. /**
  200. * @param array $data
  201. * @return array
  202. */
  203. public function createWebsiteColumn(array $data): array
  204. {
  205. $insertData = [
  206. 'column_name' => $data['column_name'],
  207. 'pid' => $data['pid'] ?? '',
  208. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  209. 'sort' => $data['sort'] ?? 0,
  210. 'remark' => $data['remark'] ?? '',
  211. ];
  212. $result = WebsiteColumn::insertGetId($insertData);
  213. if (empty($result)) {
  214. return Result::error("创建失败", 0);
  215. } else {
  216. return Result::success(["id" => $result]);
  217. }
  218. }
  219. /**
  220. * @param int $id
  221. * @param array $data
  222. * @return array
  223. */
  224. public function updateWebsiteColumn(int $id, array $data): array
  225. {
  226. $insertData = [
  227. 'column_name' => $data['column_name'],
  228. 'pid' => $data['pid'] ?? '',
  229. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  230. 'sort' => $data['sort'] ?? 0,
  231. 'remark' => $data['remark'] ?? '',
  232. ];
  233. $result = WebsiteColumn::where('id', $id)->update($insertData);
  234. if (empty($result)) {
  235. return Result::error("更新失败", 0);
  236. } else {
  237. return Result::success();
  238. }
  239. }
  240. /**
  241. * @param int $id
  242. * @return array
  243. */
  244. public function delWebsiteColumn(int $id): array
  245. {
  246. $list = WebsiteColumn::where(['pid' => $id])->get();
  247. if ($list) {
  248. return Result::error("存在子网系,不能删除,请先删除子网系", 0);
  249. }
  250. $result = WebsiteColumn::where('id', $id)->delete();
  251. if (empty($result)) {
  252. return Result::error("删除失败", 0);
  253. } else {
  254. return Result::success();
  255. }
  256. }
  257. /**
  258. * @param string $keyword
  259. * @param int $page
  260. * @param int $pageSize
  261. * @return array
  262. */
  263. public function getWebsiteRoleList(string $keyword, int $page, int $pageSize, int $websiteId): array
  264. {
  265. $where = [
  266. ['role.role_name', 'like', '%' . $keyword . '%'],
  267. ['website_role.website_id', '=', $websiteId],
  268. ];
  269. $result = WebsiteRole::where($where)
  270. ->leftJoin("role", "role.id", "website_role.role_id")
  271. ->select("role.*", "website_role.type", "website_role.role_id", "website_role.id as website_role_id", "website_role.website_id")
  272. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  273. $count = WebsiteRole::where($where)->leftJoin("role", "role.id", "website_role.role_id")->count();
  274. if (empty($result)) {
  275. return Result::error("没有数据", 0);
  276. }
  277. $data = [
  278. 'rows' => $result->toArray(),
  279. 'count' => $count,
  280. ];
  281. return Result::success($data);
  282. }
  283. /**
  284. * @param array $data
  285. * @return array
  286. */
  287. public function createWebsiteRole(array $data): array
  288. {
  289. $insertData = [
  290. 'website_id' => $data['website_id'],
  291. 'role_id' => $data['role_id'] ?? '',
  292. ];
  293. $info = WebsiteRole::where($insertData)->first();
  294. if ($info) {
  295. return Result::error("不能重复添加角色", 0);
  296. }
  297. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  298. $insertData['type'] = $data['type'] ?? '';
  299. $result = WebsiteRole::insertGetId($insertData);
  300. if (empty($result)) {
  301. return Result::error("创建失败", 0);
  302. } else {
  303. return Result::success(["id" => $result]);
  304. }
  305. }
  306. /**
  307. * 暂时用不上
  308. * @param int $id
  309. * @param array $data
  310. * @return array
  311. */
  312. public function updateWebsiteRole(int $id, array $data): array
  313. {
  314. $insertData = [
  315. 'website_id' => $data['website_id'],
  316. 'type' => $data['type'] ?? '',
  317. ];
  318. $result = WebsiteRole::where('id', $id)->update($insertData);
  319. if (empty($result)) {
  320. return Result::error("更新失败", 0);
  321. } else {
  322. return Result::success();
  323. }
  324. }
  325. /**
  326. * @param int $id
  327. * @return array
  328. */
  329. public function delWebsiteRole(int $id): array
  330. {
  331. $result = WebsiteRole::where('id', $id)->delete();
  332. if (empty($result)) {
  333. return Result::error("删除失败", 0);
  334. } else {
  335. return Result::success();
  336. }
  337. }
  338. /**
  339. * @param string $keyword
  340. * @param int $page
  341. * @param int $pageSize
  342. * @return array
  343. */
  344. public function getWebsiteRoleUserList(string $keyword, int $page, int $pageSize, int $websiteId, int $roleId): array
  345. {
  346. $where = [
  347. ['website_role_user.website_id', '=', $websiteId],
  348. ['website_role_user.role_id', '=', $roleId],
  349. ];
  350. $count = WebsiteRoleUser::where($where)->count();
  351. $where[] = ['u.user_name', 'like', '%' . $keyword . '%'];
  352. $result = WebsiteRoleUser::where($where)
  353. ->leftJoin("user as u", "website_role_user.user_id", "u.id")
  354. ->leftJoin("website as w", "website_role_user.website_id", "u.id")
  355. ->leftJoin("role as r", "website_role_user.role_id", "r.id")
  356. ->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')
  357. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  358. if (empty($result)) {
  359. return Result::error("没有数据", 0);
  360. }
  361. $data = [
  362. 'rows' => $result->toArray(),
  363. 'count' => $count,
  364. ];
  365. return Result::success($data);
  366. }
  367. /**
  368. * @param array $data
  369. * @return array
  370. */
  371. public function createWebsiteRoleUser(array $data): array
  372. {
  373. $insertData = [
  374. 'website_id' => $data['website_id'],
  375. 'user_id' => $data['user_id'] ?? '',
  376. ];
  377. $info = WebsiteRoleUser::where($insertData)->first();
  378. if ($info) {
  379. return Result::error("不能重复添加角色用户", 0);
  380. }
  381. $insertData['role_id'] = $data['role_id'] ?? '';
  382. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  383. $insertData['type'] = $data['type'] ?? '';
  384. $result = WebsiteRoleUser::insertGetId($insertData);
  385. if (empty($result)) {
  386. return Result::error("创建失败", 0);
  387. } else {
  388. return Result::success(["id" => $result]);
  389. }
  390. }
  391. /**
  392. * @param int $id
  393. * @param array $data
  394. * @return array
  395. */
  396. public function updateWebsiteRoleUser(int $id, array $data): array
  397. {
  398. $insertData = [
  399. 'website_id' => $data['website_id'],
  400. 'type' => $data['type'] ?? '',
  401. 'type_id' => $data['type_id'] ?? '',
  402. 'role_id' => $data['role_id'] ?? '',
  403. ];
  404. $result = WebsiteRoleUser::where('id', $id)->update($insertData);
  405. if (empty($result)) {
  406. return Result::error("更新失败", 0);
  407. } else {
  408. return Result::success();
  409. }
  410. }
  411. /**
  412. * @param int $id
  413. * @return array
  414. */
  415. public function delWebsiteRoleUser(int $id): array
  416. {
  417. $result = WebsiteRoleUser::where('id', $id)->delete();
  418. if (empty($result)) {
  419. return Result::error("删除失败", 0);
  420. } else {
  421. return Result::success();
  422. }
  423. }
  424. /**
  425. * 根据域名获取网站 站点id
  426. * @param array $data
  427. * @return array
  428. */
  429. public function getWebsiteId(array $data): array
  430. {
  431. $result = Website::whereJsonContains('website_url', $data['website_url'])->first();
  432. if (empty($result)) {
  433. return Result::error("查询站点失败", 0);
  434. } else {
  435. return Result::success($result);
  436. }
  437. }
  438. /**
  439. * 查询网站下面的导航
  440. * @param array $data
  441. * @return array
  442. */
  443. public function getWebsiteCategory(array $data): array
  444. {
  445. $where = [
  446. 'website_id'=>$data['website_id']
  447. ];
  448. $result = WebsiteCategory::where($where)->orderBy('sort', 'asc')->get();
  449. if (empty($result)) {
  450. return Result::error("查询站点栏目失败", 0);
  451. } else {
  452. return Result::success($result);
  453. }
  454. }
  455. /**
  456. * 查询网站的广告
  457. * @param array $data
  458. * @return array
  459. */
  460. public function getWebsiteAdvertisement(array $data): array
  461. {
  462. $where = [
  463. 'website_id' => $data['website_id'],
  464. 'ad_place.status' => 1,
  465. // 'ad.status' => 1,
  466. ];
  467. if(isset($data['ad_tag']) && !empty($data['ad_tag'])){
  468. $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
  469. $where[] = ['ad_place.ad_tag','like','%'.$data['ad_tag'].'%'];
  470. $result = AdPlace::where($where)
  471. ->leftJoin("ad", function ($join) use ($now) {
  472. $join->on("ad.pid", "=", "ad_place.id")
  473. ->where('ad.status', 1)
  474. ->where('ad.fromtime', '<=', $now)
  475. ->where('ad.totime', '>=', $now);
  476. })
  477. ->select("ad_place.*",'ad.*',"ad_place.id as ad_place_id","ad.name as ad_name")
  478. ->get()->all();
  479. if(empty($result)){
  480. return Result::error("此广告位不存在!",0);
  481. }
  482. }else{
  483. return Result::error("请选择广告位!",0);
  484. }
  485. return Result::success($result);
  486. }
  487. /**
  488. *
  489. * @param array $data
  490. * @return array
  491. */
  492. /**网站行政职能搜索 */
  493. public function selectWebsiteDepartment(array $data): array
  494. {
  495. $depart = Department::where('pid', 0)->orderBy('id', 'asc')->limit(10)->get();
  496. if (isset($data['keyword']) && !empty($data['keyword'])) {
  497. $departments = Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  498. if (empty($departments)) {
  499. $result['message'] = "未查询到与此相关职能部门";
  500. } else {
  501. $count = Department::where('name', 'like', "%{$data['keyword']}%")->count();
  502. $m = [
  503. 'department' => $depart,
  504. 'type' => $departments,
  505. 'count' => $count,
  506. ];
  507. }
  508. $result['sele'] = $m;
  509. return Result::success($result['sele']);
  510. }
  511. $result = $depart;
  512. return Result::success($result);
  513. }
  514. /**
  515. * 搜索地区
  516. * @param array $data
  517. * @return array
  518. */
  519. public function selectWebsiteArea(array $data): array
  520. {
  521. $provinces = District::where('pid', 0)->where('status', 1)->get();
  522. if (isset($data['province'])) {
  523. $province = District::where('pid', 0)->where('status', 1)->where('id', $data['province'])->orderBy('id')->get();
  524. $province = $province->toArray();
  525. if (!empty($province)) {
  526. $citys = District::where('pid', $data['province'])->where('status', 1)->orderBy('id')->get();
  527. if (!empty($citys) && isset($data['city']) && !empty($data['city'])) {
  528. // $province = $province->toArray();
  529. $province_id = [];
  530. foreach ($province as $val) {
  531. array_push($province_id, $val['id']);
  532. }
  533. // var_dump($province_id);
  534. $city = District::whereIn('pid', $province_id)->where('status', 1)->where('id', $data['city'])->orderBy('id')->get();
  535. if (!empty($city)) {
  536. $city_id = [];
  537. foreach ($city as $val) {
  538. array_push($city_id, $val['id']);
  539. }
  540. $regions = District::whereIn('pid', $city_id)->where('status', 1)->orderBy('id')->get();
  541. $result = [
  542. 'province' => $province,
  543. 'city' => $city,
  544. 'region' => $regions,
  545. ];
  546. } else {
  547. return Result::error("未查询到此城市", 0);
  548. }
  549. } else {
  550. $result = [
  551. 'province' => $province,
  552. 'city' => $citys,
  553. 'region' => null,
  554. ];
  555. }
  556. } else {
  557. return Result::error("未查询到此省份", 0);
  558. }
  559. } else {
  560. // $keys = array('data');
  561. $result = $provinces;
  562. }
  563. return Result::success($result);
  564. }
  565. /**
  566. * 获取栏目
  567. * @param array $data
  568. * @return array
  569. */
  570. public function getWebsiteModelCategory(array $data): array
  571. {
  572. $website_id=[
  573. 'website_category.website_id' => $data['website_id']
  574. ];
  575. $placeid=$data['placeid']-1;
  576. $pid=[
  577. 'website_category.pid' => $data['pid'],
  578. ];
  579. var_dump( "=======",$pid);
  580. $num = $data['num'];
  581. // return Result::success($data);
  582. $result=WebsiteCategory::where($website_id)
  583. ->leftJoin("category",'website_category.category_id','category.id')
  584. ->select('website_category.*','category.is_url','category.web_url')
  585. ->where($pid)
  586. // ->with(['children' => function ($query) use ($data) {
  587. // $query->where('website_category.website_id', $data['website_id']);
  588. // }])
  589. ->orderBy('website_category.sort')
  590. ->offset($placeid)
  591. ->limit($num)
  592. ->get();
  593. foreach($result as $k=>$v){
  594. $child[$k]['children_countent']=WebsiteCategory::where($website_id)
  595. ->where('website_category.pid',$v['category_id'])
  596. ->count();
  597. if(!empty($child[$k]['children_countent'])){
  598. $result[$k]['children_count']=$child[$k]['children_countent'];
  599. }else{
  600. $result[$k]['children_count']=0;
  601. }
  602. }
  603. return Result::success($result);
  604. if(!empty($result)){
  605. return Result::success($result);
  606. }else{
  607. return Result::error("本网站暂无栏目",0);
  608. }
  609. }
  610. /**
  611. * 获取友情链接
  612. * @param array $data
  613. * @return array
  614. */
  615. public function selectWebsiteLinks(array $data): array
  616. {
  617. $where = [
  618. 'website_id' => $data['website_id'],
  619. 'status' => 1,
  620. 'type' => $data['type']
  621. ];
  622. $num=$data['num'];
  623. $result=Link::where($where)->orderBy('sort')->limit($num)->get();
  624. if(!empty($result)){
  625. return Result::success($result);
  626. }else{
  627. return Result::error("本网站暂无此类型友情链接",0);
  628. }
  629. }
  630. /**
  631. * 网站首页数据统计, 管理员
  632. * @return void
  633. */
  634. public function getAdminIndex(array $data): array
  635. {
  636. var_dump("用户类型:", $data['type_id']);
  637. switch ($data['type_id']) {
  638. case 4:
  639. $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;');
  640. return Result::success($result);
  641. break;
  642. case 10000:
  643. $res = [];
  644. //网站
  645. $res['website']['count'] = 0;
  646. $res['website']['growth_rate'] = 0;
  647. //资讯
  648. $res['article']['count'] = 0;
  649. $res['article']['growth_rate'] = 0;
  650. //导航池
  651. $res['category']['count'] = 0;
  652. $res['category']['growth_rate'] = 0;
  653. //近一月数据
  654. $res['monthArticle'] = [];
  655. //用户类型
  656. $res['userType'] = [];
  657. $res['website']['count'] = Website::where([])->count();
  658. $res['article']['count'] = Article::whereNotIn('status', ['404'])->count();
  659. $res['category']['count'] = Category::where([])->count();
  660. $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;');
  661. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  662. return Result::success($res);
  663. }
  664. return [];
  665. }
  666. /**
  667. * 获取模板类型
  668. * @return void
  669. */
  670. public function getTemplateClass(array $data): array
  671. {
  672. $where = [];
  673. if (isset($data['name']) && $data['name']) {
  674. array_push($where, ['name', 'like', '%' . $data['name'] . '%']);
  675. }
  676. $result = TemplateClass::where($where)->orderBy('sort', 'asc')->get();
  677. if (empty($result)) {
  678. return Result::error("没有模板类型", 0);
  679. } else {
  680. return Result::success($result);
  681. }
  682. }
  683. /**
  684. * 添加模板类型
  685. * @param
  686. * @return void
  687. */
  688. public function addTemplateClass(array $data): array
  689. {
  690. $insertData = [
  691. 'name' => $data['name'],
  692. ];
  693. $result = TemplateClass::insertGetId($insertData);
  694. if (empty($result)) {
  695. return Result::error("创建失败", 0);
  696. } else {
  697. return Result::success(["id" => $result]);
  698. }
  699. }
  700. /**
  701. * 更新模板
  702. * @param array $data
  703. * @return array
  704. */
  705. public function upTemplateClass(array $data): array
  706. {
  707. $where = [
  708. 'id' => $data['id'],
  709. ];
  710. $insertData = [
  711. 'name' => $data['name'],
  712. ];
  713. $result = TemplateClass::where($where)->update($insertData);
  714. if (empty($result)) {
  715. return Result::error("更新失败", 0);
  716. } else {
  717. return Result::success();
  718. }
  719. }
  720. /**
  721. * 删除模板
  722. * @param array $data
  723. * @return array
  724. */
  725. public function delTemplateClass(array $data): array
  726. {
  727. $where = [
  728. 'id' => $data['id'],
  729. ];
  730. $result = TemplateClass::where($where)->delete();
  731. if (empty($result)) {
  732. return Result::error("删除失败", 0);
  733. } else {
  734. return Result::success();
  735. }
  736. }
  737. /**
  738. * 获取分类下的模板
  739. * @param array $data
  740. * @return array
  741. */
  742. public function getTemplate(array $data): array
  743. {
  744. $page = $data['page'];
  745. $pageSize = $data['pageSize'];
  746. $where = [];
  747. if (isset($data['template_class_id']) && $data['template_class_id']) {
  748. array_push($where, ['template_class_id', '=', $data['template_class_id']]);
  749. }
  750. $result = Template::where($where)
  751. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  752. $count = Template::where($where)->count();
  753. if (empty($result)) {
  754. return Result::error("没有数据", 0);
  755. }
  756. $data = [
  757. 'rows' => $result->toArray(),
  758. 'count' => $count,
  759. ];
  760. return Result::success($data);
  761. }
  762. /**
  763. * 创建模板
  764. * @param
  765. * @return void
  766. */
  767. public function addTemplate(array $data): array
  768. {
  769. $insertData = [
  770. 'template_name' => $data['template_name'],
  771. 'template_img' => json_encode($data['template_img']),
  772. 'template_class_id' => $data['template_class_id'],
  773. ];
  774. $result = Template::insertGetId($insertData);
  775. if (empty($result)) {
  776. return Result::error("创建模板失败", 0);
  777. } else {
  778. return Result::success(["id" => $result]);
  779. }
  780. }
  781. /**
  782. * 更新模板
  783. * @param array $data
  784. * @return array
  785. */
  786. public function upTemplate(array $data): array
  787. {
  788. $where = [
  789. 'id' => $data['id'],
  790. ];
  791. $insertData = [
  792. 'template_name' => $data['template_name'],
  793. 'template_img' => json_encode($data['template_img']),
  794. 'template_class_id' => $data['template_class_id'],
  795. ];
  796. $result = Template::where($where)->update($insertData);
  797. if (empty($result)) {
  798. return Result::error("更新模板失败", 0);
  799. } else {
  800. return Result::success();
  801. }
  802. }
  803. /**
  804. * 删除模板
  805. * @param array $data
  806. * @return array
  807. */
  808. public function delTemplate(array $data): array
  809. {
  810. $where = [
  811. 'id' => $data['id'],
  812. ];
  813. $result = Template::where($where)->delete();
  814. if (empty($result)) {
  815. return Result::error("删除模板失败", 0);
  816. } else {
  817. return Result::success();
  818. }
  819. }
  820. /**
  821. * 搜索网站
  822. * @param array $data
  823. * @return array
  824. */
  825. public function websiteList(array $data): array
  826. {
  827. $where = [];
  828. if (isset($data['keyword']) && !empty($data['keyword'])) {
  829. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  830. }
  831. $result = Website::where($where)->get();
  832. if ($result) {
  833. return Result::success($result);
  834. } else {
  835. return Result::error("没有网站", 0);
  836. }
  837. }
  838. public function addWebsiteCategory(array $data): array
  839. {
  840. $website_id = $data['website_id'];
  841. $category_arr_id = $data['category_arr_id'];
  842. $categoryList = Category::whereIn('id', $category_arr_id)->get();
  843. $categoryListIds = [];
  844. if ($categoryList) {
  845. foreach ($categoryList->toArray() as $val) {
  846. array_push($categoryListIds, $val['id']);
  847. }
  848. }
  849. $arr = [];
  850. if ($categoryListIds) {
  851. foreach ($categoryListIds as $v) {
  852. $ids = $this->getUnderlingUIds(intval($v));
  853. $ids_arr = explode(",", $ids);
  854. array_push($arr, $ids_arr);
  855. }
  856. }
  857. $mergedArray = [];
  858. foreach ($arr as $subarray) {
  859. $mergedArray = array_merge($mergedArray, $subarray);
  860. }
  861. var_dump("所有:", $arr, $mergedArray);
  862. //查询出所有的分类进行分割插入 组装数据
  863. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  864. $categoryListData = $categoryListData->toArray();
  865. $insertData = [];
  866. if ($categoryListData) {
  867. foreach ($categoryListData as $key => $value) {
  868. $insertData[$key]['website_id'] = $website_id;
  869. $insertData[$key]['name'] = $value['name'];
  870. $insertData[$key]['sort'] = $value['sort'];
  871. $insertData[$key]['pid'] = $value['pid'];
  872. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  873. $insertData[$key]['seo_title'] = $value['seo_title'];
  874. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  875. $insertData[$key]['seo_description'] = $value['seo_description'];
  876. $insertData[$key]['alias'] = $value['name'];
  877. $insertData[$key]['category_id'] = $value['id'];
  878. }
  879. }
  880. $result = WebsiteCategory::insert($insertData);
  881. var_dump("插入数据状态:", $result);
  882. if ($result) {
  883. return Result::success($result);
  884. } else {
  885. return Result::error("创建失败", 0);
  886. }
  887. }
  888. /**
  889. * 删除网站导航
  890. * @param array $data
  891. * @return array
  892. */
  893. public function delWebsiteCategory(array $data): array
  894. {
  895. $website_id = $data['website_id'] ?? 0;
  896. $category_id = $data['category_id'] ?? 0;
  897. $ids = $this->getUnderlingUIds(intval($category_id));
  898. $ids_arr = explode(",", $ids);
  899. $result = WebsiteCategory::where(['website_id' => $website_id])->whereIn("category_id", $ids_arr)->delete();
  900. if ($result) {
  901. return Result::success($result);
  902. } else {
  903. return Result::error("删除失败", 0);
  904. }
  905. }
  906. /**
  907. * 获取网站导航
  908. * @param array $data
  909. * @return array
  910. */
  911. public function getAdminWebsiteCategory(array $data): array
  912. {
  913. $where = [
  914. 'website_id' => $data['website_id'],
  915. 'pid' => 0,
  916. ];
  917. $result = WebsiteCategory::where($where)->get();
  918. if ($result) {
  919. return Result::success($result);
  920. } else {
  921. return Result::error("查询失败", 0);
  922. }
  923. }
  924. /**
  925. * 更新网站导航
  926. * @param array $data
  927. * @return array
  928. */
  929. public function upWebsiteCategory(array $data): array
  930. {
  931. Db::beginTransaction();
  932. try {
  933. //合并栏目id
  934. $reqIds = array_merge($data['old_category_arr_id'], $data['new_category_arr_id']);
  935. //对比old 数组差异化,把差异化的删除
  936. $result = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])->get();
  937. $result = $result->toArray();
  938. $categoryIds = [];
  939. if ($result) {
  940. foreach ($result as $val) {
  941. array_push($categoryIds, $val['category_id']);
  942. }
  943. }
  944. //和原始数据对比取交际
  945. $reqidsIntersect = array_intersect($reqIds, $categoryIds);
  946. //再取差集 进行对比
  947. $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds), array_diff($categoryIds, $reqidsIntersect));
  948. var_dump("差集:", $differenceIDS);
  949. $arr_ids = [];
  950. if (count($differenceIDS) > 0) {
  951. foreach ($differenceIDS as $vv) {
  952. $idV = $this->getUnderlingUIds(intval($vv));
  953. $ids_arrV = explode(",", $idV);
  954. array_push($arr_ids, $ids_arrV);
  955. }
  956. }
  957. $del_ids = array_reduce($arr_ids, 'array_merge', array());
  958. //有差异 删除
  959. if (count($del_ids) > 0) {
  960. WebsiteCategory::where(['website_id' => $data['website_id']])->whereIn("category_id", $del_ids)->delete();
  961. }
  962. //传过来的值 和 交际 对比,选出要添加的值 进行插入
  963. $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect), array_diff($reqidsIntersect, $reqIds));
  964. var_dump("要存储的:", $insertIDS);
  965. //新的数组重新创建
  966. if (count($insertIDS) > 0) {
  967. $arr = [];
  968. $categoryListIds = $insertIDS;
  969. if ($categoryListIds) {
  970. foreach ($categoryListIds as $v) {
  971. $ids = $this->getUnderlingUIds(intval($v));
  972. $ids_arr = explode(",", $ids);
  973. array_push($arr, $ids_arr);
  974. }
  975. }
  976. $mergedArray = [];
  977. foreach ($arr as $subarray) {
  978. $mergedArray = array_merge($mergedArray, $subarray);
  979. }
  980. var_dump("要插入的ID:", $mergedArray);
  981. //查询出所有的分类进行分割插入 组装数据
  982. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  983. $categoryListData = $categoryListData->toArray();
  984. $insertData = [];
  985. if ($categoryListData) {
  986. foreach ($categoryListData as $key => $value) {
  987. $insertData[$key]['website_id'] = $data['website_id'];
  988. $insertData[$key]['name'] = $value['name'];
  989. $insertData[$key]['sort'] = $value['sort'];
  990. $insertData[$key]['pid'] = $value['pid'];
  991. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  992. $insertData[$key]['seo_title'] = $value['seo_title'];
  993. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  994. $insertData[$key]['seo_description'] = $value['seo_description'];
  995. $insertData[$key]['alias'] = $value['name'];
  996. $insertData[$key]['category_id'] = $value['id'];
  997. }
  998. }
  999. WebsiteCategory::insert($insertData);
  1000. }
  1001. Db::commit();
  1002. } catch (\Throwable $ex) {
  1003. Db::rollBack();
  1004. var_dump($ex->getMessage());
  1005. return Result::error("修改失败", 0);
  1006. }
  1007. return Result::success();
  1008. }
  1009. /**
  1010. * 获取网站列表
  1011. * @param array $data
  1012. * @return array
  1013. */
  1014. public function getWebsiteCategoryList(array $data): array
  1015. {
  1016. $where = [];
  1017. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1018. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  1019. }
  1020. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  1021. array_push($where, ['website.website_column_id', '=', $data['website_column_id']]);
  1022. }
  1023. $result = Website::where($where)
  1024. ->with(["websiteCategory" => function ($query) {
  1025. $query->where(['pid' => 0])->select('website_id', 'name', 'alias', 'category_id');
  1026. }])
  1027. ->limit($data['pageSize'])->orderBy("updated_at", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1028. ->get();
  1029. $count = Website::where($where)->count();
  1030. if (empty($result)) {
  1031. return Result::error("没有数据", 0);
  1032. }
  1033. $data = [
  1034. 'rows' => $result->toArray(),
  1035. 'count' => $count,
  1036. ];
  1037. if ($result) {
  1038. return Result::success($data);
  1039. } else {
  1040. return Result::error("查询失败", 0);
  1041. }
  1042. }
  1043. /**
  1044. * 删除网站下的所有导航
  1045. * @param array $data
  1046. * @return array
  1047. */
  1048. public function delWebsiteAllCategory(array $data): array
  1049. {
  1050. $website_id = $data['website_id'];
  1051. $result = WebsiteCategory::where(['website_id' => $website_id])->delete();
  1052. if ($result) {
  1053. return Result::success($result);
  1054. } else {
  1055. return Result::error("删除失败", 0);
  1056. }
  1057. }
  1058. /**
  1059. * 获取网站下的某一个导航
  1060. * @param array $data
  1061. * @return array
  1062. */
  1063. public function getWebsiteCategoryOnes(array $data): array
  1064. {
  1065. $website_id = $data['website_id'];
  1066. $category_id = $data['category_id'];
  1067. $result = WebsiteCategory::where(['website_category.website_id' => $website_id, 'website_category.category_id' => $category_id])
  1068. ->first();
  1069. if ($result) {
  1070. return Result::success($result);
  1071. } else {
  1072. return Result::error("查询失败", 0);
  1073. }
  1074. }
  1075. /**
  1076. * 更新网闸下的某一个导航
  1077. * @param array $data
  1078. * @return array
  1079. */
  1080. public function upWebsiteCategoryones(array $data): array
  1081. {
  1082. $where = [
  1083. 'website_id' => $data['website_id'],
  1084. 'category_id' => $data['category_id'],
  1085. ];
  1086. $data['sort'] = $data['sort']??0;
  1087. $result = WebsiteCategory::where($where)->update($data);
  1088. if ($result) {
  1089. return Result::success($result);
  1090. } else {
  1091. return Result::error("更新失败", 0);
  1092. }
  1093. }
  1094. /**
  1095. * 获取网站下的所有导航(包含子导航)
  1096. * @param array $data
  1097. * @return array
  1098. */
  1099. public function getWebsiteAllCategory(array $data): array
  1100. {
  1101. $where = [];
  1102. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1103. array_push($where, ['website_category.website_id', '=', $data['website_id']]);
  1104. }
  1105. if (isset($data['name']) && !empty($data['name'])) {
  1106. array_push($where, ['website_category.name', 'like', '%' . $data['name'] . '%']);
  1107. }
  1108. if (isset($data['alias']) && !empty($data['alias'])) {
  1109. array_push($where, ['website_category.alias', 'like', '%' . $data['alias'] . '%']);
  1110. }
  1111. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1112. array_push($where, ['category.department_id', '=', $data['department_id']]);
  1113. }
  1114. if (isset($data['city_id']) && !empty($data['city_id'])) {
  1115. array_push($where, ['category.city_id', '=', $data['city_id']]);
  1116. }
  1117. $result = WebsiteCategory::where($where)
  1118. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1119. ->leftJoin("department", 'category.department_id', 'department.id')
  1120. ->leftJoin("district", 'category.city_id', 'district.id')
  1121. ->select("website_category.*", "department.name as department_name", "district.name as city_name")
  1122. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1123. ->get();
  1124. $count = WebsiteCategory::where($where)
  1125. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1126. ->leftJoin("department", 'category.department_id', 'department.id')
  1127. ->leftJoin("district", 'category.city_id', 'district.id')
  1128. ->count();
  1129. if (empty($result)) {
  1130. return Result::error("没有数据", 0);
  1131. }
  1132. $data = [
  1133. 'rows' => $result->toArray(),
  1134. 'count' => $count,
  1135. ];
  1136. if ($result) {
  1137. return Result::success($data);
  1138. } else {
  1139. return Result::error("查询失败", 0);
  1140. }
  1141. if ($result) {
  1142. return Result::success($result);
  1143. } else {
  1144. return Result::error("查询失败", 0);
  1145. }
  1146. }
  1147. /**
  1148. * 递归查询数据
  1149. * @param $id
  1150. * @param $ids
  1151. * @return string
  1152. */
  1153. public function getUnderlingUIds($id, $ids = '')
  1154. {
  1155. $back = Category::where(['pid' => $id])->get();
  1156. $back = $back->toArray();
  1157. if (!empty($back) && is_array($back)) {
  1158. foreach ($back as $v) {
  1159. //防止当前人的ID重复去查询,形成恶性循环
  1160. if ($v['id'] == $id) {
  1161. continue;
  1162. }
  1163. $back2 = Category::where(['pid' => $id])->count('id');
  1164. if ($back2 > 0) {
  1165. $ids = $this->getUnderlingUIds($v['id'], $ids);
  1166. } else {
  1167. $ids .= ',' . $v['id'];
  1168. }
  1169. }
  1170. }
  1171. $ids = $id . ',' . $ids . ',';
  1172. $ids = str_replace(',,', ",", $ids);
  1173. $ids = trim($ids, ',');
  1174. return $ids;
  1175. }
  1176. /**
  1177. * 检测网站名称是否重复
  1178. * @param array $data
  1179. * @return array
  1180. */
  1181. public function checkWebsiteName(array $data): array
  1182. {
  1183. if (isset($data['id'])) {
  1184. $data[] = ['id', "!=", $data['id']];
  1185. unset($data['id']);
  1186. }
  1187. $websiteInfo = Website::query()->where($data)->first();
  1188. if (empty($websiteInfo)) {
  1189. return Result::error("找不到网站", 0);
  1190. }
  1191. return Result::success($websiteInfo->toArray());
  1192. }
  1193. /**
  1194. * 检测网站url是否重复
  1195. * @param array $data
  1196. * @return array
  1197. */
  1198. public function checkWebsiteUrl(array $data): array
  1199. {
  1200. $whereData = [];
  1201. if (isset($data['id'])) {
  1202. $whereData = [['id', "!=", $data['id']]];
  1203. unset($data['id']);
  1204. }
  1205. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1206. if (empty($websiteInfo)) {
  1207. return Result::error("找不到URL", 0);
  1208. }
  1209. return Result::success($websiteInfo->toArray());
  1210. }
  1211. // 自助建站--fr-------------------
  1212. /**
  1213. * 获取网站底部基础信息
  1214. * @param array $data
  1215. * @return array
  1216. */
  1217. public function getWebsiteFootInfo(array $data): array
  1218. {
  1219. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1220. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1221. if (empty($website)) {
  1222. return Result::error("找不到网站", 0);
  1223. }
  1224. } else {
  1225. return Result::error("参数错误", 0);
  1226. }
  1227. $website_foot = WebsiteTemplateInfo::where('website_id', $data['website_id'])->where('status', 2)->first();
  1228. $website_head = Website::where('id', $data['website_id'])
  1229. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description')->first();
  1230. if (empty($website_foot)) {
  1231. return Result::error("暂无底部基础信息", 0);
  1232. }
  1233. if (empty($website_head)) {
  1234. return Result::error("暂无头部基础信息", 0);
  1235. }
  1236. $result = [
  1237. 'website_foot' => $website_foot,
  1238. 'website_head' => $website_head,
  1239. ];
  1240. return Result::success($result);
  1241. }
  1242. /**
  1243. * 获取网站底部导航
  1244. * @param array $data
  1245. * @return array
  1246. */
  1247. public function getWebsiteFooterCategory(array $data): array
  1248. {
  1249. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1250. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1251. if (empty($website)) {
  1252. return Result::error("找不到网站", 0);
  1253. }
  1254. } else {
  1255. return Result::error("参数错误", 0);
  1256. }
  1257. $result = FooterCategory::where('website_id', $data['website_id'])->get();
  1258. if (empty($result)) {
  1259. return Result::error("暂无底部导航", 0);
  1260. }
  1261. return Result::success($result->toArray());
  1262. }
  1263. /**
  1264. * 获取网站底部导航列表
  1265. * @param array $data
  1266. * @return array
  1267. */
  1268. public function getWebsiteFooterCategoryList(array $data): array
  1269. {
  1270. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1271. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1272. if (empty($website)) {
  1273. return Result::error("找不到网站", 0);
  1274. }
  1275. } else {
  1276. return Result::error("参数错误", 0);
  1277. }
  1278. $footercategory = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1279. // '底部导航类型 0:内容型;1:列表型;',
  1280. if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
  1281. return Result::error("底部导航id错误", 0);
  1282. } else {
  1283. $query = FooterContent::where('fcat_id', $data['fcat_id']);
  1284. if ($query->count() == 0) {
  1285. return Result::error("暂无底部导航列表", 0);
  1286. } elseif ($query->count() == 1) {
  1287. $result = $query->first();
  1288. } else {
  1289. $result = $query->get();
  1290. }
  1291. }
  1292. return Result::success($result);
  1293. }
  1294. /**
  1295. * 获取网站底部导航
  1296. * @param array $data
  1297. * @return array
  1298. */
  1299. public function getWebsiteFooterCategoryInfo(array $data): array
  1300. {
  1301. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1302. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1303. if (empty($website)) {
  1304. return Result::error("找不到网站", 0);
  1305. }
  1306. } else {
  1307. return Result::error("参数错误", 0);
  1308. }
  1309. if (isset($data['type']) && $data['type'] == 0) {
  1310. $fcatid = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1311. if (empty($fcatid)) {
  1312. return Result::error("底部导航id错误", 0);
  1313. }
  1314. $result = FooterContent::where('fcat_id', $data['fcat_id'])->first();
  1315. } else {
  1316. $result = FooterContent::where('id', $data['fcat_id'])->first();
  1317. }
  1318. if (empty($result)) {
  1319. return Result::error("暂无底部导航内容", 0);
  1320. }
  1321. return Result::success($result);
  1322. }
  1323. /*
  1324. * 搜索网站二级导航
  1325. * @param array $data
  1326. * @return array
  1327. * */
  1328. public function selectWebsiteCategory(array $data): array
  1329. {
  1330. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1331. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1332. if (empty($website)) {
  1333. return Result::error("暂无该网站", 0);
  1334. }
  1335. $category = WebsiteCategory::where('website_id',$data['website_id'])->pluck('category_id')->all();
  1336. // return Result::success($category);
  1337. if (empty($category)) {
  1338. return Result::error("暂无此导航",0);
  1339. }
  1340. $query = Category::whereIn('id', $category);
  1341. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1342. $cityid = District::where('id', $data['cityid'])->first();
  1343. if (empty($cityid)) {
  1344. return Result::error("暂无此城市", 0);
  1345. } else {
  1346. $city_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->pluck('id');
  1347. // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
  1348. if (empty($city_category)) {
  1349. return Result::error("暂无此城市下的导航", 0);
  1350. }
  1351. $result['catid'] = $city_category;
  1352. $city = 1;
  1353. // var_dump("城市====================",$result);
  1354. }
  1355. }
  1356. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1357. $departmentid = Department::where('id', $data['department_id'])->first();
  1358. if (empty($departmentid)) {
  1359. return Result::error("暂无此部门", 0);
  1360. } else {
  1361. $depart_category = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1362. if (empty($depart_category)) {
  1363. return Result::error("暂无此部门下的导航", 0);
  1364. }
  1365. $result['catid'] = $depart_category;
  1366. // var_dump("职能部门*******************",$result);
  1367. $department = 1;
  1368. }
  1369. }
  1370. if(!empty($city) && !empty($department)){
  1371. // var_dump("城市和职能部门----------------------",$result);
  1372. $sel_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1373. if (empty($sel_category)) {
  1374. return Result::error("暂无此城市和职能部门下的导航", 0);
  1375. }
  1376. $result['catid'] = $sel_category;
  1377. }
  1378. if (empty($result)) {
  1379. return Result::error("暂无导航",0);
  1380. }
  1381. // department_id
  1382. } else {
  1383. return Result::error("参数错误", 0);
  1384. }
  1385. return Result::success($result);
  1386. }
  1387. /**
  1388. * 获取网站栏目seo
  1389. * @param array $data
  1390. * @return array
  1391. */
  1392. public function getWebsiteCategoryHead(array $data): array
  1393. {
  1394. $where = [];
  1395. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1396. array_push($where, ['website_id', '=', $data['website_id']]);
  1397. }
  1398. if (isset($data['catid']) && !empty($data['catid'])) {
  1399. $fcatid = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->first();
  1400. if (empty($fcatid)) {
  1401. return Result::error("导航id错误", 0);
  1402. }
  1403. $result = Category::where('id', $data['catid'])->first();
  1404. }
  1405. if (empty($result)) {
  1406. return Result::error("暂无导航", 0);
  1407. }
  1408. return Result::success($result);
  1409. }
  1410. /*
  1411. * 获取某个栏目
  1412. * @param array $data
  1413. * @return array
  1414. * */
  1415. public function getOneWebsiteCategory(array $data): array
  1416. {
  1417. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1418. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1419. if (empty($website)) {
  1420. return Result::error("暂无该网站", 0);
  1421. }
  1422. $result = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['category_id'])->select('category_id', 'name')->first();
  1423. // return Result::success($category);
  1424. if (empty($result)) {
  1425. return Result::error("暂无此导航", 0);
  1426. }
  1427. // department_id
  1428. } else {
  1429. return Result::error("参数错误", 0);
  1430. }
  1431. return Result::success($result);
  1432. }
  1433. //20250212 网站标识
  1434. public function addWebsiteGroup(array $data): array
  1435. {
  1436. //判斷name是不是重复
  1437. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  1438. if (!empty($websiteGroupInfo)) {
  1439. return Result::error("网站标识重复", 0);
  1440. }
  1441. //添加信息
  1442. $result = WebsiteGroup::insertGetId($data);
  1443. var_dump($result);
  1444. if (empty($result)) {
  1445. return Result::error("创建失败", 0);
  1446. } else {
  1447. return Result::success($result);
  1448. }
  1449. }
  1450. public function getWebsiteGroupList(array $data): array
  1451. {
  1452. $where = [];
  1453. if (isset($data['name']) && !empty($data['name'])) {
  1454. array_push($where, ['website_group.name', 'like', '%' . $data['name'] . '%']);
  1455. }
  1456. $result = WebsiteGroup::where($where)
  1457. ->limit($data['pageSize'])->orderBy("id", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1458. ->get();
  1459. foreach ($result as $websiteGroup) {
  1460. $webIds = json_decode($websiteGroup->web_ids, true);
  1461. $websites = Website::whereIn('id', $webIds)->get();
  1462. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  1463. $websiteGroup->website_names = $websiteNames;
  1464. $websiteGroup->website_names1 = implode(',', array_values($websiteNames));
  1465. }
  1466. $count = WebsiteGroup::where($where)->count();
  1467. if (empty($result)) {
  1468. return Result::error("没有数据", 0);
  1469. }
  1470. return Result::success(['list' => $result->toArray(), 'count' => $count]);
  1471. }
  1472. public function getWebsiteGroupInfo(array $data): array
  1473. {
  1474. $websiteInfo = WebsiteGroup::query()->where('id', $data['id'])->first();
  1475. $webIds = json_decode($websiteInfo->web_ids, true);
  1476. $websites = Website::whereIn('id', $webIds)->get();
  1477. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  1478. $websiteInfo->website_names = $websiteNames;
  1479. $websiteInfo->website_names1 = implode(',', array_values($websiteNames));
  1480. if (empty($websiteInfo)) {
  1481. return Result::error("找不到URL", 0);
  1482. }
  1483. return Result::success($websiteInfo->toArray());
  1484. }
  1485. public function updateWebsiteGroup(array $data): array
  1486. {
  1487. $where = [
  1488. 'id' => $data['id'],
  1489. ];
  1490. $insertData = [
  1491. 'name' => $data['name'],
  1492. 'web_ids' => $data['web_ids'],
  1493. ];
  1494. //判斷name是不是重复
  1495. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  1496. if (!empty($websiteGroupInfo)) {
  1497. return Result::error("网站标识重复", 0);
  1498. }
  1499. $result = WebsiteGroup::where($where)->update($insertData);
  1500. var_dump($result, '------更新');
  1501. if (empty($result)) {
  1502. return Result::error("更新失败", 0);
  1503. } else {
  1504. return Result::success();
  1505. }
  1506. }
  1507. public function deleteWebsiteGroup(array $data): array
  1508. {
  1509. $where = [
  1510. 'id' => $data['id'],
  1511. ];
  1512. //看看user表是不是有这个id
  1513. $userGroup = User::query()->where('sszq', $data['id'])->first();
  1514. if (!empty($userGroup)) {
  1515. return Result::error("有用户在使用该网站标识,不能删除", 0);
  1516. }
  1517. $result = WebsiteGroup::where($where)->delete();
  1518. if (empty($result)) {
  1519. return Result::error("删除失败", 0);
  1520. } else {
  1521. return Result::success();
  1522. }
  1523. }
  1524. public function getWebsiteNavList(array $data): array
  1525. {
  1526. $where = [];
  1527. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1528. array_push($where, ['website_id', '=', $data['website_id']]);
  1529. }
  1530. if (isset($data['pid'])) {
  1531. array_push($where, ['pid', '=', $data['pid']]);
  1532. }
  1533. $list = WebsiteCategory::query()->where($where)->get();
  1534. if (empty($list)) {
  1535. return Result::error("获取失败", 0);
  1536. } else {
  1537. return Result::success($list);
  1538. }
  1539. }
  1540. //20250212 网站标识
  1541. // 自助建站--fr-------------------
  1542. /**
  1543. * 获取并搜索 网站模板信息
  1544. * @param array $data
  1545. * @return array
  1546. */
  1547. public function getWebsiteintel(array $data): array
  1548. {
  1549. //查询所有网站模板信息
  1550. $query = Website::where('website.status', 1)
  1551. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  1552. ->leftJoin("template", "template.id", "website_template_info.template_id")
  1553. ->leftJoin("template_class", "template_class.id", "template.template_class_id")
  1554. ->select(
  1555. "website_template_info.id",
  1556. "template_class.name",
  1557. "website.id as website_id",
  1558. "website.website_name",
  1559. "website.website_url",
  1560. "website_template_info.action_id",
  1561. "website_template_info.created_at",
  1562. "website_template_info.updated_at",
  1563. "website_template_info.page_type",
  1564. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  1565. "template.template_name"
  1566. );
  1567. //若存在条件;则在$query的基础上进行筛选
  1568. if(isset($data['website_name']) && !empty($data['website_name'])){
  1569. $query->where('website.website_name', 'like', '%' . $data['website_name'] . '%');
  1570. }
  1571. if(isset($data['status']) && !empty($data['status'])){
  1572. $query->where('website_template_info.status', $data['status']);
  1573. }
  1574. $count = $query->count();
  1575. $query->limit($data['pageSize'])
  1576. ->offset(($data['page'] - 1) * $data['pageSize'])
  1577. ->orderBy("website_template_info.updated_at", "desc");
  1578. $rep = $query->get();
  1579. if($rep->count()==0){
  1580. return Result::error("没有查找到相关数据",0);
  1581. } else {
  1582. $rep->each(function ($item) {
  1583. if (!empty($item->page_type)) {
  1584. $pageTypeArray = json_decode($item->page_type, true);
  1585. if (is_array($pageTypeArray)) {
  1586. $item->page_type = $pageTypeArray;
  1587. }
  1588. }
  1589. });
  1590. $result = [
  1591. "rows" => $rep->toArray(),
  1592. "count" => $count
  1593. ];
  1594. return Result::success($result);
  1595. }
  1596. // return Result::success($result);
  1597. }
  1598. /**
  1599. * 添加网站基础信息
  1600. * @param array $data
  1601. * @return array
  1602. */
  1603. public function addWebsiteTemplateintel(array $data): array
  1604. {
  1605. // var_dump("接收参数:",$data['webSiteData']['base']);
  1606. Db::beginTransaction();
  1607. try{
  1608. $websiteTemplateInfo = WebsiteTemplate::where(['website_id'=>$data['webSiteData']['base']['websiteId']])->first();
  1609. // var_dump($websiteTemplateInfo);
  1610. //原始数据
  1611. $templateList = $data['webSiteData']['template'];
  1612. if($websiteTemplateInfo){
  1613. //模板存在-更新广告
  1614. }else{
  1615. //创建广告
  1616. $adList = $this->getAdlist($templateList);
  1617. if(!empty($adList)){
  1618. AdPlace::insert($adList);
  1619. }
  1620. }
  1621. // $result = WebsiteTemplate::updateOrInsert(['website_id'=>$data['webSiteData']['base']['websiteId']],['template_data'=>json_encode($data['webSiteData']),'updated_at'=>date("Y-m-d H:i:s",time())]);
  1622. Db::commit();
  1623. } catch(\Throwable $ex){
  1624. Db::rollBack();
  1625. var_dump($ex->getMessage());
  1626. return Result::error("创建失败",0);
  1627. $website = Website::where('website.id',$data['website_id'])->first();
  1628. if(empty($website)){
  1629. return Result::error("请输入正确的网站id!", 0);
  1630. }
  1631. if(empty($website['website_column_id'])){
  1632. return Result::error("请先关联导航池!", 0);
  1633. }
  1634. // 获取此网站的底部导航 类型 type: 0:内容型底部导航(只有一条详情内容);1:列表型底部导航(可以有多条详情内容)
  1635. $foot_type = FooterCategory::where('website_id',$data['website_id'])->pluck('type')->toArray();
  1636. if (empty($foot_type)) {
  1637. return Result::error("请先关联底部导航池!", 0);
  1638. } elseif (in_array(1, $foot_type)) {
  1639. $foot_type = 1;
  1640. } else {
  1641. $foot_type = 0;
  1642. }
  1643. $result['foot_type'] = $foot_type;
  1644. // 友情链接类型'1:图片 2:文字 3:底部';
  1645. $types = Link::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1646. $missingTypes = [];
  1647. if (!in_array(1, $types)) {
  1648. $missingTypes[] = "文字链接";
  1649. }
  1650. if (!in_array(2, $types)) {
  1651. $missingTypes[] = "图片链接";
  1652. }
  1653. if (!in_array(3, $types)) {
  1654. $missingTypes[] = "底部链接";
  1655. }
  1656. if (!empty($missingTypes)) {
  1657. $errorMessage = "请先添加 " . implode(" 和 ", $missingTypes) . "!";
  1658. return Result::error($errorMessage, 0);
  1659. }
  1660. if(isset($data['page_type'])){
  1661. // 删除重复元素并重新索引数组
  1662. $data['page_type'] = array_unique($data['page_type']);
  1663. $data['page_type'] = array_values($data['page_type']);
  1664. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1665. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1666. $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1667. if (empty($info)) {
  1668. // 将数组转换为 JSON 字符串
  1669. $data['page_type'] = json_encode($data['page_type'])??'';
  1670. // 操作状态:1:填写完成基础信息;2:选择完成模板;0:未构建
  1671. $data['action_id'] = 1;
  1672. try {
  1673. $result = WebsiteTemplateInfo::insertGetId($data);
  1674. } catch (\Exception $e) {
  1675. if ($e->getCode() == 22001) {
  1676. $errorMessage = $e->getMessage();
  1677. return Result::error("请检查表单,某个字段超出了长度限制!");
  1678. } else {
  1679. // 处理其他类型的数据库错误
  1680. return Result::error("插入操作失败: " . $e->getMessage());
  1681. }
  1682. return Result::error("添加失败!", 0);
  1683. }
  1684. } else {
  1685. return Result::error("该网站已经构建过了!", 0);
  1686. }
  1687. } else {
  1688. return Result::error("请先选择首页和底部导航详情页!", 0);
  1689. }
  1690. }
  1691. }
  1692. if(empty($result)){
  1693. return Result::error("添加失败!",0);
  1694. }else{
  1695. return Result::success($result);
  1696. }
  1697. return Result::success();
  1698. }
  1699. //获取传过来的广告列表
  1700. public function getAdlist($templateList)
  1701. {
  1702. if($templateList){
  1703. $adList = [];
  1704. foreach ($templateList as $val){
  1705. if($val){
  1706. foreach ($val as $v){
  1707. if($v['componentList']){
  1708. foreach ($v['componentList'] as $p){
  1709. if($p['component_type']==3){
  1710. // var_dump("ppppppppppppp:",$p);
  1711. $adSizeInfo = AdSize::where(['width'=>$p['componentData']['width'],'height'=>$p['componentData']['height']])->first();
  1712. $adSizeInfo = $adSizeInfo->toArray();
  1713. $adData = [
  1714. 'website_id'=> $data['webSiteData']['base']['websiteId'],
  1715. 'status'=>1,
  1716. 'name'=>$p['componentData']['text'],
  1717. 'ad_id'=>$p['componentData']['ad_id'],
  1718. 'ad_size_id'=>$adSizeInfo['id'],
  1719. ];
  1720. array_push($adList,$adData);
  1721. }
  1722. }
  1723. }
  1724. }
  1725. }
  1726. }
  1727. if(count($adList)>0){
  1728. return $adList;
  1729. }
  1730. }
  1731. }
  1732. /**
  1733. * 获取网站基础信息
  1734. *
  1735. * @return array
  1736. */
  1737. public function getWebsiteTemplateintel(array $data): array
  1738. {
  1739. $result = WebsiteTemplateInfo::where('website_template_info.website_id',$data['website_id'])
  1740. ->leftJoin('footer_category','footer_category.website_id','website_template_info.website_id')
  1741. ->leftJoin('website','website.id','website_template_info.website_id')
  1742. ->select(
  1743. "website_template_info.*",
  1744. "footer_category.type",
  1745. "website.website_name",
  1746. "website.id as website_id"
  1747. )
  1748. ->first();
  1749. if(empty($result['website_name'])){
  1750. return Result::error("请输入正确的网站id!", 0);
  1751. }
  1752. if($result){
  1753. $result['page_type'] = json_decode($result['page_type'],true);
  1754. return Result::success($result);
  1755. }else{
  1756. return Result::error("请先添加网站基础信息!",0);
  1757. }
  1758. }
  1759. /**
  1760. * 修改网站基础信息
  1761. *
  1762. * @return array
  1763. */
  1764. public function upWebsiteTemplateintel(array $data): array
  1765. {
  1766. $web = Website::where('website.id',$data['website_id'])->first();
  1767. if(empty($web)){
  1768. return Result::error("请输入正确的网站id!", 0);
  1769. }
  1770. $where = ['website_id'=>$data['website_id']];
  1771. $result = WebsiteTemplateInfo::where($where)->first();
  1772. if(empty($result)){
  1773. return Result::error("请先添加网站基础信息!",0);
  1774. }else{
  1775. unset($data['website_id']);
  1776. // 删除重复元素
  1777. $data['page_type'] = array_unique($data['page_type']);
  1778. // 重新索引数组
  1779. $data['page_type'] = array_values($data['page_type']);
  1780. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1781. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1782. // 将数组转换为 JSON 字符串
  1783. $data['page_type'] = json_encode($data['page_type'])??'';
  1784. try {
  1785. $result = WebsiteTemplateInfo::where($where)->update($data);
  1786. } catch (\Exception $e) {
  1787. if ($e->getCode() == 22001) {
  1788. $errorMessage = $e->getMessage();
  1789. return Result::error("请检查表单,某个字段超出了长度限制!");
  1790. } else {
  1791. // 处理其他类型的数据库错误
  1792. return Result::error("修改操作失败: " . $e->getMessage());
  1793. }
  1794. return Result::error("修改失败!", 0);
  1795. }
  1796. }else{
  1797. return Result::error("请先选择首页和底部导航详情页!",0);
  1798. }
  1799. }
  1800. if(empty($result)){
  1801. return Result::error("修改失败!",0);
  1802. }else{
  1803. return Result::success($result);
  1804. }
  1805. }
  1806. /**
  1807. * 获取所有网站风格信息
  1808. *
  1809. * @return array
  1810. */
  1811. public function getAllTemplateClass(array $data): array
  1812. {
  1813. $result = TemplateClass::all();
  1814. if(empty($result)){
  1815. return Result::error("没有查找到相关数据!",0);
  1816. }else{
  1817. return Result::success($result);
  1818. }
  1819. }
  1820. /**
  1821. * 搜索并获取网站模板信息
  1822. * @param array $data
  1823. * @return array
  1824. */
  1825. public function getWebsiteTemplateList(array $data): array
  1826. {
  1827. $website = Website::where('website.id',$data['website_id'])->first();
  1828. if(empty($website)){
  1829. return Result::error("请输入正确的网站id!",0);
  1830. }else{
  1831. $page_type = WebsiteTemplateInfo::where('website_id',$data['website_id'])->select('page_type')->first();
  1832. if(empty($page_type)){
  1833. return Result::error("此网站还未添加基础信息!",0);
  1834. } else{
  1835. $where = json_decode($page_type['page_type'], true);
  1836. // $where = $data["page_type"];
  1837. if(isset($data['template_class_id']) && !empty($data['template_class_id'])){
  1838. $template_class = TemplateClass::where('id',$data['template_class_id'])->first();
  1839. if(empty($template_class)){
  1840. return Result::error("请输入正确的模板风格id!",0);
  1841. }else{
  1842. // 获取指定风格下的模板
  1843. $rep = Template::where('template_class_id', $data['template_class_id'])
  1844. ->where(function ($query) use ($where) {
  1845. foreach ($where as $value) {
  1846. $query->whereJsonContains('template_img', ['value' => $value]);
  1847. }
  1848. })
  1849. ->limit($data['pageSize'])
  1850. ->offset(($data['page'] - 1) * $data['pageSize'])
  1851. ->orderBy("template.updated_at", "desc")
  1852. ->get();
  1853. $count = Template::where('template_class_id', $data['template_class_id'])
  1854. ->where(function ($query) use ($where) {
  1855. foreach ($where as $value) {
  1856. $query->whereJsonContains('template_img', ['value' => $value]);
  1857. }
  1858. })->count();
  1859. }
  1860. }else{
  1861. //获取所有模板
  1862. $rep = Template::where(function ($query) use ($where) {
  1863. foreach ($where as $value) {
  1864. $query->whereJsonContains('template_img', ['value' => $value]);
  1865. }
  1866. })
  1867. ->limit($data['pageSize'])
  1868. ->offset(($data['page'] - 1) * $data['pageSize'])
  1869. ->orderBy("template.updated_at", "desc")
  1870. ->get();
  1871. $count = Template::where(function ($query) use ($where) {
  1872. foreach ($where as $value) {
  1873. $query->whereJsonContains('template_img', ['value' => $value]);
  1874. }
  1875. })->count();
  1876. }
  1877. if(empty($rep) || $rep->count()==0){
  1878. return Result::error("没有查找到相关数据!",0);
  1879. }else{
  1880. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1881. // $rep->each(function ($item) use ($where) {
  1882. // $template_img = json_decode($item->template_img, true);
  1883. // if(is_array($template_img)){
  1884. // $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1885. // return isset($img['value']) && in_array($img['value'], $where);
  1886. // });
  1887. // }
  1888. // $item->template_img = $filtered_img;
  1889. // });
  1890. // $result = [
  1891. // "rows" => $rep->toArray(),
  1892. // "count" => $count
  1893. // ];
  1894. $rep->each(function ($item) use ($where) {
  1895. $template_img = json_decode($item->template_img, true);
  1896. if (is_array($template_img)) {
  1897. $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1898. return isset($img['value']) && in_array($img['value'], $where);
  1899. });
  1900. // 对过滤后的数组进行重新排序
  1901. $sorted_img = array_values($filtered_img);
  1902. $item->template_img = $sorted_img;
  1903. } else {
  1904. $item->template_img = []; // 如果无法解码为数组,则设置为空数组
  1905. }
  1906. });
  1907. $result = [
  1908. "rows" => $rep->toArray(),
  1909. "count" => $count
  1910. ];
  1911. }
  1912. }
  1913. }
  1914. return Result::success($result);
  1915. }
  1916. /**
  1917. * 添加网站模板
  1918. * @param array $data
  1919. */
  1920. public function addWebsiteTemplateclassintel(array $data): array
  1921. {
  1922. $template = Template::where('id',$data['template_id'])->first();
  1923. $web = Website::where('id',$data['website_id'])->first();
  1924. if(empty($template)){
  1925. return Result::error("请输入正确的模板id",0);
  1926. }
  1927. if(empty($web)){
  1928. return Result::error("请输入正确的网站id",0);
  1929. }
  1930. $result = WebsiteTemplateInfo::where('website_id',$data['website_id'])->update(['template_id'=>$data['template_id'],'action_id'=>2]);
  1931. if(empty($result)){
  1932. return Result::error("添加失败",0);
  1933. }else{
  1934. return Result::success($result);
  1935. }
  1936. }
  1937. /**
  1938. * 获取网站模板信息
  1939. * @param array $data
  1940. */
  1941. public function getWebsiteTemplateclassintel(array $data): array
  1942. {
  1943. // return Result::success($data);
  1944. $template = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
  1945. if(empty($template)){
  1946. return Result::error("请输入正确的搭建网站id",0);
  1947. }
  1948. $page_type = json_decode($template['page_type'], true);
  1949. // 获取指定网站下的基础信息和模板及风格信息
  1950. $result = WebsiteTemplateInfo::where([
  1951. ['website_template_info.website_id',$data['website_id']],
  1952. ['template_id','!=',null]
  1953. ])
  1954. ->leftJoin('template','template.id','website_template_info.template_id')
  1955. ->leftJoin('template_class','template_class.id','template.template_class_id')
  1956. ->where(function ($query) use ($page_type) {
  1957. // 假设 $data['page_type'] 是一个数组,包含需要匹配的 page_type 值
  1958. foreach ($page_type as $pageType) {
  1959. $query->orWhereJsonContains('template.template_img', ['value' => $pageType]);
  1960. }
  1961. })
  1962. ->select(
  1963. 'template.template_name',
  1964. 'template.template_img',
  1965. 'template.id as tid',
  1966. 'template_class.name',
  1967. 'template_class.id as class_id',
  1968. 'website_template_info.page_type',
  1969. 'website_template_info.website_id')
  1970. ->first();
  1971. if(empty($result)){
  1972. return Result::error("没有查找到相关数据",0);
  1973. }
  1974. // return Result::success($result);
  1975. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1976. $template_img = $result['template_img'] !== null ? json_decode($result['template_img'], true) : [];
  1977. $page_type = $result['page_type'] !== null ? json_decode($result['page_type'], true) : [];
  1978. foreach ($template_img as $key => $value) {
  1979. if (!in_array($value['value'], $page_type)) {
  1980. unset($template_img[$key]);
  1981. }
  1982. }
  1983. // return Result::success($result);
  1984. $result['template_img'] = array_values($template_img);
  1985. $result['page_type'] = $page_type;
  1986. // $templateList = $this->getWebsiteTemplateList($data);
  1987. // $count = $templateList['data']['count']??'';
  1988. // $pages = $count / $data['pageSize'];
  1989. // $found = false;
  1990. // while ($pages && !$found) {
  1991. // $templates = $this->getWebsiteTemplateList($pages,$data['pageSize']);
  1992. // $index = array_search($template['template_id'], array_column($templates['rows'], 'id'));
  1993. // if ($index !== false) {
  1994. // $found = true;
  1995. // $result['page'] = $pages;
  1996. // $pages = 0;
  1997. // // echo "查询到的 template 在第 $page 页";
  1998. // }
  1999. // $pages--;
  2000. // }
  2001. return Result::success($result);
  2002. }
  2003. /**
  2004. * 获取网站模板下的板块信息
  2005. * @param array $data
  2006. */
  2007. public function getWebsiteSectorList(array $data): array
  2008. {
  2009. $website = Website::where('id',$data['website_id'])->first();
  2010. if(empty($website)){
  2011. return Result::error("请输入正确的网站id",0);
  2012. }
  2013. $template = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
  2014. if(empty($template['template_id'])){
  2015. return Result::error("请先添加网站模板",0);
  2016. }
  2017. $query = Sector::where('template_id',$template['template_id']);
  2018. if($query->count() == 0){
  2019. return Result::error("没有查找到相关板块数据",0);
  2020. }elseif($query->count() == 1){
  2021. $sector = $query->first();
  2022. }else{
  2023. $sector = $query->get();
  2024. }
  2025. $result['page_type'] = $template['page_type'];
  2026. $result['tid'] = $template['template_id'];
  2027. $result = [
  2028. "tid" => $template['template_id'],
  2029. "page_type" => $template['page_type'],
  2030. "sector" => $sector
  2031. ];
  2032. return Result::success($result);
  2033. }
  2034. // 自助建站---------------fr---------------
  2035. // 自助建站------liu-------------
  2036. /**
  2037. * 风格下的板块
  2038. * @return void
  2039. */
  2040. public function templateSectorList(array $data): array
  2041. {
  2042. $where = [
  2043. 'template_id'=>$data['template_id']
  2044. ];
  2045. $result = Sector::where($where)->whereJsonContains("page_type",$data['page_type'])
  2046. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
  2047. ->get();
  2048. $count = Sector::where($where)->count();
  2049. if (empty($result)) {
  2050. return Result::error("没有数据",0);
  2051. }
  2052. $data = [
  2053. 'rows'=>$result->toArray(),
  2054. 'count'=>$count
  2055. ];
  2056. if (empty($result)) {
  2057. return Result::error("没有数据",0);
  2058. }
  2059. return Result::success($data);
  2060. }
  2061. /**
  2062. * 板块下的组件
  2063. * @param array $data
  2064. * @return array
  2065. */
  2066. public function sectorComponentList(array $data): array
  2067. {
  2068. $where = [
  2069. 'template_id'=>$data['template_id'],
  2070. 'sector_id'=>$data['sector_id'],
  2071. ];
  2072. $result = Component::where($where)
  2073. ->select("*")
  2074. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
  2075. ->get();
  2076. $count = Component::where($where)->count();
  2077. if (empty($result)) {
  2078. return Result::error("没有数据",0);
  2079. }
  2080. $data = [
  2081. 'rows'=>$result->toArray(),
  2082. 'count'=>$count
  2083. ];
  2084. if (empty($result)) {
  2085. return Result::error("没有数据",0);
  2086. }
  2087. return Result::success($data);
  2088. }
  2089. /**
  2090. * 获取模板内容
  2091. * @return void
  2092. */
  2093. public function getWebsiteTemplateInfo(array $data): array //丢了
  2094. {
  2095. $wehre = [
  2096. "website_id" =>$data['website_id']
  2097. ];
  2098. $result = WebsiteTemplate::where($wehre)->first();
  2099. if($result){
  2100. return Result::success($result);
  2101. }else{
  2102. return Result::error("没有数据",0);
  2103. }
  2104. }
  2105. /**
  2106. * 保存网站模板
  2107. * @param array $data
  2108. * @return array
  2109. */
  2110. public function addWebsiteTemplate(array $data): array
  2111. {
  2112. // var_dump("接收参数:",$data['webSiteData']['base']);
  2113. Db::beginTransaction();
  2114. try{
  2115. $websiteTemplateInfo = WebsiteTemplate::where(['website_id'=>$data['webSiteData']['base']['websiteId']])->first();
  2116. // var_dump($websiteTemplateInfo);
  2117. //原始数据
  2118. $templateList = $data['webSiteData']['template'];
  2119. if($websiteTemplateInfo){
  2120. //模板存在-更新广告
  2121. }else{
  2122. //创建广告
  2123. $adList = $this->getAdlist($templateList);
  2124. if(!empty($adList)){
  2125. AdPlace::insert($adList);
  2126. }
  2127. }
  2128. // $result = WebsiteTemplate::updateOrInsert(['website_id'=>$data['webSiteData']['base']['websiteId']],['template_data'=>json_encode($data['webSiteData']),'updated_at'=>date("Y-m-d H:i:s",time())]);
  2129. Db::commit();
  2130. } catch(\Throwable $ex){
  2131. Db::rollBack();
  2132. var_dump($ex->getMessage());
  2133. return Result::error("创建失败",0);
  2134. }
  2135. return Result::success();
  2136. }
  2137. /**
  2138. * 预览网站首页模板数据
  2139. * @param array $data
  2140. * @return array
  2141. */
  2142. public function getWebsiteTemplateData(array $data): array
  2143. {
  2144. $wehre = [
  2145. "website_id" =>$data['website_id']
  2146. ];
  2147. $result = WebsiteTemplate::where($wehre)->first();
  2148. if($result){
  2149. $templateData = json_decode($result['template_data'],true);
  2150. // var_dump("数据:",$templateData[1]);
  2151. $templateData[1] = $this->getNewsList($templateData[1]);
  2152. return Result::success($templateData);
  2153. }else{
  2154. return Result::error("没有数据",0);
  2155. }
  2156. }
  2157. /**
  2158. * 获取列表数据
  2159. * @return void
  2160. */
  2161. public function getNewsList(array $data): array
  2162. {
  2163. if($data){
  2164. foreach ($data as $key=>$val){
  2165. if($val){
  2166. foreach ($val['data'] as $k=>$item){
  2167. if($item['isReturn'] && intval($item['isReturn'])==1){
  2168. $imgList = [];
  2169. if($item['data']['imgNum'] && intval($item['data']['imgNum'])>0){
  2170. $imgList = Article::where('imgurl',"!=","")
  2171. ->where('catid',$item['data']['category_id'])
  2172. ->select($item['data']['selectField'])
  2173. ->orderBy("created_at","desc")
  2174. ->offset(0)
  2175. ->limit(intval($item['data']['imgNum']))
  2176. ->get();
  2177. $imgList = $imgList->toArray();
  2178. $listIds = [];
  2179. if ($imgList){
  2180. $listIds = array_column($imgList, 'id');
  2181. }
  2182. $dataList = Article::whereNotIn('id',$listIds)
  2183. ->where('catid',$item['data']['category_id'])
  2184. ->select($item['data']['selectField'])
  2185. ->orderBy("created_at","desc")
  2186. ->offset(0)
  2187. ->limit(intval($item['data']['pageSize'])-intval($item['data']['imgNum']))
  2188. ->get();
  2189. $dataList = $dataList->toArray();
  2190. var_dump("图片列表:",$imgList,"数据列表:",$dataList);
  2191. $datas = array_merge($imgList,$dataList);
  2192. // return $datas;
  2193. var_dump("合并列表:",$datas);
  2194. $data[$key]['data'][$k]['dataList'] = $datas;
  2195. }else{
  2196. $dataList = Article::where('catid',$item['data']['category_id'])
  2197. ->select($item['data']['selectField'])
  2198. ->orderBy("created_at","desc")
  2199. ->offset(0)
  2200. ->limit(intval($item['data']['pageSize']))
  2201. ->get();
  2202. $dataList = $dataList->toArray();
  2203. var_dump("数据列表:",$dataList);
  2204. }
  2205. }
  2206. }
  2207. }
  2208. }
  2209. }
  2210. return $data;
  2211. }
  2212. /**
  2213. * 获取底部导航列表
  2214. * @param array $data
  2215. * @return array
  2216. */
  2217. public function getFooterCategoryList(array $data): array
  2218. {
  2219. $where = [
  2220. "website_id"=>$data['website_id']
  2221. ];
  2222. $result = FooterCategory::where($where)->get();
  2223. if($result){
  2224. return Result::success($result);
  2225. }else{
  2226. return Result::error("没有数据");
  2227. }
  2228. }
  2229. //获取底部导航内容列表
  2230. public function getFooterContentList(array $data): array
  2231. {
  2232. $where = [
  2233. "fcat_id"=>$data['fcat_id'],
  2234. ];
  2235. switch (intval($data['type'])){
  2236. case 0:
  2237. $result = FooterContent::where($where)->first();
  2238. break;
  2239. case 1:
  2240. $result = FooterContent::where($where)->get();
  2241. break;
  2242. }
  2243. if($result){
  2244. return Result::success($result);
  2245. }else{
  2246. return Result::error("没有数据");
  2247. }
  2248. }
  2249. //获取底部导航内容详情
  2250. public function getFooterContentInfo(array $data): array
  2251. {
  2252. $where = [
  2253. "id"=>$data['content_id']
  2254. ];
  2255. $result = FooterContent::where($where)->first();
  2256. if($result){
  2257. return Result::success($result);
  2258. }else{
  2259. return Result::error("没有数据");
  2260. }
  2261. }
  2262. // 自传建站---------------liu------------
  2263. }