WebsiteService.php 104 KB

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