WebsiteService.php 113 KB

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