WebsiteService.php 127 KB

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