WebsiteService.php 104 KB

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