PublicRpcService.php 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\BlackWord;
  4. use App\Model\Department;
  5. use App\Model\District;
  6. use App\Model\LetterOfComplaint;
  7. use App\Model\LetterType;
  8. use App\Model\LevelUser;
  9. use App\Model\UserLevel;
  10. use App\Tools\Result;
  11. use Hyperf\DbConnection\Db;
  12. use Hyperf\Di\Annotation\Inject;
  13. use Hyperf\RpcServer\Annotation\RpcService;
  14. use App\Service\MinioService;
  15. use Hyperf\Redis\Redis;
  16. use Overtrue\ChineseCalendar\Calendar;
  17. use App\Model\TemplateClass;
  18. use App\Model\Template;
  19. use App\Model\WebsiteTemplate;
  20. use App\Model\WebsiteTemplateInfo;
  21. use App\Model\Sector;
  22. use App\Model\Component;
  23. use App\Model\Link;
  24. use App\Model\FooterCategory;
  25. use App\Model\Size;
  26. use App\Model\Website;
  27. use App\Model\SectorPlace;
  28. #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  29. class PublicRpcService implements PublicRpcServiceInterface
  30. {
  31. #[Inject]
  32. protected Redis $redis;
  33. /**
  34. * @param array $data
  35. * @return array
  36. */
  37. public function getDistrictList(array $data): array
  38. {
  39. $where = [];
  40. if (isset($data['keyWord'])) {
  41. $where = [
  42. ['name', 'like', '%' . $data['keyWord'] . '%']
  43. ];
  44. }
  45. $result = [];
  46. if (isset($data['pageSize'])) {
  47. $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("code", "asc")->get();
  48. $count = District::where($where)->count();
  49. $result = [
  50. 'rows' => $rep,
  51. 'count' => $count
  52. ];
  53. } else {
  54. $result = District::where($data)->orderBy("code", "asc")->get();
  55. }
  56. return $result ? Result::success($result) : Result::error("没有查到数据");
  57. }
  58. /**
  59. * @param array $data
  60. * @return array
  61. */
  62. public function getUserLevelList(array $data): array
  63. {
  64. $where = [];
  65. if (isset($data['keyWord'])) {
  66. $where = [
  67. ['name', 'like', '%' . $data['keyWord'] . '%'],
  68. ];
  69. }
  70. $result = [];
  71. if (isset($data['pageSize'])) {
  72. $rep = UserLevel::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("id", "asc")->get();
  73. $count = UserLevel::where($where)->count();
  74. $result = [
  75. 'rows' => $rep,
  76. 'count' => $count,
  77. ];
  78. } else {
  79. $result = UserLevel::orderBy("id", "asc")->get();
  80. }
  81. return $result ? Result::success($result) : Result::error("没有查到数据");
  82. }
  83. /**
  84. * 添加用户等级
  85. * @param array $data
  86. * @return array
  87. */
  88. public function addUserLevel(array $data): array
  89. {
  90. LevelUser::insertGetId($data);
  91. return Result::success([]);
  92. }
  93. /**
  94. * 更新等级
  95. * @param array $data
  96. * @return array
  97. */
  98. public function updateUserLevel(array $data): array
  99. {
  100. $result = LevelUser::where(['id' => $data['id']])->update($data);
  101. if ($result) {
  102. return Result::success($result);
  103. }
  104. return Result::error("更新失败");
  105. }
  106. /**
  107. * 删除等级
  108. * @param array $data
  109. * @return array
  110. */
  111. public function delUserLevel(array $data): array
  112. {
  113. $result = LevelUser::where(['id' => $data['id']])->delete();
  114. if ($result) {
  115. return Result::success($result);
  116. }
  117. return Result::error("删除失败");
  118. }
  119. /**
  120. * 查询投诉举报信息
  121. * @param array $data
  122. * @return array
  123. */
  124. public function getLetterOfComplaint(array $data = []): array
  125. {
  126. var_dump("====");
  127. $where = [];
  128. if (isset($data['user_id']) && !empty($data['user_id'])) {
  129. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  130. }
  131. if (isset($data['nature']) && !empty($data['nature'])) {
  132. array_push($where, ['letter_of_complaint.nature', '=', $data['nature']]);
  133. }
  134. if (isset($data['nature_level0']) && !empty($data['nature_level0'])) {
  135. array_push($where, ['letter_of_complaint.nature_level0', '=', $data['nature_level0']]);
  136. }
  137. if (isset($data['status']) && !empty($data['status'])) {
  138. array_push($where, ['letter_of_complaint.status', '=', $data['status']]);
  139. }
  140. $result = [];
  141. if (isset($data['pageSize'])) {
  142. $rep = LetterOfComplaint::where($where)
  143. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  144. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  145. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  146. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  147. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  148. ->select(
  149. "letter_of_complaint.*",
  150. "type_a.type_name as nature_name",
  151. "type_b.type_name as nature_name1",
  152. "type_c.type_name as nature_name0",
  153. "type_d.type_name as status_name",
  154. "type_e.type_name as nature_name3"
  155. )
  156. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("letter_of_complaint.id", "desc")->get();
  157. $count = LetterOfComplaint::where($where)->count();
  158. if ($rep) {
  159. foreach ($rep as $val) {
  160. if ($val['judgment']) {
  161. $val['judgment'] = json_decode($val['judgment']);
  162. }
  163. if ($val['audio_and_video']) {
  164. $val['audio_and_video'] = json_decode($val['audio_and_video']);
  165. }
  166. if ($val['contract']) {
  167. $val['contract'] = json_decode($val['contract']);
  168. }
  169. if ($val['qualifications']) {
  170. $val['qualifications'] = json_decode($val['qualifications']);
  171. }
  172. }
  173. }
  174. $result = [
  175. 'rows' => $rep,
  176. 'count' => $count,
  177. ];
  178. } else {
  179. $result = LetterOfComplaint::where($where)
  180. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  181. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  182. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  183. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  184. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  185. ->select(
  186. "letter_of_complaint.*",
  187. "type_a.type_name as nature_name",
  188. "type_b.type_name as nature_name1",
  189. "type_c.type_name as nature_name0",
  190. "type_d.type_name as status_name",
  191. "type_e.type_name as nature_name3"
  192. )
  193. ->orderBy("letter_of_complaint.id", "desc")->get();
  194. }
  195. return $result ? Result::success($result) : Result::error("没有查到数据");
  196. }
  197. /**
  198. * 添加投诉举报信息
  199. * @param array $data
  200. * @return array
  201. */
  202. public function addLetterOfComplaint(array $data): array
  203. {
  204. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  205. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  206. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  207. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  208. unset($data['id']);
  209. $result = LetterOfComplaint::insertGetId($data);
  210. if (empty($result)) {
  211. return Result::error("创建失败", 0);
  212. } else {
  213. return Result::success(["id" => $result]);
  214. }
  215. }
  216. /**
  217. * 用户端更新投诉举报
  218. * @param array $data
  219. * @return array
  220. */
  221. public function userUpLetterOfComplaint(array $data): array
  222. {
  223. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  224. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  225. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  226. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  227. $result = LetterOfComplaint::where(['id' => $data['id']])->update($data);
  228. if (empty($result)) {
  229. return Result::error("创建失败", 0);
  230. } else {
  231. return Result::success(["id" => $result]);
  232. }
  233. }
  234. /**
  235. * 管理后台更新投诉举报信息
  236. * @param array $data
  237. * @return array
  238. */
  239. public function upLetterOfComplaint(array $data): array
  240. {
  241. var_dump("admin:", $data);
  242. $where = [
  243. 'id' => $data['id'],
  244. ];
  245. $filtered_array = array_filter($data, function ($value) {
  246. return $value !== "" && $value !== null && $value !== false && !is_array($value) || !empty($value);
  247. });
  248. $filtered_array['judgment'] = isset($filtered_array['judgment']) ? json_encode($filtered_array['judgment']) : '';
  249. $filtered_array['audio_and_video'] = isset($filtered_array['audio_and_video']) ? json_encode($filtered_array['audio_and_video']) : '';
  250. $filtered_array['contract'] = isset($filtered_array['contract']) ? json_encode($filtered_array['contract']) : '';
  251. $filtered_array['qualifications'] = isset($filtered_array['qualifications']) ? json_encode($filtered_array['qualifications']) : '';
  252. unset($filtered_array['nature_name']);
  253. unset($filtered_array['type_name']);
  254. unset($filtered_array['nature_level_name']);
  255. unset($filtered_array['status_name']);
  256. unset($filtered_array['is_admin']);
  257. unset($filtered_array['type_level_name']);
  258. $result = LetterOfComplaint::where($where)->update($filtered_array);
  259. if ($result) {
  260. return Result::success($result);
  261. }
  262. return Result::error("更新失败", 0);
  263. }
  264. /**
  265. * 查询投诉举报记录
  266. * @param array $data
  267. * @return array
  268. */
  269. public function getLetterOfComplaintInfo(array $data): array
  270. {
  271. $where = [
  272. 'letter_of_complaint.id' => $data['id'],
  273. ];
  274. if (isset($data['user_id']) && !empty($data['user_id'])) {
  275. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  276. }
  277. $result = LetterOfComplaint::where($where)
  278. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  279. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  280. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  281. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  282. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  283. ->select(
  284. "letter_of_complaint.*",
  285. "type_a.type_name as nature_name",
  286. "type_b.type_name as nature_name1",
  287. "type_c.type_name as nature_name0",
  288. "type_d.type_name as status_name",
  289. "type_e.type_name as nature_name3"
  290. )
  291. ->first();
  292. return Result::success($result);
  293. }
  294. /**
  295. * 删除投诉举报信息
  296. * @param array $data
  297. * @return array
  298. */
  299. public function delLetterOfComplaint(array $data): array
  300. {
  301. $result = LetterOfComplaint::when($data, function ($query) use ($data) {
  302. if (isset($data['id']) && !empty($data['id'])) {
  303. $query->where(['id' => $data['id']]);
  304. }
  305. if (isset($data['user_id']) && !empty($data['user_id'])) {
  306. $query->where(['user_id' => $data['user_id']]);
  307. }
  308. })->delete();
  309. if (empty($result)) {
  310. return Result::error("删除失败", 0);
  311. } else {
  312. return Result::success();
  313. }
  314. }
  315. /**
  316. * 获取举报信息类型
  317. * @param array $data
  318. * @return array
  319. */
  320. public function getLetterType(array $data): array
  321. {
  322. $where = [];
  323. if (isset($data['type'])) {
  324. array_push($where, ['type', '=', $data['type']]);
  325. }
  326. if (isset($data['pid']) && $data['pid'] > 0) {
  327. array_push($where, ['pid', '=', $data['pid']]);
  328. }
  329. $result = LetterType::where($where)->orderBy('sort', 'asc')->get();
  330. return $result ? Result::success($result) : Result::error("没有查到数据");
  331. }
  332. /**
  333. * 更新举报类型
  334. * @param array $data
  335. * @return array
  336. */
  337. public function upLetterType(array $data): array
  338. {
  339. return [];
  340. }
  341. /**
  342. * 添加举报类型
  343. * @param array $data
  344. * @return array
  345. */
  346. public function addLetterType(array $data): array
  347. {
  348. $result = LetterType::insertGetId($data);
  349. if (empty($result)) {
  350. return Result::error("创建失败", 0);
  351. } else {
  352. return Result::success(["id" => $result]);
  353. }
  354. }
  355. /**
  356. * 删除举报类型
  357. * @param array $data
  358. * @return array
  359. */
  360. public function delLetterType(array $data): array
  361. {
  362. $result = LetterType::where('id', $data['id'])->delete();
  363. if (empty($result)) {
  364. return Result::error("删除失败", 0);
  365. } else {
  366. return Result::success();
  367. }
  368. }
  369. /**
  370. * 检测是否已经被接案
  371. * @param array $data
  372. * @return array
  373. */
  374. public function checkMeasure(array $data): array
  375. {
  376. $where = [
  377. 'id' => $data['id'],
  378. ];
  379. $letterOfComplaintInfo = LetterOfComplaint::where($where)->first();
  380. var_dump("查询数据:", $letterOfComplaintInfo['admin_id'], $data['user_id']);
  381. //操作人和当前登陆用户id 相等说明是当前人接收的案件
  382. if (($letterOfComplaintInfo['admin_id'] == $data['user_id']) || empty($letterOfComplaintInfo['admin_id'])) {
  383. return Result::success();
  384. } else {
  385. return Result::error("您不能处理其他人已经接过的案件", 0);
  386. }
  387. }
  388. /**
  389. * 后台获取职能部门
  390. * @param array $data
  391. * @return array
  392. */
  393. public function getZhinengbumenList(array $data): array
  394. {
  395. // 获取分页参数,默认每页 10 条记录
  396. $page = isset($data['page']) ? (int) $data['page'] : 1;
  397. $perPage = isset($data['pagesize']) ? (int) $data['pagesize'] : 10;
  398. // 查询数据并分页
  399. $query = Department::query();
  400. // 可以在这里添加更多的查询条件
  401. if (isset($data['search'])) {
  402. $query->where('name', 'like', '%' . $data['search'] . '%');
  403. }
  404. // 执行分页查询
  405. $result = $query->paginate($perPage, ['*'], 'page', $page);
  406. // 返回分页结果
  407. return Result::success([
  408. 'count' => $result->total(),
  409. 'current_page' => $result->currentPage(),
  410. 'last_page' => $result->lastPage(),
  411. 'pagesize' => $result->perPage(),
  412. 'rows' => $result->items(),
  413. ]);
  414. }
  415. /**
  416. * 添加获取职能部门
  417. * @param array $data
  418. * @return array
  419. */
  420. public function addZhinengbumen(array $data): array
  421. {
  422. $result = Department::insertGetId($data);
  423. if (empty($result)) {
  424. return Result::error("创建失败", 0);
  425. } else {
  426. return Result::success(["id" => $result]);
  427. }
  428. }
  429. public function delZhinengbumen(array $data): array
  430. {
  431. $result = Department::where('id', $data['id'])->delete();
  432. if (empty($result)) {
  433. return Result::error("删除失败", 0);
  434. } else {
  435. return Result::success();
  436. }
  437. }
  438. public function getZhinengbumen(array $data): array
  439. {
  440. $result = Department::where('id', $data['id'])->first();
  441. return Result::success($result);
  442. }
  443. public function getPidZhinengbumen(array $data): array
  444. {
  445. if (empty($data['pid'])) {
  446. $data['pid'] = 0;
  447. }
  448. $result = Department::where('pid', $data['pid'])->get();
  449. return Result::success($result);
  450. }
  451. public function modZhinengbumen(array $data): array
  452. {
  453. $result = Department::where('id', $data['id'])->update($data);
  454. if (empty($result)) {
  455. return Result::error("修改失败", 0);
  456. } else {
  457. return Result::success();
  458. }
  459. }
  460. /**
  461. * 查询职能列表
  462. * @param array $data
  463. * @return array
  464. */
  465. public function getDepartment(array $data): array
  466. {
  467. $where = [];
  468. if (isset($data['pid'])) {
  469. $where = [
  470. 'pid' => $data['pid'] ?? 0
  471. ];
  472. }
  473. $result = Department::when(!empty($where), function ($query) use ($where) {
  474. $query->where($where);
  475. })->orderBy("sort", "desc")->get();
  476. if (empty($result)) {
  477. return Result::error("查询失败", 0);
  478. } else {
  479. return Result::success($result);
  480. }
  481. }
  482. /**
  483. * 获取所有的buckets
  484. * @param array $data
  485. * @return array
  486. */
  487. public function getBuckets(array $data): array
  488. {
  489. $result = new MinioService();
  490. // 调用服务层的方法获取存储桶列表
  491. $bucketsResponse = $result->listBuckets();
  492. // 直接返回服务层生成的响应
  493. return Result::success($bucketsResponse['data']);
  494. }
  495. /**
  496. * 上传文件
  497. * @param array $data
  498. * @return array
  499. */
  500. public function uploadFile(array $data): array
  501. {
  502. $result = new MinioService();
  503. $rep = $result->uploadFile($data);
  504. if ($rep['code'] == 200) {
  505. return Result::success($rep['data']);
  506. } else {
  507. return Result::error("上传失败!");
  508. }
  509. }
  510. /**
  511. * 黑名单管理
  512. * @param array $data
  513. * @return array
  514. */
  515. public function getBlackWordList(array $data): array
  516. {
  517. $result = BlackWord::when($data, function ($query) use ($data) {
  518. if (isset($data['name']) && $data['name']) {
  519. $query->where('black_word.name', 'like', '%' . $data['name'] . '%');
  520. }
  521. })->orderBy('black_word.id', 'desc')
  522. ->paginate(
  523. intval($data['pageSize']),
  524. [
  525. 'black_word.*',
  526. ],
  527. 'page',
  528. intval($data['page'])
  529. );
  530. $count = $result->total();
  531. $returnData = [
  532. 'rows' => $result->items(),
  533. 'count' => $count
  534. ];
  535. return Result::success($returnData);
  536. }
  537. /**
  538. * 添加黑名单
  539. * @param array $data
  540. * @return array
  541. */
  542. public function addBlackWord(array $data): array
  543. {
  544. Db::beginTransaction();
  545. try {
  546. $info = BlackWord::where(['name' => $data['name']])->first();
  547. if ($info) {
  548. Db::rollBack();
  549. return Result::error("该黑名单已存在", 0);
  550. }
  551. $data['type'] = 10;
  552. $result = BlackWord::insertGetId($data);
  553. $redisKey = 'black_word';
  554. $this->redis->sAdd($redisKey, $data['name']);
  555. Db::commit();
  556. return Result::success(["id" => $result]);
  557. } catch (\Exception $e) {
  558. Db::rollBack();
  559. return Result::error("创建失败" . $e->getMessage(), 0);
  560. }
  561. }
  562. /**
  563. * 删除黑名单
  564. * @param array $data
  565. * @return array
  566. */
  567. public function delBlackWord(array $data): array
  568. {
  569. Db::beginTransaction();
  570. try {
  571. BlackWord::where(['name' => $data['name']])->delete();
  572. $redisKey = 'black_word';
  573. $this->redis->sRem($redisKey, $data['name']);
  574. Db::commit();
  575. return Result::success([]);
  576. } catch (\Exception $e) {
  577. Db::rollBack();
  578. return Result::error("删除失败" . $e->getMessage(), 0);
  579. }
  580. }
  581. /**
  582. * 修改违禁词
  583. * @param array $data
  584. * @return array
  585. */
  586. public function upBlackWord(array $data): array
  587. {
  588. Db::beginTransaction();
  589. try {
  590. $checkInfo = BlackWord::where(['name' => $data['name']])->first();
  591. if ($checkInfo) {
  592. Db::rollBack();
  593. return Result::error("该违禁词已经存在", 0);
  594. }
  595. $blackWordInfo = BlackWord::where(['id' => $data['id']])->first();
  596. if ($blackWordInfo) {
  597. //先删除redis
  598. $blackWordInfo = $blackWordInfo->toArray();
  599. $redisKey = 'black_word';
  600. $this->redis->sRem($redisKey, $blackWordInfo['name']);
  601. $this->redis->sAdd($redisKey, $data['name']);
  602. BlackWord::where(['id' => $data['id']])->update(['name' => $data['name']]);
  603. Db::commit();
  604. return Result::success([]);
  605. } else {
  606. Db::rollBack();
  607. return Result::error("系统错误", 0);
  608. }
  609. } catch (\Exception $e) {
  610. Db::rollBack();
  611. return Result::error("修改失败" . $e->getMessage(), 0);
  612. }
  613. }
  614. /**
  615. * 获取风格
  616. * @return void
  617. */
  618. public function getTemplateClassList(array $data): array
  619. {
  620. $where = [];
  621. if (isset($data['name']) && $data['name']) {
  622. array_push($where, ['template_class.name', 'like', '%' . $data['name'] . '%']);
  623. }
  624. if(isset($data['keyword']) && $data['keyword']){
  625. array_push($where, ['template_class.keyword', 'like', '%'. $data['keyword']. '%']);
  626. }
  627. $template = TemplateClass::when($where, function ($query) use ($where) {
  628. $query->where($where);
  629. });
  630. $count = $template->count();
  631. // $countQuery = clone $template;
  632. $row = $template
  633. ->leftJoin('template', function ($join) {
  634. $join->on('template_class.class_id', '=', 'template.template_class_id');
  635. })
  636. ->select('template_class.*', DB::raw('COUNT(template.template_class_id) as template_count'))
  637. ->groupBy('template_class.id')
  638. ->orderBy('template_class.id', 'desc')
  639. ->offset(($data['page'] - 1) * $data['pageSize'])
  640. ->limit($data['pageSize'])
  641. ->get();
  642. $result = [
  643. 'rows' => $row,
  644. 'count' => $count,
  645. ];
  646. if ($row->isEmpty()) {
  647. return Result::error("暂无风格", 0);
  648. } else {
  649. return Result::success($result);
  650. }
  651. }
  652. /**
  653. * 添加风格
  654. * @param
  655. * @return void
  656. */
  657. public function addTemplateClass(array $data): array
  658. {
  659. $data['keyword'] = json_encode($data['keyword']);
  660. $template_class = TemplateClass::where('name', $data['name'])
  661. ->orWhere('class_id', $data['class_id'])
  662. ->first();
  663. if ($template_class) {
  664. return Result::error("风格名称或者风格编号已存在,不可添加!", 0);
  665. }
  666. $result = TemplateClass::insertGetId($data);
  667. if (empty($result)) {
  668. return Result::error("创建风格失败", 0);
  669. } else {
  670. return Result::success(["id" => $result]);
  671. }
  672. }
  673. /**
  674. * 更新风格
  675. * @param array $data
  676. * @return array
  677. */
  678. public function upTemplateClass(array $data): array
  679. {
  680. $where = [
  681. 'id' => $data['id'],
  682. ];
  683. $template_class = TemplateClass::where($where)->first();
  684. if (empty($template_class)) {
  685. return Result::error("未查询到风格", 0);
  686. }
  687. if($template_class->type == 1){
  688. return Result::error("默认风格不能修改", 0);
  689. }
  690. $template = TemplateClass::where('id','!=',$data['id'])
  691. // ->where(['name' => $data['name']])
  692. // ->orWhere(['class_id' => $data['class_id']])
  693. ->where(function ($query) use ($data) {
  694. $query->where('name', $data['name'])
  695. ->orWhere('class_id', $data['class_id']);
  696. })
  697. ->first();
  698. if ($template) {
  699. return Result::error("风格名称或者风格编号已存在,不可编辑!", 0);
  700. }
  701. $updateData = [
  702. 'name' => $data['name'],
  703. 'keyword' => json_encode($data['keyword']),
  704. 'class_id' => $data['class_id'],
  705. ];
  706. $result = TemplateClass::where($where)->update($updateData);
  707. if (empty($result)) {
  708. return Result::error("更新失败", 0);
  709. } else {
  710. return Result::success($result);
  711. }
  712. }
  713. /**
  714. * 删除风格
  715. * @param array $data
  716. * @return array
  717. */
  718. public function delTemplateClass(array $data): array
  719. {
  720. $where = [
  721. 'id' => $data['id'],
  722. ];
  723. $template_class = TemplateClass::where($where)->first();
  724. if (empty($template_class)) {
  725. return Result::error("未查询到风格", 0);
  726. }
  727. if($template_class->type == 1){
  728. return Result::error("默认风格不能删除", 0);
  729. }
  730. $template = Template::where('template_class_id',$template_class['class_id'])->get();
  731. if(!empty($template->all())){
  732. try{
  733. // 默认风格 1
  734. Db::beginTransaction();
  735. $template = Template::where('template_class_id',$template['class_id'])->update(['template_class_id'=>1]);
  736. if(empty($template)){
  737. Db::rollBack();
  738. return Result::error("删除失败", 0);
  739. }
  740. $result = TemplateClass::where($where)->delete();
  741. }catch (\Exception $e){
  742. return Result::error("删除失败".$e->getMessage(), 0);
  743. }
  744. }else{
  745. $result = TemplateClass::where('id',$data['id'])->delete();
  746. }
  747. if(empty($result)){
  748. return Result::error("删除失败", 0);
  749. }
  750. return Result::success($result);
  751. }
  752. /**
  753. * 根据风格名称-获取获取所有风格
  754. * @param array $data
  755. * @return array
  756. */
  757. public function getTemplateClass(array $data): array
  758. {
  759. $where = [];
  760. if (!empty($data['template_name'])) {
  761. $where['name'] = $data['template_name'];
  762. }
  763. $result = TemplateClass::where($where)->get();
  764. if(empty($result)){
  765. return Result::error("暂无风格", 0);
  766. }
  767. return Result::success($result);
  768. }
  769. /**
  770. * 获取皮肤列表
  771. * @param array $data
  772. * @return array
  773. */
  774. public function getTemplateList(array $data): array
  775. {
  776. $where = [];
  777. if (!empty($data['template_class_id'])) {
  778. $where['template_class_id'] = $data['template_class_id'];
  779. }
  780. if (!empty($data['template_name'])) {
  781. array_push($where, ['template_name', 'like', '%'. $data['template_name']. '%']);
  782. }
  783. if (!empty($data['template_keyword'])) {
  784. array_push($where, ['template_keyword', 'like', '%'. $data['template_keyword']. '%']);
  785. }
  786. $result = Template::where($where)
  787. ->leftJoin('template_class', 'template.template_class_id', 'template_class.class_id')
  788. ->select('template.*', 'template_class.name as template_class_name')
  789. ->orderBy('template.id', 'desc')
  790. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  791. if(empty($result)){
  792. return Result::error("暂无皮肤", 0);
  793. }
  794. return Result::success($result);
  795. }
  796. public function getTemplateInfo(array $data): array
  797. {
  798. $result = Template::where('template.id', $data['id'])
  799. ->leftJoin('template_class', 'template.template_class_id', 'template_class.class_id')
  800. ->select('template.*', 'template_class.name as template_class_name')
  801. ->first();
  802. if(empty($result)){
  803. return Result::error("暂无皮肤", 0);
  804. }
  805. return Result::success($result);
  806. }
  807. /**
  808. * 添加皮肤
  809. * @param array $data
  810. * @return array
  811. */
  812. public function addTemplate(array $data): array
  813. {
  814. var_dump($data);
  815. unset($data['user_id']);
  816. $template = Template::where('template_name', $data['template_name'])
  817. ->orWhere('template_id', $data['template_id'])
  818. ->first();
  819. if ($template) {
  820. return Result::error("皮肤名称或者皮肤编号已存在,不可添加!", 0);
  821. }
  822. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  823. $page_type = json_decode($data['page_type'], true);
  824. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  825. $result = Template::insertGetId($data);
  826. if(empty($result)){
  827. return Result::error("创建失败", 0);
  828. }else{
  829. return Result::success($result);
  830. }
  831. }
  832. /**
  833. * 删除皮肤
  834. * @param array $data
  835. * @return array
  836. */
  837. public function delTemplate(array $data): array
  838. {
  839. $rector = Sector::where('template_id', $data['id'])->first();
  840. if (!empty($rector)) {
  841. return Result::error("此皮肤已被绑定通栏,不可删除", 0);
  842. }
  843. $template = WebsiteTemplateInfo::where('template_id', $data['id'])->first();
  844. if(empty($template)){
  845. return Result::error("此皮肤已被绑定网站,不可删除", 0);
  846. }
  847. if($template->type == 1){
  848. return Result::error("默认皮肤不能删除", 0);
  849. }
  850. $result = Template::where('id', $data['id'])->delete();
  851. var_dump($result, '-------------------delete');
  852. if ($result) {
  853. return Result::success($result);
  854. } else {
  855. return Result::error("删除失败", 0);
  856. }
  857. }
  858. /**
  859. * 更新皮肤
  860. * @param array $data
  861. * @return array
  862. */
  863. public function updateTemplate(array $data): array
  864. {
  865. unset($data['user_id']);
  866. $template = Template::where('id', $data['id'])
  867. ->first();
  868. if (empty($template)) {
  869. return Result::error("此皮肤不存在!", 0);
  870. }
  871. $template = Template::where('id', '!=', $data['id'])
  872. ->where(function ($query) use ($data) {
  873. $query->where('template_name', $data['template_name'])
  874. ->orWhere('template_id', $data['template_id']);
  875. })
  876. ->first();
  877. if ($template) {
  878. return Result::error("皮肤名称或者皮肤编号已存在,不可编辑!", 0);
  879. }
  880. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  881. $page_type = json_decode($data['page_type'], true);
  882. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  883. $result = Template::where('id', $data['id'])->update($data);
  884. var_dump($result, '-------------------update');
  885. if (!$result) {
  886. return Result::error("更新失败", 0);
  887. } else {
  888. return Result::success('更新成功');
  889. }
  890. }
  891. /**
  892. * 获取所有尺寸
  893. * @param array $data
  894. * @return array
  895. */
  896. public function getAllSize(array $data): array
  897. {
  898. if(isset($data['id']) && !empty($data['id'])){
  899. $result = Size::where('id', $data['id'])->get()->all();
  900. }else{
  901. $result = Size::get()->all();
  902. }
  903. if(empty($result)){
  904. return Result::error("暂无尺寸", 0);
  905. }
  906. return Result::success($result);
  907. }
  908. /**
  909. * 根据皮肤名称-获取所有皮肤
  910. * @param array $data
  911. * @return array
  912. */
  913. public function getAllTemplate(array $data): array
  914. {
  915. $where = [];
  916. if(isset($data['template_class_id']) && !empty($data['template_class_id'])){
  917. $where[] = ['template_class_id', $data['template_class_id']];
  918. }
  919. if(isset($data['template_name']) && !empty($data['template_name'])){
  920. $where[] = ['template_name', 'like', '%'.$data['template_name'].'%'];
  921. }
  922. $result = Template::where($where)->get()->all();
  923. if(empty($result)){
  924. return Result::error("暂无皮肤", 0);
  925. }
  926. return Result::success($result);
  927. }
  928. /**
  929. * 获取通栏列表
  930. * @param array $data
  931. * @return array
  932. */
  933. public function getSectorList(array $data): array
  934. {
  935. $where = [];
  936. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  937. $where['template.template_class_id'] = $data['template_class_id'];
  938. }
  939. if (isset($data['template_id']) && !empty($data['template_id'])) {
  940. array_push($where, ['template.template_id', $data['template_id']]);
  941. }
  942. if (isset($data['sector_name']) && !empty($data['sector_name'])) {
  943. array_push($where, ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%']);
  944. }
  945. if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])){
  946. $size_id = Size::where('width','like','%' .$data['width'].'%')->where('height','like','%' .$data['height'].'%')->pluck('id');
  947. } else if( isset($data['width']) && !empty($data['width'])){
  948. $size_id = Size::where('width','like','%' .$data['width'].'%')->pluck('id');
  949. }else if( isset($data['height']) && !empty($data['height'])){
  950. $size_id = Size::where('height','like','%' .$data['height'].'%')->pluck('id');
  951. }else{
  952. $size_id = [];
  953. }
  954. $result = Sector::when(!empty($size_id), function ($query) use ($size_id) {
  955. $query->whereIn('size_id', $size_id);
  956. })
  957. ->leftJoin('size', 'size.id', '=', 'sector.size_id')
  958. ->leftJoin('template', 'template.template_id', '=', 'sector.template_id')
  959. ->leftJoin('template_class', 'template_class.class_id', '=', 'template.template_class_id')
  960. ->where($where)
  961. ->select('sector.*', 'size.width','size.height','template_class.name as class_name','template.template_name')
  962. ->orderBy('sector.id', 'desc')
  963. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  964. if(empty($result)){
  965. return Result::error('暂无通栏!');
  966. }
  967. return Result::success($result);
  968. }
  969. /**
  970. * 获取通栏详情
  971. * @param array $data
  972. * @return array
  973. */
  974. public function getSectorInfo(array $data): array
  975. {
  976. $where = [];
  977. $where[] = ['sector.id', '=', $data['id']];
  978. $result = Sector::where($where)
  979. ->leftJoin('size', 'size.id', '=', 'sector.size_id')
  980. ->select('sector.*', 'size.width','size.height')
  981. ->orderBy('sector.id', 'desc')
  982. ->first();
  983. if(empty($result)){
  984. return Result::error('此通栏不存在!');
  985. }
  986. return Result::success($result);
  987. }
  988. /**
  989. * 获取经纬度信息
  990. * @return void
  991. */
  992. public function getIpInfo(array $data) :array
  993. {
  994. $client_ip = isset($data['ip']) && $data['ip']??$_SERVER['REMOTE_ADDR'];
  995. // 使用 IPinfo 服务获取 IP 信息
  996. $api_url = "https://ipinfo.io/{$client_ip}/json";
  997. $ch = curl_init($api_url);
  998. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  999. $response = curl_exec($ch);
  1000. curl_close($ch);
  1001. // 解析 JSON 响应
  1002. $ip_info = json_decode($response, true);
  1003. // 提取地址和经纬度
  1004. if ($ip_info && !isset($ip_info['bogon'])) {
  1005. $latitude = explode(',', $ip_info['loc'])[0];
  1006. $longitude = explode(',', $ip_info['loc'])[1];
  1007. $ip_info['latitude'] = $latitude;
  1008. $ip_info['longitude'] = $longitude;
  1009. return Result::success($ip_info);
  1010. } else {
  1011. $data['ip'] = '101.254.114.212';
  1012. $this->getIpinfo(["ip"=>$data['ip']]);
  1013. }
  1014. }
  1015. /**
  1016. * 获取天气
  1017. * @param array $data
  1018. * @return array
  1019. */
  1020. public function getWeatherInfo(array $data) :array
  1021. {
  1022. $month = $data['month'] ?? date('m');
  1023. $day = $data['day'] ?? date('d');
  1024. // 使用缓存键
  1025. $cacheKey = "tsbb_data_weather_{$month}_{$day}";
  1026. // 尝试从缓存获取数据
  1027. $container = \Hyperf\Context\ApplicationContext::getContainer();
  1028. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  1029. if ($cachedData = $cache->get($cacheKey)) {
  1030. return Result::success(unserialize($cachedData));
  1031. }
  1032. $location = $data['latitude'].":".$data['longitude'];
  1033. $api_url = "https://api.seniverse.com/v3/weather/now.json?key=".\Hyperf\Support\env('WEATHER_KEY')."&location=".$location."&language=zh-Hans&unit=c";
  1034. $ch = curl_init($api_url);
  1035. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1036. $response = curl_exec($ch);
  1037. curl_close($ch);
  1038. // 解析 JSON 响应
  1039. $WeatherInfo = json_decode($response, true);
  1040. // 缓存结果,设置1小时过期
  1041. $cache->set($cacheKey, serialize($WeatherInfo), 3600);
  1042. if($WeatherInfo){
  1043. return Result::success($WeatherInfo);
  1044. }else{
  1045. return Result::error("获取天气失败", 0);
  1046. }
  1047. }
  1048. /**
  1049. * 获取农历信息
  1050. * @return void
  1051. */
  1052. public function getCalendar(array $data) :array
  1053. {
  1054. $calendar = new Calendar();
  1055. $result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历
  1056. return Result::success($result);
  1057. }
  1058. /**
  1059. * 添加通栏
  1060. * @param array $data
  1061. * @return array
  1062. */
  1063. public function addSector(array $data): array
  1064. {
  1065. unset($data['user_id']);
  1066. // 对传入的 page_type 数组进行去重、转换为整数并重新索引
  1067. $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
  1068. $data['page_type'] = json_encode($data['page_type']);
  1069. $template = Template::where('template_id', $data['template_id'])
  1070. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$data['page_type']])
  1071. ->first();
  1072. if(empty($template)){
  1073. return Result::error('皮肤不存在!');
  1074. }
  1075. $sector_id = Sector::where('sector_id',$data['sector_id'])->first();
  1076. if(!empty($sector_id)){
  1077. return Result::error('通栏编号已存在!');
  1078. }
  1079. $result = Sector::insertGetId($data);
  1080. if(empty($result)){
  1081. return Result::error('添加失败');
  1082. }
  1083. return Result::success($result);
  1084. }
  1085. /**
  1086. * 删除通栏
  1087. * @param array $data
  1088. * @return array
  1089. */
  1090. public function delSector(array $data): array
  1091. {
  1092. $component_id = Component::where('sector_id', $data['id'])->pluck('id')->toArray();
  1093. if(!empty($component_id)){
  1094. return Result::error('请先删除相关组件!');
  1095. }
  1096. $result = Sector::where('id', $data['id'])->delete();
  1097. if ($result == 1) {
  1098. return Result::success('删除成功');
  1099. } else {
  1100. return Result::error('删除失败');
  1101. }
  1102. }
  1103. /**
  1104. * 修改通栏
  1105. * @param array $data
  1106. * @return array
  1107. */
  1108. public function updateSector(array $data): array
  1109. {
  1110. unset($data['user_id']);
  1111. $sector = Sector::where('id', $data['id'])->first();
  1112. if(empty($sector)){
  1113. return Result::error('通栏不存在!');
  1114. }
  1115. if($sector['sector_id'] != $data['sector_id']){
  1116. $sector_id = Sector::where('sector_id',$data['sector_id'])->first();
  1117. if(!empty($sector_id)){
  1118. return Result::error('通栏编号已存在!');
  1119. }
  1120. }
  1121. // 对传入的 page_type 数组进行去重、转换为整数并重新索引
  1122. $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
  1123. $data['page_type'] = json_encode($data['page_type']);
  1124. $template = Template::where('template_id', $data['template_id'])
  1125. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$data['page_type']])
  1126. ->first();
  1127. if(empty($template)){
  1128. return Result::error('皮肤不存在!');
  1129. }
  1130. $result = Sector::where('id', $data['id'])->update($data);
  1131. if ($result == 1) {
  1132. return Result::success('修改成功');
  1133. } else {
  1134. return Result::error('修改失败');
  1135. }
  1136. }
  1137. public function getComponentList(array $data): array
  1138. {
  1139. var_dump($data, '---------');
  1140. $where = [];
  1141. // $where[] = ['sector.id', '=', $data['id']];
  1142. if (!empty($data['template_class_id'])) {
  1143. $where['template_class.id'] = $data['template_class_id'];
  1144. }
  1145. if (!empty($data['component_name'])) {
  1146. $where['component.component_name'] = $data['component_name'];
  1147. }
  1148. if (!empty($data['sector_id'])) {
  1149. $where['sector.id'] = $data['sector_id'];
  1150. };
  1151. $result = Component::where($where)
  1152. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  1153. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  1154. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  1155. ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'template_class.id as template_class_id', 'sector.sector_name as sector_name', 'component.*', 'sector.id as sector_id') // 修改这一行)
  1156. ->orderBy('sector.updated_at', 'desc')
  1157. ->orderBy('sector.created_at', 'desc')
  1158. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  1159. return Result::success($result);
  1160. }
  1161. public function getComponentInfo(array $data): array
  1162. {
  1163. $where = [];
  1164. $result = Component::where($where)
  1165. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  1166. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  1167. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  1168. ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'sector.sector_name as sector_name', 'component.*')
  1169. ->get();
  1170. return Result::success($result);
  1171. }
  1172. public function addComponent(array $data): array
  1173. {
  1174. unset($data['user_id']);
  1175. $result = Component::insertGetId($data);
  1176. if ($result) {
  1177. return Result::success($result);
  1178. } else {
  1179. return Result::error('添加失败');
  1180. }
  1181. }
  1182. public function delComponent(array $data): array
  1183. {
  1184. $result = Component::where('id', $data['id'])->delete();
  1185. return Result::success($result);
  1186. }
  1187. public function updateComponent(array $data): array
  1188. {
  1189. $result = Component::where('id', $data['id'])->update($data);
  1190. return Result::success($result);
  1191. }
  1192. public function getWebsiteTemplateInfo(array $data)
  1193. {
  1194. $where = [];
  1195. if (isset($data['id'])) {
  1196. $where[] = ['id', '=', $data['id']];
  1197. }
  1198. $result = WebsiteTemplateInfo::where($where)
  1199. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  1200. ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
  1201. ->select('website_template_info.*', 'website.website_name')
  1202. ->get();
  1203. if ($result) {
  1204. return Result::success($result);
  1205. } else {
  1206. return Result::error('暂无数据');
  1207. }
  1208. }
  1209. /**
  1210. * 自助建站----1.获取页面类型回显
  1211. * @param array $data
  1212. * @return array
  1213. */
  1214. public function getWebPageType(array $data): array
  1215. {
  1216. // 1:图片 2:文字 3:底部
  1217. $friend_link = Link::where('website_id', $data['website_id'])->where('type',3)->get();
  1218. if(empty($friend_link->toArray())){
  1219. return Result::error('暂无友情链接数据!');
  1220. }
  1221. $footer_category = FooterCategory::where('website_id', $data['website_id'])->get();
  1222. if(empty($footer_category->toArray())){
  1223. return Result::error('暂无底部导航数据!');
  1224. }
  1225. $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->value('page_type');
  1226. if(empty($page_type)){
  1227. $page_type = [];
  1228. }else{
  1229. $page_type = json_decode($page_type,true);
  1230. }
  1231. // '网站页面类型(存数组)1:首页 2:分类页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页
  1232. if(isset($page_type) && in_array(5,$page_type)){
  1233. $page_type = 1;
  1234. }else{
  1235. $page_type = 0;
  1236. }
  1237. $result = [
  1238. 'friend_link' => $friend_link,
  1239. 'footer_category' => $footer_category,
  1240. 'page_type' => $page_type,
  1241. ];
  1242. return Result::success($result);
  1243. }
  1244. /**
  1245. * 自助建站----2.添加页面类型
  1246. * @param array $data
  1247. * @return array
  1248. */
  1249. public function addWebPageType(array $data): array
  1250. {
  1251. // return Result::success($data);
  1252. // 1:首页 2:频道页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页'
  1253. if($data['is_search'] == 1){
  1254. $page_type = json_encode([1,2,3,4,5,6,7]);
  1255. }else{
  1256. $page_type = json_encode([1,2,3,4,6,7]);
  1257. }
  1258. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1259. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1260. // return Result::success($website_template_info);
  1261. // return Result::success(empty($website_template_info));
  1262. if(empty($website_template_info)){
  1263. $result = WebsiteTemplateInfo::insertGetId(['website_id' => $data['website_id'], 'page_type' => $page_type, 'user_id' => $data['user_id']]);
  1264. }else{
  1265. if($website_template_info['status'] == 2){
  1266. return Result::error('网站已应用,不可再次修改!');
  1267. }
  1268. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type],['action_id' => 1,'user_id' => $data['user_id']]);
  1269. }
  1270. if ($result) {
  1271. return Result::success($result);
  1272. } else {
  1273. return Result::error('添加失败');
  1274. }
  1275. }
  1276. /**
  1277. * 自助建站---流程---3.选择皮肤列表
  1278. * @param array $data
  1279. * @return array
  1280. */
  1281. public function getWebsiteTemplateList(array $data): array
  1282. {
  1283. $where = [];
  1284. if(isset($data['template_class_id']) && $data['template_class_id']){
  1285. $where[] = ['template_class_id', '=', $data['template_class_id']];
  1286. }
  1287. // 0:未构建 1:未应用 2:已应用 status
  1288. $templste_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1289. if(empty($templste_info)){
  1290. return Result::error('请先填写网站基础信息!');
  1291. }
  1292. if($templste_info['status'] == 2){
  1293. return Result::error('网站已应用,不可再次修改!');
  1294. }
  1295. if(isset($data['keyword']) && !empty($data['keyword'])){
  1296. if (is_array($data['keyword'])) {
  1297. // 拼接多个模糊查询条件
  1298. $query = Template::query();
  1299. foreach ($data['keyword'] as $kw) {
  1300. $escapedKw = addcslashes($kw, '%_'); // 转义通配符
  1301. $query->WhereRaw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?", ["%$escapedKw%"]);
  1302. }
  1303. } else {
  1304. $escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符
  1305. $where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
  1306. }
  1307. }else{
  1308. $query = Template::where($where);
  1309. }
  1310. $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
  1311. // return Result::success($template_id);
  1312. if(!empty($template_id['page_type']) && $templste_info['page_type'] != '[]' && is_string($templste_info['page_type'])){
  1313. $template_page = is_string($templste_info['page_type']) ? json_decode($templste_info['page_type'], true) : [];
  1314. }else{
  1315. $template_page = [];
  1316. }
  1317. if(!empty($template_id['template_id'])){
  1318. $result['template_id'] = $templste_info['template_id'];
  1319. }
  1320. // 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定
  1321. $template_page_str = json_encode($template_page);
  1322. $result['template'] = $query->where($where)
  1323. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
  1324. ->orderBy('updated_at','desc')
  1325. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1326. if (empty($result['template'])) {
  1327. $result['template'] = Template::orderBy('updated_at','desc')
  1328. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1329. }
  1330. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->value('template_id');
  1331. if($template){
  1332. $result['template_id'] = $template;
  1333. }else{
  1334. $result['template_id'] = 0;
  1335. }
  1336. return Result::success($result);
  1337. }
  1338. /**
  1339. * 自助建站---流程---4.选择皮肤
  1340. * @param array $data
  1341. * @return array
  1342. */
  1343. public function chooseWebsiteTemplate(array $data): array
  1344. {
  1345. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1346. if(empty($website_template_info)){
  1347. return Result::error('请先填写网站基础信息!');
  1348. }
  1349. // 0:未构建 1:未应用 2:已应用 status
  1350. if($website_template_info['status'] == 2){
  1351. return Result::error('网站已应用,不可再次修改!');
  1352. }
  1353. $template = Template::where('template_id', $data['template_id'])->first();
  1354. if(empty($template)){
  1355. return Result::error('未查询到皮肤!');
  1356. }
  1357. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1358. $web_template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'],'action_id' => 2]);
  1359. if ($web_template) {
  1360. return Result::success($web_template);
  1361. } else {
  1362. return Result::error('选择皮肤失败!');
  1363. }
  1364. }
  1365. /**
  1366. * 自助建站---流程---5.保存模版
  1367. * @param array $data
  1368. * @return array
  1369. */
  1370. public function saveWebsiteTemplate(array $data): array
  1371. {
  1372. // return Result::success($data);
  1373. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1374. if(empty($website_template_info) || empty($website_template_info->template_id) || empty($website_template_info->page_type)){
  1375. return Result::error('请先填写网站基础信息!');
  1376. }
  1377. // 0:未构建 1:未应用 2:已应用 status
  1378. if($website_template_info['status'] == 2){
  1379. return Result::error('网站已应用,不可再次保存!');
  1380. }
  1381. if($website_template_info['action_id'] != 2){
  1382. return Result::error('请完成之前的步骤!');
  1383. }
  1384. $template_info = WebsiteTemplate::where('website_id', $data['website_id'])->first();
  1385. // var_dump($data['template_data']);
  1386. try{
  1387. Db::beginTransaction();
  1388. if(empty($template_info)){
  1389. $template = WebsiteTemplate::insertGetId([
  1390. 'website_id' => $data['website_id'],
  1391. 'template_data' => $data['template_data'],
  1392. 'user_id' => $data['user_id'],
  1393. 'canvas_data' => $data['canvas_data'],
  1394. 'page_type' => $website_template_info['page_type'],
  1395. 'template_id' => $website_template_info['template_id'],
  1396. ]);
  1397. }else{
  1398. $template = WebsiteTemplate::where('website_id', $data['website_id'])->update(
  1399. ['template_data' => $data['template_data'],'user_id' => $data['user_id'],'canvas_data' => $data['canvas_data'],
  1400. 'page_type' => $website_template_info['page_type'],
  1401. 'template_id' => $website_template_info['template_id'],
  1402. ]);
  1403. }
  1404. if(empty($template)){
  1405. Db::rollback();
  1406. return Result::error('保存失败!');
  1407. }else{
  1408. $tempalte_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['status' => 1]);
  1409. if(empty($tempalte_info)){
  1410. Db::rollback();
  1411. return Result::error('保存失败!');
  1412. }
  1413. Db::commit();
  1414. }
  1415. }catch (\Exception $e){
  1416. return Result::error('模版数据格式错误!');
  1417. }
  1418. return Result::success($template);
  1419. }
  1420. /**
  1421. * 自助建站---流程---6.返显保存的模版
  1422. * @param array $data
  1423. * @return array
  1424. */
  1425. public function getWebsiteTemplate(array $data): array
  1426. {
  1427. $web = Website::where('id', $data['website_id'])->first();
  1428. if(empty($web)){
  1429. return Result::error('未查询到网站信息!');
  1430. }
  1431. $template = WebsiteTemplate::where('website_id', $data['website_id'])
  1432. ->first(['website_id','template_id','page_type','template_data','canvas_data']);
  1433. if(empty($template)){
  1434. return Result::error('未查询到模版!');
  1435. }
  1436. return Result::success($template);
  1437. }
  1438. /**
  1439. * 自助建站-通栏管理-获取通栏位置
  1440. */
  1441. public function getSectorPlace(array $data): array
  1442. {
  1443. $template = SectorPlace::where('sector_place.sector_num', $data['sector_num'])
  1444. ->leftJoin('size','sector_place.size_id','=','size.id')
  1445. ->select('sector_place.*','size.width','size.height')
  1446. ->get()->all();
  1447. if(empty($template)){
  1448. return Result::error('未查询到通栏位置相关模版!');
  1449. }
  1450. return Result::success($template);
  1451. }
  1452. }